Be more careful about pageshow only fire with doc.readyState === "loading"

This commit is contained in:
Simon Kornblith 2012-02-29 02:56:31 -05:00
parent 635cc8bd15
commit d35c2d9a4f

View file

@ -489,6 +489,11 @@ Zotero.HTTP = new function() {
* @return {browser} Hidden browser used for loading * @return {browser} Hidden browser used for loading
*/ */
this.processDocuments = function(urls, processor, done, exception, dontDelete, cookieSandbox) { this.processDocuments = function(urls, processor, done, exception, dontDelete, cookieSandbox) {
// (Approximately) how many seconds to wait if the document is left in the loading state and
// pageshow is called before we call pageshow with an incomplete document
const LOADING_STATE_TIMEOUT = 120;
var firedLoadEvent;
/** /**
* Removes event listener for the load event and deletes the hidden browser * Removes event listener for the load event and deletes the hidden browser
*/ */
@ -504,6 +509,7 @@ Zotero.HTTP = new function() {
var doLoad = function() { var doLoad = function() {
if(urls.length) { if(urls.length) {
var url = urls.shift(); var url = urls.shift();
firedLoadEvent = 0;
try { try {
Zotero.debug("loading "+url); Zotero.debug("loading "+url);
hiddenBrowser.loadURI(url); hiddenBrowser.loadURI(url);
@ -529,7 +535,13 @@ Zotero.HTTP = new function() {
var onLoad = function() { var onLoad = function() {
var doc = hiddenBrowser.contentDocument, var doc = hiddenBrowser.contentDocument,
url = doc.location.href.toString(); url = doc.location.href.toString();
if(url == "about:blank" || doc.readyState === "loading") return; if(url == "about:blank") return;
if(doc.readyState === "loading" && firedLoadEvent < 120) {
// Try again in a second
firedLoadEvent++;
Zotero.setTimeout(onLoad, 1000);
return;
}
if(url !== prevUrl) { // Just in case it fires too many times if(url !== prevUrl) { // Just in case it fires too many times
prevUrl = url; prevUrl = url;
try { try {