Backed out changeset 4a955a640a52 (bug 1397390) for eslint failure at toolkit/components/thumbnails/PageThumbUtils.jsm:142: 'error' is not defined. r=backout
authorSebastian Hengst <archaeopteryx@coole-files.de>
Thu, 07 Sep 2017 23:59:05 +0200
changeset 379539 b3acfa3577e2
parent 379538 f82f69a3381a
child 379540 c70b23f06f9f
push id50700
push userarchaeopteryx@coole-files.de
push dateThu, 07 Sep 2017 21:59:24 +0000
treeherderautoland@b3acfa3577e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1397390
milestone57.0a1
backs out4a955a640a52
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 4a955a640a52 (bug 1397390) for eslint failure at toolkit/components/thumbnails/PageThumbUtils.jsm:142: 'error' is not defined. r=backout
toolkit/components/thumbnails/BackgroundPageThumbs.jsm
toolkit/components/thumbnails/PageThumbUtils.jsm
toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
toolkit/components/thumbnails/test/browser.ini
toolkit/components/thumbnails/test/browser_thumbnails_bg_image_capture.js
toolkit/components/thumbnails/test/sample_image_blue_300x600.jpg
toolkit/components/thumbnails/test/sample_image_green_1024x1024.jpg
toolkit/components/thumbnails/test/sample_image_red_1920x1080.jpg
--- a/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
+++ b/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
@@ -52,19 +52,16 @@ const BackgroundPageThumbs = {
    *                 properties are the following, and all are optional:
    * @opt onDone     A function that will be asynchronously called when the
    *                 capture is complete or times out.  It's called as
    *                   onDone(url),
    *                 where `url` is the captured URL.
    * @opt timeout    The capture will time out after this many milliseconds have
    *                 elapsed after the capture has progressed to the head of
    *                 the queue and started.  Defaults to 30000 (30 seconds).
-   * @opt isImage    If true, backgroundPageThumbsContent will attempt to render
-   *                 the url directly to canvas. Note that images will mostly get
-   *                 detected and rendered as such anyway, but this will ensure it.
    */
   capture(url, options = {}) {
     if (!PageThumbs._prefEnabled()) {
       if (options.onDone)
         schedule(() => options.onDone(url));
       return;
     }
     this._captureQueue = this._captureQueue || [];
@@ -402,17 +399,17 @@ Capture.prototype = {
                   DEFAULT_CAPTURE_TIMEOUT;
     this._timeoutTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     this._timeoutTimer.initWithCallback(this, timeout,
                                         Ci.nsITimer.TYPE_ONE_SHOT);
 
     // didCapture registration
     this._msgMan = messageManager;
     this._msgMan.sendAsyncMessage("BackgroundPageThumbs:capture",
-                                  { id: this.id, url: this.url, isImage: this.options.isImage });
+                                  { id: this.id, url: this.url });
     this._msgMan.addMessageListener("BackgroundPageThumbs:didCapture", this);
   },
 
   /**
    * The only intended external use of this method is by the service when it's
    * uninitializing and doing things like destroying the thumbnail browser.  In
    * that case the consumer's completion callback will never be called.
    */
--- a/toolkit/components/thumbnails/PageThumbUtils.jsm
+++ b/toolkit/components/thumbnails/PageThumbUtils.jsm
@@ -109,57 +109,16 @@ this.PageThumbUtils = {
     // Even in RTL mode, scrollbars are always on the right.
     // So there's no need to determine a left offset.
     let width = aWindow.innerWidth - sbWidth.value;
     let height = aWindow.innerHeight - sbHeight.value;
 
     return [width, height];
   },
 
-  /**
-   * Renders an image onto a new canvas of a given width and proportional
-   * height. Uses an image that exists in the window and is loaded, or falls
-   * back to loading the url into a new image element.
-   */
-  async createImageThumbnailCanvas(window, url, targetWidth = 448) {
-    // 224px is the width of cards in ActivityStream; capture thumbnails at 2x
-    const doc = (window || Services.appShell.hiddenDOMWindow).document;
-
-    let image = doc.querySelector("img");
-    if (!image || image.src !== url) {
-      image = doc.createElementNS(this.HTML_NAMESPACE, "img");
-    }
-    if (!image.complete) {
-      await new Promise(resolve => {
-        image.onload = () => resolve();
-        image.onerror = () => { throw new Error("Image failed to load"); }
-        image.src = url;
-      });
-    }
-
-    // <img src="*.svg"> has width/height but not naturalWidth/naturalHeight
-    const imageWidth = image.naturalWidth || image.width;
-    const imageHeight = image.naturalHeight || image.height;
-    if (imageWidth === 0 || imageHeight === 0) {
-      throw new error("Image has zero dimension");
-    }
-    const width = Math.min(targetWidth, imageWidth);
-    const height = imageHeight * width / imageWidth;
-
-    // As we're setting the width and maintaining the aspect ratio, if an image
-    // is very tall we might get a very large thumbnail. Restricting the canvas
-    // size to {width}x{width} solves this problem. Here we choose to clip the
-    // image at the bottom rather than centre it vertically, based on an
-    // estimate that the focus of a tall image is most likely to be near the top
-    // (e.g., the face of a person).
-    const canvas = this.createCanvas(window, width, Math.min(height, width));
-    canvas.getContext("2d").drawImage(image, 0, 0, width, height);
-    return canvas;
-  },
-
   /** *
    * Given a browser window, this creates a snapshot of the content
    * and returns a canvas with the resulting snapshot of the content
    * at the thumbnail size. It has to do this through a two step process:
    *
    * 1) Render the content at the window size to a canvas that is 2x the thumbnail size
    * 2) Downscale the canvas from (1) down to the thumbnail size
    *
--- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
+++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
@@ -73,17 +73,16 @@ const backgroundPageThumbsContent = {
   get _webNav() {
     return docShell.QueryInterface(Ci.nsIWebNavigation);
   },
 
   _onCapture(msg) {
     this._nextCapture = {
       id: msg.data.id,
       url: msg.data.url,
-      isImage: msg.data.isImage
     };
     if (this._currentCapture) {
       if (this._state == STATE_LOADING) {
         // Cancel the current capture.
         this._state = STATE_CANCELED;
         this._loadAboutBlank();
       }
       // Let the current capture finish capturing, or if it was just canceled,
@@ -159,32 +158,25 @@ const backgroundPageThumbsContent = {
         }
       }
     }
   },
 
   _captureCurrentPage() {
     let win = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                       .getInterface(Ci.nsIDOMWindow);
-    win.requestIdleCallback(async () => {
+    win.requestIdleCallback(() => {
       let capture = this._currentCapture;
       capture.finalURL = this._webNav.currentURI.spec;
       capture.pageLoadTime = new Date() - capture.pageLoadStartDate;
 
       let canvasDrawDate = new Date();
 
       docShell.isActive = true;
-
-      let finalCanvas;
-      if (capture.isImage || content.document instanceof content.ImageDocument) {
-        finalCanvas = await PageThumbUtils.createImageThumbnailCanvas(content, capture.url);
-      } else {
-        finalCanvas = PageThumbUtils.createSnapshotThumbnail(content, null);
-      }
-
+      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();
       });
--- a/toolkit/components/thumbnails/test/browser.ini
+++ b/toolkit/components/thumbnails/test/browser.ini
@@ -1,17 +1,14 @@
 [DEFAULT]
 support-files =
   authenticate.sjs
   background_red.html
   background_red_redirect.sjs
   background_red_scroll.html
-  sample_image_red_1920x1080.jpg
-  sample_image_green_1024x1024.jpg
-  sample_image_blue_300x600.jpg
   head.js
   privacy_cache_control.sjs
   thumbnails_background.sjs
   thumbnails_update.sjs
 
 [browser_thumbnails_bg_bad_url.js]
 [browser_thumbnails_bg_crash_during_capture.js]
 skip-if = !crashreporter
@@ -23,17 +20,16 @@ skip-if = !crashreporter
 [browser_thumbnails_bg_redirect.js]
 [browser_thumbnails_bg_destroy_browser.js]
 [browser_thumbnails_bg_no_cookies_sent.js]
 [browser_thumbnails_bg_no_cookies_stored.js]
 [browser_thumbnails_bg_no_auth_prompt.js]
 [browser_thumbnails_bg_no_alert.js]
 [browser_thumbnails_bg_no_duplicates.js]
 [browser_thumbnails_bg_captureIfMissing.js]
-[browser_thumbnails_bg_image_capture.js]
 [browser_thumbnails_bug726727.js]
 [browser_thumbnails_bug727765.js]
 [browser_thumbnails_bug818225.js]
 [browser_thumbnails_capture.js]
 skip-if = os == "mac" && !debug # bug 1314039
 [browser_thumbnails_expiration.js]
 [browser_thumbnails_privacy.js]
 [browser_thumbnails_redirect.js]
deleted file mode 100644
--- a/toolkit/components/thumbnails/test/browser_thumbnails_bg_image_capture.js
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
-
-const BASE_URL = "http://mochi.test:8888/browser/toolkit/components/thumbnails/";
-
-/**
- * These tests ensure that when trying to capture a url that is an image file,
- * the image itself is captured instead of the the browser window displaying the
- * image, and that the thumbnail maintains the image aspect ratio.
- */
-function* runTests() {
-  for (const {url, color, width, height} of [{
-    url: BASE_URL + "test/sample_image_red_1920x1080.jpg",
-    color: [255, 0, 0],
-    width: 1920,
-    height: 1080
-  }, {
-    url: BASE_URL + "test/sample_image_green_1024x1024.jpg",
-    color: [0, 255, 0],
-    width: 1024,
-    height: 1024
-  }, {
-    url: BASE_URL + "test/sample_image_blue_300x600.jpg",
-    color: [0, 0, 255],
-    width: 300,
-    height: 600
-  }]) {
-    dontExpireThumbnailURLs([url]);
-    const capturedPromise = new Promise(resolve => {
-      bgAddPageThumbObserver(url).then(() => {
-        ok(true, `page-thumbnail created for ${url}`);
-        resolve();
-      });
-    });
-    yield bgCapture(url);
-    yield capturedPromise;
-    ok(thumbnailExists(url), "The image thumbnail should exist after capture");
-
-    const thumb = PageThumbs.getThumbnailURL(url);
-    const htmlns = "http://www.w3.org/1999/xhtml";
-    const img = document.createElementNS(htmlns, "img");
-    yield new Promise(resolve => {
-      img.onload = () => resolve();
-      img.src = thumb;
-    });
-
-    // 448px is the default max-width of an image thumbnail
-    const expectedWidth = Math.min(448, width);
-    // Tall images are clipped to {width}x{width}
-    const expectedHeight = Math.min(expectedWidth * height / width, expectedWidth);
-    // Fuzzy equality to account for rounding
-    ok(Math.abs(img.naturalWidth - expectedWidth) <= 1,
-      "The thumbnail should have the right width");
-    ok(Math.abs(img.naturalHeight - expectedHeight) <= 1,
-      "The thumbnail should have the right height");
-
-    // Draw the image to a canvas and compare the pixel color values.
-    const canvas = document.createElementNS(htmlns, "canvas");
-    canvas.width = expectedWidth;
-    canvas.height = expectedHeight;
-    const ctx = canvas.getContext("2d");
-    ctx.drawImage(img, 0, 0, expectedWidth, expectedHeight);
-    const [r, g, b] = ctx.getImageData(0, 0, expectedWidth, expectedHeight).data;
-    // Fuzzy equality to account for image encoding
-    ok((Math.abs(r - color[0]) <= 2 &&
-        Math.abs(g - color[1]) <= 2 &&
-        Math.abs(b - color[2]) <= 2),
-        "The thumbnail should have the right color");
-
-    removeThumbnail(url);
-  }
-}
deleted file mode 100644
index ad5b44ecbc721ef793d81716e9e519aaf2c56d7b..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 7d91079ecd21b337c0b62cd764ae7bc18ce6f68c..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 7a2bec4d5e8d2f7169858ea8a5c06173831d5948..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001