Remove deprecated retrieveSource and retrieveDocument calls
This commit is contained in:
parent
d456117ebe
commit
bf53fe8825
|
@ -284,101 +284,6 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
|
||||||
}, myException, true, translate.cookieSandbox);
|
}, myException, true, translate.cookieSandbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the DOM document object corresponding to the page located at URL, but avoids locking the
|
|
||||||
* UI while the request is in process.
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
* @param {String} url URL to load
|
|
||||||
* @return {Document} DOM document object
|
|
||||||
*/
|
|
||||||
Zotero.Utilities.Translate.prototype.retrieveDocument = function(url) {
|
|
||||||
if(!Zotero.isFx) throw "Zotero.Utilities.retrieveDocument() is unsupported outside of Firefox";
|
|
||||||
this._translate._debug("WARNING: Zotero.Utilities.retrieveDocument() is unsupported outside of Firefox", 1);
|
|
||||||
|
|
||||||
url = this._convertURL(url);
|
|
||||||
|
|
||||||
var mainThread = Zotero.mainThread;
|
|
||||||
var loaded = false;
|
|
||||||
var listener = function() {
|
|
||||||
loaded = hiddenBrowser.contentDocument.location.href != "about:blank";
|
|
||||||
}
|
|
||||||
|
|
||||||
var hiddenBrowser = Zotero.Browser.createHiddenBrowser();
|
|
||||||
if(this._translate.cookieSandbox) this._translate.cookieSandbox.attachToBrowser(hiddenBrowser);
|
|
||||||
|
|
||||||
hiddenBrowser.addEventListener("pageshow", listener, true);
|
|
||||||
hiddenBrowser.loadURI(url);
|
|
||||||
|
|
||||||
// Use a timeout of 2 minutes. Without a timeout, a request to an IP at which no system is
|
|
||||||
// configured will continue indefinitely, and hang Firefox as it shuts down. No same request
|
|
||||||
// should ever take longer than 2 minutes.
|
|
||||||
var endTime = Date.now() + 120000;
|
|
||||||
while(!loaded && Date.now() < endTime) {
|
|
||||||
// This processNextEvent call is used to handle a deprecated case
|
|
||||||
mainThread.processNextEvent(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
hiddenBrowser.removeEventListener("pageshow", listener, true);
|
|
||||||
hiddenBrowser.contentWindow.setTimeout(function() {
|
|
||||||
Zotero.Browser.deleteHiddenBrowser(hiddenBrowser);
|
|
||||||
}, 1);
|
|
||||||
|
|
||||||
if(!loaded) throw "retrieveDocument failed: request timeout";
|
|
||||||
return hiddenBrowser.contentDocument;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the source of the page located at URL, but avoids locking the UI while the request is in
|
|
||||||
* process.
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
* @param {String} url URL to load
|
|
||||||
* @param {String} [body=null] Request body to POST to the URL; a GET request is
|
|
||||||
* executed if no body is present
|
|
||||||
* @param {Object} [headers] HTTP headers to include in request;
|
|
||||||
* Content-Type defaults to application/x-www-form-urlencoded
|
|
||||||
* for POST; ignored if no body
|
|
||||||
* @param {String} [responseCharset] Character set to force on the response
|
|
||||||
* @return {String} Request body
|
|
||||||
*/
|
|
||||||
Zotero.Utilities.Translate.prototype.retrieveSource = function(url, body, headers, responseCharset) {
|
|
||||||
this._translate._debug("WARNING: Use of Zotero.Utilities.retrieveSource() is deprecated. "+
|
|
||||||
"The main thread will be frozen when Zotero.Utilities.retrieveSource() is called outside "+
|
|
||||||
"of Firefox, and cross-domain requests will not work.", 1);
|
|
||||||
|
|
||||||
if(Zotero.isFx) {
|
|
||||||
/* Apparently, a synchronous XMLHttpRequest would have the behavior of this routine in FF3, but
|
|
||||||
* in FF3.5, synchronous XHR blocks all JavaScript on the thread. See
|
|
||||||
* http://hacks.mozilla.org/2009/07/synchronous-xhr/. */
|
|
||||||
url = this._convertURL(url);
|
|
||||||
if(!headers) headers = null;
|
|
||||||
if(!responseCharset) responseCharset = null;
|
|
||||||
|
|
||||||
var mainThread = Zotero.mainThread;
|
|
||||||
var finished = false;
|
|
||||||
var listener = function() { finished = true };
|
|
||||||
|
|
||||||
if(body) {
|
|
||||||
var xmlhttp = Zotero.HTTP.doPost(url, body, listener, headers, responseCharset, this._translate.cookieSandbox);
|
|
||||||
} else {
|
|
||||||
var xmlhttp = Zotero.HTTP.doGet(url, listener, responseCharset, this._translate.cookieSandbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
// This processNextEvent call is used to handle a deprecated case
|
|
||||||
while(!finished) mainThread.processNextEvent(true);
|
|
||||||
} else {
|
|
||||||
// Use a synchronous XMLHttpRequest, even though this is inadvisable
|
|
||||||
var xmlhttp = new XMLHttpRequest();
|
|
||||||
xmlhttp.open((body ? "POST" : "GET"), url, false);
|
|
||||||
xmlhttp.send(body ? body : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(xmlhttp.status >= 400) throw "Zotero.Utilities.retrieveSource() failed: "+xmlhttp.status+" "+xmlhttp.statusText;
|
|
||||||
|
|
||||||
return xmlhttp.responseText;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an HTTP GET request via XMLHTTPRequest
|
* Send an HTTP GET request via XMLHTTPRequest
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user