Bug 666903 uriloader should use mozilla::Preferences r=bz
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 01 Jul 2011 15:26:10 +0900
changeset 72896 d970a2b0f2c25a702754ffb13f9bd9c6bdab189f
parent 72895 26ecb4d6c3d0ea6d879940eae4f320b7dc2d83e1
child 72897 5577368c8692e8ef8001fa046541eb840e9a8ae2
push id45
push userffxbld
push dateThu, 22 Sep 2011 17:29:26 +0000
treeherdermozilla-release@b3273da80b44 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs666903
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 666903 uriloader should use mozilla::Preferences r=bz
uriloader/exthandler/nsExternalHelperAppService.cpp
uriloader/exthandler/os2/nsMIMEInfoOS2.cpp
uriloader/exthandler/os2/nsMIMEInfoOS2.h
uriloader/exthandler/os2/nsOSHelperAppService.cpp
uriloader/exthandler/os2/nsOSHelperAppService.h
uriloader/exthandler/unix/nsOSHelperAppService.cpp
uriloader/exthandler/unix/nsOSHelperAppService.h
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
uriloader/prefetch/nsPrefetchService.cpp
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -113,17 +113,16 @@
 #include "nsEscape.h"
 
 #include "nsIStringBundle.h" // XXX needed to localize error msgs
 #include "nsIPrompt.h"
 
 #include "nsITextToSubURI.h" // to unescape the filename
 #include "nsIMIMEHeaderParam.h"
 
-#include "nsIPrefService.h"
 #include "nsIWindowWatcher.h"
 
 #include "nsIDownloadHistory.h" // to mark downloads as visited
 #include "nsDocShellCID.h"
 
 #include "nsIDOMWindow.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsIDocShell.h"
