Bug 1257565 - Remove coupling betweeen XML and Gfx draft
authorMathieu Leplatre <mathieu@mozilla.com>
Wed, 18 May 2016 17:41:09 +0200
changeset 368356 9925aec862ad545d64000a597b83748e83f9cc3c
parent 368355 4c11781a829e3bb3aecfd52ecacb5063da609f9f
child 368357 28aee9e47330dfba254fe4eb016eba090b74a15c
push id18498
push usermleplatre@mozilla.com
push dateWed, 18 May 2016 16:10:25 +0000
bugs1257565
milestone49.0a1
Bug 1257565 - Remove coupling betweeen XML and Gfx MozReview-Commit-ID: 4JDiU1ej9rR
toolkit/mozapps/extensions/nsBlocklistService.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -660,16 +660,17 @@ Blocklist.prototype = {
     }
 
     var oldAddonEntries = this._addonEntries;
     var oldPluginEntries = this._pluginEntries;
 
     this._loadBlocklistFromXMLString(request.responseText);
     // We don't inform the users when the graphics blocklist changed at runtime.
     // However addons and plugins blocking status is refreshed.
+    this._notifyObserversBlocklistGFX();
     this._blocklistUpdated(oldAddonEntries, oldPluginEntries);
 
     try {
       let path = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
       yield OS.File.writeAtomic(path, request.responseText, {tmpPath: path + ".tmp"});
     } catch (e) {
       LOG("Blocklist::onXMLLoad: " + e);
     }
@@ -703,16 +704,17 @@ Blocklist.prototype = {
    */
   _loadBlocklist: function() {
     if (!gBlocklistEnabled) {
       LOG("Blocklist::_loadBlocklistFromFile: blocklist is disabled");
       return;
     }
     const content = this._loadBlocklistFromFile(FILE_BLOCKLIST);
     this._loadBlocklistFromXMLString(content);
+    this._notifyObserversBlocklistGFX();
   },
 
   _loadBlocklistFromFile: function(filename) {
     let file = FileUtils.getFile(KEY_PROFILEDIR, [filename]);
     if (!file.exists()) {
       let appFile = FileUtils.getFile(KEY_APPDIR, [filename]);
       if (appFile.exists()) {
         file = appFile;
@@ -764,17 +766,19 @@ Blocklist.prototype = {
       if (fstream)
         fstream.close();
     }
 
     return text;
   },
 
   _isBlocklistLoaded: function() {
-    return this._addonEntries != null && this._pluginEntries != null;
+    return (this._addonEntries != null &&
+            this._gfxEntries != null &&
+            this._pluginEntries != null);
   },
 
   /* Used for testing */
   _clear: function() {
     this._addonEntries = null;
     this._gfxEntries = null;
     this._pluginEntries = null;
     this._preloadedBlocklistContent = {};
@@ -938,19 +942,16 @@ Blocklist.prototype = {
           break;
         default:
           LOG("Blocklist::_loadBlocklistFromXMLString: ignored entries " + element.localName);
         }
       }
       if (populateCertBlocklist) {
         gCertBlocklistService.saveEntries();
       }
-      if (this._gfxEntries.length > 0) {
-        this._notifyObserversBlocklistGFX();
-      }
     }
     catch (e) {
       LOG("Blocklist::_loadBlocklistFromXMLString: Error constructing blocklist " + e);
       return;
     }
   },
 
   _processItemNodes: function(itemNodes, itemName, handler) {
@@ -1298,16 +1299,19 @@ Blocklist.prototype = {
     if (!blockEntry.blockID) {
       return null;
     }
 
     return blockEntry.infoURL;
   },
 
   _notifyObserversBlocklistGFX: function () {
+    if (this._gfxEntries.length === 0) {
+      return;
+    }
     // Notify `GfxInfoBase`, by passing a string serialization.
     // This way we avoid spreading XML structure logics there.
     const payload = this._gfxEntries.map((r) => {
       return Object.keys(r).sort().filter((k) => !/id|last_modified/.test(k)).map((key) => {
         let value = r[key];
         if (Array.isArray(value)) {
           value = value.join(",");
         } else if (value.hasOwnProperty("minVersion")) {