Bug 661101 widget should use mozilla::Preferences r=roc
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 07 Jun 2011 16:38:00 +0900
changeset 71189 9014863a7e2a93d4a45c8ff09e73bfdff58ba292
parent 71188 f4321cdcef371260055dcf51ad195d2c69603228
child 71190 66cbdac564691a2b69c6a6470f4866d4ce9645c6
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs661101
milestone7.0a1
first release with
nightly linux32
9014863a7e2a / 7.0a1 / 20110607030744 / files
nightly linux64
9014863a7e2a / 7.0a1 / 20110607030744 / files
nightly mac
9014863a7e2a / 7.0a1 / 20110607030744 / files
nightly win32
9014863a7e2a / 7.0a1 / 20110607030744 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 661101 widget should use mozilla::Preferences r=roc
layout/generic/nsImageFrame.cpp
layout/generic/nsImageFrame.h
widget/src/android/AndroidBridge.cpp
widget/src/android/GfxInfo.cpp
widget/src/android/nsAppShell.cpp
widget/src/android/nsWindow.cpp
widget/src/cocoa/GfxInfo.mm
widget/src/os2/nsDeviceContextSpecOS2.cpp
widget/src/os2/nsWindow.cpp
widget/src/qt/nsDeviceContextSpecQt.cpp
widget/src/qt/nsWindow.cpp
widget/src/windows/GfxInfo.cpp
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1882,24 +1882,29 @@ NS_IMPL_ISUPPORTS2(nsImageFrame::IconLoa
 static const char* kIconLoadPrefs[] = {
   "browser.display.force_inline_alttext",
   "browser.display.show_image_placeholders",
   nsnull
 };
 
 nsImageFrame::IconLoad::IconLoad()
 {
+  mHasShutdown = PR_FALSE;
   // register observers
   Preferences::AddStrongObservers(this, kIconLoadPrefs);
   GetPrefs();
 }
 
 void
 nsImageFrame::IconLoad::Shutdown()
 {
+  if (mHasShutdown) {
+    return;
+  }
+  mHasShutdown = PR_TRUE;
   Preferences::RemoveObservers(this, kIconLoadPrefs);
   // in case the pref service releases us later
   if (mLoadingImage) {
     mLoadingImage->CancelAndForgetObserver(NS_ERROR_FAILURE);
     mLoadingImage = nsnull;
   }
   if (mBrokenImage) {
     mBrokenImage->CancelAndForgetObserver(NS_ERROR_FAILURE);
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -322,16 +322,20 @@ private:
                     imgIRequest **aRequest);
 
   class IconLoad : public nsIObserver,
                    public imgIDecoderObserver {
     // private class that wraps the data and logic needed for
     // broken image and loading image icons
   public:
     IconLoad();
+    ~IconLoad()
+    {
+      Shutdown();
+    }
 
     void Shutdown();
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
     NS_DECL_IMGICONTAINEROBSERVER
     NS_DECL_IMGIDECODEROBSERVER
 
@@ -354,16 +358,17 @@ private:
     nsTObserverArray<nsImageFrame*> mIconObservers;
 
 
   public:
     nsCOMPtr<imgIRequest> mLoadingImage;
     nsCOMPtr<imgIRequest> mBrokenImage;
     PRPackedBool     mPrefForceInlineAltText;
     PRPackedBool     mPrefShowPlaceholders;
+    PRPackedBool     mHasShutdown;
   };
   
 public:
   static IconLoad* gIconLoad; // singleton pattern: one LoadIcons instance is used
   
   friend class nsDisplayImage;
 };
 
--- a/widget/src/android/AndroidBridge.cpp
+++ b/widget/src/android/AndroidBridge.cpp
@@ -40,18 +40,18 @@
 #include "nsXULAppAPI.h"
 #include <pthread.h>
 #include <prthread.h>
 #include "nsXPCOMStrings.h"
 
 #include "AndroidBridge.h"
 #include "nsAppShell.h"
 #include "nsOSHelperAppService.h"
-#include "nsIPrefService.h"
 #include "nsWindow.h"
+#include "mozilla/Preferences.h"
 
 #ifdef DEBUG
 #define ALOG_BRIDGE(args...) ALOG(args)
 #else
 #define ALOG_BRIDGE(args...)
 #endif
 
 #define IME_FULLSCREEN_PREF "widget.ime.android.landscape_fullscreen"
@@ -244,39 +244,36 @@ AndroidBridge::NotifyIMEEnabled(int aSta
     nsPromiseFlatString actionHint(aActionHint);
 
     jvalue args[4];
     AutoLocalJNIFrame jniFrame(1);
     args[0].i = aState;
     args[1].l = JNI()->NewString(typeHint.get(), typeHint.Length());
     args[2].l = JNI()->NewString(actionHint.get(), actionHint.Length());
     args[3].z = false;
-    nsCOMPtr<nsIPrefBranch> prefs = 
-        do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs) {
-        PRInt32 landscapeFS;
-        nsresult rv = prefs->GetIntPref(IME_FULLSCREEN_PREF, &landscapeFS);
-        if (NS_SUCCEEDED(rv)) {
-            if (landscapeFS == 1) {
-                args[3].z = true;
-            } else if (landscapeFS == -1){
-                rv = prefs->GetIntPref(IME_FULLSCREEN_THRESHOLD_PREF, 
-                                       &landscapeFS);
-                if (NS_SUCCEEDED(rv)) {
-                    // the threshold is hundreths of inches, so convert the 
-                    // threshold to pixels and multiply the height by 100
-                    if (nsWindow::GetAndroidScreenBounds().height  * 100 < 
-                        landscapeFS * Bridge()->GetDPI())
-                        args[3].z = true;
+
+    PRInt32 landscapeFS;
+    if (NS_SUCCEEDED(Preferences::GetInt(IME_FULLSCREEN_PREF, &landscapeFS))) {
+        if (landscapeFS == 1) {
+            args[3].z = true;
+        } else if (landscapeFS == -1){
+            if (NS_SUCCEEDED(
+                  Preferences::GetInt(IME_FULLSCREEN_THRESHOLD_PREF,
+                                      &landscapeFS))) {
+                // the threshold is hundreths of inches, so convert the 
+                // threshold to pixels and multiply the height by 100
+                if (nsWindow::GetAndroidScreenBounds().height  * 100 < 
+                    landscapeFS * Bridge()->GetDPI()) {
+                    args[3].z = true;
                 }
+            }
 
-            }
         }
     }
-    
+
     JNI()->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
                                  sBridge->jNotifyIMEEnabled, args);
 }
 
 void
 AndroidBridge::NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen,
                                int aStart, int aEnd, int aNewEnd)
 {
--- a/widget/src/android/GfxInfo.cpp
+++ b/widget/src/android/GfxInfo.cpp
@@ -42,17 +42,16 @@
 #include "EGLUtils.h"
 
 #include "AndroidBridge.h"
 
 #if defined(MOZ_CRASHREPORTER)
 #include "nsExceptionHandler.h"
 #include "nsICrashReporter.h"
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
-#include "nsIPrefService.h"
 #endif
 
 using namespace mozilla::widget;
 
 /* GetD2DEnabled and GetDwriteEnabled shouldn't be called until after gfxPlatform initialization
  * has occurred because they depend on it for information. (See bug 591561) */
 nsresult
 GfxInfo::GetD2DEnabled(PRBool *aEnabled)
--- a/widget/src/android/nsAppShell.cpp
+++ b/widget/src/android/nsAppShell.cpp
@@ -38,28 +38,26 @@
 
 #include "nsAppShell.h"
 #include "nsWindow.h"
 #include "nsThreadUtils.h"
 #include "nsICommandLineRunner.h"
 #include "nsIObserverService.h"
 #include "nsIAppStartup.h"
 #include "nsIGeolocationProvider.h"
-#include "nsIPrefService.h"
-#include "nsIPrefLocalizedString.h"
 
 #include "mozilla/Services.h"
 #include "mozilla/unused.h"
+#include "mozilla/Preferences.h"
 #include "prenv.h"
 
 #include "AndroidBridge.h"
 #include "nsAccelerometerSystem.h"
 #include <android/log.h>
 #include <pthread.h>
-#include "nsIPrefBranch2.h"
 #include <wchar.h>
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG
 #include "prlog.h"
 #endif
 
 #ifdef ANDROID_DEBUG_EVENTS
@@ -97,16 +95,24 @@ nsAppShell::~nsAppShell()
 
 void
 nsAppShell::NotifyNativeEvent()
 {
     MutexAutoLock lock(mCondLock);
     mQueueCond.Notify();
 }
 
+#define PREFNAME_MATCH_OS  "intl.locale.matchOS"
+#define PREFNAME_UA_LOCALE "general.useragent.locale"
+static const char* kObservedPrefs[] = {
+  PREFNAME_MATCH_OS,
+  PREFNAME_UA_LOCALE,
+  nsnull
+};
+
 nsresult
 nsAppShell::Init()
 {
 #ifdef PR_LOGGING
     if (!gWidgetLog)
         gWidgetLog = PR_NewLogModule("Widget");
 #endif
 
@@ -121,46 +127,31 @@ nsAppShell::Init()
         mozilla::services::GetObserverService();
     if (obsServ) {
         obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE);
     }
 
     if (!bridge)
         return rv;
 
-    nsCOMPtr<nsIPrefBranch2> branch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    branch->AddObserver("intl.locale.matchOS", this, PR_FALSE);
-    branch->AddObserver("general.useragent.locale", this, PR_FALSE);
+    Preferences::AddStrongObservers(this, kObservedPrefs);
 
-    nsString locale;
-    PRBool match = PR_FALSE;
-    rv = branch->GetBoolPref("intl.locale.matchOS", &match);
-
+    PRBool match;
+    rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (match) {
         bridge->SetSelectedLocale(EmptyString());
         return NS_OK;
     }
-    nsCOMPtr<nsIPrefLocalizedString> pls;
-    rv = branch->GetComplexValue("general.useragent.locale",
-                                 NS_GET_IID(nsIPrefLocalizedString),
-                                 getter_AddRefs(pls));
-    if (NS_SUCCEEDED(rv) && pls) {
-        nsXPIDLString uval;
-        pls->ToString(getter_Copies(uval));
-        if (uval)
-            locale.Assign(uval);
-    } else {
-        nsXPIDLCString cval;
-        rv = branch->GetCharPref("general.useragent.locale",
-                                 getter_Copies(cval));
-        if (NS_SUCCEEDED(rv) && cval)
-            locale.AssignWithConversion(cval);
+
+    nsAutoString locale;
+    rv = Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale);
+    if (NS_FAILED(rv)) {
+        rv = Preferences::GetString(PREFNAME_UA_LOCALE, &locale);
     }
 
     bridge->SetSelectedLocale(locale);
     return rv;
 }
 
 NS_IMETHODIMP
 nsAppShell::Observe(nsISupports* aSubject,
@@ -169,50 +160,37 @@ nsAppShell::Observe(nsISupports* aSubjec
 {
     if (!strcmp(aTopic, "xpcom-shutdown")) {
         // We need to ensure no observers stick around after XPCOM shuts down
         // or we'll see crashes, as the app shell outlives XPConnect.
         mObserversHash.Clear();
         return nsBaseAppShell::Observe(aSubject, aTopic, aData);
     } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && (
                    nsDependentString(aData).Equals(
-                       NS_LITERAL_STRING("general.useragent.locale")) ||
+                       NS_LITERAL_STRING(PREFNAME_UA_LOCALE)) ||
                    nsDependentString(aData).Equals(
-                       NS_LITERAL_STRING("intl.locale.matchOS"))))
-    {
+                       NS_LITERAL_STRING(PREFNAME_MATCH_OS)))) {
         AndroidBridge* bridge = AndroidBridge::Bridge();
-        nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
-        if (!prefs || !bridge)
+        if (!bridge) {
             return NS_OK;
+        }
 
-        nsString locale;
-        PRBool match = PR_FALSE;
-        nsresult rv = prefs->GetBoolPref("intl.locale.matchOS", &match);
+        PRBool match;
+        nsresult rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match);
         NS_ENSURE_SUCCESS(rv, rv);
 
         if (match) {
             bridge->SetSelectedLocale(EmptyString());
             return NS_OK;
         }
