[REF] web, *: remove JSONP support
JSONP can be entirely replaced by the CORS mechanism, which is simpler. We support CORS in our routes since 8.0 (odoo/odoo@9cce88a), so it's about time to get rid of JSONP.
This commit is contained in:
@@ -45,7 +45,6 @@ function genericJsonRpc (fct_name, params, settings, fct) {
|
||||
var def = $.Deferred();
|
||||
return def.reject.apply(def, ["communication"].concat(_.toArray(arguments)));
|
||||
});
|
||||
// FIXME: jsonp?
|
||||
deferred.abort = function () {
|
||||
deferred.reject({message: "XmlHttpRequestError abort"}, $.Event('abort'));
|
||||
if (xhr.abort) {
|
||||
@@ -106,78 +105,6 @@ function jsonRpc(url, fct_name, params, settings) {
|
||||
});
|
||||
}
|
||||
|
||||
function jsonpRpc(url, fct_name, params, settings) {
|
||||
settings = settings || {};
|
||||
return genericJsonRpc(fct_name, params, settings, function(data) {
|
||||
var payload_str = JSON.stringify(data, time.date_to_utc);
|
||||
var payload_url = $.param({r:payload_str});
|
||||
var force2step = settings.force2step || false;
|
||||
delete settings.force2step;
|
||||
if (payload_url.length < 2000 && ! force2step) {
|
||||
return $.ajax(url, _.extend({}, settings, {
|
||||
url: url,
|
||||
dataType: 'jsonp',
|
||||
jsonp: 'jsonp',
|
||||
type: 'GET',
|
||||
cache: false,
|
||||
data: {r: payload_str}
|
||||
}));
|
||||
} else {
|
||||
var args = {id: data.id};
|
||||
var ifid = _.uniqueId('oe_rpc_iframe');
|
||||
var html = "<iframe src='javascript:false;' name='" + ifid + "' id='" + ifid + "' style='display:none'></iframe>";
|
||||
var $iframe = $(html);
|
||||
var nurl = 'jsonp=1&' + $.param(args);
|
||||
nurl = url.indexOf("?") !== -1 ? url + "&" + nurl : url + "?" + nurl;
|
||||
var $form = $('<form>')
|
||||
.attr('method', 'POST')
|
||||
.attr('target', ifid)
|
||||
.attr('enctype', "multipart/form-data")
|
||||
.attr('action', nurl)
|
||||
.append($('<input type="hidden" name="r" />').attr('value', payload_str))
|
||||
.hide()
|
||||
.appendTo($('body'));
|
||||
var cleanUp = function() {
|
||||
if ($iframe) {
|
||||
$iframe.unbind("load").remove();
|
||||
}
|
||||
$form.remove();
|
||||
};
|
||||
var deferred = $.Deferred();
|
||||
// the first bind is fired up when the iframe is added to the DOM
|
||||
$iframe.bind('load', function() {
|
||||
// the second bind is fired up when the result of the form submission is received
|
||||
$iframe.unbind('load').bind('load', function() {
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: 'jsonp',
|
||||
jsonp: 'jsonp',
|
||||
type: 'GET',
|
||||
cache: false,
|
||||
data: {id: data.id}
|
||||
}).always(function() {
|
||||
cleanUp();
|
||||
}).done(function() {
|
||||
deferred.resolve.apply(deferred, arguments);
|
||||
}).fail(function() {
|
||||
deferred.reject.apply(deferred, arguments);
|
||||
});
|
||||
});
|
||||
// now that the iframe can receive data, we fill and submit the form
|
||||
$form.submit();
|
||||
});
|
||||
// append the iframe to the DOM (will trigger the first load)
|
||||
$form.after($iframe);
|
||||
if (settings.timeout) {
|
||||
realSetTimeout(function() {
|
||||
deferred.reject({});
|
||||
}, settings.timeout);
|
||||
}
|
||||
return deferred;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// helper function to make a rpc with a function name hardcoded to 'call'
|
||||
function rpc(url, params, settings) {
|
||||
return jsonRpc(url, 'call', params, settings);
|
||||
@@ -310,7 +237,7 @@ function get_file(options) {
|
||||
xhr.open('POST', options.url);
|
||||
data = new FormData();
|
||||
_.each(options.data || {}, function (v, k) {
|
||||
data.append(k, v)
|
||||
data.append(k, v);
|
||||
});
|
||||
}
|
||||
data.append('token', 'dummy-because-api-expects-one');
|
||||
@@ -358,7 +285,7 @@ function get_file(options) {
|
||||
name: String(xhr.status),
|
||||
title: nodes.length > 0 ? nodes[0].textContent : '',
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
options.error(err);
|
||||
};
|
||||
@@ -373,7 +300,7 @@ function get_file(options) {
|
||||
}
|
||||
};
|
||||
if (options.complete) {
|
||||
xhr.onloadend = function () { options.complete(); }
|
||||
xhr.onloadend = function () { options.complete(); };
|
||||
}
|
||||
|
||||
xhr.send(data);
|
||||
@@ -594,7 +521,6 @@ function loadLibs (libs) {
|
||||
|
||||
var ajax = {
|
||||
jsonRpc: jsonRpc,
|
||||
jsonpRpc: jsonpRpc,
|
||||
rpc: rpc,
|
||||
loadCSS: loadCSS,
|
||||
loadJS: loadJS,
|
||||
|
||||
@@ -308,17 +308,11 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
|
||||
_.extend(options, url);
|
||||
url = url.url;
|
||||
}
|
||||
var fct;
|
||||
if (self.origin_server) {
|
||||
fct = ajax.jsonRpc;
|
||||
} else if (self.use_cors) {
|
||||
fct = ajax.jsonRpc;
|
||||
url = self.url(url, null);
|
||||
} else {
|
||||
fct = ajax.jsonpRpc;
|
||||
if (self.use_cors) {
|
||||
url = self.url(url, null);
|
||||
}
|
||||
return fct(url, "call", params, options);
|
||||
|
||||
return ajax.jsonRpc(url, "call", params, options);
|
||||
},
|
||||
url: function (path, params) {
|
||||
params = _.extend(params || {});
|
||||
|
||||
@@ -47,8 +47,8 @@ odoo.define('website_sale.tour_shop_customize', function (require) {
|
||||
args: ['product.group_product_variant', false],
|
||||
kwargs: {}
|
||||
};
|
||||
ajax.jsonpRpc('/web/dataset/call_kw', 'call', get_group_payload).then(function(group_id) {
|
||||
ajax.jsonpRpc('/web/dataset/call_kw', 'call', {
|
||||
ajax.jsonRpc('/web/dataset/call_kw', 'call', get_group_payload).then(function(group_id) {
|
||||
ajax.jsonRpc('/web/dataset/call_kw', 'call', {
|
||||
model: 'res.groups',
|
||||
method: 'write',
|
||||
args: [group_id, {'users': [[4, 1]]}],
|
||||
|
||||
+4
-36
@@ -579,34 +579,14 @@ class JsonRequest(WebRequest):
|
||||
def __init__(self, *args):
|
||||
super(JsonRequest, self).__init__(*args)
|
||||
|
||||
self.jsonp_handler = None
|
||||
self.params = {}
|
||||
|
||||
args = self.httprequest.args
|
||||
jsonp = args.get('jsonp')
|
||||
self.jsonp = jsonp
|
||||
request = None
|
||||
request_id = args.get('id')
|
||||
|
||||
if jsonp and self.httprequest.method == 'POST':
|
||||
# jsonp 2 steps step1 POST: save call
|
||||
def handler():
|
||||
self.session['jsonp_request_%s' % (request_id,)] = self.httprequest.form['r']
|
||||
self.session.modified = True
|
||||
headers=[('Content-Type', 'text/plain; charset=utf-8')]
|
||||
r = werkzeug.wrappers.Response(request_id, headers=headers)
|
||||
return r
|
||||
self.jsonp_handler = handler
|
||||
return
|
||||
elif jsonp and args.get('r'):
|
||||
# jsonp method GET
|
||||
request = args.get('r')
|
||||
elif jsonp and request_id:
|
||||
# jsonp 2 steps step2 GET: run and return result
|
||||
request = self.session.pop('jsonp_request_%s' % (request_id,), '{}')
|
||||
else:
|
||||
# regular jsonrpc2
|
||||
request = self.httprequest.get_data().decode(self.httprequest.charset)
|
||||
# regular jsonrpc2
|
||||
request = self.httprequest.get_data().decode(self.httprequest.charset)
|
||||
|
||||
# Read POST content or POST Form Data named "request"
|
||||
try:
|
||||
@@ -630,16 +610,8 @@ class JsonRequest(WebRequest):
|
||||
if result is not None:
|
||||
response['result'] = result
|
||||
|
||||
if self.jsonp:
|
||||
# If we use jsonp, that's mean we are called from another host
|
||||
# Some browser (IE and Safari) do no allow third party cookies
|
||||
# We need then to manage http sessions manually.
|
||||
response['session_id'] = self.session.sid
|
||||
mime = 'application/javascript'
|
||||
body = "%s(%s);" % (self.jsonp, json.dumps(response, default=date_utils.json_default))
|
||||
else:
|
||||
mime = 'application/json'
|
||||
body = json.dumps(response, default=date_utils.json_default)
|
||||
mime = 'application/json'
|
||||
body = json.dumps(response, default=date_utils.json_default)
|
||||
|
||||
return Response(
|
||||
body, status=error and error.pop('http_status', 200) or 200,
|
||||
@@ -674,8 +646,6 @@ class JsonRequest(WebRequest):
|
||||
return self._json_response(error=error)
|
||||
|
||||
def dispatch(self):
|
||||
if self.jsonp_handler:
|
||||
return self.jsonp_handler()
|
||||
try:
|
||||
rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG)
|
||||
rpc_response_flag = rpc_response.isEnabledFor(logging.DEBUG)
|
||||
@@ -1388,8 +1358,6 @@ class Root(object):
|
||||
|
||||
def get_request(self, httprequest):
|
||||
# deduce type of request
|
||||
if httprequest.args.get('jsonp'):
|
||||
return JsonRequest(httprequest)
|
||||
if httprequest.mimetype in ("application/json", "application/json-rpc"):
|
||||
return JsonRequest(httprequest)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user