[FIX] jsonp wasn't working on some browse due to security restriction that do not store the third parties cookies.

bzr revid: chs@openerp.com-20121114113335-nag3ljcwwx0yfdnu
This commit is contained in:
Christophe Simonis
2012-11-14 12:33:35 +01:00
parent 524c3d500d
commit e1f5dfc388
2 changed files with 19 additions and 3 deletions
+7
View File
@@ -227,6 +227,10 @@ class JsonRequest(WebRequest):
_logger.debug("<--\n%s", pprint.pformat(response))
if 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['httpsessionid'] = self.httpsession.sid
mime = 'application/javascript'
body = "%s(%s);" % (jsonp, simplejson.dumps(response, cls=nonliterals.NonLiteralEncoder),)
else:
@@ -364,6 +368,9 @@ def session_context(request, storage_path, session_cookie='httpsessionid'):
STORES[storage_path] = session_store, session_lock
sid = request.cookies.get(session_cookie)
if not sid:
sid = request.args.get('sid')
with session_lock:
if sid:
request.session = session_store.get(sid)
+12 -3
View File
@@ -1309,8 +1309,17 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
// extracted from payload to set on the url
var data = {
session_id: this.session_id,
id: payload.id
id: payload.id,
sid: this.httpsessionid,
};
var set_sid = function (response, textStatus, jqXHR) {
// If response give us the http session id, we store it for next requests...
if (response.httpsessionid) {
self.httpsessionid = response.httpsessionid;
}
};
url.url = this.get_url(url.url);
var ajax = _.extend({
type: "GET",
@@ -1326,7 +1335,7 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
if(payload_url.length < 2000) {
// Direct jsonp request
ajax.data.r = payload_str;
return $.ajax(ajax);
return $.ajax(ajax).done(set_sid);
} else {
// Indirect jsonp request
var ifid = _.uniqueId('oe_rpc_iframe');
@@ -1364,7 +1373,7 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
});
// append the iframe to the DOM (will trigger the first load)
$form.after($iframe);
return deferred;
return deferred.done(set_sid);
}
},
get_url: function (file) {