Bug 698217 DeCOMtaminate nsIPrefServiceInternal r=roc
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Wed, 02 Nov 2011 14:51:39 +0000
changeset 79563 921e1db5cf11f7877a9f85bb91aa99fce618e2bc
parent 79562 06292dba305205f823d4043be55f35988806fc1d
child 79598 9b291cc0cd86047392136dcd02ed6fe471986e02
child 81286 d6352d960dd24bb29dc3365b9b2e686e7fbcd812
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs698217
milestone10.0a1
Bug 698217 DeCOMtaminate nsIPrefServiceInternal r=roc
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
modules/libpref/public/Preferences.h
modules/libpref/public/nsIPrefService.idl
modules/libpref/src/Preferences.cpp
toolkit/xre/nsXREDirProvider.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -55,25 +55,25 @@
 #include "mozilla/dom/ExternalHelperAppChild.h"
 #include "mozilla/dom/PCrashReporterChild.h"
 #include "mozilla/dom/StorageChild.h"
 #include "mozilla/hal_sandbox/PHalChild.h"
 #include "mozilla/ipc/TestShellChild.h"
 #include "mozilla/ipc/XPCShellEnvironment.h"
 #include "mozilla/jsipc/PContextWrapperChild.h"
 #include "mozilla/net/NeckoChild.h"
+#include "mozilla/Preferences.h"
 
 #if defined(MOZ_SYDNEYAUDIO)
 #include "nsAudioStream.h"
 #endif
 #include "nsIMemoryReporter.h"
 #include "nsIObserverService.h"
 #include "nsTObserverArray.h"
 #include "nsIObserver.h"
-#include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsXULAppAPI.h"
 #include "nsWeakReference.h"
 #include "nsIScriptError.h"
 #include "nsIConsoleService.h"
 #include "nsJSEnvironment.h"
 #include "SandboxHal.h"
 