@@ -144,16 +143,20 @@
 #include "nsIDocShellTreeOwner.h"
 #include "nsIDocShellTreeItem.h"
 #include "ExternalHelperAppChild.h"
 
 #ifdef ANDROID
 #include "AndroidBridge.h"
 #endif
 
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
+
 // Buffer file writes in 32kb chunks
 #define BUFFERED_OUTPUT_SIZE (1024 * 32)
 
 // Download Folder location constants
 #define NS_PREF_DOWNLOAD_DIR        "browser.download.dir"
 #define NS_PREF_DOWNLOAD_FOLDERLIST "browser.download.folderList"
 enum {
   NS_FOLDER_VALUE_DESKTOP = 0
@@ -167,19 +170,20 @@ PRLogModuleInfo* nsExternalHelperAppServ
 
 // Using level 3 here because the OSHelperAppServices use a log level
 // of PR_LOG_DEBUG (4), and we want less detailed output here
 // Using 3 instead of PR_LOG_WARN because we don't output warnings
 #undef LOG
 #define LOG(args) PR_LOG(mLog, 3, args)
 #define LOG_ENABLED() PR_LOG_TEST(mLog, 3)
 
-static const char NEVER_ASK_PREF_BRANCH[] = "browser.helperApps.neverAsk.";
-static const char NEVER_ASK_FOR_SAVE_TO_DISK_PREF[] = "saveToDisk";
-static const char NEVER_ASK_FOR_OPEN_FILE_PREF[]    = "openFile";
+static const char NEVER_ASK_FOR_SAVE_TO_DISK_PREF[] =
+  "browser.helperApps.neverAsk.saveToDisk";
+static const char NEVER_ASK_FOR_OPEN_FILE_PREF[] =
+  "browser.helperApps.neverAsk.openFile";
 
 /**
  * Contains a pointer to the helper app service, set in its constructor
  */
 nsExternalHelperAppService* gExtProtSvc;
 
 // Helper functions for Content-Disposition headers
 
@@ -415,31 +419,25 @@ static PRBool GetFilenameAndExtensionFro
  * helper apps use the downloads directory, this should be kept in
  * sync with nsDownloadManager.cpp
  */
 static nsresult GetDownloadDirectory(nsIFile **_directory)
 {
   nsCOMPtr<nsIFile> dir;
 #ifdef XP_MACOSX
   // On OS X, we first try to get the users download location, if it's set.
-  nsCOMPtr<nsIPrefBranch> prefs =
-    do_GetService(NS_PREFSERVICE_CONTRACTID);
-  NS_ENSURE_TRUE(prefs, NS_ERROR_UNEXPECTED);
-
-  PRInt32 folderValue = -1;
-  (void) prefs->GetIntPref(NS_PREF_DOWNLOAD_FOLDERLIST, &folderValue);
-  switch (folderValue) {
+  switch (Preferences::GetInt(NS_PREF_DOWNLOAD_FOLDERLIST, -1)) {
     case NS_FOLDER_VALUE_DESKTOP:
       (void) NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(dir));
       break;
     case NS_FOLDER_VALUE_CUSTOM:
       {
-        (void) prefs->GetComplexValue(NS_PREF_DOWNLOAD_DIR,
-                                      NS_GET_IID(nsILocalFile),
-                                      getter_AddRefs(dir));
+        Preferences::GetComplex(NS_PREF_DOWNLOAD_DIR,
+                                NS_GET_IID(nsILocalFile),
+                                getter_AddRefs(dir));
         if (!dir) break;
 
         // We have the directory, and now we need to make sure it exists
         PRBool dirExists = PR_FALSE;
         (void) dir->Exists(&dirExists);
         if (dirExists) break;
 
         nsresult rv = dir->Create(nsIFile::DIRECTORY_TYPE, 0755);
@@ -935,45 +933,33 @@ NS_IMETHODIMP nsExternalHelperAppService
   }
 
   // if not, fall back on an os-based handler
   return OSProtocolHandlerExists(aProtocolScheme, aHandlerExists);
 }
 
 NS_IMETHODIMP nsExternalHelperAppService::IsExposedProtocol(const char * aProtocolScheme, PRBool * aResult)
 {
+  // check the per protocol setting first.  it always takes precedence.
+  // if not set, then use the global setting.
+
+  nsCAutoString prefName("network.protocol-handler.expose.");
+  prefName += aProtocolScheme;
+  PRBool val;
+  if (NS_SUCCEEDED(Preferences::GetBool(prefName.get(), &val))) {
+    *aResult = val;
+    return NS_OK;
+  }
+
   // by default, no protocol is exposed.  i.e., by default all link clicks must
   // go through the external protocol service.  most applications override this
   // default behavior.
-  *aResult = PR_FALSE;
-
-  nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-  if (prefs)
-  {
-    PRBool val;
-    nsresult rv;
-
-    // check the per protocol setting first.  it always takes precidence.
-    // if not set, then use the global setting.
-
-    nsCAutoString name;
-    name = NS_LITERAL_CSTRING("network.protocol-handler.expose.")
-         + nsDependentCString(aProtocolScheme);
-    rv = prefs->GetBoolPref(name.get(), &val);
-    if (NS_SUCCEEDED(rv))
-    {
-      *aResult = val;
-    }
-    else
-    {
-      rv = prefs->GetBoolPref("network.protocol-handler.expose-all", &val);
-      if (NS_SUCCEEDED(rv) && val)
-        *aResult = PR_TRUE;
-    }
-  }
+  *aResult =
+    Preferences::GetBool("network.protocol-handler.expose-all", PR_FALSE);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP nsExternalHelperAppService::LoadUrl(nsIURI * aURL)
 {
   return LoadURI(aURL, nsnull);
 }
 
@@ -1005,32 +991,31 @@ nsExternalHelperAppService::LoadURI(nsIU
   nsresult rv = ios->NewURI(spec, nsnull, nsnull, getter_AddRefs(uri));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCAutoString scheme;
   uri->GetScheme(scheme);
   if (scheme.IsEmpty())
     return NS_OK; // must have a scheme
 
-  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (!prefs)
-    return NS_OK; // deny if we can't check prefs
-
   // Deny load if the prefs say to do so
   nsCAutoString externalPref(kExternalProtocolPrefPrefix);
   externalPref += scheme;
   PRBool allowLoad  = PR_FALSE;
-  rv = prefs->GetBoolPref(externalPref.get(), &allowLoad);
-  if (NS_FAILED(rv))
-  {
+  if (NS_FAILED(Preferences::GetBool(externalPref.get(), &allowLoad))) {
     // no scheme-specific value, check the default
-    rv = prefs->GetBoolPref(kExternalProtocolDefaultPref, &allowLoad);
+    if (NS_FAILED(Preferences::GetBool(kExternalProtocolDefaultPref,
+                                       &allowLoad))) {
+      return NS_OK; // missing default pref
+    }
   }
-  if (NS_FAILED(rv) || !allowLoad)
-    return NS_OK; // explicitly denied or missing default pref
+
+  if (!allowLoad) {
+    return NS_OK; // explicitly denied
+  }
 
  
   nsCOMPtr<nsIHandlerInfo> handler;
   rv = GetProtocolHandlerInfo(scheme, getter_AddRefs(handler));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsHandlerInfoAction preferredAction;
   handler->GetPreferredAction(&preferredAction);
@@ -1162,30 +1147,25 @@ nsExternalHelperAppService::SetProtocolH
   // this type isn't in our database, so we've only got an OS default handler,
   // if one exists
 
   if (aOSHandlerExists) {
     // we've got a default, so use it
     aHandlerInfo->SetPreferredAction(nsIHandlerInfo::useSystemDefault);
 
     // whether or not to ask the user depends on the warning preference
-    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-    if (!prefs)
-      return NS_OK; // deny if we can't check prefs
-
     nsCAutoString scheme;
     aHandlerInfo->GetType(scheme);
     
     nsCAutoString warningPref(kExternalWarningPrefPrefix);
     warningPref += scheme;
-    PRBool warn = PR_TRUE;
-    nsresult rv = prefs->GetBoolPref(warningPref.get(), &warn);
-    if (NS_FAILED(rv)) {
+    PRBool warn;
+    if (NS_FAILED(Preferences::GetBool(warningPref.get(), &warn))) {
       // no scheme-specific value, check the default
-      prefs->GetBoolPref(kExternalWarningDefaultPref, &warn);
+      warn = Preferences::GetBool(kExternalWarningDefaultPref, PR_TRUE);
     }
     aHandlerInfo->SetAlwaysAskBeforeHandling(warn);
   } else {
     // If no OS default existed, we set the preferred action to alwaysAsk. 
     // This really means not initialized (i.e. there's no available handler)
     // to all the code...
     aHandlerInfo->SetPreferredAction(nsIHandlerInfo::alwaysAsk);
   }
@@ -1271,27 +1251,17 @@ nsExternalAppHandler::nsExternalAppHandl
     mTempFileExtension.ReplaceChar(unsafeBidiCharacters[i], '_');
   }
   
   // Make sure extension is correct.
   EnsureSuggestedFileName();
 
   gExtProtSvc->AddRef();
 
-  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (!prefs)
-    return;
-
-  mBufferSize = 4096;
-  PRInt32 size;
-  nsresult rv = prefs->GetIntPref("network.buffer.cache.size", &size);
-  if (NS_SUCCEEDED(rv)) {
-    mBufferSize = size;
-  }
-
+  mBufferSize = Preferences::GetUint("network.buffer.cache.size", 4096);
   mDataBuffer = (char*) malloc(mBufferSize);
   if (!mDataBuffer)
     return;
 }
 
 nsExternalAppHandler::~nsExternalAppHandler()
 {
   // Not using NS_RELEASE, since we don't want to set gExtProtSvc to NULL
@@ -2333,30 +2303,28 @@ nsresult nsExternalAppHandler::OpenWithA
     return NS_OK;
   
   // we only should have gotten here if the on stop request had been fired already.
 
   NS_ASSERTION(mStopRequestIssued, "uhoh, how did we get here if we aren't done getting data?");
   // if a stop request was already issued then proceed with launching the application.
   if (mStopRequestIssued)
   {
-    PRBool deleteTempFileOnExit;
-    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-    if (!prefs || NS_FAILED(prefs->GetBoolPref(
-        "browser.helperApps.deleteTempFileOnExit", &deleteTempFileOnExit))) {
-      // No prefservice or no pref set; use default value
+
+    // Note for the default value:
+    // Mac users have been very verbal about temp files being deleted on
+    // app exit - they don't like it - but we'll continue to do this on
+    // other platforms for now.
+    PRBool deleteTempFileOnExit =
+      Preferences::GetBool("browser.helperApps.deleteTempFileOnExit",
 #if !defined(XP_MACOSX)
-      // Mac users have been very verbal about temp files being deleted on
-      // app exit - they don't like it - but we'll continue to do this on
-      // other platforms for now.
-      deleteTempFileOnExit = PR_TRUE;
+                           PR_TRUE);
 #else
-      deleteTempFileOnExit = PR_FALSE;
+                           PR_FALSE);
 #endif
-    }
 
     // make the tmp file readonly so users won't edit it and lose the changes
     // only if we're going to delete the file
     if (deleteTempFileOnExit || gExtProtSvc->InPrivateBrowsing())
       mFinalFileDestination->SetPermissions(0400);
 
     rv = mMimeInfo->LaunchWithFile(mFinalFileDestination);
     if (NS_FAILED(rv))
@@ -2523,38 +2491,28 @@ void nsExternalAppHandler::ProcessAnyRef
      }
      mOriginalChannel = nsnull;
    }
 }
 
 PRBool nsExternalAppHandler::GetNeverAskFlagFromPref(const char * prefName, const char * aContentType)
 {
   // Search the obsolete pref strings.
-  nsresult rv;
-  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-  nsCOMPtr<nsIPrefBranch> prefBranch;
-  if (prefs)
-    rv = prefs->GetBranch(NEVER_ASK_PREF_BRANCH, getter_AddRefs(prefBranch));
-  if (NS_SUCCEEDED(rv) && prefBranch)
-  {
-    nsXPIDLCString prefCString;
-    nsCAutoString prefValue;
-    rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
-    if (NS_SUCCEEDED(rv) && !prefCString.IsEmpty())
-    {
-      NS_UnescapeURL(prefCString);
-      nsACString::const_iterator start, end;
-      prefCString.BeginReading(start);
-      prefCString.EndReading(end);
-      if (CaseInsensitiveFindInReadable(nsDependentCString(aContentType), start, end))
-        return PR_FALSE;
-    }
+  nsAdoptingCString prefCString = Preferences::GetCString(prefName);
+  if (prefCString.IsEmpty()) {
+    // Default is true, if not found in the pref string.
+    return PR_TRUE;
   }
-  // Default is true, if not found in the pref string.
-  return PR_TRUE;
+
+  NS_UnescapeURL(prefCString);
+  nsACString::const_iterator start, end;
+  prefCString.BeginReading(start);
+  prefCString.EndReading(end);
+  return !CaseInsensitiveFindInReadable(nsDependentCString(aContentType),
+                                        start, end);
 }
 
 nsresult nsExternalAppHandler::MaybeCloseWindow()
 {
   nsCOMPtr<nsIDOMWindow> window(do_GetInterface(mWindowContext));
   nsCOMPtr<nsIDOMWindowInternal> internalWindow = do_QueryInterface(window);
   NS_ENSURE_STATE(internalWindow);
 
--- a/uriloader/exthandler/os2/nsMIMEInfoOS2.cpp
+++ b/uriloader/exthandler/os2/nsMIMEInfoOS2.cpp
@@ -53,16 +53,19 @@
 #include "nsReadableUtils.h"
 #include "nsIProcess.h"
 #include "nsNetUtil.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIVariant.h"
 #include "nsArrayEnumerator.h"
 #include "nsIRwsService.h"
 #include <stdlib.h>
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 //------------------------------------------------------------------------
 
 #define SALT_SIZE 8
 #define TABLE_SIZE 36
 static const PRUnichar table[] = 
   { 'a','b','c','d','e','f','g','h','i','j',
     'k','l','m','n','o','p','q','r','s','t',
@@ -291,48 +294,39 @@ void nsMIMEInfoOS2::SetDefaultAppHandle(
   return;
 }
 
 //------------------------------------------------------------------------
 
 nsresult nsMIMEInfoOS2::LoadUriInternal(nsIURI *aURL)
 {
   nsresult rv;
-  nsCOMPtr<nsIPrefService> thePrefsService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  if (!thePrefsService) {
-    return NS_ERROR_FAILURE;
-  }
+  NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
 
   /* Convert SimpleURI to StandardURL */
   nsCOMPtr<nsIURI> uri = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
   if (NS_FAILED(rv)) {
     return NS_ERROR_FAILURE;
   }
   nsCAutoString urlSpec;
   aURL->GetSpec(urlSpec);
   uri->SetSpec(urlSpec);
 
   /* Get the protocol so we can look up the preferences */
   nsCAutoString uProtocol;
   uri->GetScheme(uProtocol);
 
-  nsCAutoString prefName;
-  prefName = NS_LITERAL_CSTRING("applications.") + uProtocol;
-
-  nsCOMPtr<nsIPrefBranch> prefBranch;
-  rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch));
-  nsXPIDLCString prefString;
-  if (NS_SUCCEEDED(rv)) {
-    rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(prefString));
-  }
+  nsCAutoString branchName = NS_LITERAL_CSTRING("applications.") + uProtocol;
+  nsCAutoString prefName = branchName + branchName;
+  nsAdoptingCString prefString = Preferences::GetCString(prefName.get());
 
   nsCAutoString applicationName;
   nsCAutoString parameters;
 
-  if (NS_FAILED(rv) || prefString.IsEmpty()) {
+  if (prefString.IsEmpty()) {
     char szAppFromINI[CCHMAXPATH];
     char szParamsFromINI[MAXINIPARAMLENGTH];
     /* did OS2.INI contain application? */
     rv = GetApplicationAndParametersFromINI(uProtocol,
                                             szAppFromINI, sizeof(szAppFromINI),
                                             szParamsFromINI, sizeof(szParamsFromINI));
     if (NS_SUCCEEDED(rv)) {
       applicationName = szAppFromINI;
@@ -380,67 +374,68 @@ nsresult nsMIMEInfoOS2::LoadUriInternal(
   NS_NAMED_LITERAL_CSTRING(msgid, "%msgid%");
   NS_NAMED_LITERAL_CSTRING(channel, "%channel%");
 
   PRBool replaced = PR_FALSE;
   if (applicationName.IsEmpty() && parameters.IsEmpty()) {
     /* Put application name in parameters */
     applicationName.Append(prefString);
 
-    prefName.Append(".");
-    nsCOMPtr<nsIPrefBranch> prefBranch;
-    rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch));
-    if (NS_SUCCEEDED(rv) && prefBranch) {
-      rv = prefBranch->GetCharPref("parameters", getter_Copies(prefString));
-      /* If parameters have been specified, use them instead of the separate entities */
-      if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-        parameters.Append(" ");
-        parameters.Append(prefString);
+    branchName.Append(".");
+    prefName = branchName + NS_LITERAL_CSTRING("parameters");
+    prefString = Preferences::GetCString(prefName.get());
+    /* If parameters have been specified, use them instead of the separate entities */
+    if (!prefString.IsEmpty()) {
+      parameters.Append(" ");
+      parameters.Append(prefString);
 
-        PRInt32 pos = parameters.Find(url.get());
-        if (pos != kNotFound) {
-          nsCAutoString uURL;
-          aURL->GetSpec(uURL);
-          NS_UnescapeURL(uURL);
-          uURL.Cut(0, uProtocol.Length()+1);
-          parameters.Replace(pos, url.Length(), uURL);
-          replaced = PR_TRUE;
+      PRInt32 pos = parameters.Find(url.get());
+      if (pos != kNotFound) {
+        nsCAutoString uURL;
+        aURL->GetSpec(uURL);
+        NS_UnescapeURL(uURL);
+        uURL.Cut(0, uProtocol.Length()+1);
+        parameters.Replace(pos, url.Length(), uURL);
+        replaced = PR_TRUE;
+      }
+    } else {
+      /* port */
+      if (!uPort.IsEmpty()) {
+        prefName = branchName + NS_LITERAL_CSTRING("port");
+        prefString = Preferences::GetCString(prefName.get());
+        if (!prefString.IsEmpty()) {
+          parameters.Append(" ");
+          parameters.Append(prefString);
         }
-      } else {
-        /* port */
-        if (!uPort.IsEmpty()) {
-          rv = prefBranch->GetCharPref("port", getter_Copies(prefString));
-          if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-            parameters.Append(" ");
-            parameters.Append(prefString);
-          }
+      }
+      /* username */
+      if (!uUsername.IsEmpty()) {
+        prefName = branchName + NS_LITERAL_CSTRING("username");
+        prefString = Preferences::GetCString(prefName.get());
+        if (!prefString.IsEmpty()) {
+          parameters.Append(" ");
+          parameters.Append(prefString);
         }
-        /* username */
-        if (!uUsername.IsEmpty()) {
-          rv = prefBranch->GetCharPref("username", getter_Copies(prefString));
-          if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-            parameters.Append(" ");
-            parameters.Append(prefString);
-          }
+      }
+      /* password */
+      if (!uPassword.IsEmpty()) {
+        prefName = branchName + NS_LITERAL_CSTRING("password");
+        prefString = Preferences::GetCString(prefName.get());
+        if (!prefString.IsEmpty()) {
+          parameters.Append(" ");
+          parameters.Append(prefString);
         }
-        /* password */
-        if (!uPassword.IsEmpty()) {
-          rv = prefBranch->GetCharPref("password", getter_Copies(prefString));
-          if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-            parameters.Append(" ");
-            parameters.Append(prefString);
-          }
-        }
-        /* host */
-        if (!uHost.IsEmpty()) {
-          rv = prefBranch->GetCharPref("host", getter_Copies(prefString));
-          if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-            parameters.Append(" ");
-            parameters.Append(prefString);
-          }
+      }
+      /* host */
+      if (!uHost.IsEmpty()) {
+        prefName = branchName + NS_LITERAL_CSTRING("host");
+        prefString = Preferences::GetCString(prefName.get());
+        if (!prefString.IsEmpty()) {
+          parameters.Append(" ");
+          parameters.Append(prefString);
         }
       }
     }
   }
 
 #ifdef DEBUG_peter
   printf("uURL=%s\n", uURL.get());
   printf("uUsername=%s\n", uUsername.get());
--- a/uriloader/exthandler/os2/nsMIMEInfoOS2.h
+++ b/uriloader/exthandler/os2/nsMIMEInfoOS2.h
@@ -39,18 +39,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsMIMEInfoOS2_h_
 #define nsMIMEInfoOS2_h_
 
 #include "nsMIMEInfoImpl.h"
 #include "nsIPropertyBag.h"
 
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
 #include "nsNetCID.h"
 #include "nsEscape.h"
 
 #define INCL_DOS
 #define INCL_DOSMISC
 #define INCL_DOSERRORS
 #define INCL_WINSHELLDATA
 #include <os2.h>
--- a/uriloader/exthandler/os2/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/os2/nsOSHelperAppService.cpp
@@ -58,18 +58,21 @@
 #include "nsCRT.h"
 #include "prenv.h"      // for PR_GetEnv()
 #include "nsMIMEInfoOS2.h"
 #include "nsAutoPtr.h"
 #include "nsIRwsService.h"
 #include "nsIStringBundle.h"
 #include "nsLocalHandlerApp.h"
 #include "mozilla/Services.h"
+#include "mozilla/Preferences.h"
 #include <stdlib.h>     // for system()
 
+using namespace mozilla;
+
 //------------------------------------------------------------------------
 
 // reduces overhead by preventing calls to nsRws when it isn't present
 static PRBool sUseRws = PR_TRUE;
 
 static nsresult
 FindSemicolon(nsAString::const_iterator& aSemicolon_iter,
               const nsAString::const_iterator& aEnd_iter);
@@ -191,115 +194,89 @@ ParseMIMEType(const nsAString::const_ite
 
   return NS_OK;
 }
 
 // static
 nsresult
 nsOSHelperAppService::GetFileLocation(const char* aPrefName,
                                       const char* aEnvVarName,
-                                      PRUnichar** aFileLocation) {
+                                      nsAString& aFileLocation) {
   LOG(("-- GetFileLocation.  Pref: '%s'  EnvVar: '%s'\n",
        aPrefName,
        aEnvVarName));
   NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!");
-  
-  nsresult rv;
-  *aFileLocation = nsnull;
+
+  aFileLocation.Truncate();
   /* The lookup order is:
      1) user pref
      2) env var
      3) pref
   */
-  nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIPrefBranch> prefBranch;
-  rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
 
   /*
     If we have an env var we should check whether the pref is a user
     pref.  If we do not, we don't care.
   */
-  nsCOMPtr<nsISupportsString> prefFileName;
-  PRBool isUserPref = PR_FALSE;
-  prefBranch->PrefHasUserValue(aPrefName, &isUserPref);
-  if (isUserPref) {
-    rv = prefBranch->GetComplexValue(aPrefName,
-                                     NS_GET_IID(nsISupportsString),
-                                     getter_AddRefs(prefFileName));
-    if (NS_SUCCEEDED(rv)) {
-      return prefFileName->ToString(aFileLocation);
-    }
+  if (Preferences::HasUserValue(aPrefName) &&
+      NS_SUCCEEDED(Preferences::GetString(aPrefName, &aFileLocation))) {
+    return NS_OK;
   }
 
   if (aEnvVarName && *aEnvVarName) {
     char* prefValue = PR_GetEnv(aEnvVarName);
     if (prefValue && *prefValue) {
       // the pref is in the system charset and it's a filepath... The
       // natural way to do the charset conversion is by just initing
       // an nsIFile with the native path and asking it for the Unicode
       // version.
       nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = file->InitWithNativePath(nsDependentCString(prefValue));
       NS_ENSURE_SUCCESS(rv, rv);
 
-      nsAutoString unicodePath;
-      rv = file->GetPath(unicodePath);
+      rv = file->GetPath(aFileLocation);
       NS_ENSURE_SUCCESS(rv, rv);
-      
-      *aFileLocation = ToNewUnicode(unicodePath);
-      if (!*aFileLocation)
-        return NS_ERROR_OUT_OF_MEMORY;
       return NS_OK;
     }
   }
-  
-  rv = prefBranch->GetComplexValue(aPrefName,
-                                   NS_GET_IID(nsISupportsString),
-                                   getter_AddRefs(prefFileName));
-  if (NS_SUCCEEDED(rv)) {
-    return prefFileName->ToString(aFileLocation);
-  }
-  
-  return rv;
+
+  return Preferences::GetString(aPrefName, &aFileLocation);
 }
 
 
 /* Get the mime.types file names from prefs and look up info in them
    based on extension */
 // static
 nsresult
 nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
                                                nsAString& aMajorType,
                                                nsAString& aMinorType,
                                                nsAString& aDescription) {
   LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
        NS_LossyConvertUTF16toASCII(aFileExtension).get()));
   nsresult rv = NS_OK;
-  nsXPIDLString mimeFileName;
+  nsAutoString mimeFileName;
 
   rv = GetFileLocation("helpers.private_mime_types_file",
-                       nsnull,
-                       getter_Copies(mimeFileName));
+                       nsnull, mimeFileName);
   if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
     rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
                                                 aFileExtension,
                                                 aMajorType,
                                                 aMinorType,
                                                 aDescription);
   } else {
     rv = NS_ERROR_NOT_AVAILABLE;
   }
   if (NS_FAILED(rv) || aMajorType.IsEmpty()) {
     rv = GetFileLocation("helpers.global_mime_types_file",
-                         nsnull,
-                         getter_Copies(mimeFileName));
+                         nsnull, mimeFileName);
     if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
       rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
                                                   aFileExtension,
                                                   aMajorType,
                                                   aMinorType,
                                                   aDescription);
     } else {
       rv = NS_ERROR_NOT_AVAILABLE;
@@ -501,34 +478,32 @@ nsresult
 nsOSHelperAppService::LookUpExtensionsAndDescription(const nsAString& aMajorType,
                                                      const nsAString& aMinorType,
                                                      nsAString& aFileExtensions,
                                                      nsAString& aDescription) {
   LOG(("-- LookUpExtensionsAndDescription for type '%s/%s'\n",
        NS_LossyConvertUTF16toASCII(aMajorType).get(),
        NS_LossyConvertUTF16toASCII(aMinorType).get()));
   nsresult rv = NS_OK;
-  nsXPIDLString mimeFileName;
+  nsAutoString mimeFileName;
 
   rv = GetFileLocation("helpers.private_mime_types_file",
-                       nsnull,
-                       getter_Copies(mimeFileName));
+                       nsnull, mimeFileName);
   if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
     rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
                                                       aMajorType,
                                                       aMinorType,
                                                       aFileExtensions,
                                                       aDescription);
   } else {
     rv = NS_ERROR_NOT_AVAILABLE;
   }
   if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) {
     rv = GetFileLocation("helpers.global_mime_types_file",
-                         nsnull,
-                         getter_Copies(mimeFileName));
+                         nsnull, mimeFileName);
     if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
       rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
                                                         aMajorType,
                                                         aMinorType,
                                                         aFileExtensions,
                                                         aDescription);
     } else {
       rv = NS_ERROR_NOT_AVAILABLE;
@@ -904,36 +879,34 @@ nsOSHelperAppService::LookUpHandlerAndDe
                                                   nsHashtable& aTypeOptions,
                                                   nsAString& aHandler,
                                                   nsAString& aDescription,
                                                   nsAString& aMozillaFlags) {
   LOG(("-- LookUpHandlerAndDescription for type '%s/%s'\n",
        NS_LossyConvertUTF16toASCII(aMajorType).get(),
        NS_LossyConvertUTF16toASCII(aMinorType).get()));
   nsresult rv = NS_OK;
-  nsXPIDLString mailcapFileName;
+  nsAutoString mailcapFileName;
 
   rv = GetFileLocation("helpers.private_mailcap_file",
-                       "PERSONAL_MAILCAP",
-                       getter_Copies(mailcapFileName));
+                       "PERSONAL_MAILCAP", mailcapFileName);
   if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
     rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
                                                  aMajorType,
                                                  aMinorType,
                                                  aTypeOptions,
                                                  aHandler,
                                                  aDescription,
                                                  aMozillaFlags);
   } else {
     rv = NS_ERROR_NOT_AVAILABLE;
   }
   if (NS_FAILED(rv) || aHandler.IsEmpty()) {
     rv = GetFileLocation("helpers.global_mailcap_file",
-                         "MAILCAP",
-                         getter_Copies(mailcapFileName));
+                         "MAILCAP", mailcapFileName);
     if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
       rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
                                                    aMajorType,
                                                    aMinorType,
                                                    aTypeOptions,
                                                    aHandler,
                                                    aDescription,
                                                    aMozillaFlags);
