From 3959cf7fd00c25b20ea9962e07409514fcf588a9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 31 Oct 2009 07:26:15 +0000 Subject: [PATCH] - Fix XMLHTTPRequest in Firefox 3.6 - Restore sending of cookies even if "Allow third-party cookies" is disabled (requires Firefox 3.6; not tested) - Added Zotero.isFx36 for 1.9.2 --- chrome/content/zotero/xpcom/utilities.js | 146 +++++++++++++---------- chrome/content/zotero/xpcom/zotero.js | 1 + 2 files changed, 85 insertions(+), 62 deletions(-) diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index d9a61ffe1c..95aa00905b 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -1012,28 +1012,35 @@ Zotero.Utilities.HTTP = new function() { return false; } - /* - var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] - .createInstance(); - // Prevent certificate/authentication dialogs from popping up - xmlhttp.mozBackgroundRequest = true; - xmlhttp.open('GET', url, true); - */ - // Workaround for "Accept third-party cookies" being off in Firefox 3.0.1 // https://www.zotero.org/trac/ticket/1070 - const Cc = Components.classes; - const Ci = Components.interfaces; - var ds = Cc["@mozilla.org/webshell;1"]. - createInstance(Components.interfaces.nsIDocShellTreeItem). - QueryInterface(Ci.nsIInterfaceRequestor); - ds.itemType = Ci.nsIDocShellTreeItem.typeContent; - var xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. - createInstance(Ci.nsIXMLHttpRequest); - xmlhttp.mozBackgroundRequest = true; - xmlhttp.open("GET", url, true); - xmlhttp.channel.loadGroup = ds.getInterface(Ci.nsILoadGroup); - xmlhttp.channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI; + if (Zotero.isFx30) { + const Cc = Components.classes; + const Ci = Components.interfaces; + var ds = Cc["@mozilla.org/webshell;1"]. + createInstance(Components.interfaces.nsIDocShellTreeItem). + QueryInterface(Ci.nsIInterfaceRequestor); + ds.itemType = Ci.nsIDocShellTreeItem.typeContent; + var xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. + createInstance(Ci.nsIXMLHttpRequest); + xmlhttp.mozBackgroundRequest = true; + xmlhttp.open("GET", url, true); + xmlhttp.channel.loadGroup = ds.getInterface(Ci.nsILoadGroup); + xmlhttp.channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI; + } + else { + var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(); + // Prevent certificate/authentication dialogs from popping up + xmlhttp.mozBackgroundRequest = true; + xmlhttp.open('GET', url, true); + // Send cookie even if "Allow third-party cookies" is disabled (>=Fx3.6 only) + if (!Zotero.isFx35) { + var channel = xmlhttp.channel; + channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal); + channel.forceAllowThirdPartyCookie = true; + } + } /** @ignore */ xmlhttp.onreadystatechange = function() { @@ -1080,28 +1087,35 @@ Zotero.Utilities.HTTP = new function() { return false; } - /* - var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] - .createInstance(); - // Prevent certificate/authentication dialogs from popping up - xmlhttp.mozBackgroundRequest = true; - xmlhttp.open('POST', url, true); - */ - // Workaround for "Accept third-party cookies" being off in Firefox 3.0.1 // https://www.zotero.org/trac/ticket/1070 - const Cc = Components.classes; - const Ci = Components.interfaces; - var ds = Cc["@mozilla.org/webshell;1"]. - createInstance(Components.interfaces.nsIDocShellTreeItem). - QueryInterface(Ci.nsIInterfaceRequestor); - ds.itemType = Ci.nsIDocShellTreeItem.typeContent; - var xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. - createInstance(Ci.nsIXMLHttpRequest); - xmlhttp.mozBackgroundRequest = true; - xmlhttp.open("POST", url, true); - xmlhttp.channel.loadGroup = ds.getInterface(Ci.nsILoadGroup); - xmlhttp.channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI; + if (Zotero.isFx30) { + const Cc = Components.classes; + const Ci = Components.interfaces; + var ds = Cc["@mozilla.org/webshell;1"]. + createInstance(Components.interfaces.nsIDocShellTreeItem). + QueryInterface(Ci.nsIInterfaceRequestor); + ds.itemType = Ci.nsIDocShellTreeItem.typeContent; + var xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. + createInstance(Ci.nsIXMLHttpRequest); + xmlhttp.mozBackgroundRequest = true; + xmlhttp.open("POST", url, true); + xmlhttp.channel.loadGroup = ds.getInterface(Ci.nsILoadGroup); + xmlhttp.channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI; + } + else { + var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(); + // Prevent certificate/authentication dialogs from popping up + xmlhttp.mozBackgroundRequest = true; + xmlhttp.open('POST', url, true); + // Send cookie even if "Allow third-party cookies" is disabled (>=Fx3.6 only) + if (!Zotero.isFx35) { + var channel = xmlhttp.channel; + channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal); + channel.forceAllowThirdPartyCookie = true; + } + } if (headers) { if (typeof headers == 'string') { @@ -1162,37 +1176,45 @@ Zotero.Utilities.HTTP = new function() { return false; } - /* - var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] - .createInstance(); - // Prevent certificate/authentication dialogs from popping up - xmlhttp.mozBackgroundRequest = true; - xmlhttp.open('HEAD', url, true); - */ - // Workaround for "Accept third-party cookies" being off in Firefox 3.0.1 // https://www.zotero.org/trac/ticket/1070 - const Cc = Components.classes; - const Ci = Components.interfaces; - var ds = Cc["@mozilla.org/webshell;1"]. - createInstance(Components.interfaces.nsIDocShellTreeItem). - QueryInterface(Ci.nsIInterfaceRequestor); - ds.itemType = Ci.nsIDocShellTreeItem.typeContent; - var xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. - createInstance(Ci.nsIXMLHttpRequest); - // Prevent certificate/authentication dialogs from popping up - xmlhttp.mozBackgroundRequest = true; - xmlhttp.open("HEAD", url, true); + if (Zotero.isFx30) { + const Cc = Components.classes; + const Ci = Components.interfaces; + var ds = Cc["@mozilla.org/webshell;1"]. + createInstance(Components.interfaces.nsIDocShellTreeItem). + QueryInterface(Ci.nsIInterfaceRequestor); + ds.itemType = Ci.nsIDocShellTreeItem.typeContent; + var xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]. + createInstance(Ci.nsIXMLHttpRequest); + // Prevent certificate/authentication dialogs from popping up + xmlhttp.mozBackgroundRequest = true; + xmlhttp.open("HEAD", url, true); + xmlhttp.channel.loadGroup = ds.getInterface(Ci.nsILoadGroup); + xmlhttp.channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI; + } + else { + var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(); + // Prevent certificate/authentication dialogs from popping up + xmlhttp.mozBackgroundRequest = true; + xmlhttp.open('HEAD', url, true); + // Send cookie even if "Allow third-party cookies" is disabled (>=Fx3.6 only) + if (!Zotero.isFx35) { + var channel = xmlhttp.channel; + channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal); + channel.forceAllowThirdPartyCookie = true; + } + } + if (requestHeaders) { for (var header in requestHeaders) { xmlhttp.setRequestHeader(header, requestHeaders[header]); } } - xmlhttp.channel.loadGroup = ds.getInterface(Ci.nsILoadGroup); - xmlhttp.channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI; // Don't cache HEAD requests - xmlhttp.channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE; + xmlhttp.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE; /** @ignore */ xmlhttp.onreadystatechange = function(){ diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 64bdf67d8d..82dd394088 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -197,6 +197,7 @@ var Zotero = new function(){ || appInfo.platformVersion.indexOf('1.9.0') === 0; this.isFx35 = appInfo.platformVersion.indexOf('1.9.1') === 0; this.isFx31 = this.isFx35; + this.isFx36 = appInfo.platformVersion.indexOf('1.9.2') === 0; // OS platform var win = Components.classes["@mozilla.org/appshell/appShellService;1"]