Bug 1293499 - Fix PageThumbs.captureAndStore for e10s: redirects and channel errors. r?markh draft
authorDrew Willcoxon <adw@mozilla.com>
Mon, 08 Aug 2016 18:23:14 -0700
changeset 398359 86ab3cfa70926d96f2069d90b8e98bbb4f591975
parent 398318 c86dba04ed3d030385692c96280b7409577d5288
child 527638 dd8a09e5938fead86230483eecc564bcbf639f2b
push id25504
push userdwillcoxon@mozilla.com
push dateTue, 09 Aug 2016 01:23:30 +0000
reviewersmarkh
bugs1293499
milestone51.0a1
Bug 1293499 - Fix PageThumbs.captureAndStore for e10s: redirects and channel errors. r?markh MozReview-Commit-ID: HULg4Ja0NmF
toolkit/components/thumbnails/PageThumbUtils.jsm
toolkit/components/thumbnails/PageThumbs.jsm
toolkit/components/thumbnails/test/browser.ini
toolkit/content/browser-child.js
--- a/toolkit/components/thumbnails/PageThumbUtils.jsm
+++ b/toolkit/components/thumbnails/PageThumbUtils.jsm
@@ -319,10 +319,29 @@ this.PageThumbUtils = {
 
       // Don't capture HTTPS pages unless the user explicitly enabled it.
       if (uri.schemeIs("https") &&
           !Services.prefs.getBoolPref("browser.cache.disk_cache_ssl")) {
         return false;
       }
     } // httpChannel
     return true;
-  }
+  },
+
+  /**
+   * Given a channel, returns true if it should be considered an "error
+   * response", false otherwise.
+   */
+  isChannelErrorResponse: function(channel) {
+    // No valid document channel sounds like an error to me!
+    if (!channel)
+      return true;
+    if (!(channel instanceof Ci.nsIHttpChannel))
+      // it might be FTP etc, so assume it's ok.
+      return false;
+    try {
+      return !channel.requestSucceeded;
+    } catch (_) {
+      // not being able to determine success is surely failure!
+      return true;
+    }
+  },
 };
--- a/toolkit/components/thumbnails/PageThumbs.jsm
+++ b/toolkit/components/thumbnails/PageThumbs.jsm
@@ -363,27 +363,36 @@ this.PageThumbs = {
     if (!this._prefEnabled()) {
       return;
     }
 
     let url = aBrowser.currentURI.spec;
     let originalURL;
     let channelError = false;
 
-    if (!aBrowser.isRemoteBrowser) {
-      let channel = aBrowser.docShell.currentDocumentChannel;
-      originalURL = channel.originalURI.spec;
-      // see if this was an error response.
-      channelError = this._isChannelErrorResponse(channel);
-    } else {
-      // We need channel info (bug 1073957)
-      originalURL = url;
-    }
+    Task.spawn((function* task() {
+      if (!aBrowser.isRemoteBrowser) {
+        let channel = aBrowser.docShell.currentDocumentChannel;
+        originalURL = channel.originalURI.spec;
+        // see if this was an error response.
+        channelError = PageThumbUtils.isChannelErrorResponse(channel);
+      } else {
+        let resp = yield new Promise(resolve => {
+          let mm = aBrowser.messageManager;
+          let respName = "Browser:Thumbnail:GetOriginalURL:Response";
+          mm.addMessageListener(respName, function onResp(msg) {
+            mm.removeMessageListener(respName, onResp);
+            resolve(msg.data);
+          });
+          mm.sendAsyncMessage("Browser:Thumbnail:GetOriginalURL");
+        });
+        originalURL = resp.originalURL || url;
+        channelError = resp.channelError;
+      }
 
-    Task.spawn((function* task() {
       let isSuccess = true;
       try {
         let blob = yield this.captureToBlob(aBrowser);
         let buffer = yield TaskUtils.readBlob(blob);
         yield this._store(originalURL, url, buffer, channelError);
       } catch (ex) {
         Components.utils.reportError("Exception thrown during thumbnail capture: '" + ex + "'");
         isSuccess = false;
@@ -490,35 +499,16 @@ this.PageThumbs = {
    * @param aWindow The document of this window will be used to create the
    *                canvas.  If not given, the hidden window will be used.
    * @return The newly created canvas.
    */
   createCanvas: function PageThumbs_createCanvas(aWindow) {
     return PageThumbUtils.createCanvas(aWindow);
   },
 
-  /**
-   * Given a channel, returns true if it should be considered an "error
-   * response", false otherwise.
-   */
-  _isChannelErrorResponse: function(channel) {
-    // No valid document channel sounds like an error to me!
-    if (!channel)
-      return true;
-    if (!(channel instanceof Ci.nsIHttpChannel))
-      // it might be FTP etc, so assume it's ok.
-      return false;
-    try {
-      return !channel.requestSucceeded;
-    } catch (_) {
-      // not being able to determine success is surely failure!
-      return true;
-    }
-  },
-
   _prefEnabled: function PageThumbs_prefEnabled() {
     try {
       return !Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled");
     }
     catch (e) {
       return true;
     }
   },
--- a/toolkit/components/thumbnails/test/browser.ini
+++ b/toolkit/components/thumbnails/test/browser.ini
@@ -29,14 +29,13 @@ skip-if = buildapp == 'mulet' || !crashr
 [browser_thumbnails_bug726727.js]
 skip-if = buildapp == 'mulet'
 [browser_thumbnails_bug727765.js]
 [browser_thumbnails_bug818225.js]
 [browser_thumbnails_capture.js]
 [browser_thumbnails_expiration.js]
 [browser_thumbnails_privacy.js]
 [browser_thumbnails_redirect.js]
-skip-if = e10s # bug 1050869
 [browser_thumbnails_storage.js]
 [browser_thumbnails_storage_migrate3.js]
 skip-if = buildapp == 'mulet'
 [browser_thumbnails_update.js]
 skip-if = e10s # tries to open crypto/local file from the child
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -544,16 +544,32 @@ addMessageListener("Browser:Thumbnail:Re
  */
 addMessageListener("Browser:Thumbnail:CheckState", function (aMessage) {
   let result = PageThumbUtils.shouldStoreContentThumbnail(content, docShell);
   sendAsyncMessage("Browser:Thumbnail:CheckState:Response", {
     result: result
   });
 });
 
+/**
+ * Remote GetOriginalURL request handler for PageThumbs.
+ */
+addMessageListener("Browser:Thumbnail:GetOriginalURL", function (aMessage) {
+  let channel = docShell.currentDocumentChannel;
+  let channelError = PageThumbUtils.isChannelErrorResponse(channel);
+  let originalURL;
+  try {
+    originalURL = channel.originalURI.spec;
+  } catch (ex) {}
+  sendAsyncMessage("Browser:Thumbnail:GetOriginalURL:Response", {
+    channelError: channelError,
+    originalURL: originalURL,
+  });
+});
+
 // The AddonsChild needs to be rooted so that it stays alive as long as
 // the tab.
 var AddonsChild = RemoteAddonsChild.init(this);
 if (AddonsChild) {
   addEventListener("unload", () => {
     RemoteAddonsChild.uninit(AddonsChild);
   });
 }