@@ -1140,32 +1113,26 @@ nsOSHelperAppService::GetHandlerAndDescr
 nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
 {
   LOG(("-- nsOSHelperAppService::OSProtocolHandlerExists for '%s'\n",
        aProtocolScheme));
   *aHandlerExists = PR_FALSE;
 
   /* if applications.protocol is in prefs, then we have an external protocol handler */
   nsresult rv;
-  nsCAutoString prefName;
-  prefName = NS_LITERAL_CSTRING("applications.") + nsDependentCString(aProtocolScheme);
+  nsCAutoString branchName =
+    NS_LITERAL_CSTRING("applications.") + nsDependentCString(aProtocolScheme);
+  nsCAutoString prefName = branchName + branchName;
 
-  nsCOMPtr<nsIPrefService> thePrefsService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  if (NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsIPrefBranch> prefBranch;
-    rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch));
-    if (NS_SUCCEEDED(rv)) {
-      nsXPIDLCString prefString;
-      rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(prefString));
-      *aHandlerExists = NS_SUCCEEDED(rv) && !prefString.IsEmpty();
-      if (*aHandlerExists) {
-        return NS_OK;
-      }
-    }
+  nsAdoptingCString prefString = Preferences::GetCString(prefName.get());
+  *aHandlerExists = !prefString.IsEmpty();
+  if (*aHandlerExists) {
+    return NS_OK;
   }
