diff --git a/chrome/content/zotero/errorReport.xul b/chrome/content/zotero/errorReport.xul
index 868edb5b3f..b0042802cb 100644
--- a/chrome/content/zotero/errorReport.xul
+++ b/chrome/content/zotero/errorReport.xul
@@ -53,8 +53,13 @@
body += key + '=' + encodeURIComponent(parts[key]) + '&';
}
body = body.substr(0, body.length - 1);
- Zotero.HTTP.doPost("https://repo.zotero.org/repo/report", body,
- _sendErrorReportCallback);
+ var url = 'https://repo.zotero.org/repo/report';
+ Zotero.HTTP.promise('POST', url,
+ { body: body, successCodes: false, foreground: true })
+ .then(function (xmlhttp) {
+ _sendErrorReportCallback(xmlhttp);
+ })
+ .done();
});
}
diff --git a/chrome/content/zotero/preferences/preferences_sync.js b/chrome/content/zotero/preferences/preferences_sync.js
index 8b4263e734..4b3af6a883 100644
--- a/chrome/content/zotero/preferences/preferences_sync.js
+++ b/chrome/content/zotero/preferences/preferences_sync.js
@@ -333,7 +333,11 @@ Zotero_Preferences.Sync = {
// TODO: better way of checking for an active session?
if (Zotero.Sync.Server.sessionIDComponent == 'sessionid=') {
- Zotero.Sync.Server.login(callback);
+ Zotero.Sync.Server.login()
+ .then(function () {
+ callback();
+ })
+ .done();
}
else {
callback();
diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js
index fd52a66ecf..fec534de72 100644
--- a/chrome/content/zotero/xpcom/http.js
+++ b/chrome/content/zotero/xpcom/http.js
@@ -53,11 +53,12 @@ Zotero.HTTP = new function() {
*
cookieSandbox - The sandbox from which cookies should be taken
* debug - Log response text and status code
* dontCache - If set, specifies that the request should not be fulfilled from the cache
+ * foreground - Make a foreground request, showing certificate/authentication dialogs if necessary
* headers - HTTP headers to include in the request
* requestObserver - Callback to receive XMLHttpRequest after open()
* responseType - The type of the response. See XHR 2 documentation for legal values
* responseCharset - The charset the response should be interpreted as
- * successCodes - HTTP status codes that are considered successful
+ * successCodes - HTTP status codes that are considered successful, or FALSE to allow all
*
* @param {Zotero.CookieSandbox} [cookieSandbox] Cookie sandbox object
* @return {Promise} A promise resolved with the XMLHttpRequest object if the request
@@ -105,7 +106,9 @@ Zotero.HTTP = new function() {
var xmlhttp = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance();
// Prevent certificate/authentication dialogs from popping up
- xmlhttp.mozBackgroundRequest = true;
+ if (!options || !options.foreground) {
+ xmlhttp.mozBackgroundRequest = true;
+ }
xmlhttp.open(method, url, true);
// Pass the request to a callback
@@ -157,6 +160,10 @@ Zotero.HTTP = new function() {
if (options && options.successCodes) {
var success = options.successCodes.indexOf(status) != -1;
}
+ // Explicit FALSE means allow any status code
+ else if (options && options.successCodes === false) {
+ var success = true;
+ }
else if(isFile) {
var success = status == 200 || status == 0;
}
diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js
index 52b9b3eadf..d4d9df50f4 100644
--- a/chrome/content/zotero/xpcom/sync.js
+++ b/chrome/content/zotero/xpcom/sync.js
@@ -1345,7 +1345,7 @@ Zotero.Sync.Server = new function () {
}
};
- function login(callback) {
+ function login() {
var url = _serverURL + "login";
var username = Zotero.Sync.Server.username;
@@ -1368,7 +1368,9 @@ Zotero.Sync.Server = new function () {
Zotero.Sync.Runner.setSyncStatus(Zotero.getString('sync.status.loggingIn'));
- Zotero.HTTP.doPost(url, body, function (xmlhttp) {
+ return Zotero.HTTP.promise("POST", url,
+ { body: body, successCodes: false, foreground: !Zotero.Sync.Runner.background })
+ .then(function (xmlhttp) {
_checkResponse(xmlhttp, true);
var response = xmlhttp.responseXML.childNodes[0];
@@ -1396,10 +1398,6 @@ Zotero.Sync.Server = new function () {
//Zotero.debug('Got session ID ' + _sessionID + ' from server');
-
- if (callback) {
- callback();
- }
});
}
@@ -1416,9 +1414,11 @@ Zotero.Sync.Server = new function () {
if (!_sessionID) {
Zotero.debug("Session ID not available -- logging in");
- Zotero.Sync.Server.login(function () {
+ Zotero.Sync.Server.login()
+ .then(function () {
Zotero.Sync.Server.sync(_callbacks);
- });
+ })
+ .done();
return;
}
@@ -1472,9 +1472,11 @@ Zotero.Sync.Server = new function () {
Zotero.debug("Invalid session ID -- logging in");
_sessionID = false;
_syncInProgress = false;
- Zotero.Sync.Server.login(function () {
+ Zotero.Sync.Server.login()
+ .then(function () {
Zotero.Sync.Server.sync(_callbacks);
- });
+ })
+ .done();
return;
}
@@ -1800,9 +1802,11 @@ Zotero.Sync.Server = new function () {
function clear(callback) {
if (!_sessionID) {
Zotero.debug("Session ID not available -- logging in");
- Zotero.Sync.Server.login(function () {
+ Zotero.Sync.Server.login()
+ .then(function () {
Zotero.Sync.Server.clear(callback);
- });
+ })
+ .done();
return;
}
@@ -1814,9 +1818,11 @@ Zotero.Sync.Server = new function () {
if (_invalidSession(xmlhttp)) {
Zotero.debug("Invalid session ID -- logging in");
_sessionID = false;
- Zotero.Sync.Server.login(function () {
+ Zotero.Sync.Server.login()
+ .then(function () {
Zotero.Sync.Server.clear(callback);
- });
+ })
+ .done();
return;
}
@@ -1896,27 +1902,29 @@ Zotero.Sync.Server = new function () {
if (!xmlhttp.responseText) {
var channel = xmlhttp.channel;
// Check SSL cert
- var secInfo = channel.securityInfo;
- if (secInfo instanceof Ci.nsITransportSecurityInfo) {
- secInfo.QueryInterface(Ci.nsITransportSecurityInfo);
- if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_INSECURE) == Ci.nsIWebProgressListener.STATE_IS_INSECURE) {
- var url = channel.name;
- var ios = Components.classes["@mozilla.org/network/io-service;1"].
- getService(Components.interfaces.nsIIOService);
- try {
- var uri = ios.newURI(url, null, null);
- var host = uri.host;
+ if (channel) {
+ var secInfo = channel.securityInfo;
+ if (secInfo instanceof Ci.nsITransportSecurityInfo) {
+ secInfo.QueryInterface(Ci.nsITransportSecurityInfo);
+ if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_INSECURE) == Ci.nsIWebProgressListener.STATE_IS_INSECURE) {
+ var url = channel.name;
+ var ios = Components.classes["@mozilla.org/network/io-service;1"].
+ getService(Components.interfaces.nsIIOService);
+ try {
+ var uri = ios.newURI(url, null, null);
+ var host = uri.host;
+ }
+ catch (e) {
+ Zotero.debug(e);
+ }
+ var kbURL = 'http://zotero.org/support/kb/ssl_certificate_error';
+ _error(Zotero.getString('sync.storage.error.webdav.sslCertificateError', host) + "\n\n"
+ + Zotero.getString('general.seeForMoreInformation', kbURL),
+ false, noReloadOnFailure);
}
- catch (e) {
- Zotero.debug(e);
+ else if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_BROKEN) == Ci.nsIWebProgressListener.STATE_IS_BROKEN) {
+ _error(Zotero.getString('sync.error.sslConnectionError'), false, noReloadOnFailure);
}
- var kbURL = 'http://zotero.org/support/kb/ssl_certificate_error';
- _error(Zotero.getString('sync.storage.error.webdav.sslCertificateError', host) + "\n\n"
- + Zotero.getString('general.seeForMoreInformation', kbURL),
- false, noReloadOnFailure);
- }
- else if ((secInfo.securityState & Ci.nsIWebProgressListener.STATE_IS_BROKEN) == Ci.nsIWebProgressListener.STATE_IS_BROKEN) {
- _error(Zotero.getString('sync.error.sslConnectionError'), false, noReloadOnFailure);
}
}
if (xmlhttp.status === 0) {