From e4180f41c7720e23b9a9c87fdcee30ebf6a6cf7b Mon Sep 17 00:00:00 2001 From: Jim Mathies Date: Wed, 29 Apr 2015 06:33:09 -0500 Subject: [PATCH] Bug 1129040 - Forward blocklist update notifications to the content process. r=Mossop --- .../mozapps/extensions/nsBlocklistService.js | 17 +++++--- .../extensions/nsBlocklistServiceContent.js | 42 ++++++++++++++++--- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/toolkit/mozapps/extensions/nsBlocklistService.js b/toolkit/mozapps/extensions/nsBlocklistService.js index 06bda12e9607..cbcfb4e989ab 100644 --- a/toolkit/mozapps/extensions/nsBlocklistService.js +++ b/toolkit/mozapps/extensions/nsBlocklistService.js @@ -298,7 +298,7 @@ function Blocklist() { 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 = { @@ -322,7 +322,7 @@ Blocklist.prototype = { 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); }, @@ -359,7 +359,7 @@ Blocklist.prototype = { // 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); @@ -1192,6 +1192,11 @@ Blocklist.prototype = { return blockEntry.infoURL; }, + _notifyObserversBlocklistUpdated: function () { + Services.obs.notifyObservers(this, "blocklist-updated", ""); + Services.ppmm.broadcastAsyncMessage("Blocklist:blocklistInvalidated", {}); + }, + _blocklistUpdated: function Blocklist_blocklistUpdated(oldAddonEntries, oldPluginEntries) { var addonList = []; @@ -1296,7 +1301,7 @@ Blocklist.prototype = { } if (addonList.length == 0) { - Services.obs.notifyObservers(self, "blocklist-updated", ""); + self._notifyObserversBlocklistUpdated(); return; } @@ -1308,7 +1313,7 @@ Blocklist.prototype = { } catch (e) { LOG(e); } - Services.obs.notifyObservers(self, "blocklist-updated", ""); + self._notifyObserversBlocklistUpdated(); return; } @@ -1342,7 +1347,7 @@ Blocklist.prototype = { if (args.restart) restartApp(); - Services.obs.notifyObservers(self, "blocklist-updated", ""); + self._notifyObserversBlocklistUpdated(); Services.obs.removeObserver(applyBlocklistChanges, "addon-blocklist-closed"); } diff --git a/toolkit/mozapps/extensions/nsBlocklistServiceContent.js b/toolkit/mozapps/extensions/nsBlocklistServiceContent.js index 972daa1a4809..bb24c61008f2 100644 --- a/toolkit/mozapps/extensions/nsBlocklistServiceContent.js +++ b/toolkit/mozapps/extensions/nsBlocklistServiceContent.js @@ -21,6 +21,7 @@ const kMissingAPIMessage = "Unsupported blocklist call in the child process." */ function Blocklist() { + this.init(); } Blocklist.prototype = { @@ -28,12 +29,41 @@ Blocklist.prototype = { 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. @@ -57,7 +87,7 @@ Blocklist.prototype = { }, 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