+
   /* Check the OS/2 INI for the protocol */
   char szAppFromINI[CCHMAXPATH];
   char szParamsFromINI[MAXINIPARAMLENGTH];
   rv = GetApplicationAndParametersFromINI(nsDependentCString(aProtocolScheme),
                                           szAppFromINI, sizeof(szAppFromINI),
                                           szParamsFromINI, sizeof(szParamsFromINI));
   if (NS_SUCCEEDED(rv)) {
     *aHandlerExists = PR_TRUE;
@@ -1637,41 +1604,35 @@ nsOSHelperAppService::GetProtocolHandler
   return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
 {
   nsresult rv;
-  nsCOMPtr<nsIPrefService> thePrefsService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsCAutoString prefName = NS_LITERAL_CSTRING("applications.") + aScheme;
-  nsCOMPtr<nsIPrefBranch> prefBranch;
+  nsCAutoString branchName = NS_LITERAL_CSTRING("applications.") + aScheme;
   nsCAutoString applicationName;
 
-  rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch));
-  if (NS_FAILED(rv)) {
+  nsCAutoString prefName = branchName + branchName;
+  nsAdoptingCString prefString = Preferences::GetCString(prefName.get());
+  if (!prefString) { // failed
     char szAppFromINI[CCHMAXPATH];
     char szParamsFromINI[MAXINIPARAMLENGTH];
     /* did OS2.INI contain application? */
     rv = GetApplicationAndParametersFromINI(aScheme,
                                             szAppFromINI, sizeof(szAppFromINI),
                                             szParamsFromINI, sizeof(szParamsFromINI));
     if (NS_SUCCEEDED(rv)) {
       applicationName = szAppFromINI;
     } else {
       return NS_ERROR_NOT_AVAILABLE;
     }
-  } else {
-    nsXPIDLCString prefString;
-    rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(prefString));
-    if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-      applicationName.Append(prefString);
-    }
+  } else if (!prefString.IsEmpty()) { // succeeded and not empty
+    applicationName.Append(prefString);
   }
 
 
   nsCOMPtr<nsILocalFile> application;
   rv = NS_NewNativeLocalFile(nsDependentCString(applicationName.get()),
                              PR_FALSE,
                              getter_AddRefs(application));
   if (NS_FAILED(rv)) {
--- a/uriloader/exthandler/os2/nsOSHelperAppService.h
+++ b/uriloader/exthandler/os2/nsOSHelperAppService.h
@@ -87,17 +87,17 @@ private:
   // Helper methods which have to access static members
   static nsresult UnescapeCommand(const nsAString& aEscapedCommand,
                                   const nsAString& aMajorType,
                                   const nsAString& aMinorType,
                                   nsHashtable& aTypeOptions,
                                   nsACString& aUnEscapedCommand);
   static nsresult GetFileLocation(const char* aPrefName,
                                   const char* aEnvVarName,
-                                  PRUnichar** aFileLocation);
+                                  nsAString& aFileLocation);
   static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
                                            nsAString& aMajorType,
                                            nsAString& aMinorType,
                                            nsAString& aDescription);
   static nsresult CreateInputStream(const nsAString& aFilename,
                                     nsIFileInputStream ** aFileInputStream,
                                     nsILineInputStream ** aLineInputStream,
                                     nsACString& aBuffer,
--- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp
+++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp
@@ -56,27 +56,28 @@
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsXPIDLString.h"
 #include "nsIURL.h"
 #include "nsIFileStreams.h"
 #include "nsILineInputStream.h"
 #include "nsILocalFile.h"
 #include "nsIProcess.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
 #include "nsNetCID.h"
 #include "nsXPCOM.h"
 #include "nsISupportsPrimitives.h"
 #include "nsHashtable.h"
 #include "nsCRT.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "prenv.h"      // for PR_GetEnv()
 #include "nsAutoPtr.h"
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 #define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args)
 #define LOG_ENABLED() PR_LOG_TEST(mLog, PR_LOG_DEBUG)
 
 static nsresult
 FindSemicolon(nsAString::const_iterator& aSemicolon_iter,
               const nsAString::const_iterator& aEnd_iter);
 static nsresult
@@ -198,106 +199,82 @@ ParseMIMEType(const nsAString::const_ite
 
   return NS_OK;
 }
 
 // static
 nsresult
 nsOSHelperAppService::GetFileLocation(const char* aPrefName,
                                       const char* aEnvVarName,
-                                      PRUnichar** aFileLocation) {
+                                      nsAString& aFileLocation) {
   LOG(("-- GetFileLocation.  Pref: '%s'  EnvVar: '%s'\n",
        aPrefName,
        aEnvVarName));
   NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!");
   
-  nsresult rv;
-  *aFileLocation = nsnull;
+  aFileLocation.Truncate();
   /* The lookup order is:
      1) user pref
      2) env var
      3) pref
   */
-  nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIPrefBranch> prefBranch;
-  rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
 
   /*
     If we have an env var we should check whether the pref is a user
     pref.  If we do not, we don't care.
   */
-  nsCOMPtr<nsISupportsString> prefFileName;
-  PRBool isUserPref = PR_FALSE;
-  prefBranch->PrefHasUserValue(aPrefName, &isUserPref);
-  if (isUserPref) {
-    rv = prefBranch->GetComplexValue(aPrefName,
-                                     NS_GET_IID(nsISupportsString),
-                                     getter_AddRefs(prefFileName));
-    if (NS_SUCCEEDED(rv)) {
-      return prefFileName->ToString(aFileLocation);
-    }
+  if (Preferences::HasUserValue(aPrefName) &&
+      NS_SUCCEEDED(Preferences::GetString(aPrefName, &aFileLocation))) {
+    return NS_OK;
   }
 
   if (aEnvVarName && *aEnvVarName) {
     char* prefValue = PR_GetEnv(aEnvVarName);
     if (prefValue && *prefValue) {
       // the pref is in the system charset and it's a filepath... The
       // natural way to do the charset conversion is by just initing
       // an nsIFile with the native path and asking it for the Unicode
       // version.
+      nsresult rv;
       nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = file->InitWithNativePath(nsDependentCString(prefValue));
       NS_ENSURE_SUCCESS(rv, rv);
 
-      nsAutoString unicodePath;
-      rv = file->GetPath(unicodePath);
+      rv = file->GetPath(aFileLocation);
       NS_ENSURE_SUCCESS(rv, rv);
-      
-      *aFileLocation = ToNewUnicode(unicodePath);
-      if (!*aFileLocation)
-        return NS_ERROR_OUT_OF_MEMORY;
+
       return NS_OK;
     }
   }
-  
-  rv = prefBranch->GetComplexValue(aPrefName,
-                                   NS_GET_IID(nsISupportsString),
-                                   getter_AddRefs(prefFileName));
-  if (NS_SUCCEEDED(rv)) {
-    return prefFileName->ToString(aFileLocation);
-  }
-  
-  return rv;
+
+  return Preferences::GetString(aPrefName, &aFileLocation);
 }
 
 
 /* Get the mime.types file names from prefs and look up info in them
    based on extension */
 // static
 nsresult
 nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
                                                nsAString& aMajorType,
                                                nsAString& aMinorType,
                                                nsAString& aDescription,
                                                PRBool aUserData) {
   LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
        NS_LossyConvertUTF16toASCII(aFileExtension).get()));
   nsresult rv = NS_OK;