-        nsCOMPtr<nsIPrefLocalizedString> pls;
-        rv = prefs->GetComplexValue("general.useragent.locale",
-                                    NS_GET_IID(nsIPrefLocalizedString),
-                                    getter_AddRefs(pls));
-        if (NS_SUCCEEDED(rv) && pls) {
-            nsXPIDLString uval;
-            pls->ToString(getter_Copies(uval));
-            if (uval)
-                locale.Assign(uval);
-        }
-        else {
-            nsXPIDLCString cval;
-            rv = prefs->GetCharPref("general.useragent.locale",
-                                    getter_Copies(cval));
-            if (NS_SUCCEEDED(rv) && cval)
-                locale.AssignWithConversion(cval);
+
+        nsAutoString locale;
+        if (NS_FAILED(Preferences::GetLocalizedString(PREFNAME_UA_LOCALE,
+                                                      &locale))) {
+            locale = Preferences::GetString(PREFNAME_UA_LOCALE);
         }
 
         bridge->SetSelectedLocale(locale);
         return NS_OK;
     }
     return NS_OK;
 }
 
@@ -357,19 +335,20 @@ nsAppShell::ProcessNextNativeEvent(PRBoo
             appSvc->Quit(nsIAppStartup::eForceQuit);
         break;
     }
 
     case AndroidGeckoEvent::ACTIVITY_PAUSING: {
         // We really want to send a notification like profile-before-change,
         // but profile-before-change ends up shutting some things down instead
         // of flushing data
-        nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (prefs)
+        nsIPrefService* prefs = Preferences::GetService();
+        if (prefs) {
             prefs->SavePrefFile(nsnull);
+        }
 
         break;
     }
 
     case AndroidGeckoEvent::LOAD_URI: {
         nsCOMPtr<nsICommandLineRunner> cmdline
             (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
         if (!cmdline)
--- a/widget/src/android/nsWindow.cpp
+++ b/widget/src/android/nsWindow.cpp
@@ -38,26 +38,26 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include <android/log.h>
 #include <math.h>
 
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/unused.h"
+#include "mozilla/Preferences.h"
 
 using mozilla::dom::ContentParent;
 using mozilla::dom::ContentChild;
 using mozilla::unused;
 
 #include "nsAppShell.h"
 #include "nsIdleService.h"
 #include "nsWindow.h"
 #include "nsIObserverService.h"
-#include "nsIPrefService.h"
 
 #include "nsRenderingContext.h"
 #include "nsIDOMSimpleGestureEvent.h"
 
 #include "nsWidgetAtoms.h"
 #include "nsWidgetsCID.h"
 #include "nsGfxCIID.h"
 
@@ -1744,24 +1744,20 @@ nsWindow::SetInputMode(const IMEContext&
     ALOGIME("IME: SetInputMode: s=%d trusted=%d", aContext.mStatus, aContext.mReason);
 
     mIMEContext = aContext;
 
     // Ensure that opening the virtual keyboard is allowed for this specific
     // IMEContext depending on the content.ime.strict.policy pref
     if (aContext.mStatus != nsIWidget::IME_STATUS_DISABLED && 
         aContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) {
-      nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-
-      PRBool useStrictPolicy = PR_FALSE;
-      if (NS_SUCCEEDED(prefs->GetBoolPref("content.ime.strict_policy", &useStrictPolicy))) {
-        if (useStrictPolicy && !aContext.FocusMovedByUser() && 
-            aContext.FocusMovedInContentProcess()) {
-          return NS_OK;
-        }
+      if (Preferences::GetBool("content.ime.strict_policy", PR_FALSE) &&
+          !aContext.FocusMovedByUser() &&
+          aContext.FocusMovedInContentProcess()) {
+        return NS_OK;
       }
     }
 
     AndroidBridge::NotifyIMEEnabled(int(aContext.mStatus), aContext.mHTMLInputType, aContext.mActionHint);
     return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/widget/src/cocoa/GfxInfo.mm
+++ b/widget/src/cocoa/GfxInfo.mm
@@ -43,17 +43,16 @@
 #include "nsUnicharUtils.h"
 #include "mozilla/FunctionTimer.h"
 #include "nsToolkit.h"
 
 #if defined(MOZ_CRASHREPORTER)
 #include "nsExceptionHandler.h"
 #include "nsICrashReporter.h"
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
-#include "nsIPrefService.h"
 #endif
 
 using namespace mozilla::widget;
 
 nsresult
 GfxInfo::Init()
 {
   NS_TIME_FUNCTION;
--- a/widget/src/os2/nsDeviceContextSpecOS2.cpp
+++ b/widget/src/os2/nsDeviceContextSpecOS2.cpp
@@ -39,18 +39,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include <stdlib.h>
 #include "nsDeviceContextSpecOS2.h"
 
 #include "nsReadableUtils.h"
 #include "nsTArray.h"
 
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
 #include "prenv.h" /* for PR_GetEnv */
 #include "prtime.h"
 
 #include "nsPrintfCString.h"
 #include "nsIServiceManager.h"
 #include "nsUnicharUtils.h"
 #include "nsStringFwd.h"
 #include "nsStringEnumerator.h"
@@ -59,16 +57,20 @@
 
 #include "nsILocalFile.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIFileStreams.h"
 #include "gfxPDFSurface.h"
 #include "gfxOS2Surface.h"
 #include "nsIPrintSettingsService.h"
 
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
+
 PRINTDLG nsDeviceContextSpecOS2::PrnDlg;
 
 //----------------------------------------------------------------------------------
 // The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecOS2
 // The PrinterEnumerator creates the printer info
 // but the nsDeviceContextSpecOS2 cleans it up
 // If it gets created (via the Page Setup Dialog) but the user never prints anything
 // then it will never be delete, so this class takes care of that.
@@ -652,41 +654,40 @@ nsresult GlobalPrinters::InitializeGloba
   mGlobalNumPrinters = nsDeviceContextSpecOS2::PrnDlg.GetNumPrinters();
   if (!mGlobalNumPrinters) 
     return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; 
 
   mGlobalPrinterList = new nsTArray<nsString>();
   if (!mGlobalPrinterList) 
      return NS_ERROR_OUT_OF_MEMORY;
 
-  nsresult rv;
-  nsCOMPtr<nsIPrefBranch> pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-  BOOL prefFailed = NS_FAILED(rv); // don't return on failure, optional feature
+  // don't return on failure, optional feature
+  BOOL prefFailed = (Preferences::GetRootBranch() != nsnull);
 
   for (ULONG i = 0; i < mGlobalNumPrinters; i++) {
     nsXPIDLCString printer;
     nsDeviceContextSpecOS2::PrnDlg.GetPrinter(i, getter_Copies(printer));
 
     nsAutoChar16Buffer printerName;
     PRInt32 printerNameLength;
-    rv = MultiByteToWideChar(0, printer, strlen(printer),
-                             printerName, printerNameLength);
+    nsresult rv = MultiByteToWideChar(0, printer, strlen(printer),
+                                      printerName, printerNameLength);
     mGlobalPrinterList->AppendElement(nsDependentString(printerName.Elements()));
 
     // store printer description in prefs for the print dialog
     if (!prefFailed) {
        nsCAutoString printerDescription;
        printerDescription = nsCAutoString(nsDeviceContextSpecOS2::PrnDlg.GetPrintDriver(i)->szDeviceName);
        printerDescription += " (";
        printerDescription += nsCAutoString(nsDeviceContextSpecOS2::PrnDlg.GetDriverType(i));
        printerDescription += ")";
-       pPrefs->SetCharPref(nsPrintfCString(256,
-                                           "print.printer_%s.printer_description",
-                                           printer.get()).get(),
-                           printerDescription.get());
+       nsCAutoString prefName("print.printer_");
+       prefName += printer;
+       prefName += ".printer_description";
+       Preferences::SetCString(prefName.get(), printerDescription);
     }
   } 
   return NS_OK;
 }
 
 void GlobalPrinters::GetDefaultPrinterName(PRUnichar*& aDefaultPrinterName)
 {
   aDefaultPrinterName = nsnull;
--- a/widget/src/os2/nsWindow.cpp
+++ b/widget/src/os2/nsWindow.cpp
@@ -70,25 +70,28 @@
 #include "gfxContext.h"
 #include "gfxOS2Surface.h"
 #include "imgIContainer.h"
 #include "npapi.h"
 #include "nsDragService.h"
 #include "nsGfxCIID.h"
 #include "nsHashKeys.h"
 #include "nsIMenuRollup.h"
-#include "nsIPrefService.h"
 #include "nsIRollupListener.h"
 #include "nsIScreenManager.h"
 #include "nsOS2Uni.h"
 #include "nsTHashtable.h"
 #include "nsToolkit.h"
 #include "nsWidgetAtoms.h"
 #include "wdgtos2rc.h"
 
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
+
 //=============================================================================
 //  Macros
 //=============================================================================
 
 // Drag and Drop
 
 // d&d flags - actions that might cause problems during d&d
 #define ACTION_PAINT    1
@@ -304,24 +307,18 @@ void nsWindow::InitGlobals()
     gOS2Flags |= kIsDBCS;
   }
 
   // This is ugly. The Thinkpad TrackPoint driver checks to see whether
   // or not a window actually has a scroll bar as a child before sending
   // it scroll messages. Needless to say, no Mozilla window has real scroll
   // bars. So if you have the "os2.trackpoint" preference set, we put an
   // invisible scroll bar on every child window so we can scroll.
-  nsresult rv;
-  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  if (NS_SUCCEEDED(rv) && prefs) {
-    PRBool isTrackPoint = PR_FALSE;
-    prefs->GetBoolPref("os2.trackpoint", &isTrackPoint);
-    if (isTrackPoint) {
-      gOS2Flags |= kIsTrackPoint;
-    }
+  if (Preferences::GetBool("os2.trackpoint", PR_FALSE)) {
+    gOS2Flags |= kIsTrackPoint;
   }
 }
 
 //-----------------------------------------------------------------------------
 // Release Module-level variables.
 
 // static
 void nsWindow::ReleaseGlobals()
--- a/widget/src/qt/nsDeviceContextSpecQt.cpp
+++ b/widget/src/qt/nsDeviceContextSpecQt.cpp
@@ -51,18 +51,16 @@
 #define FORCE_PR_LOG 1 /* Allow logging in the release build */
 #endif /* MOZ_LOGGING */
 #include "prlog.h"
 
 #include "plstr.h"
 
 #include "nsDeviceContextSpecQt.h"
 
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
 #include "prenv.h" /* for PR_GetEnv */
 
 #include "nsPrintfCString.h"
 #include "nsReadableUtils.h"
 #include "nsStringEnumerator.h"
 #include "nsIServiceManager.h"
 #include "nsPrintSettingsQt.h"
 #include "nsIFileStreams.h"
--- a/widget/src/qt/nsWindow.cpp
+++ b/widget/src/qt/nsWindow.cpp
@@ -97,19 +97,18 @@ using namespace QtMobility;
 #include "nsIdleService.h"
 #include "nsRenderingContext.h"
 #include "nsIRegion.h"
 #include "nsIRollupListener.h"
 #include "nsIMenuRollup.h"
 #include "nsWidgetsCID.h"
 #include "nsQtKeyUtils.h"
 #include "mozilla/Services.h"
-
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
+#include "mozilla/Preferences.h"
+
 #include "nsIStringBundle.h"
 #include "nsGfxCIID.h"
 
 #include "imgIContainer.h"
 #include "nsGfxCIID.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsAutoPtr.h"
 
@@ -2492,25 +2491,19 @@ nsWindow::InitDragEvent(nsMouseEvent &aE
 // This will update the drag action based on the information in the
 // drag context.
 
 /* static */
 nsresult
 initialize_prefs(void)
 {
     // check to see if we should set our raise pref
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!prefs)
-        return NS_OK;
-
-    PRBool val = PR_TRUE;
-    nsresult rv;
-    rv = prefs->GetBoolPref("mozilla.widget.disable-native-theme", &val);
-    if (NS_SUCCEEDED(rv))
-        gDisableNativeTheme = val;
+    gDisableNativeTheme =
+        Preferences::GetBool("mozilla.widget.disable-native-theme",
+                             gDisableNativeTheme);
 
     return NS_OK;
 }
 
 inline PRBool
 is_context_menu_key(const nsKeyEvent& aKeyEvent)
 {
     return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.isShift &&
@@ -3042,21 +3035,18 @@ nsWindow::SetInputMode(const IMEContext&
 {
     NS_ENSURE_TRUE(mWidget, NS_ERROR_FAILURE);
 
     mIMEContext = aContext;
     switch (aContext.mStatus) {
         case nsIWidget::IME_STATUS_ENABLED:
         case nsIWidget::IME_STATUS_PASSWORD:
             {
-                PRInt32 openDelay = 200;
-                nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-                if (prefs)
-                  prefs->GetIntPref("ui.vkb.open.delay", &openDelay);
-
+                PRInt32 openDelay =
+                    Preferences::GetInt("ui.vkb.open.delay", 200);
                 mWidget->requestVKB(openDelay);
             }
             break;
         default:
             mWidget->hideVKB();
             break;
     }
 
--- a/widget/src/windows/GfxInfo.cpp
+++ b/widget/src/windows/GfxInfo.cpp
@@ -47,17 +47,16 @@
 #include "prenv.h"
 #include "prprf.h"
 #include "GfxDriverInfo.h"
 
 #if defined(MOZ_CRASHREPORTER)
 #include "nsExceptionHandler.h"
 #include "nsICrashReporter.h"
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
-#include "nsIPrefService.h"
 #endif
 
 
 using namespace mozilla::widget;
 
 #ifdef DEBUG
 NS_IMPL_ISUPPORTS_INHERITED1(GfxInfo, GfxInfoBase, nsIGfxInfoDebug)
 #endif