@@ -633,34 +633,24 @@ ContentChild::AddRemoteAlertObserver(con
     NS_ASSERTION(aObserver, "Adding a null observer?");
     mAlertObservers.AppendElement(new AlertObserver(aObserver, aData));
     return NS_OK;
 }
 
 bool
 ContentChild::RecvPreferenceUpdate(const PrefTuple& aPref)
 {
-    nsCOMPtr<nsIPrefServiceInternal> prefs = do_GetService("@mozilla.org/preferences-service;1");
-    if (!prefs)
-        return false;
-
-    prefs->SetPreference(&aPref);
-
+    Preferences::SetPreference(&aPref);
     return true;
 }
 
 bool
 ContentChild::RecvClearUserPreference(const nsCString& aPrefName)
 {
-    nsCOMPtr<nsIPrefServiceInternal> prefs = do_GetService("@mozilla.org/preferences-service;1");
-    if (!prefs)
-        return false;
-
-    prefs->ClearContentPref(aPrefName);
-
+    Preferences::ClearContentPref(aPrefName.get());
     return true;
 }
 
 bool
 ContentChild::RecvNotifyAlertsObserver(const nsCString& aType, const nsString& aData)
 {
     for (PRUint32 i = 0; i < mAlertObservers.Length();
          /*we mutate the array during the loop; ++i iff no mutation*/) {
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -46,17 +46,16 @@
 #include "mozilla/net/NeckoParent.h"
 #include "mozilla/Preferences.h"
 #include "nsHashPropertyBag.h"
 #include "nsIFilePicker.h"
 #include "nsIWindowWatcher.h"
 #include "nsIDOMWindow.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefBranch2.h"
-#include "nsIPrefService.h"
 #include "nsIPrefLocalizedString.h"
 #include "nsIObserverService.h"
 #include "nsContentUtils.h"
 #include "nsAutoPtr.h"
 #include "nsCOMPtr.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsChromeRegistryChrome.h"
@@ -456,17 +455,17 @@ ContentParent::IsAlive()
 {
     return mIsAlive;
 }
 
 bool
 ContentParent::RecvReadPrefsArray(InfallibleTArray<PrefTuple> *prefs)
 {
     EnsurePrefService();
-    mPrefService->MirrorPreferences(prefs);
+    Preferences::MirrorPreferences(prefs);
     return true;
 }
 
 bool
 ContentParent::RecvReadFontList(InfallibleTArray<FontListEntry>* retValue)
 {
 #ifdef ANDROID
     gfxAndroidPlatform::GetPlatform()->GetFontList(retValue);
@@ -702,43 +701,19 @@ ContentParent::Observe(nsISupports* aSub
     if (!strcmp(aTopic, "memory-pressure")) {
         unused << SendFlushMemory(nsDependentString(aData));
     }
     // listening for remotePrefs...
     else if (!strcmp(aTopic, "nsPref:changed")) {
         // We know prefs are ASCII here.
         NS_LossyConvertUTF16toASCII strData(aData);
 
-        nsCOMPtr<nsIPrefServiceInternal> prefService =
-          do_GetService("@mozilla.org/preferences-service;1");
-
-        bool prefNeedUpdate;
-        prefService->PrefHasUserValue(strData, &prefNeedUpdate);
-
-        // If the pref does not have a user value, check if it exist on the
-        // default branch or not
-        if (!prefNeedUpdate) {
-          nsCOMPtr<nsIPrefBranch> defaultBranch;
-          nsCOMPtr<nsIPrefService> prefsService = do_QueryInterface(prefService);
-          prefsService->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch));
-
-          PRInt32 prefType = nsIPrefBranch::PREF_INVALID;
-          defaultBranch->GetPrefType(strData.get(), &prefType);
-          prefNeedUpdate = (prefType != nsIPrefBranch::PREF_INVALID);
-        }
-
+        PrefTuple pref;
+        bool prefNeedUpdate = Preferences::MirrorPreference(strData.get(), &pref);
         if (prefNeedUpdate) {
-          // Pref was created, or previously existed and its value
-          // changed.
-          PrefTuple pref;
-#ifdef DEBUG
-          nsresult rv =
-#endif
-          prefService->MirrorPreference(strData, &pref);
-          NS_ASSERTION(NS_SUCCEEDED(rv), "Pref has value but can't mirror?");
           if (!SendPreferenceUpdate(pref)) {
               return NS_ERROR_NOT_AVAILABLE;
           }
         } else {
           // Pref wasn't found.  It was probably removed.
           if (!SendClearUserPreference(strData)) {
               return NS_ERROR_NOT_AVAILABLE;
           }
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -236,17 +236,17 @@ private:
 
     // This is a cache of all of the memory reporters
     // registered in the child process.  To update this, one
     // can broadcast the topic "child-memory-reporter-request" using
     // the nsIObserverService.
     nsCOMArray<nsIMemoryReporter> mMemoryReporters;
 
     bool mIsAlive;
-    nsCOMPtr<nsIPrefServiceInternal> mPrefService;
+    nsCOMPtr<nsIPrefService> mPrefService;
 
     bool mSendPermissionUpdates;
 
     nsRefPtr<nsFrameMessageManager> mMessageManager;
 
     friend class CrashReporterParent;
 };
 
--- a/modules/libpref/public/Preferences.h
+++ b/modules/libpref/public/Preferences.h
@@ -60,25 +60,23 @@ class nsAdoptingCString;
 #ifndef have_PrefChangedFunc_typedef
 typedef int (*PR_CALLBACK PrefChangedFunc)(const char *, void *);
 #define have_PrefChangedFunc_typedef
 #endif
 
 namespace mozilla {
 
 class Preferences : public nsIPrefService,
-                    public nsIPrefServiceInternal,
                     public nsIObserver,
                     public nsIPrefBranchInternal,
                     public nsSupportsWeakReference
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPREFSERVICE
-  NS_DECL_NSIPREFSERVICEINTERNAL
   NS_FORWARD_NSIPREFBRANCH(sRootBranch->)
   NS_FORWARD_NSIPREFBRANCH2(sRootBranch->)
   NS_DECL_NSIOBSERVER
 
   Preferences();
   virtual ~Preferences();
 
   nsresult Init();
@@ -336,16 +334,24 @@ public:
   static nsresult GetDefaultLocalizedCString(const char* aPref,
                                              nsACString* aResult);
   static nsresult GetDefaultLocalizedString(const char* aPref,
                                             nsAString* aResult);
 
   static nsresult GetDefaultComplex(const char* aPref, const nsIID &aType,
                                     void** aResult);
 
+  // Used to synchronise preferences between chrome and content processes.
+  static nsresult ReadExtensionPrefs(nsIFile *aFile);
+  static void MirrorPreferences(nsTArray<PrefTuple,
+                                nsTArrayInfallibleAllocator> *aArray);
+  static bool MirrorPreference(const char *aPref, PrefTuple *aTuple);
+  static void ClearContentPref(const char *aPref);
+  static void SetPreference(const PrefTuple *aTuple);
+
 protected:
   nsresult NotifyServiceObservers(const char *aSubject);
   nsresult UseDefaultPrefFile();
   nsresult UseUserPrefFile();
   nsresult ReadAndOwnUserPrefFile(nsIFile *aFile);
   nsresult ReadAndOwnSharedUserPrefFile(nsIFile *aFile);
   nsresult SavePrefFileInternal(nsIFile* aFile);
   nsresult WritePrefFile(nsIFile* aFile);
--- a/modules/libpref/public/nsIPrefService.idl
+++ b/modules/libpref/public/nsIPrefService.idl
@@ -158,39 +158,16 @@ interface nsIPrefService : nsISupports
    * @return nsIPrefBranch The object representing the requested default branch.
    *
    * @see getBranch
    */
   nsIPrefBranch getDefaultBranch(in string aPrefRoot);
 
 };
 
-[scriptable, uuid(08c8cd2f-8345-45ee-938d-37ee6d3661b2)]
-interface nsIPrefServiceInternal : nsISupports
-{
-  /**
-   * Called to read the preferences in the defaults/preferences/
-   * directory of a zip file
-   *
-   * @param aFile The zip file to be read.
-   *
-   * @return NS_OK The file was read and processed.
-   * @return Other The file failed to read or contained invalid data.
-   *
-   * @see readUserPrefs
-   */
-  void readExtensionPrefs(in nsILocalFile aFile);
-
-  [noscript] void mirrorPreferences(in nsPreferencesArrayPtr aArray);
-  [noscript] void mirrorPreference(in ACString aPrefName, in nsPreferencePtr aPref);
-  [noscript] boolean prefHasUserValue(in ACString aPrefName);
-  [noscript] void setPreference(in nsPreferencePtrConst aPref);
-  [noscript] void clearContentPref(in ACString aPrefName);
-};
-
 %{C++
 
 #define NS_PREFSERVICE_CID                             \
   { /* {1cd91b88-1dd2-11b2-92e1-ed22ed298000} */       \
     0x91ca2441,                                        \
     0x050f,                                            \
     0x4f7c,                                            \
     { 0x9d, 0xf8, 0x75, 0xb4, 0x0e, 0xa4, 0x01, 0x56 } \
--- a/modules/libpref/src/Preferences.cpp
+++ b/modules/libpref/src/Preferences.cpp
@@ -298,17 +298,16 @@ Preferences::~Preferences()
  */
 
 NS_IMPL_THREADSAFE_ADDREF(Preferences)
 NS_IMPL_THREADSAFE_RELEASE(Preferences)
 
 NS_INTERFACE_MAP_BEGIN(Preferences)
     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefService)
     NS_INTERFACE_MAP_ENTRY(nsIPrefService)
-    NS_INTERFACE_MAP_ENTRY(nsIPrefServiceInternal)
     NS_INTERFACE_MAP_ENTRY(nsIObserver)
     NS_INTERFACE_MAP_ENTRY(nsIPrefBranch)
     NS_INTERFACE_MAP_ENTRY(nsIPrefBranch2)
     NS_INTERFACE_MAP_ENTRY(nsIPrefBranchInternal)
     NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END
 
 
@@ -458,19 +457,18 @@ Preferences::SavePrefFile(nsIFile *aFile
   if (XRE_GetProcessType() == GeckoProcessType_Content) {
     NS_ERROR("cannot save prefs from content process");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   return SavePrefFileInternal(aFile);
 }
 
-/* part of nsIPrefServiceInternal */
-NS_IMETHODIMP
-Preferences::ReadExtensionPrefs(nsILocalFile *aFile)
+nsresult
+Preferences::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);
 
@@ -508,57 +506,45 @@ Preferences::ReadExtensionPrefs(nsILocal
         break;
       }
     }
     PREF_FinalizeParseState(&ps);
   }
   return rv;
 }
 
-NS_IMETHODIMP
-Preferences::PrefHasUserValue(const nsACString& aPrefName, bool* aHasValue)
+void
+Preferences::SetPreference(const PrefTuple *aPref)
 {
-  *aHasValue = PREF_HasUserPref(aPrefName.BeginReading());
-  return NS_OK;
+  pref_SetPrefTuple(*aPref, true);
 }
 
-NS_IMETHODIMP
-Preferences::SetPreference(const PrefTuple *aPref)
+void
+Preferences::ClearContentPref(const char *aPref)
 {
-  return pref_SetPrefTuple(*aPref, true);
+  PREF_ClearUserPref(aPref);
 }
 
-NS_IMETHODIMP
-Preferences::ClearContentPref(const nsACString& aPrefName)
+bool
+Preferences::MirrorPreference(const char *aPref, PrefTuple *aTuple)
 {
-  return PREF_ClearUserPref(aPrefName.BeginReading());
+  PrefHashEntry *entry = pref_HashTableLookup(aPref);
+  if (!entry)
+    return false;
+
+  pref_GetTupleFromEntry(entry, aTuple);
+  return true;
 }
 
-NS_IMETHODIMP
-Preferences::MirrorPreference(const nsACString& aPrefName, PrefTuple *aPref)
-{
-  PrefHashEntry *pref = pref_HashTableLookup(PromiseFlatCString(aPrefName).get());
-
-  if (!pref)
-    return NS_ERROR_NOT_AVAILABLE;
-
-  pref_GetTupleFromEntry(pref, aPref);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
+void
 Preferences::MirrorPreferences(nsTArray<PrefTuple,
                                         nsTArrayInfallibleAllocator> *aArray)
 {
   aArray->SetCapacity(PL_DHASH_TABLE_SIZE(&gHashTable));
-
   PL_DHashTableEnumerate(&gHashTable, pref_MirrorPrefs, aArray);
-
-  return NS_OK;
 }
 
 NS_IMETHODIMP
 Preferences::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
 {
   nsresult rv;
 
   if ((nsnull != aPrefRoot) && (*aPrefRoot != '\0')) {
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -44,17 +44,16 @@
 
 #include "jsapi.h"
 
 #include "nsIJSContextStack.h"
 #include "nsIDirectoryEnumerator.h"
 #include "nsILocalFile.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
-#include "nsIPrefService.h"
 #include "nsIProfileChangeStatus.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIToolkitChromeRegistry.h"
 
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsXULAppAPI.h"
@@ -63,16 +62,17 @@
 #include "nsINIParser.h"
 #include "nsDependentString.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsEnumeratorUtils.h"
 #include "nsReadableUtils.h"
 #include "mozilla/Services.h"
 #include "mozilla/Omnijar.h"
+#include "mozilla/Preferences.h"
 
 #include <stdlib.h>
 
 #ifdef XP_WIN
 #include <windows.h>
 #include <shlobj.h>
 #endif
 #ifdef XP_MACOSX
@@ -503,17 +503,17 @@ nsXREDirProvider::GetFiles(const char* a
 static void
 LoadExtensionDirectories(nsINIParser &parser,
                          const char *aSection,
                          nsCOMArray<nsIFile> &aDirectories,
                          NSLocationType aType)
 {
   nsresult rv;
   PRInt32 i = 0;
-  nsCOMPtr<nsIPrefServiceInternal> prefs =
+  nsCOMPtr<nsIPrefService> prefs =
     do_GetService("@mozilla.org/preferences-service;1");
   do {
     nsCAutoString buf("Extension");
     buf.AppendInt(i++);
 
     nsCAutoString path;
     rv = parser.GetString(aSection, buf.get(), path);
     if (NS_FAILED(rv))
@@ -526,17 +526,17 @@ LoadExtensionDirectories(nsINIParser &pa
     rv = dir->SetPersistentDescriptor(path);
     if (NS_FAILED(rv))
       continue;
 
     if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_CSTRING(".xpi"))) {
       XRE_AddJarManifestLocation(aType, dir);
       if (!prefs)
         continue;
-      prefs->ReadExtensionPrefs(dir);
+      mozilla::Preferences::ReadExtensionPrefs(dir);
     }
     else {
       aDirectories.AppendObject(dir);
 
       nsCOMPtr<nsILocalFile> manifest =
         CloneAndAppend(dir, "chrome.manifest");
       XRE_AddManifestLocation(aType, manifest);
     }