-  nsXPIDLString mimeFileName;
+  nsAutoString mimeFileName;
 
   const char* filenamePref = aUserData ?
     "helpers.private_mime_types_file" : "helpers.global_mime_types_file";
   
-  rv = GetFileLocation(filenamePref,
-                       nsnull,
-                       getter_Copies(mimeFileName));
+  rv = GetFileLocation(filenamePref, nsnull, mimeFileName);
   if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
     rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
                                                 aFileExtension,
                                                 aMajorType,
                                                 aMinorType,
                                                 aDescription);
   } else {
     rv = NS_ERROR_NOT_AVAILABLE;
@@ -498,34 +475,31 @@ nsresult
 nsOSHelperAppService::LookUpExtensionsAndDescription(const nsAString& aMajorType,
                                                      const nsAString& aMinorType,
                                                      nsAString& aFileExtensions,
                                                      nsAString& aDescription) {
   LOG(("-- LookUpExtensionsAndDescription for type '%s/%s'\n",
        NS_LossyConvertUTF16toASCII(aMajorType).get(),
        NS_LossyConvertUTF16toASCII(aMinorType).get()));
   nsresult rv = NS_OK;
-  nsXPIDLString mimeFileName;
+  nsAutoString mimeFileName;
 
-  rv = GetFileLocation("helpers.private_mime_types_file",
-                       nsnull,
-                       getter_Copies(mimeFileName));
+  rv = GetFileLocation("helpers.private_mime_types_file", nsnull, mimeFileName);
   if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
     rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
                                                       aMajorType,
                                                       aMinorType,
                                                       aFileExtensions,
                                                       aDescription);
   } else {
     rv = NS_ERROR_NOT_AVAILABLE;
   }
   if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) {
     rv = GetFileLocation("helpers.global_mime_types_file",
-                         nsnull,
-                         getter_Copies(mimeFileName));
+                         nsnull, mimeFileName);
     if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
       rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
                                                         aMajorType,
                                                         aMinorType,
                                                         aFileExtensions,
                                                         aDescription);
     } else {
       rv = NS_ERROR_NOT_AVAILABLE;
@@ -959,26 +933,24 @@ nsOSHelperAppService::DoLookUpHandlerAnd
                                                     nsAString& aHandler,
                                                     nsAString& aDescription,
                                                     nsAString& aMozillaFlags,
                                                     PRBool aUserData) {
   LOG(("-- LookUpHandlerAndDescription for type '%s/%s'\n",
        NS_LossyConvertUTF16toASCII(aMajorType).get(),
        NS_LossyConvertUTF16toASCII(aMinorType).get()));
   nsresult rv = NS_OK;
-  nsXPIDLString mailcapFileName;
+  nsAutoString mailcapFileName;
 
   const char * filenamePref = aUserData ?
     "helpers.private_mailcap_file" : "helpers.global_mailcap_file";
   const char * filenameEnvVar = aUserData ?
     "PERSONAL_MAILCAP" : "MAILCAP";
   
-  rv = GetFileLocation(filenamePref,
-                       filenameEnvVar,
-                       getter_Copies(mailcapFileName));
+  rv = GetFileLocation(filenamePref, filenameEnvVar, mailcapFileName);
   if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
     rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
                                                  aMajorType,
                                                  aMinorType,
                                                  aTypeOptions,
                                                  aHandler,
                                                  aDescription,
                                                  aMozillaFlags);
