From 7a0a6f75a251d5c277fc72c77463dd40f92119ec Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 12 Jan 2007 08:40:09 +0000 Subject: [PATCH] Fixes #496, Snapshot doesn't complete on some web pages I'm not entirely sure this won't break attachment saving in other cases, so people should keep an eye out for failed snapshots. --- chrome/content/zotero/xpcom/attachments.js | 2 +- chrome/content/zotero/xpcom/zotero.js | 27 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 0c114f49fe..83303921f3 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -451,7 +451,7 @@ Zotero.Attachments = new function(){ Zotero.DB.commitTransaction(); if (mimeType == 'text/html') { - Zotero.debug('Saving with saveDocument()'); + Zotero.debug('Saving with saveDocument() to ' + destDir.path); wbp.saveDocument(document, file, destDir, mimeType, encodingFlags, false); } else { diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 2549366470..9566b41452 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1284,16 +1284,35 @@ Zotero.Browser = new function() { * Implements nsIWebProgressListener */ Zotero.WebProgressFinishListener = function(onFinish) { + var _finished = false; + this.onStateChange = function(wp, req, stateFlags, status) { //Zotero.debug('onStageChange: ' + stateFlags); if ((stateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) && (stateFlags & Components.interfaces.nsIWebProgressListener.STATE_IS_NETWORK)) { + if (_finished) { + //Zotero.debug('onFinish() called before STATE_STOP in WebProgressFinishListener.onStateChange()'); + return; + } + onFinish(); } } - this.onLocationChange = function() {} - this.onProgressChange = function() {} - this.onSecurityChange = function() {} - this.onStatusChange = function() {} + this.onProgressChange = function(wp, req, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) { + //Zotero.debug('onProgressChange'); + //Zotero.debug('Current: ' + curTotalProgress); + //Zotero.debug('Max: ' + maxTotalProgress); + + // STATE_STOP alone (in onStateChange) doesn't always do the trick, + // so we check for max progress too + if (curTotalProgress == maxTotalProgress) { + _finished = true; + onFinish(); + } + } + + this.onLocationChange = function(wp, req, location) {} + this.onSecurityChange = function(wp, req, stateFlags, status) {} + this.onStatusChange = function(wp, req, status, msg) {} } \ No newline at end of file