Bug 1473264: Catch failures to get the favicon expiration. r=mak
authorDave Townsend <dtownsend@oxymoronical.com>
Wed, 04 Jul 2018 12:36:13 +0000
changeset 425015 19e3352e9f6793a8cea2a6a1abd7c62886e97d72
parent 425014 27257fdd6c6777ca72ac965501da3ef360846bb4
child 425016 53c113af05482bed213b4c3e9e4e4660edb90c0b
push id34231
push userrgurzau@mozilla.com
push dateWed, 04 Jul 2018 16:28:29 +0000
treeherdermozilla-central@a07cf0515fe3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1473264
milestone63.0a1
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
Bug 1473264: Catch failures to get the favicon expiration. r=mak This ignores failures to get expiration data from favicon requests. It also adds some safety to the rest of onStopRequest wrapping it in a try...catch block to catch any unexpected errors and correctly reject the waiting promise. Differential Revision: https://phabricator.services.mozilla.com/D1938
browser/modules/ContentLinkHandler.jsm
--- a/browser/modules/ContentLinkHandler.jsm
+++ b/browser/modules/ContentLinkHandler.jsm
@@ -149,47 +149,49 @@ class FaviconLoad {
 
     // Attempt to get an expiration time from the cache.  If this fails, we'll
     // use this default.
     let expiration = Date.now() + MAX_FAVICON_EXPIRATION;
 
     // This stuff isn't available after onStopRequest returns (so don't start
     // any async operations before this!).
     if (this.channel instanceof Ci.nsICacheInfoChannel) {
-      expiration = Math.min(this.channel.cacheTokenExpirationTime * 1000, expiration);
+      try {
+        expiration = Math.min(this.channel.cacheTokenExpirationTime * 1000, expiration);
+      } catch (e) {
+        // Ignore failures to get the expiration time.
+      }
     }
 
-    let type = this.channel.contentType;
-    let blob = new Blob(this.buffers, { type });
+    try {
+      let type = this.channel.contentType;
+      let blob = new Blob(this.buffers, { type });
 
-    if (type != "image/svg+xml") {
-      let octets = await promiseBlobAsOctets(blob);
-      let sniffer = Cc["@mozilla.org/image/loader;1"].
-                    createInstance(Ci.nsIContentSniffer);
-      try {
+      if (type != "image/svg+xml") {
+        let octets = await promiseBlobAsOctets(blob);
+        let sniffer = Cc["@mozilla.org/image/loader;1"].
+                      createInstance(Ci.nsIContentSniffer);
         type = sniffer.getMIMETypeFromContent(this.channel, octets, octets.length);
-      } catch (e) {
-        this._deferred.reject(e);
-        return;
+
+        if (!type) {
+          throw Components.Exception(`Favicon at "${this.icon.iconUri.spec}" did not match a known mimetype.`, Cr.NS_ERROR_FAILURE);
+        }
+
+        blob = blob.slice(0, blob.size, type);
       }
 
-      if (!type) {
-        this._deferred.reject(Components.Exception(`Favicon at "${this.icon.iconUri.spec}" did not match a known mimetype.`, Cr.NS_ERROR_FAILURE));
-        return;
-      }
+      let dataURL = await promiseBlobAsDataURL(blob);
 
-      blob = blob.slice(0, blob.size, type);
+      this._deferred.resolve({
+        expiration,
+        dataURL,
+      });
+    } catch (e) {
+      this._deferred.reject(e);
     }
-
-    let dataURL = await promiseBlobAsDataURL(blob);
-
-    this._deferred.resolve({
-      expiration,
-      dataURL,
-    });
   }
 
   getInterface(iid) {
     if (iid.equals(Ci.nsIChannelEventSink)) {
       return this;
     }
     throw Cr.NS_ERROR_NO_INTERFACE;
   }