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 656886 ebaecb5deef4299c592559e19cddd5f3280d31aa
parent 656885 5a2bc27bebafb3607b846b390d018075cc7a736b
child 729277 7175173120abe4bf597208c2350840fcb89bfe07
push id77361
push userksteuber@mozilla.com
push dateThu, 31 Aug 2017 20:19:55 +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", {