Bug 1413413 (part 2) - Remove support for extensions having their own prefs file. r=glandium,aswan. draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 31 Oct 2017 16:34:57 +1100
changeset 689898 a7b084bd939754fdf3a7d11d0de5701e079f36f3
parent 689897 a7377b8b242cf07eb7a48cd0cb431b4768792326
child 738418 43351c46deb39d3da72ab5d1fe5ff474d1c41558
push id87136
push usernnethercote@mozilla.com
push dateWed, 01 Nov 2017 03:42:29 +0000
reviewersglandium, aswan
bugs1413413
milestone58.0a1
Bug 1413413 (part 2) - Remove support for extensions having their own prefs file. r=glandium,aswan. It's no longer needed, now that legacy extensions aren't supported. Pieces removed include the following. - The "load-extension-default" observer notification. - The code for reading defaults/preferences/*.js. - The unit test for this stuff. - A crash reporter annotation relating to very long prefs set by add-ons. - All references to "ExtPrefDL". MozReview-Commit-ID: IS2B9DK356
modules/libpref/Preferences.cpp
modules/libpref/nsIPrefService.idl
modules/libpref/test/unit/test_extprefs.js
modules/libpref/test/unit/xpcshell.ini
services/sync/tests/unit/head_helpers.js
toolkit/xre/nsXREDirProvider.cpp
xpcom/io/nsAppDirectoryServiceDefs.h
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -2566,30 +2566,17 @@ nsPrefBranch::GetComplexValue(const char
 
   if (aType.Equals(NS_GET_IID(nsISupportsString))) {
     nsCOMPtr<nsISupportsString> theString(
       do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
 
     if (NS_SUCCEEDED(rv)) {
       // Debugging to see why we end up with very long strings here with
       // some addons, see bug 836263.
-      nsAutoString wdata;
-      if (!AppendUTF8toUTF16(utf8String, wdata, mozilla::fallible)) {
-#ifdef MOZ_CRASHREPORTER
-        nsCOMPtr<nsICrashReporter> cr =
-          do_GetService("@mozilla.org/toolkit/crash-reporter;1");
-        if (cr) {
-          cr->AnnotateCrashReport(NS_LITERAL_CSTRING("bug836263-size"),
-                                  nsPrintfCString("%x", utf8String.Length()));
-          cr->RegisterAppMemory(uint64_t(utf8String.BeginReading()),
-                                std::min(0x1000U, utf8String.Length()));
-        }
-#endif
-        MOZ_CRASH("bug836263");
-      }
+      NS_ConvertUTF8toUTF16 wdata(utf8String);
       theString->SetData(wdata);
       theString.forget(reinterpret_cast<nsISupportsString**>(aRetVal));
     }
     return rv;
   }
 
   NS_WARNING("nsPrefBranch::GetComplexValue - Unsupported interface type");
   return NS_NOINTERFACE;
@@ -3900,17 +3887,16 @@ Preferences::Init()
     mozilla::services::GetObserverService();
   if (!observerService) {
     return Err("GetObserverService() failed (1)");
   }
 
   observerService->AddObserver(this, "profile-before-change-telemetry", true);
   rv = observerService->AddObserver(this, "profile-before-change", true);
 
-  observerService->AddObserver(this, "load-extension-defaults", true);
   observerService->AddObserver(this, "suspend_process_notification", true);
 
   if (NS_FAILED(rv)) {
     return Err("AddObserver(\"profile-before-change\") failed");
   }
 
   return Ok();
 }
@@ -3964,19 +3950,16 @@ Preferences::Observe(nsISupports* aSubje
   } else if (!nsCRT::strcmp(aTopic, "profile-before-change-telemetry")) {
     // It's possible that a profile-before-change observer after ours
     // set a pref. A blocking save here re-saves if necessary and also waits
     // for any pending saves to complete.
     SavePrefFileBlocking();
     MOZ_ASSERT(!mDirty, "Preferences should not be dirty");
     mProfileShutdown = true;
 
-  } else if (!strcmp(aTopic, "load-extension-defaults")) {
-    pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
-
   } else if (!nsCRT::strcmp(aTopic, "reload-default-prefs")) {
     // Reload the default prefs from file.
     Unused << pref_InitInitialObjects();
 
   } else if (!nsCRT::strcmp(aTopic, "suspend_process_notification")) {
     // Our process is being suspended. The OS may wake our process later,
     // or it may kill the process. In case our process is going to be killed
     // from the suspended state, we save preferences before suspending.
@@ -4072,64 +4055,16 @@ Preferences::SavePrefFileAsynchronous()
 
 NS_IMETHODIMP
 Preferences::SavePrefFile(nsIFile* aFile)
 {
   // This is the method accessible from service API. Make it off main thread.
   return SavePrefFileInternal(aFile, SaveMethod::Asynchronous);
 }
 
-static nsresult
-ReadExtensionPrefs(nsIFile* aFile)
-{
-  nsresult rv;
-  nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = reader->Open(aFile);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIUTF8StringEnumerator> files;
-  rv = reader->FindEntries(
-    nsDependentCString("defaults/preferences/*.(J|j)(S|s)$"),
-    getter_AddRefs(files));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  char buffer[4096];
-
-  bool more;
-  while (NS_SUCCEEDED(rv = files->HasMore(&more)) && more) {
-    nsAutoCString entry;
-    rv = files->GetNext(entry);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIInputStream> stream;
-    rv = reader->GetInputStream(entry, getter_AddRefs(stream));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    uint64_t avail;
-    uint32_t read;
-
-    PrefParseState ps;
-    PREF_InitParseState(&ps, PREF_ReaderCallback, ReportToConsole, nullptr);
-    while (NS_SUCCEEDED(rv = stream->Available(&avail)) && avail) {
-      rv = stream->Read(buffer, 4096, &read);
-      if (NS_FAILED(rv)) {
-        NS_WARNING("Pref stream read failed");
-        break;
-      }
-
-      PREF_ParseBuf(&ps, buffer, read);
-    }
-    PREF_FinalizeParseState(&ps);
-  }
-
-  return rv;
-}
-
 void
 Preferences::SetPreference(const PrefSetting& aPref)
 {
   pref_SetPref(aPref);
 }
 
 void
 Preferences::GetPreference(PrefSetting* aPref)
@@ -4575,25 +4510,18 @@ pref_LoadPrefsInDirList(const char* aLis
       continue;
     }
 
     nsCOMPtr<nsIFile> path = do_QueryInterface(elem);
     if (!path) {
       continue;
     }
 
-    nsAutoCString leaf;
-    path->GetNativeLeafName(leaf);
-
     // Do we care if a file provided by this process fails to load?
-    if (Substring(leaf, leaf.Length() - 4).EqualsLiteral(".xpi")) {
-      ReadExtensionPrefs(path);
-    } else {
-      pref_LoadPrefsInDir(path, nullptr, 0);
-    }
+    pref_LoadPrefsInDir(path, nullptr, 0);
   }
 
   return NS_OK;
 }
 
 static nsresult
 pref_ReadPrefFromJar(nsZipArchive* aJarReader, const char* aName)
 {
@@ -4791,20 +4719,16 @@ pref_InitInitialObjects()
 
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   NS_ENSURE_SUCCESS(rv, Err("GetObserverService() failed (2)"));
 
   observerService->NotifyObservers(
     nullptr, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nullptr);
 
-  rv = pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
-  NS_ENSURE_SUCCESS(
-    rv, Err("pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST) failed"));
-
   return Ok();
 }
 
 //----------------------------------------------------------------------------
 // Static utilities
 //----------------------------------------------------------------------------
 
 /* static */ nsresult
