Bug 1129040 - Forward blocklist update notifications to the content process. r=Mossop
authorJim Mathies <jmathies@mozilla.com>
Fri, 01 May 2015 10:07:18 -0500
changeset 273377 665696faba4629a2fe1c020323e4321d7ab4d912
parent 273376 c0b2da7ea0f9b4bf844b8183dfc645b58ea91786
child 273378 d4e278c065d6b440612686209f1dc42e5002d61d
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1129040
milestone40.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 1129040 - Forward blocklist update notifications to the content process. r=Mossop
toolkit/mozapps/extensions/nsBlocklistService.js
toolkit/mozapps/extensions/nsBlocklistServiceContent.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -293,17 +293,17 @@ function Blocklist() {
   gLoggingEnabled = getPref("getBoolPref", PREF_EM_LOGGING_ENABLED, false);
   gBlocklistEnabled = getPref("getBoolPref", PREF_BLOCKLIST_ENABLED, true);
   gBlocklistLevel = Math.min(getPref("getIntPref", PREF_BLOCKLIST_LEVEL, DEFAULT_LEVEL),
                                      MAX_BLOCK_LEVEL);
   gPref.addObserver("extensions.blocklist.", this, false);
   gPref.addObserver(PREF_EM_LOGGING_ENABLED, this, false);
   this.wrappedJSObject = this;
   // requests from child processes come in here, see receiveMessage.
-  Services.ppmm.addMessageListener("Blocklist::getPluginBlocklistState", this);
+  Services.ppmm.addMessageListener("Blocklist:getPluginBlocklistState", this);
 }
 
 Blocklist.prototype = {
   /**
    * Extension ID -> array of Version Ranges
    * Each value in the version range array is a JS Object that has the
    * following properties:
    *   "minVersion"  The minimum version in a version range (default = 0)
@@ -317,17 +317,17 @@ Blocklist.prototype = {
    *                   "maxVersion"  The maximum version in a version range
    *                                 (default = *)
    */
   _addonEntries: null,
   _pluginEntries: null,
 
   shutdown: function () {
     Services.obs.removeObserver(this, "xpcom-shutdown");
-    Services.ppmm.removeMessageListener("Blocklist::getPluginBlocklistState", this);
+    Services.ppmm.removeMessageListener("Blocklist:getPluginBlocklistState", this);
     gPref.removeObserver("extensions.blocklist.", this);
     gPref.removeObserver(PREF_EM_LOGGING_ENABLED, this);
   },
 
   observe: function Blocklist_observe(aSubject, aTopic, aData) {
     switch (aTopic) {
     case "xpcom-shutdown":
       this.shutdown();
@@ -354,17 +354,17 @@ Blocklist.prototype = {
       this._preloadBlocklist();
       break;
     }
   },
 
   // Message manager message handlers
   receiveMessage: function (aMsg) {
     switch (aMsg.name) {
-      case "Blocklist::getPluginBlocklistState":
+      case "Blocklist:getPluginBlocklistState":
         return this.getPluginBlocklistState(aMsg.data.addonData,
                                             aMsg.data.appVersion,
                                             aMsg.data.toolkitVersion);
       default:
         throw new Error("Unknown blocklist message received from content: " + aMsg.name);
     }
   },
 
@@ -1187,16 +1187,21 @@ Blocklist.prototype = {
     let {entry: blockEntry, version: blockEntryVersion} = r;
     if (!blockEntry.blockID) {
       return null;
     }
 
     return blockEntry.infoURL;
   },
 
+  _notifyObserversBlocklistUpdated: function () {
+    Services.obs.notifyObservers(this, "blocklist-updated", "");
+    Services.ppmm.broadcastAsyncMessage("Blocklist:blocklistInvalidated", {});
+  },
+
   _blocklistUpdated: function Blocklist_blocklistUpdated(oldAddonEntries, oldPluginEntries) {
     var addonList = [];
 
     // A helper function that reverts the prefs passed to default values.
     function resetPrefs(prefs) {
       for (let pref of prefs)
         gPref.clearUserPref(pref);
     }
@@ -1291,29 +1296,29 @@ Blocklist.prototype = {
               item: plugin,
               url: self.getPluginBlocklistURL(plugin),
             });
           }
         }
       }
 
       if (addonList.length == 0) {
-        Services.obs.notifyObservers(self, "blocklist-updated", "");
+        self._notifyObserversBlocklistUpdated();
         return;
       }
 
       if ("@mozilla.org/addons/blocklist-prompt;1" in Cc) {
         try {
           let blockedPrompter = Cc["@mozilla.org/addons/blocklist-prompt;1"]
                                  .getService(Ci.nsIBlocklistPrompt);
           blockedPrompter.prompt(addonList);
         } catch (e) {
           LOG(e);
         }
-        Services.obs.notifyObservers(self, "blocklist-updated", "");
+        self._notifyObserversBlocklistUpdated();
         return;
       }
 
       var args = {
         restart: false,
         list: addonList
       };
       // This lets the dialog get the raw js object
