Bug 1257565 - Ship blocklist.xml in defaults folder draft
authorMathieu Leplatre <mathieu@mozilla.com>
Tue, 28 Feb 2017 13:05:51 +0100
changeset 490450 0622b1b73c5565912577fade1d9eac50cf9f3c09
parent 490449 982d8bd33ccce100e1cf8f4bec9f38fa1c58f645
child 547255 d95e9b6abd29f1e66c21da81665451f7b897c59f
push id47094
push usermleplatre@mozilla.com
push dateTue, 28 Feb 2017 12:06:20 +0000
bugs1257565
milestone54.0a1
Bug 1257565 - Ship blocklist.xml in defaults folder MozReview-Commit-ID: FsJcwa90H9S
browser/app/moz.build
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/nsBlocklistService.js
toolkit/mozapps/extensions/test/xpcshell/test_overrideblocklist.js
--- a/browser/app/moz.build
+++ b/browser/app/moz.build
@@ -11,19 +11,21 @@ GeckoProgram(CONFIG['MOZ_APP_NAME'])
 JS_PREFERENCE_PP_FILES += [
     'profile/firefox.js',
 ]
 
 SOURCES += [
     'nsBrowserApp.cpp',
 ]
 
-FINAL_TARGET_FILES += ['blocklist.xml']
 FINAL_TARGET_FILES.defaults.profile += ['profile/prefs.js']
-FINAL_TARGET_FILES.defaults += ['permissions']
+FINAL_TARGET_FILES.defaults += [
+    'blocklist.xml',
+    'permissions'
+]
 
 DEFINES['APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 
 LOCAL_INCLUDES += [
     '!/build',
     '/toolkit/xre',
     '/xpcom/base',
     '/xpcom/build',
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -663,17 +663,17 @@ var AddonManagerInternal = {
   telemetryDetails: {},
   upgradeListeners: new Map(),
 
   recordTimestamp(name, value) {
     this.TelemetryTimestamps.add(name, value);
   },
 
   validateBlocklist() {
-    let appBlocklist = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
+    let appBlocklist = FileUtils.getFile(KEY_APPDIR, ["defaults", FILE_BLOCKLIST]);
 
     // If there is no application shipped blocklist then there is nothing to do
     if (!appBlocklist.exists())
       return;
 
     let profileBlocklist = FileUtils.getFile(KEY_PROFILEDIR, [FILE_BLOCKLIST]);
 
     // If there is no blocklist in the profile then copy the application shipped
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -730,24 +730,20 @@ Blocklist.prototype = {
       this._loadBlocklistFromJSONStrings(addonsJson, pluginsJson, gfxJson);
       // Certificates revocation happens directly in OneCRLBlocklistClient from
       // services/common/BlocklistClients.js.
     }
   },
 
   _loadBlocklistFromFile(filename) {
     const filePath = filename.split("/");
+    const appFile = FileUtils.getFile(KEY_APPDIR, ["defaults"].concat(filePath));
     let file = FileUtils.getFile(KEY_PROFILEDIR, filePath);
     if (!file.exists()) {
-      let appFile = FileUtils.getFile(KEY_APPDIR, filePath);
-      if (appFile.exists()) {
-        file = appFile;
-      } else {
-        file = FileUtils.getFile(KEY_APPDIR, ["defaults"].concat(filePath));
-      }
+      file = appFile;
     }
 
     let telemetry = Services.telemetry;
 
     // Check if preloaded content exists for this file.
     if (this._preloadedBlocklistContent.has(file.path)) {
       telemetry.getHistogramById("BLOCKLIST_SYNC_FILE_LOAD").add(false);
       const text = this._preloadedBlocklistContent.get(file.path);
@@ -820,25 +816,22 @@ Blocklist.prototype = {
       yield this._preloadBlocklistFile(BlocklistClients.GfxBlocklistClient.filename);
     }
   }),
 
   _preloadBlocklistFile: Task.async(function*(filename){
     const filePath = filename.split("/");
     let file = FileUtils.getFile(KEY_PROFILEDIR, filePath);
     if (!file.exists()) {
-      let appFile = FileUtils.getFile(KEY_APPDIR, filePath);
-      if (!appFile.exists()) {
-        appFile = FileUtils.getFile(KEY_APPDIR, ["defaults"].concat(filePath));
-        if (appFile.exists()) {
-          file = appFile;
-        } else {
-          LOG(`Blocklist::_preloadBlocklistFile: no ${filename} file found`);
-          return;
-        }
+      let appFile = FileUtils.getFile(KEY_APPDIR, ["defaults"].concat(filePath));
+      if (appFile.exists()) {
+        file = appFile;
+      } else {
+        LOG(`Blocklist::_preloadBlocklistFile: no ${filename} file found`);
+        return;
       }
     }
     const path = file.path;
     if (this._preloadedBlocklistContent.has(path)) {
       // The file has been already loaded.
       return;
     }
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_overrideblocklist.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_overrideblocklist.js
@@ -9,17 +9,17 @@ const FILE_BLOCKLIST                  = 
 const PREF_BLOCKLIST_ENABLED          = "extensions.blocklist.enabled";
 
 const OLD = do_get_file("data/test_overrideblocklist/old.xml");
 const NEW = do_get_file("data/test_overrideblocklist/new.xml");
 const ANCIENT = do_get_file("data/test_overrideblocklist/ancient.xml");
 const OLD_TSTAMP = 1296046918000;
 const NEW_TSTAMP = 1396046918000;
 
-const gAppDir = FileUtils.getFile(KEY_APPDIR, []);
+const gAppDir = FileUtils.getFile(KEY_APPDIR, ["defaults"]);
 
 var oldAddon = {
   id: "old@tests.mozilla.org",
   version: 1
 }
 var newAddon = {
   id: "new@tests.mozilla.org",
   version: 1
@@ -33,17 +33,17 @@ var invalidAddon = {
   version: 1
 }
 
 function incrementAppVersion() {
   gAppInfo.version = "" + (parseInt(gAppInfo.version) + 1);
 }
 
 function clearBlocklists() {
-  let blocklist = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
+  let blocklist = FileUtils.getFile(KEY_APPDIR, ["defaults", FILE_BLOCKLIST]);
   if (blocklist.exists())
     blocklist.remove(true);
 
   blocklist = FileUtils.getFile(KEY_PROFILEDIR, [FILE_BLOCKLIST]);
   if (blocklist.exists())
     blocklist.remove(true);
 }
 
@@ -62,17 +62,17 @@ function copyToProfile(file, tstamp) {
   file = gProfD.clone();
   file.append(FILE_BLOCKLIST);
   file.lastModifiedTime = tstamp;
 }
 
 function run_test() {
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
 
-  let appBlocklist = FileUtils.getFile(KEY_APPDIR, [FILE_BLOCKLIST]);
+  let appBlocklist = FileUtils.getFile(KEY_APPDIR, ["defaults", FILE_BLOCKLIST]);
   if (appBlocklist.exists()) {
     try {
       appBlocklist.moveTo(gAppDir, "blocklist.old");
     } catch (e) {
       todo(false, "Aborting test due to unmovable blocklist file: " + e);
       return;
     }
     do_register_cleanup(function() {