--- a/modules/libpref/nsIPrefService.idl
+++ b/modules/libpref/nsIPrefService.idl
@@ -142,14 +142,13 @@ interface nsIPrefService : nsISupports
 /**
  * Notification sent when resetPrefs has been called, but before the actual
  * reset process occurs.
  */
 #define NS_PREFSERVICE_RESET_TOPIC_ID "prefservice:before-reset"
 
 /**
  * Notification sent when after reading app-provided default
- * preferences, but before user profile override defaults or extension
- * defaults are loaded.
+ * preferences, but before user profile override defaults are loaded.
  */
 #define NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID "prefservice:after-app-defaults"
 
 %}
deleted file mode 100644
--- a/modules/libpref/test/unit/test_extprefs.js
+++ /dev/null
@@ -1,70 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/licenses/publicdomain/  */
-
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
-
-// The profile directory is already set up in the head_ files.
-
-function arrayenumerator(a)
-{
-  return {
-    i_: 0,
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
-    hasMoreElements: function ae_hasMoreElements() {
-      return this.i_ < a.length;
-    },
-    getNext: function ae_getNext() {
-      return a[this.i_++];
-    }
-  };
-}
-
-function run_test() {
-  var ps = Cc["@mozilla.org/preferences-service;1"].
-    getService(Ci.nsIPrefService).QueryInterface(Ci.nsIPrefBranch);
-
-  var extprefs = [do_get_file("extdata")];
-  
-  var extProvider = {
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
-                                           Ci.nsIDirectoryServiceProvider2]),
-    getFile: function ep_getFile() {
-      throw Cr.NS_ERROR_FAILURE;
-    },
-    
-    getFiles: function ep_getFiles(key) {
-      if (key != "ExtPrefDL")
-        throw Cr.NS_ERROR_FAILURE;
-
-      return arrayenumerator(extprefs);
-    }
-  };
-  
-  let prefFile = do_get_file("data/testPref.js");
-
-  do_check_throws(function() {
-    ps.getBoolPref("testExtPref.bool");
-  }, Cr.NS_ERROR_UNEXPECTED);
-  do_check_throws(function() {
-    ps.getBoolPref("testPref.bool1");
-  }, Cr.NS_ERROR_UNEXPECTED);
-  
-  ps.readUserPrefsFromFile(prefFile);
-
-  do_check_true(ps.getBoolPref("testPref.bool1"));
-  ps.setBoolPref("testPref.bool1", false);
-  do_check_false(ps.getBoolPref("testPref.bool1"));
-  
-  dirSvc.registerProvider(extProvider);
-  Services.obs.notifyObservers(null, "load-extension-defaults");
-
-  // The extension default should be available.
-  do_check_true(ps.getBoolPref("testExtPref.bool"));
-
-  // The extension default should not override existing user prefs
-  do_check_false(ps.getBoolPref("testPref.bool2"));
-
-  // The extension default should not modify existing set values
-  do_check_false(ps.getBoolPref("testPref.bool1"));
-}
--- a/modules/libpref/test/unit/xpcshell.ini
+++ b/modules/libpref/test/unit/xpcshell.ini
@@ -9,11 +9,10 @@ support-files =
 [test_bug506224.js]
 [test_bug577950.js]
 [test_bug790374.js]
 [test_stickyprefs.js]
 support-files = data/testPrefSticky.js data/testPrefStickyUser.js
 [test_changeType.js]
 [test_defaultValues.js]
 [test_dirtyPrefs.js]
