Bug 1348280 - Try to ensure thumbnail creation happens when the thread is idle
MozReview-Commit-ID: HoEb5J0QCyw
--- a/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
+++ b/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
@@ -282,16 +282,17 @@ const BackgroundPageThumbs = {
});
}
// else: we must have been idle and not currently doing a capture (eg,
// maybe a GC or similar crashed) - so there's no need to attempt a
// queue restart - the next capture request will set everything up.
});
browser.messageManager.loadFrameScript(FRAME_SCRIPT_URL, false);
+ browser.docShellIsActive = false;
this._thumbBrowser = browser;
},
_destroyBrowser() {
if (!this._thumbBrowser)
return;
this._thumbBrowser.remove();
delete this._thumbBrowser;
--- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
+++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
@@ -156,29 +156,35 @@ const backgroundPageThumbsContent = {
delete this._cancelTimer;
}, 0, Ci.nsITimer.TYPE_ONE_SHOT);
}
}
}
},
_captureCurrentPage() {
- let capture = this._currentCapture;
- capture.finalURL = this._webNav.currentURI.spec;
- capture.pageLoadTime = new Date() - capture.pageLoadStartDate;
+ let win = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindow);
+ win.requestIdleCallback(() => {
+ let capture = this._currentCapture;
+ capture.finalURL = this._webNav.currentURI.spec;
+ capture.pageLoadTime = new Date() - capture.pageLoadStartDate;
- let canvasDrawDate = new Date();
+ let canvasDrawDate = new Date();
- let finalCanvas = PageThumbUtils.createSnapshotThumbnail(content, null);
- capture.canvasDrawTime = new Date() - canvasDrawDate;
+ docShell.isActive = true;
+ let finalCanvas = PageThumbUtils.createSnapshotThumbnail(content, null);
+ docShell.isActive = false;
+ capture.canvasDrawTime = new Date() - canvasDrawDate;
- finalCanvas.toBlob(blob => {
- capture.imageBlob = new Blob([blob]);
- // Load about:blank to finish the capture and wait for onStateChange.
- this._loadAboutBlank();
+ finalCanvas.toBlob(blob => {
+ capture.imageBlob = new Blob([blob]);
+ // Load about:blank to finish the capture and wait for onStateChange.
+ this._loadAboutBlank();
+ });
});
},
_finishCurrentCapture() {
let capture = this._currentCapture;
let fileReader = new FileReader();
fileReader.onloadend = () => {
sendAsyncMessage("BackgroundPageThumbs:didCapture", {