Bug 1473294 - Load default pref files in reverse order to match original behaviour. r=philipp DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 13 Aug 2018 15:41:45 +1200
changeset 24481 d06d9961fcf5a32c608f4a520283e4e36aae0589
parent 24480 60848497b6311ca57ffb14fb544db9758ddc33ed
child 24482 859d577a9c3e21f472f401a1fe2c7ba77535a8a3
push id14733
push usermozilla@jorgk.com
push dateTue, 14 Aug 2018 07:12:01 +0000
treeherdercomm-central@d06d9961fcf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1473294
Bug 1473294 - Load default pref files in reverse order to match original behaviour. r=philipp DONTBUILD
common/src/extensionSupport.jsm
--- a/common/src/extensionSupport.jsm
+++ b/common/src/extensionSupport.jsm
@@ -29,31 +29,17 @@ function extensionDefaults() {
   for (let addonFile of fixIterator(enabledAddons, Ci.nsIFile)) {
     loadAddonPrefs(addonFile);
   }
 }
 
 var ExtensionSupport = {
   loadAddonPrefs(addonFile) {
     function setPref(preferDefault, name, value) {
-      let branch = Services.prefs.getBranch("");
-      if (preferDefault) {
-        let defaultBranch = Services.prefs.getDefaultBranch("");
-        if (defaultBranch.getPrefType(name) == Ci.nsIPrefBranch.PREF_INVALID) {
-          // Only use the default branch if it doesn't already have the pref set.
-          // If there is already a pref with this value on the default branch, the
-          // extension wants to override a built-in value.
-          branch = defaultBranch;
-        } else if (defaultBranch.prefHasUserValue(name)) {
-          // If a pref already has a user-set value it proper type
-          // will be returned (not PREF_INVALID). In that case keep the user's
-          // value and overwrite the default.
-          branch = defaultBranch;
-        }
-      }
+      let branch = preferDefault ? Services.prefs.getDefaultBranch("") : Services.prefs.getBranch("");
 
       if (typeof value == "boolean") {
         branch.setBoolPref(name, value);
       } else if (typeof value == "string") {
         if (value.startsWith("chrome://") && value.endsWith(".properties")) {
           let valueLocal = Cc["@mozilla.org/pref-localizedstring;1"]
                            .createInstance(Ci.nsIPrefLocalizedString);
           valueLocal.data = value;
@@ -76,29 +62,37 @@ var ExtensionSupport = {
         return [];
 
       if (prefFile.isDirectory()) {
         prefFile.append("defaults");
         prefFile.append("preferences");
         if (!prefFile.exists() || !prefFile.isDirectory())
           return [];
 
+        let unsortedFiles = [];
         for (let file of fixIterator(prefFile.directoryEntries, Ci.nsIFile)) {
           if (file.isFile() && file.leafName.toLowerCase().endsWith(".js")) {
-            foundPrefStrings.push(IOUtils.loadFileToString(file));
+            unsortedFiles.push(file);
           }
         }
+
+        for (let file of unsortedFiles.sort((a, b) => a.path < b.path ? 1 : -1)) {
+          foundPrefStrings.push(IOUtils.loadFileToString(file));
+        }
       } else if (prefFile.isFile() && prefFile.leafName.endsWith("xpi")) {
         let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
                           .createInstance(Ci.nsIZipReader);
         zipReader.open(prefFile);
         let entries = zipReader.findEntries("defaults/preferences/*.js");
-
+        let unsortedEntries = [];
         while (entries.hasMore()) {
-          let entryName = entries.getNext();
+          unsortedEntries.push(entries.getNext());
+        }
+
+        for (let entryName of unsortedEntries.sort().reverse()) {
           let stream = zipReader.getInputStream(entryName);
           let entrySize = zipReader.getEntry(entryName).realSize;
           if (entrySize > 0) {
             let content = NetUtil.readInputStreamToString(stream, entrySize, { charset: "utf-8", replacement: "?" });
             foundPrefStrings.push(content);
           }
         }
       }