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
--- 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;
}