- 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
This commit is contained in:
Dan Stillman 2009-10-31 07:26:15 +00:00
parent e15acb3e7e
commit 3959cf7fd0
2 changed files with 85 additions and 62 deletions

View file

@ -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(){

View file

@ -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"]