Bug 1454563 - actually add real fallback from profile to appdir blocklist if loading the profile one fails, r?kmag draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 17 Apr 2018 23:56:45 +0100
changeset 784239 048e576a7065bf8333e8f8c38b2ca7bea34217cc
parent 783966 789e30ff2e3d6e1fcfce1a373c1e5635488d24da
push id106887
push usergijskruitbosch@gmail.com
push dateWed, 18 Apr 2018 10:20:30 +0000
reviewerskmag
bugs1454563
milestone61.0a1
Bug 1454563 - actually add real fallback from profile to appdir blocklist if loading the profile one fails, r?kmag MozReview-Commit-ID: AbRLwACqrzU
toolkit/mozapps/extensions/nsBlocklistService.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -810,41 +810,41 @@ Blocklist.prototype = {
 
     if (!gBlocklistEnabled) {
       LOG("Blocklist::_preloadBlocklistFile: blocklist is disabled");
       return;
     }
 
     let text = await OS.File.read(path, { encoding: "utf-8" });
 
-    await new Promise(resolve => {
-      Services.tm.idleDispatchToMainThread(() => {
+    await new Promise((resolve, reject) => {
+      ChromeUtils.idleDispatch(() => {
         if (!this.isLoaded) {
           Services.telemetry.getHistogramById("BLOCKLIST_SYNC_FILE_LOAD").add(false);
-          this._loadBlocklistFromString(text);
+          try {
+            this._loadBlocklistFromString(text);
+          } catch (ex) {
+            // Loading the blocklist failed. Ensure the caller knows.
+            reject(ex);
+          }
         }
         resolve();
       });
     });
   },
 
   _loadBlocklistFromString(text) {
-    try {
-      var parser = Cc["@mozilla.org/xmlextras/domparser;1"].
-                   createInstance(Ci.nsIDOMParser);
-      var doc = parser.parseFromString(text, "text/xml");
-      if (doc.documentElement.namespaceURI != XMLURI_BLOCKLIST) {
-        LOG("Blocklist::_loadBlocklistFromString: aborting due to incorrect " +
-            "XML Namespace.\r\nExpected: " + XMLURI_BLOCKLIST + "\r\n" +
-            "Received: " + doc.documentElement.namespaceURI);
-        return;
-      }
-    } catch (e) {
-      LOG("Blocklist::_loadBlocklistFromString: Error constructing blocklist " + e);
-      return;
+    var parser = Cc["@mozilla.org/xmlextras/domparser;1"].
+                 createInstance(Ci.nsIDOMParser);
+    var doc = parser.parseFromString(text, "text/xml");
+    if (doc.documentElement.namespaceURI != XMLURI_BLOCKLIST) {
+      LOG("Blocklist::_loadBlocklistFromString: aborting due to incorrect " +
+          "XML Namespace.\r\nExpected: " + XMLURI_BLOCKLIST + "\r\n" +
+          "Received: " + doc.documentElement.namespaceURI);
+      throw new Error("Couldn't find an XML doc with the right namespace!");
     }
     this._loadBlocklistFromXML(doc);
   },
 
   _loadBlocklistFromXML(doc) {
     this._addonEntries = [];
     this._gfxEntries = [];
     this._pluginEntries = [];