@@ -1337,17 +1342,17 @@ Blocklist.prototype = {
             let prefs = self._getAddonPrefs(addon.item);
             resetPrefs(prefs);
           }
         }
 
         if (args.restart)
           restartApp();
 
-        Services.obs.notifyObservers(self, "blocklist-updated", "");
+        self._notifyObserversBlocklistUpdated();
         Services.obs.removeObserver(applyBlocklistChanges, "addon-blocklist-closed");
       }
 
       Services.obs.addObserver(applyBlocklistChanges, "addon-blocklist-closed", false);
 
       if (getPref("getBoolPref", PREF_BLOCKLIST_SUPPRESSUI, false)) {
         applyBlocklistChanges();
         return;
--- a/toolkit/mozapps/extensions/nsBlocklistServiceContent.js
+++ b/toolkit/mozapps/extensions/nsBlocklistServiceContent.js
@@ -16,29 +16,59 @@ const kMissingAPIMessage = "Unsupported 
 /*
  * A lightweight blocklist proxy for the content process that traps plugin
  * related blocklist checks and forwards them to the parent. This interface is
  * primarily designed to insure overlays work.. it does not control plugin
  * or addon loading.
  */
 
 function Blocklist() {
+  this.init();
 }
 
 Blocklist.prototype = {
   classID: Components.ID("{e0a106ed-6ad4-47a4-b6af-2f1c8aa4712d}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIBlocklistService]),
 
+  init: function () {
+    Services.cpmm.addMessageListener("Blocklist:blocklistInvalidated", this);
+    Services.obs.addObserver(this, "xpcom-shutdown", false);
+  },
+
+  uninit: function () {
+    Services.cpmm.removeMessageListener("Blocklist:blocklistInvalidated", this);
+    Services.obs.removeObserver(this, "xpcom-shutdown", false);
+  },
+
+  observe: function (aSubject, aTopic, aData) {
+    switch (aTopic) {
+    case "xpcom-shutdown":
+      this.uninit();
+      break;
+    }
+  },
+
+  // Message manager message handlers
+  receiveMessage: function (aMsg) {
+    switch (aMsg.name) {
+      case "Blocklist:blocklistInvalidated":
+        Services.obs.notifyObservers(null, "blocklist-updated", null);
+        break;
+      default:
+        throw new Error("Unknown blocklist message received from content: " + aMsg.name);
+    }
+  },
+
   /*
-    * A helper that queries key data from a plugin or addon object
-    * and generates a simple data wrapper suitable for ipc. We hand
-    * these directly to the nsBlockListService in the parent which
-    * doesn't query for much.. allowing us to get away with this.
-    */
+   * A helper that queries key data from a plugin or addon object
+   * and generates a simple data wrapper suitable for ipc. We hand
+   * these directly to the nsBlockListService in the parent which
+   * doesn't query for much.. allowing us to get away with this.
+   */
   flattenObject: function (aTag) {
     // Based on debugging the nsBlocklistService, these are the props the
     // parent side will check on our objects.
     let props = ["name", "description", "filename", "version"];
     let dataWrapper = {};
     for (let prop of props) {
       dataWrapper[prop] = aTag[prop];
     }
@@ -52,17 +82,17 @@ Blocklist.prototype = {
     throw new Error(kMissingAPIMessage);
   },
 
   getAddonBlocklistState: function (aAddon, aAppVersion, aToolkitVersion) {
     throw new Error(kMissingAPIMessage);
   },
 
   getPluginBlocklistState: function (aPluginTag, aAppVersion, aToolkitVersion) {
-    return Services.cpmm.sendSyncMessage("Blocklist::getPluginBlocklistState", {
+    return Services.cpmm.sendSyncMessage("Blocklist:getPluginBlocklistState", {
       addonData: this.flattenObject(aPluginTag),
       appVersion: aAppVersion,
       toolkitVersion: aToolkitVersion
     })[0];
   },
 
   getAddonBlocklistURL: function (aAddon, aAppVersion, aToolkitVersion) {
     throw new Error(kMissingAPIMessage);