Bug 1387580 - Some top sites never get screenshots of redirected pages. r=adw

MozReview-Commit-ID: IzmzXhGnPcH

--HG--
extra : rebase_source : 48b7e3425268af2cfdc8ab8f8ea5c31a366915bc
This commit is contained in:
Ed Lee 2017-08-05 00:34:25 -07:00
Родитель 48a85c4492
Коммит 97f29a6cfb
1 изменённых файлов: 22 добавлений и 5 удалений

Просмотреть файл

@ -4,7 +4,7 @@
/* eslint-env mozilla/frame-script */
var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
var { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
Cu.importGlobalProperties(["Blob", "FileReader"]);
@ -12,6 +12,10 @@ Cu.import("resource://gre/modules/PageThumbUtils.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
// Let the page settle for this amount of milliseconds before capturing to allow
// for any in-page changes or redirects.
const SETTLE_WAIT_TIME = 2500;
const STATE_LOADING = 1;
const STATE_CAPTURING = 2;
const STATE_CANCELED = 3;
@ -122,10 +126,23 @@ const backgroundPageThumbsContent = {
this._startNextCapture();
}
} else if (this._state == STATE_LOADING &&
Components.isSuccessCode(status)) {
// The requested page has loaded. Capture it.
this._state = STATE_CAPTURING;
this._captureCurrentPage();
(Components.isSuccessCode(status) ||
status === Cr.NS_BINDING_ABORTED)) {
// The requested page has loaded or stopped/aborted, so capture the page
// soon but first let it settle in case of in-page redirects
if (this._captureTimer) {
// There was additional activity, so restart the wait timer
this._captureTimer.delay = SETTLE_WAIT_TIME;
} else {
// Stay in LOADING until we're actually ready to be CAPTURING
this._captureTimer =
Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._captureTimer.init(() => {
this._state = STATE_CAPTURING;
this._captureCurrentPage();
delete this._captureTimer;
}, SETTLE_WAIT_TIME, Ci.nsITimer.TYPE_ONE_SHOT);
}
} else if (this._state != STATE_CANCELED) {
// Something went wrong. Cancel the capture. Loading about:blank
// while onStateChange is still on the stack does not actually stop