Bug 1215659 - Use destination canvas for thumbnail size if provided one. r=adw, a=ritu
authorMason Chang <mchang@mozilla.com>
Fri, 30 Oct 2015 12:26:30 -0700
changeset 305388 7b8547621a2ea5ff58fbbd2e5a8b9c7c6727b768
parent 305387 ae4965be0983ef9f2655c3cec4b8b2dbe155cb22
child 305389 cc7fe955ffdd7f99c2fa9dc5bd2a81d475e33fd7
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, ritu
bugs1215659
milestone44.0a2
Bug 1215659 - Use destination canvas for thumbnail size if provided one. r=adw, a=ritu
toolkit/components/thumbnails/PageThumbUtils.jsm
toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
--- a/toolkit/components/thumbnails/PageThumbUtils.jsm
+++ b/toolkit/components/thumbnails/PageThumbUtils.jsm
@@ -143,17 +143,19 @@ this.PageThumbUtils = {
    * @return Canvas with a scaled thumbnail of the window.
    */
   createSnapshotThumbnail: function(aWindow, aDestCanvas = null) {
     if (Cu.isCrossProcessWrapper(aWindow)) {
       throw new Error('Do not pass cpows here.');
     }
 
     let [contentWidth, contentHeight] = this.getContentSize(aWindow);
-    let [thumbnailWidth, thumbnailHeight] = this.getThumbnailSize(aWindow);
+    let [thumbnailWidth, thumbnailHeight] = aDestCanvas ?
+                                            [aDestCanvas.width, aDestCanvas.height] :
+                                            this.getThumbnailSize(aWindow);
     let intermediateWidth = thumbnailWidth * 2;
     let intermediateHeight = thumbnailHeight * 2;
     let skipDownscale = false;
     let snapshotCanvas = undefined;
 
     // Our intermediate thumbnail is bigger than content,
     // which can happen on hiDPI devices like a retina macbook pro.
     // In those cases, just render at the final size.
@@ -180,17 +182,16 @@ this.PageThumbUtils = {
       snapshotCanvas = this.createCanvas(aWindow, intermediateWidth, intermediateHeight);
     }
 
     // This is step 1.
     // Also by default, canvas does not draw the scrollbars, so no need to
     // remove the scrollbar sizes.
     let scale = Math.min(Math.max(intermediateWidth / contentWidth,
                                   intermediateHeight / contentHeight), 1);
-
     let snapshotCtx = snapshotCanvas.getContext("2d");
     snapshotCtx.save();
     snapshotCtx.scale(scale, scale);
     snapshotCtx.drawWindow(aWindow, 0, 0, contentWidth, contentHeight,
                            PageThumbUtils.THUMBNAIL_BG_COLOR,
                            snapshotCtx.DRAWWINDOW_DO_NOT_FLUSH);
     snapshotCtx.restore();
     if (skipDownscale) {
--- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
+++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
@@ -94,17 +94,17 @@ const backgroundPageThumbsContent = {
       delete this._currentCapture;
       this._startNextCapture();
     }
   },
 
   onStateChange: function (webProgress, req, flags, status) {
     if (webProgress.isTopLevel &&
         (flags & Ci.nsIWebProgressListener.STATE_STOP) &&
-        this._currentCapture) {
+        this._currentCapture && Components.isSuccessCode(status)) {
       if (req.name == "about:blank") {
         if (this._state == STATE_CAPTURING) {
           // about:blank has loaded, ending the current capture.
           this._finishCurrentCapture();
           delete this._currentCapture;
           this._startNextCapture();
         }
         else if (this._state == STATE_CANCELED) {