Bug 1348280 - Try to ensure thumbnail creation happens when the thread is idle draft
authorKirk Steuber <ksteuber@mozilla.com>
Wed, 16 Aug 2017 13:24:22 -0700
changeset 648368 187e93918e547ca34f3a6c23f5d811a8ef0b184d
parent 647624 07ce8c96222d533fc89c02802143d35d7c351f9c
child 726804 07c2db7b5c14e4711d86c25fbda673eea5f4330b
push id74733
push userksteuber@mozilla.com
push dateThu, 17 Aug 2017 17:25:54 +0000
bugs1348280
milestone57.0a1
Bug 1348280 - Try to ensure thumbnail creation happens when the thread is idle MozReview-Commit-ID: HoEb5J0QCyw
toolkit/components/thumbnails/BackgroundPageThumbs.jsm
toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
--- 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", {