Bug 1257565 - Reload from disk when kinto blocklist was updated draft
authorMathieu Leplatre <mathieu@mozilla.com>
Fri, 24 Feb 2017 18:39:46 +0100
changeset 490449 982d8bd33ccce100e1cf8f4bec9f38fa1c58f645
parent 490448 af531f1d0397d811a597ac75f3aa28f28f74f30c
child 490450 0622b1b73c5565912577fade1d9eac50cf9f3c09
push id47093
push usermleplatre@mozilla.com
push dateTue, 28 Feb 2017 11:38:14 +0000
bugs1257565
milestone54.0a1
Bug 1257565 - Reload from disk when kinto blocklist was updated MozReview-Commit-ID: JPrDybWvbGc
toolkit/mozapps/extensions/nsBlocklistService.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_kinto.js
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -297,16 +297,17 @@ function Blocklist() {
   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:content-blocklist-updated", this);
+  Services.ppmm.addMessageListener("Blocklist:reload-from-disk", 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)
@@ -368,16 +369,30 @@ Blocklist.prototype = {
 
   // Message manager message handlers
   receiveMessage(aMsg) {
     switch (aMsg.name) {
       case "Blocklist:getPluginBlocklistState":
         return this.getPluginBlocklistState(aMsg.data.addonData,
                                             aMsg.data.appVersion,
                                             aMsg.data.toolkitVersion);
+      case "Blocklist:reload-from-disk":
+        // If blocklist updates are managed via Kinto, reload the new blocklist
+        // content from the recently updated files.
+        // Certificates are not concerned, their revokation is updated in
+        // OneCRLBlocklistClient from services/common/KintoBlocklist.js.
+        if (!gBlocklistFromXML) {
+          const oldAddonEntries = this._addonEntries;
+          const oldPluginEntries = this._pluginEntries;
+          // Read JSON files from disk.
+          this._loadBlocklist();
+          // Update status of addons/plugins (mimic what happens in onXMLLoad()).
+          this._blocklistUpdated(oldAddonEntries, oldPluginEntries);
+        }
+        break;
       case "Blocklist:content-blocklist-updated":
         Services.obs.notifyObservers(null, "content-blocklist-updated", null);
         break;
       default:
         throw new Error("Unknown blocklist message received from content: " + aMsg.name);
     }
     return undefined;
   },
--- a/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_kinto.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_kinto.js
@@ -323,16 +323,35 @@ add_task(function* load_uses_preloaded_j
 
   // Data loaded comes from preloaded content.
   equal(blocklist._addonEntries[0].blockID, SAMPLE_ADDON_RECORD.blockID);
   equal(blocklist._gfxEntries[0].blockID, SAMPLE_GFX_RECORD.blockID);
   equal(blocklist._pluginEntries[0].blockID, SAMPLE_PLUGIN_RECORD.blockID);
 });
 
 
+add_task(function* test_blocklist_is_reloaded_when_message_is_received() {
+  const blocklist = Blocklist();
+
+  blocklist._loadBlocklist();
+
+  // Write a fake JSON file in profile dir.
+  copyToProfile(SAMPLE_FILE, "addons");
+
+  // Send message.
+  yield Services.cpmm.sendAsyncMessage("Blocklist:reload-from-disk");
+
+  // Since message is loaded asynchronously, wait for its reception.
+  yield new Promise((resolve) => setTimeout(() => resolve(), 100));
+
+  // Blocklist was reloaded with the content from file.
+  equal(blocklist._addonEntries[0].blockID, "i53923");
+});
+
+
 add_task(function* test_read_json_from_app_or_profile() {
   const blocklist = Blocklist();
 
   // Reads from app dir by default.
   clearProfile("addons");
   blocklist._loadBlocklist();
   ok(blocklist._addonEntries.length >= 416);