--- a/uriloader/exthandler/unix/nsOSHelperAppService.h
+++ b/uriloader/exthandler/unix/nsOSHelperAppService.h
@@ -88,17 +88,17 @@ private:
   // Helper methods which have to access static members
   static nsresult UnescapeCommand(const nsAString& aEscapedCommand,
                                   const nsAString& aMajorType,
                                   const nsAString& aMinorType,
                                   nsHashtable& aTypeOptions,
                                   nsACString& aUnEscapedCommand);
   static nsresult GetFileLocation(const char* aPrefName,
                                   const char* aEnvVarName,
-                                  PRUnichar** aFileLocation);
+                                  nsAString& aFileLocation);
   static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
                                            nsAString& aMajorType,
                                            nsAString& aMinorType,
                                            nsAString& aDescription,
                                            PRBool aUserData);
   static nsresult CreateInputStream(const nsAString& aFilename,
                                     nsIFileInputStream ** aFileInputStream,
                                     nsILineInputStream ** aLineInputStream,
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -56,29 +56,30 @@
 #include "nsIDocument.h"
 #include "nsIObserverService.h"
 #include "nsIURL.h"
 #include "nsIWebProgress.h"
 #include "nsICryptoHash.h"
 #include "nsICacheEntryDescriptor.h"
 #include "nsIPermissionManager.h"
 #include "nsIPrincipal.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "prlog.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
+#include "mozilla/Preferences.h"
 
 #include "nsXULAppAPI.h"
 
+using namespace mozilla;
+
 static const PRUint32 kRescheduleLimit = 3;
 
 #if defined(PR_LOGGING)
 //
 // To enable logging (see prlog.h for full details):
 //
 //    set NSPR_LOG_MODULES=nsOfflineCacheUpdate:5
 //    set NSPR_LOG_FILE=offlineupdate.log
@@ -1024,21 +1025,18 @@ nsOfflineManifestItem::CheckNewManifestC
     }
 
     return NS_OK;
 }
 
 void
 nsOfflineManifestItem::ReadStrictFileOriginPolicyPref()
 {
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     mStrictFileOriginPolicy =
-        (!prefs ||
-         NS_FAILED(prefs->GetBoolPref("security.fileuri.strict_origin_policy",
-                                      &mStrictFileOriginPolicy)));
+        Preferences::GetBool("security.fileuri.strict_origin_policy", PR_TRUE);
 }
 
 NS_IMETHODIMP
 nsOfflineManifestItem::OnStartRequest(nsIRequest *aRequest,
                                       nsISupports *aContext)
 {
     nsresult rv;
 
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -59,26 +59,27 @@
 #include "nsIDocument.h"
 #include "nsIObserverService.h"
 #include "nsIURL.h"
 #include "nsIWebProgress.h"
 #include "nsICryptoHash.h"
 #include "nsICacheEntryDescriptor.h"
 #include "nsIPermissionManager.h"
 #include "nsIPrincipal.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStreamUtils.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "prlog.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 static nsOfflineCacheUpdateService *gOfflineCacheUpdateService = nsnull;
 
 typedef mozilla::docshell::OfflineCacheUpdateParent OfflineCacheUpdateParent;
 typedef mozilla::docshell::OfflineCacheUpdateChild OfflineCacheUpdateChild;
 typedef mozilla::docshell::OfflineCacheUpdateGlue OfflineCacheUpdateGlue;
 
 #if defined(PR_LOGGING)
@@ -564,25 +565,21 @@ nsOfflineCacheUpdateService::OfflineAppA
     if (!permissionManager) {
         return NS_OK;
     }
 
     PRUint32 perm;
     permissionManager->TestExactPermission(innerURI, "offline-app", &perm);
 
     if (perm == nsIPermissionManager::UNKNOWN_ACTION) {
-        nsCOMPtr<nsIPrefBranch> branch = aPrefBranch;
-        if (!branch) {
-            branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        }
-        if (branch) {
-            rv = branch->GetBoolPref("offline-apps.allow_by_default", aAllowed);
-            if (NS_FAILED(rv)) {
-                *aAllowed = PR_FALSE;
-            }
+        static const char kPrefName[] = "offline-apps.allow_by_default";
+        if (aPrefBranch) {
+            aPrefBranch->GetBoolPref(kPrefName, aAllowed);
+        } else {
+            *aAllowed = Preferences::GetBool(kPrefName, PR_FALSE);
         }
 
         return NS_OK;
     }
 
     if (perm == nsIPermissionManager::DENY_ACTION) {
         return NS_OK;
     }
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -36,18 +36,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsPrefetchService.h"
 #include "nsICacheSession.h"
 #include "nsICacheService.h"
 #include "nsIServiceManager.h"
 #include "nsICategoryManager.h"
 #include "nsIObserverService.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch2.h"
 #include "nsIDocCharset.h"
 #include "nsIWebProgress.h"
 #include "nsCURILoader.h"
 #include "nsICachingChannel.h"
 #include "nsICacheVisitor.h"
 #include "nsIHttpChannel.h"
 #include "nsIURL.h"
 #include "nsISimpleEnumerator.h"
@@ -56,16 +54,19 @@
 #include "nsXPIDLString.h"
 #include "nsReadableUtils.h"
 #include "nsStreamUtils.h"
 #include "nsAutoPtr.h"
 #include "prtime.h"
 #include "prlog.h"
 #include "plstr.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 #if defined(PR_LOGGING)
 //
 // To enable logging (see prlog.h for full details):
 //
 //    set NSPR_LOG_MODULES=nsPrefetch:5
 //    set NSPR_LOG_FILE=prefetch.log
 //
@@ -409,41 +410,35 @@ nsPrefetchService::nsPrefetchService()
     , mStopCount(0)
     , mHaveProcessed(PR_FALSE)
     , mDisabled(PR_TRUE)
 {
 }
 
 nsPrefetchService::~nsPrefetchService()
 {
+    Preferences::RemoveObserver(this, PREFETCH_PREF);
     // cannot reach destructor if prefetch in progress (listener owns reference
     // to this service)
     EmptyQueue();
 }
 
 nsresult
 nsPrefetchService::Init()
 {
 #if defined(PR_LOGGING)
     if (!gPrefetchLog)
         gPrefetchLog = PR_NewLogModule("nsPrefetch");
 #endif
 
     nsresult rv;
 
     // read prefs and hook up pref observer
-    nsCOMPtr<nsIPrefBranch2> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-    if (NS_SUCCEEDED(rv)) {
-      PRBool enabled;
-      rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
-      if (NS_SUCCEEDED(rv) && enabled)
-        mDisabled = PR_FALSE;
-
-      prefs->AddObserver(PREFETCH_PREF, this, PR_TRUE);
-    }
+    mDisabled = !Preferences::GetBool(PREFETCH_PREF, !mDisabled);
+    Preferences::AddWeakObserver(this, PREFETCH_PREF);
 
     // Observe xpcom-shutdown event
     nsCOMPtr<nsIObserverService> observerService =
       mozilla::services::GetObserverService();
     if (!observerService)
       return NS_ERROR_FAILURE;
 
     rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
@@ -940,20 +935,17 @@ nsPrefetchService::Observe(nsISupports  
     LOG(("nsPrefetchService::Observe [topic=%s]\n", aTopic));
 
     if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
         StopPrefetching();
         EmptyQueue();
         mDisabled = PR_TRUE;
     }
     else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
-        nsCOMPtr<nsIPrefBranch> prefs(do_QueryInterface(aSubject));
-        PRBool enabled;
-        nsresult rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
-        if (NS_SUCCEEDED(rv) && enabled) {
+        if (Preferences::GetBool(PREFETCH_PREF, PR_FALSE)) {
             if (mDisabled) {
                 LOG(("enabling prefetching\n"));
                 mDisabled = PR_FALSE;
                 AddProgressListener();
             }
         } 
         else {
             if (!mDisabled) {