-[test_extprefs.js]
 [test_libPrefs.js]
 [test_bug1354613.js]
--- a/services/sync/tests/unit/head_helpers.js
+++ b/services/sync/tests/unit/head_helpers.js
@@ -57,30 +57,16 @@ XPCOMUtils.defineLazyGetter(this, "SyncP
 
 XPCOMUtils.defineLazyGetter(this, "SyncPingValidator", function() {
   let ns = {};
   Cu.import("resource://testing-common/ajv-4.1.1.js", ns);
   let ajv = new ns.Ajv({ async: "co*" });
   return ajv.compile(SyncPingSchema);
 });
 
-var provider = {
-  getFile(prop, persistent) {
-    persistent.value = true;
-    switch (prop) {
-      case "ExtPrefDL":
-        return [Services.dirsvc.get("CurProcD", Ci.nsIFile)];
-      default:
-        throw Cr.NS_ERROR_FAILURE;
-    }
-  },
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider])
-};
-Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
-
 // This is needed for loadAddonTestFunctions().
 var gGlobalScope = this;
 
 function ExtensionsTestPath(path) {
   if (path[0] != "/") {
     throw Error("Path must begin with '/': " + path);
   }
 
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -885,34 +885,16 @@ nsXREDirProvider::GetFilesInternal(const
     nsCOMArray<nsIFile> directories;
 
     LoadDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
     LoadDirsIntoArray(mAppBundleDirectories,
                       kAppendPrefDir, directories);
 
     rv = NS_NewArrayEnumerator(aResult, directories);
   }
-  else if (!strcmp(aProperty, NS_EXT_PREFS_DEFAULTS_DIR_LIST)) {
-    nsCOMArray<nsIFile> directories;
-
-    LoadDirsIntoArray(AddonManagerStartup::GetSingleton().ExtensionPaths(),
-                      kAppendPrefDir, directories);
-
-    if (mProfileDir) {
-      nsCOMPtr<nsIFile> overrideFile;
-      mProfileDir->Clone(getter_AddRefs(overrideFile));
-      overrideFile->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
-
-      bool exists;
-      if (NS_SUCCEEDED(overrideFile->Exists(&exists)) && exists)
-        directories.AppendObject(overrideFile);
-    }
-
-    rv = NS_NewArrayEnumerator(aResult, directories);
-  }
   else if (!strcmp(aProperty, NS_APP_CHROME_DIR_LIST)) {
     // NS_APP_CHROME_DIR_LIST is only used to get default (native) icons
     // for OS window decoration.
 
     static const char *const kAppendChromeDir[] = { "chrome", nullptr };
     nsCOMArray<nsIFile> directories;
     LoadDirIntoArray(mXULAppDir,
                      kAppendChromeDir,
@@ -1030,17 +1012,16 @@ nsXREDirProvider::DoStartup()
     // Init the Extension Manager
     nsCOMPtr<nsIObserver> em = do_GetService("@mozilla.org/addons/integration;1");
     if (em) {
       em->Observe(nullptr, "addons-startup", nullptr);
     } else {
       NS_WARNING("Failed to create Addons Manager.");
     }
 
-    obsSvc->NotifyObservers(nullptr, "load-extension-defaults", nullptr);
     obsSvc->NotifyObservers(nullptr, "profile-after-change", kStartup);
 
     // Any component that has registered for the profile-after-change category
     // should also be created at this time.
     (void)NS_CreateServicesFromCategory("profile-after-change", nullptr,
                                         "profile-after-change");
 
     if (gSafeMode && safeModeNecessary) {
--- a/xpcom/io/nsAppDirectoryServiceDefs.h
+++ b/xpcom/io/nsAppDirectoryServiceDefs.h
@@ -55,17 +55,16 @@
 // other users of the profile. Without this prefix, the consumer
 // has exclusive access to this location.
 
 #define NS_SHARED                               "SHARED"
 
 #define NS_APP_PREFS_50_DIR                     "PrefD"         // Directory which contains user prefs
 #define NS_APP_PREFS_50_FILE                    "PrefF"
 #define NS_APP_PREFS_DEFAULTS_DIR_LIST          "PrefDL"
-#define NS_EXT_PREFS_DEFAULTS_DIR_LIST          "ExtPrefDL"
 #define NS_APP_PREFS_OVERRIDE_DIR               "PrefDOverride" // Directory for per-profile defaults
 
 #define NS_APP_USER_PROFILE_50_DIR              "ProfD"
 #define NS_APP_USER_PROFILE_LOCAL_50_DIR        "ProfLD"
 
 #define NS_APP_USER_CHROME_DIR                  "UChrm"
 #define NS_APP_USER_SEARCH_DIR                  "UsrSrchPlugns"