Bug 663036 part.3 gfx should use mozilla::Preferences r=roc+joe
authorMasayuki Nakano <masayuki@d-toybox.com>
Sun, 12 Jun 2011 11:30:16 +0900
changeset 70930 1abe9e62753397f24176e42e1b5ea114b95d44e0
parent 70929 a1cebab4dc0ff0fee1a4f89e98fbaa99ea9a61a3
child 70931 e37011790a8a929a3dbfbe6b81c8194e57c35bf7
push id20451
push usermasayuki@d-toybox.com
push dateSun, 12 Jun 2011 02:31:08 +0000
treeherdermozilla-central@e37011790a8a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs663036
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 663036 part.3 gfx should use mozilla::Preferences r=roc+joe
gfx/layers/d3d9/DeviceManagerD3D9.cpp
gfx/layers/d3d9/LayerManagerD3D9.cpp
gfx/layers/opengl/LayerManagerOGL.cpp
gfx/src/nsDeviceContext.cpp
gfx/tests/gfxFontSelectionTest.cpp
gfx/tests/gfxTextRunPerfTest.cpp
gfx/tests/gfxWordCacheTest.cpp
gfx/thebes/GLContextProviderEGL.cpp
gfx/thebes/GLContextProviderOSMesa.cpp
gfx/thebes/gfxDWriteCommon.h
gfx/thebes/gfxDWriteFontList.cpp
gfx/thebes/gfxFT2Fonts.cpp
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFontUtils.cpp
gfx/thebes/gfxFontconfigUtils.cpp
gfx/thebes/gfxOS2Fonts.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
gfx/thebes/gfxPlatformFontList.cpp
gfx/thebes/gfxPlatformFontList.h
gfx/thebes/gfxPlatformMac.cpp
gfx/thebes/gfxQtPlatform.cpp
gfx/thebes/gfxTextRunWordCache.cpp
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
gfx/thebes/gfxXlibSurface.cpp
--- a/gfx/layers/d3d9/DeviceManagerD3D9.cpp
+++ b/gfx/layers/d3d9/DeviceManagerD3D9.cpp
@@ -36,17 +36,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "DeviceManagerD3D9.h"
 #include "LayerManagerD3D9Shaders.h"
 #include "ThebesLayerD3D9.h"
 #include "nsIServiceManager.h"
 #include "nsIConsoleService.h"
 #include "nsPrintfCString.h"
-#include "nsIPrefService.h" 
 #include "Nv3DVUtils.h"
 #include "plstr.h"
 
 namespace mozilla {
 namespace layers {
 
 const LPCWSTR kClassName       = L"D3D9WindowClass";
 
--- a/gfx/layers/d3d9/LayerManagerD3D9.cpp
+++ b/gfx/layers/d3d9/LayerManagerD3D9.cpp
@@ -41,19 +41,18 @@
 #include "ContainerLayerD3D9.h"
 #include "ImageLayerD3D9.h"
 #include "ColorLayerD3D9.h"
 #include "CanvasLayerD3D9.h"
 #include "ReadbackLayerD3D9.h"
 #include "gfxWindowsPlatform.h"
 #include "nsIGfxInfo.h"
 #include "nsServiceManagerUtils.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch2.h"
 #include "gfxFailure.h"
+#include "mozilla/Preferences.h"
 
 #include "gfxCrashReporterUtils.h"
 
 namespace mozilla {
 namespace layers {
 
 DeviceManagerD3D9 *LayerManagerD3D9::mDefaultDeviceManager = nsnull;
 
@@ -70,25 +69,19 @@ LayerManagerD3D9::~LayerManagerD3D9()
   Destroy();
 }
 
 PRBool
 LayerManagerD3D9::Initialize()
 {
   ScopedGfxFeatureReporter reporter("D3D9 Layers");
 
-  nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-
   /* XXX: this preference and blacklist code should move out of the layer manager */
-  PRBool forceAccelerate = PR_FALSE;
-  if (prefs) {
-    // we should use Preferences::AddBoolVarCache
-    prefs->GetBoolPref("layers.acceleration.force-enabled",
-                       &forceAccelerate);
-  }
+  PRBool forceAccelerate =
+    Preferences::GetBool("layers.acceleration.force-enabled", PR_FALSE);
 
   nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
   if (gfxInfo) {
     PRInt32 status;
     if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_DIRECT3D_9_LAYERS, &status))) {
       if (status != nsIGfxInfo::FEATURE_NO_INFO && !forceAccelerate)
       {
         NS_WARNING("Direct3D 9-accelerated layers are not supported on this system.");
--- a/gfx/layers/opengl/LayerManagerOGL.cpp
+++ b/gfx/layers/opengl/LayerManagerOGL.cpp
@@ -52,18 +52,16 @@
 #include "gfxContext.h"
 #include "nsIWidget.h"
 
 #include "GLContext.h"
 #include "GLContextProvider.h"
 
 #include "nsIServiceManager.h"
 #include "nsIConsoleService.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch2.h"
 
 #include "gfxCrashReporterUtils.h"
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gl;
 
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -40,21 +40,21 @@
 #include "nsDeviceContext.h"
 #include "nsCRT.h"
 #include "nsFontMetrics.h"
 #include "nsRenderingContext.h"
 #include "nsIView.h"
 #include "nsIWidget.h"
 
 #include "mozilla/Services.h"
+#include "mozilla/Preferences.h"
 #include "nsIServiceManager.h"
 #include "nsILanguageAtomService.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
-#include "nsIPrefService.h"
 
 #include "gfxImageSurface.h"
 
 #ifdef MOZ_ENABLE_GTK2
 #include "nsSystemFontsGTK2.h"
 #include "gfxPDFSurface.h"
 #include "gfxPSSurface.h"
 static nsSystemFontsGTK2 *gSystemFonts = nsnull;
@@ -79,16 +79,17 @@ static nsSystemFontsQt *gSystemFonts = n
 #elif defined(ANDROID)
 #include "nsSystemFontsAndroid.h"
 #include "gfxPDFSurface.h"
 static nsSystemFontsAndroid *gSystemFonts = nsnull;
 #else
 #error Need to declare gSystemFonts!
 #endif
 
+using namespace mozilla;
 using mozilla::services::GetObserverService;
 
 class nsFontCache : public nsIObserver
 {
 public:
     nsFontCache()   { MOZ_COUNT_CTOR(nsFontCache); }
     ~nsFontCache()  { MOZ_COUNT_DTOR(nsFontCache); }
 
@@ -363,29 +364,21 @@ nsDeviceContext::SetDPI()
         default:
             NS_NOTREACHED("Unexpected printing surface type");
             break;
         }
 
         mAppUnitsPerDevNotScaledPixel =
             NS_lround((AppUnitsPerCSSPixel() * 96) / dpi);
     } else {
-        nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-
         // A value of -1 means use the maximum of 96 and the system DPI.
         // A value of 0 means use the system DPI. A positive value is used as the DPI.
         // This sets the physical size of a device pixel and thus controls the
         // interpretation of physical units.
-        PRInt32 prefDPI = -1;
-        if (prefs) {
-            nsresult rv = prefs->GetIntPref("layout.css.dpi", &prefDPI);
-            if (NS_FAILED(rv)) {
-                prefDPI = -1;
-            }
-        }
+        PRInt32 prefDPI = Preferences::GetInt("layout.css.dpi", -1);
 
         if (prefDPI > 0) {
             dpi = prefDPI;
         } else if (mWidget) {
             dpi = mWidget->GetDPI();
 
             if (prefDPI < 0) {
                 dpi = PR_MAX(96.0f, dpi);
@@ -394,22 +387,19 @@ nsDeviceContext::SetDPI()
             dpi = 96.0f;
         }
 
         // The number of device pixels per CSS pixel. A value <= 0 means choose
         // automatically based on the DPI. A positive value is used as-is. This effectively
         // controls the size of a CSS "px".
         float devPixelsPerCSSPixel = -1.0;
 
-        if (prefs) {
-            nsXPIDLCString prefString;
-            nsresult rv = prefs->GetCharPref("layout.css.devPixelsPerPx", getter_Copies(prefString));
-            if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
-                devPixelsPerCSSPixel = static_cast<float>(atof(prefString));
-            }
+        nsAdoptingCString prefString = Preferences::GetCString("layout.css.devPixelsPerPx");
+        if (!prefString.IsEmpty()) {
+            devPixelsPerCSSPixel = static_cast<float>(atof(prefString));
         }
 
         if (devPixelsPerCSSPixel <= 0) {
             if (mWidget) {
                 devPixelsPerCSSPixel = mWidget->GetDefaultScale();
             } else {
                 devPixelsPerCSSPixel = 1.0;
             }
--- a/gfx/tests/gfxFontSelectionTest.cpp
+++ b/gfx/tests/gfxFontSelectionTest.cpp
@@ -35,35 +35,35 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
+#include "mozilla/Preferences.h"
 
 #include "gfxContext.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 #include "gfxTextRunWordCache.h"
 
 #include "gfxFontTest.h"
 
 #if defined(XP_MACOSX)
 #include "gfxTestCocoaHelper.h"
 #endif
 
 #ifdef MOZ_WIDGET_GTK2
 #include "gtk/gtk.h"
 #endif
 
+using namespace mozilla;
+
 enum {
     S_UTF8 = 0,
     S_ASCII = 1
 };
 
 class FrameTextRunCache;
 
 static gfxTextRunWordCache *gTextRunCache;
@@ -353,31 +353,17 @@ main (int argc, char **argv) {
     // let's get all the xpcom goop out of the system
     fflush (stderr);
     fflush (stdout);
 
     // don't need to query, we might need to set up some prefs later
     if (0) {
         nsresult rv;
 
-        nsCOMPtr<nsIPrefService> prefsvc = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (!prefsvc) {
-            printf ("Pref svc get failed!\n");
-        }
-
-        nsCOMPtr<nsIPrefBranch> branch;
-        rv = prefsvc->GetBranch(nsnull, getter_AddRefs(branch));
-        if (NS_FAILED(rv))
-            printf ("Failed 0x%08x\n", rv);
-
-        nsXPIDLCString str;
-        rv = branch->GetCharPref("font.name.sans-serif.x-western", getter_Copies(str));
-        if (NS_FAILED(rv))
-            printf ("Failed[2] 0x%08x\n", rv);
-
+        nsAdoptingCString str = Preferences::GetCString("font.name.sans-serif.x-western");
         printf ("sans-serif.x-western: %s\n", nsPromiseFlatCString(str).get());
     }
 
     // set up the tests
     SetupTests();
 
     nsRefPtr<gfxContext> context = MakeContext();
 
--- a/gfx/tests/gfxTextRunPerfTest.cpp
+++ b/gfx/tests/gfxTextRunPerfTest.cpp
@@ -37,20 +37,16 @@
 
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
 #include "prinrval.h"
 
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
-
 #include "gfxContext.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 
 #if defined(XP_MACOSX)
 #include "gfxTestCocoaHelper.h"
--- a/gfx/tests/gfxWordCacheTest.cpp
+++ b/gfx/tests/gfxWordCacheTest.cpp
@@ -37,20 +37,16 @@
 
 #include "nsCOMPtr.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsDependentString.h"
 
 #include "prinrval.h"
 
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
-
 #include "gfxContext.h"
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 
 #include "gfxFontTest.h"
 
 #include "gfxTextRunWordCache.h"
 
--- a/gfx/thebes/GLContextProviderEGL.cpp
+++ b/gfx/thebes/GLContextProviderEGL.cpp
@@ -73,18 +73,17 @@ typedef void *EGLNativeDisplayType;
 typedef void *EGLNativePixmapType;
 typedef void *EGLNativeWindowType;
 
 #define EGL_LIB "/system/lib/libEGL.so"
 #define GLES2_LIB "/system/lib/libGLESv2.so"
 
 #elif defined(XP_WIN)
 
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefBranch.h"
+#include "mozilla/Preferences.h"
 #include "nsILocalFile.h"
 
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN 1
 #endif
 
 #include <windows.h>
 
@@ -313,24 +312,20 @@ public:
         }
 
         mozilla::ScopedGfxFeatureReporter reporter("EGL");
 
 #ifdef XP_WIN
         // Allow for explicitly specifying the location of libEGL.dll and
         // libGLESv2.dll.
         do {
-            nsCOMPtr<nsIPrefBranch> prefs = do_GetService("@mozilla.org/preferences-service;1");
             nsCOMPtr<nsILocalFile> eglFile, glesv2File;
-            if (!prefs)
-                break;
-
-            nsresult rv = prefs->GetComplexValue("gfx.angle.egl.path",
-                                                 NS_GET_IID(nsILocalFile),
-                                                 getter_AddRefs(eglFile));
+            nsresult rv = Preferences::GetComplex("gfx.angle.egl.path",
+                                                  NS_GET_IID(nsILocalFile),
+                                                  getter_AddRefs(eglFile));
             if (NS_FAILED(rv) || !eglFile)
                 break;
 
             nsCAutoString s;
 
             // note that we have to load the libs in this order, because libEGL.dll
             // depends on libGLESv2.dll, but is not/may not be in our search path.
             nsCOMPtr<nsIFile> f;
--- a/gfx/thebes/GLContextProviderOSMesa.cpp
+++ b/gfx/thebes/GLContextProviderOSMesa.cpp
@@ -38,17 +38,17 @@
 #include "GLContextProvider.h"
 #include "GLContext.h"
 #include "nsDebug.h"
 #include "nsString.h"
 #include "nsIWidget.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsIConsoleService.h"
-#include "nsIPrefService.h"
+#include "mozilla/Preferences.h"
 #include "gfxASurface.h"
 #include "gfxImageSurface.h"
 
 #include "gfxCrashReporterUtils.h"
 
 // from GL/osmesa.h. We don't include that file so as to avoid having a build-time dependency on OSMesa.
 #define OSMESA_RGBA     GL_RGBA
 #define OSMESA_BGRA     0x1
@@ -101,32 +101,18 @@ private:
 OSMesaLibrary sOSMesaLibrary;
 
 PRBool
 OSMesaLibrary::EnsureInitialized()
 {
     if (mInitialized)
         return PR_TRUE;
 
-    nsresult rv;
-
-    nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, PR_FALSE);
-
-    nsCOMPtr<nsIPrefBranch> prefBranch;
-    rv = prefService->GetBranch("webgl.", getter_AddRefs(prefBranch));
-    NS_ENSURE_SUCCESS(rv, PR_FALSE);
-
-    nsCString osmesalib;
-
-    rv = prefBranch->GetCharPref("osmesalib", getter_Copies(osmesalib));
-
-    if (NS_FAILED(rv) ||
-        osmesalib.Length() == 0)
-    {
+    nsAdoptingCString osmesalib = Preferences::GetCString("webgl.osmesalib");
+    if (osmesalib.IsEmpty()) {
         return PR_FALSE;
     }
 
     mOSMesaLibrary = PR_LoadLibrary(osmesalib.get());
 
     if (!mOSMesaLibrary) {
         LogMessage("Couldn't open OSMesa lib for software rendering -- webgl.osmesalib path is incorrect, or not a valid shared library");
         return PR_FALSE;
--- a/gfx/thebes/gfxDWriteCommon.h
+++ b/gfx/thebes/gfxDWriteCommon.h
@@ -35,17 +35,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef GFX_DWRITECOMMON_H
 #define GFX_DWRITECOMMON_H
 
 // Mozilla includes
 #include "nscore.h"
-#include "nsIPrefService.h"
 #include "nsIServiceManager.h"
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "cairo-features.h"
 #include "gfxFontConstants.h"
 #include "nsTArray.h"
 #include "gfxWindowsPlatform.h"
 #include "nsIUUIDGenerator.h"
--- a/gfx/thebes/gfxDWriteFontList.cpp
+++ b/gfx/thebes/gfxDWriteFontList.cpp
@@ -37,20 +37,19 @@
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif /* MOZ_LOGGING */
 
 #include "gfxDWriteFontList.h"
 #include "gfxDWriteFonts.h"
 #include "nsUnicharUtils.h"
 #include "nsILocaleService.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch2.h"
 #include "nsServiceManagerUtils.h"
 #include "nsCharSeparatedTokenizer.h"
+#include "mozilla/Preferences.h"
 
 #include "gfxGDIFontList.h"
 
 #include "nsIWindowsRegKey.h"
 
 using namespace mozilla;
 
 #ifdef PR_LOGGING
@@ -691,25 +690,17 @@ gfxDWriteFontList::InitFontList()
 #endif
 
     HRESULT hr;
     gfxFontCache *fc = gfxFontCache::GetCache();
     if (fc) {
         fc->AgeAllGenerations();
     }
 
-    nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    nsresult rv;
-
-    rv = pref->GetBoolPref(
-             "gfx.font_rendering.directwrite.use_gdi_table_loading", 
-             &mGDIFontTableAccess);
-    if (NS_FAILED(rv)) {
-        mGDIFontTableAccess = PR_FALSE;
-    }
+    mGDIFontTableAccess = Preferences::GetBool("gfx.font_rendering.directwrite.use_gdi_table_loading", PR_FALSE);
 
     gfxPlatformFontList::InitFontList();
 
     mFontSubstitutes.Clear();
     mNonExistingFonts.Clear();
 
 #ifdef PR_LOGGING
     if (LOG_FONTINIT_ENABLED()) {
@@ -948,38 +939,32 @@ gfxDWriteFontList::DelayedInitFontList()
 #endif
             }
 
             // remove Gills Sans
             mFontFamilies.Remove(nameGillSans);
         }
     }
 
-    nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    nsXPIDLCString classicFamilies;
-    nsresult rv = pref->GetCharPref(
-             "gfx.font_rendering.cleartype_params.force_gdi_classic_for_families",
-             getter_Copies(classicFamilies));
-    if (NS_SUCCEEDED(rv)) {
+    nsAdoptingCString classicFamilies =
+        Preferences::GetCString("gfx.font_rendering.cleartype_params.force_gdi_classic_for_families");
+    if (classicFamilies) {
         nsCCharSeparatedTokenizer tokenizer(classicFamilies, ',');
         while (tokenizer.hasMoreTokens()) {
             NS_ConvertUTF8toUTF16 name(tokenizer.nextToken());
             BuildKeyNameFromFontName(name);
             gfxFontFamily *family = mFontFamilies.GetWeak(name);
             if (family) {
                 static_cast<gfxDWriteFontFamily*>(family)->SetForceGDIClassic(true);
             }
         }
     }
-    PRInt32 forceGDIClassicMaxFontSize = 0;
-    rv = pref->GetIntPref("gfx.font_rendering.cleartype_params.force_gdi_classic_max_size",
-                          &forceGDIClassicMaxFontSize);
-    if (NS_SUCCEEDED(rv)) {
-        mForceGDIClassicMaxFontSize = forceGDIClassicMaxFontSize;
-    }
+    mForceGDIClassicMaxFontSize =
+        Preferences::GetInt("gfx.font_rendering.cleartype_params.force_gdi_classic_max_size",
+                            mForceGDIClassicMaxFontSize);
 
     StartLoader(kDelayBeforeLoadingFonts, kIntervalBetweenLoadingFonts);
 
     LOGREGISTRY(L"DelayedInitFontList end");
 
 #ifdef PR_LOGGING
     if (LOG_FONTINIT_ENABLED()) {
         QueryPerformanceCounter(&t3);
--- a/gfx/thebes/gfxFT2Fonts.cpp
+++ b/gfx/thebes/gfxFT2Fonts.cpp
@@ -62,23 +62,25 @@
 #include FT_TRUETYPE_TAGS_H
 #include FT_TRUETYPE_TABLES_H
 #include "gfxFontUtils.h"
 #include "gfxHarfBuzzShaper.h"
 #include "gfxUnicodeProperties.h"
 #include "gfxAtoms.h"
 #include "nsTArray.h"
 #include "nsUnicodeRange.h"
-#include "nsIPrefService.h"
-#include "nsIPrefLocalizedString.h"
-#include "nsServiceManagerUtils.h"
 #include "nsCRT.h"
 
 #include "prlog.h"
 #include "prinit.h"
+
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
+
 static PRLogModuleInfo *gFontLog = PR_NewLogModule("ft2fonts");
 
 static const char *sCJKLangGroup[] = {
     "ja",
     "ko",
     "zh-cn",
     "zh-hk",
     "zh-tw"
@@ -505,35 +507,19 @@ void gfxFT2FontGroup::GetCJKPrefFonts(ns
     gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
 
     nsCAutoString key("x-internal-cjk-");
     key.AppendInt(mStyle.style);
     key.Append("-");
     key.AppendInt(mStyle.weight);
 
     if (!platform->GetPrefFontEntries(key, &aFontEntryList)) {
-        nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (!prefs)
-            return;
-
-        nsCOMPtr<nsIPrefBranch> prefBranch;
-        prefs->GetBranch(0, getter_AddRefs(prefBranch));
-        if (!prefBranch)
-            return;
-
+        NS_ENSURE_TRUE(Preferences::GetRootBranch(), );
         // Add the CJK pref fonts from accept languages, the order should be same order
-        nsCAutoString list;
-        nsCOMPtr<nsIPrefLocalizedString> val;
-        nsresult rv = prefBranch->GetComplexValue("intl.accept_languages", NS_GET_IID(nsIPrefLocalizedString),
-                                                  getter_AddRefs(val));
-        if (NS_SUCCEEDED(rv) && val) {
-            nsAutoString temp;
-            val->ToString(getter_Copies(temp));
-            LossyCopyUTF16toASCII(temp, list);
-        }
+        nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
         if (!list.IsEmpty()) {
             const char kComma = ',';
             const char *p, *p_end;
             list.BeginReading(p);
             list.EndReading(p_end);
             while (p < p_end) {
                 while (nsCRT::IsAsciiSpace(*p)) {
                     if (++p == p_end)
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -38,17 +38,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif
 #include "prlog.h"
 
-#include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsReadableUtils.h"
 #include "nsExpirationTracker.h"
 #include "nsILanguageAtomService.h"
 
 #include "gfxFont.h"
 #include "gfxPlatform.h"
 #include "gfxAtoms.h"
@@ -61,16 +60,17 @@
 #include "gfxPlatformFontList.h"
 #include "gfxScriptItemizer.h"
 #include "gfxUnicodeProperties.h"
 #include "nsMathUtils.h"
 #include "nsBidiUtils.h"
 #include "nsUnicodeRange.h"
 #include "nsCompressedCharMap.h"
 #include "nsStyleConsts.h"
+#include "mozilla/Preferences.h"
 
 #include "cairo.h"
 #include "gfxFontTest.h"
 
 #include "harfbuzz/hb-blob.h"
 
 #include "nsCRT.h"
 
@@ -2173,26 +2173,23 @@ gfxFontGroup::ForEachFontInternal(const 
             groupAtom = gLangService->GetLanguageGroup(aLanguage, &rv);
         }
     }
     if (!groupAtom) {
         groupAtom = gfxAtoms::x_unicode;
     }
     groupAtom->ToUTF8String(groupString);
 
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-
     nsPromiseFlatString families(aFamilies);
     const PRUnichar *p, *p_end;
     families.BeginReading(p);
     families.EndReading(p_end);
     nsAutoString family;
     nsCAutoString lcFamily;
     nsAutoString genericFamily;
-    nsXPIDLCString value;
 
     while (p < p_end) {
         while (nsCRT::IsAsciiSpace(*p) || *p == kComma)
             if (++p == p_end)
                 return PR_TRUE;
 
         PRBool generic;
         if (*p == kSingleQuote || *p == kDoubleQuote) {
@@ -2234,22 +2231,20 @@ gfxFontGroup::ForEachFontInternal(const 
 
                 ToLowerCase(NS_LossyConvertUTF16toASCII(family), lcFamily);
 
                 nsCAutoString prefName("font.name.");
                 prefName.Append(lcFamily);
                 prefName.AppendLiteral(".");
                 prefName.Append(groupString);
 
-                // prefs file always uses (must use) UTF-8 so that we can use
-                // |GetCharPref| and treat the result as a UTF-8 string.
-                nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
-                if (NS_SUCCEEDED(rv)) {
+                nsAdoptingString value = Preferences::GetString(prefName.get());
+                if (value) {
                     CopyASCIItoUTF16(lcFamily, genericFamily);
-                    CopyUTF8toUTF16(value, family);
+                    family = value;
                 }
             } else {
                 generic = PR_FALSE;
                 genericFamily.SetIsVoid(PR_TRUE);
             }
         }
 
         if (generic) {
@@ -2288,20 +2283,19 @@ gfxFontGroup::ForEachFontInternal(const 
             }
         }
 
         if (generic && aResolveGeneric) {
             nsCAutoString prefName("font.name-list.");
             prefName.Append(lcFamily);
             prefName.AppendLiteral(".");
             prefName.Append(groupString);
-            nsresult rv = prefs->GetCharPref(prefName.get(), getter_Copies(value));
-            if (NS_SUCCEEDED(rv)) {
-                ForEachFontInternal(NS_ConvertUTF8toUTF16(value),
-                                    groupAtom, PR_FALSE, aResolveFontName,
+            nsAdoptingString value = Preferences::GetString(prefName.get());
+            if (value) {
+                ForEachFontInternal(value, groupAtom, PR_FALSE, aResolveFontName,
                                     fc, closure);
             }
         }
 
         ++p; // may advance past p_end
     }
 
     return PR_TRUE;
--- a/gfx/thebes/gfxFontUtils.cpp
+++ b/gfx/thebes/gfxFontUtils.cpp
@@ -36,20 +36,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "gfxFontUtils.h"
 
 #include "nsServiceManagerUtils.h"
 
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
-#include "nsIPrefLocalizedString.h"
-#include "nsISupportsPrimitives.h"
+#include "mozilla/Preferences.h"
+
 #include "nsIStreamBufferAccess.h"
 #include "nsIUUIDGenerator.h"
 #include "nsMemory.h"
 #include "nsICharsetConverterManager.h"
 
 #include "plbase64.h"
 
 #include "woff.h"
@@ -857,27 +855,21 @@ PRUint8 gfxFontUtils::CharRangeBit(PRUin
 
 void gfxFontUtils::GetPrefsFontList(const char *aPrefName, nsTArray<nsString>& aFontList)
 {
     const PRUnichar kComma = PRUnichar(',');
     
     aFontList.Clear();
     
     // get the list of single-face font families
-    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
+    nsAdoptingString fontlistValue = Preferences::GetString(aPrefName);
+    if (!fontlistValue) {
+        return;
+    }
 
-    nsAutoString fontlistValue;
-    if (prefs) {
-        nsCOMPtr<nsISupportsString> prefString;
-        prefs->GetComplexValue(aPrefName, NS_GET_IID(nsISupportsString), getter_AddRefs(prefString));
-        if (!prefString) 
-            return;
-        prefString->GetData(fontlistValue);
-    }
-    
     // append each font name to the list
     nsAutoString fontname;
     nsPromiseFlatString fonts(fontlistValue);
     const PRUnichar *p, *p_end;
     fonts.BeginReading(p);
     fonts.EndReading(p_end);
 
      while (p < p_end) {
--- a/gfx/thebes/gfxFontconfigUtils.cpp
+++ b/gfx/thebes/gfxFontconfigUtils.cpp
@@ -39,25 +39,26 @@
 
 #include "gfxFontconfigUtils.h"
 #include "gfxFont.h"
 #include "gfxAtoms.h"
 
 #include <locale.h>
 #include <fontconfig/fontconfig.h>
 
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsILanguageAtomService.h"
 #include "nsTArray.h"
+#include "mozilla/Preferences.h"
 
 #include "nsIAtom.h"
 #include "nsCRT.h"
 
+using namespace mozilla;
+
 /* static */ gfxFontconfigUtils* gfxFontconfigUtils::sUtils = nsnull;
 static nsILanguageAtomService* gLangService = nsnull;
 
 /* static */ void
 gfxFontconfigUtils::Shutdown() {
     if (sUtils) {
         delete sUtils;
         sUtils = nsnull;
@@ -582,27 +583,18 @@ gfxFontconfigUtils::UpdateFontListIntern
         }
     }
 
     // XXX we don't support all alias names.
     // Because if we don't check whether the given font name is alias name,
     // fontconfig converts the non existing font to sans-serif.
     // This is not good if the web page specifies font-family
     // that has Windows font name in the first.
-    nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!prefs)
-        return NS_ERROR_FAILURE;
-
-    nsCOMPtr<nsIPrefBranch> prefBranch;
-    prefs->GetBranch(0, getter_AddRefs(prefBranch));
-    if (!prefBranch)
-        return NS_ERROR_FAILURE;
-
-    nsXPIDLCString list;
-    prefBranch->GetCharPref("font.alias-list", getter_Copies(list));
+    NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
+    nsAdoptingCString list = Preferences::GetCString("font.alias-list");
 
     if (!list.IsEmpty()) {
         const char kComma = ',';
         const char *p, *p_end;
         list.BeginReading(p);
         list.EndReading(p_end);
         while (p < p_end) {
             while (nsCRT::IsAsciiSpace(*p)) {
--- a/gfx/thebes/gfxOS2Fonts.cpp
+++ b/gfx/thebes/gfxOS2Fonts.cpp
@@ -42,20 +42,21 @@
 #include "gfxContext.h"
 
 #include "gfxOS2Platform.h"
 #include "gfxOS2Surface.h"
 #include "gfxOS2Fonts.h"
 #include "nsTArray.h"
 #include "gfxAtoms.h"
 
-#include "nsIServiceManager.h"
 #include "nsIPlatformCharset.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
+
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 /**********************************************************************
  * class gfxOS2Font
  **********************************************************************/
 
 gfxOS2Font::gfxOS2Font(gfxOS2FontEntry *aFontEntry, const gfxFontStyle *aFontStyle)
     : gfxFont(aFontEntry, aFontStyle),
       mFontFace(nsnull), mScaledFont(nsnull),
@@ -63,28 +64,24 @@ gfxOS2Font::gfxOS2Font(gfxOS2FontEntry *
       mHinting(FC_HINT_MEDIUM), mAntialias(FcTrue)
 {
 #ifdef DEBUG_thebes_2
     printf("gfxOS2Font[%p]::gfxOS2Font(%p \"%s\", aFontStyle)\n",
            (void *)this, (void *)aFontEntry,
            NS_LossyConvertUTF16toASCII(aFontEntry->Name()).get());
 #endif
     // try to get the preferences for hinting, antialias, and embolden options
-    nsCOMPtr<nsIPrefBranch> prefbranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefbranch) {
-        int value;
-        nsresult rv = prefbranch->GetIntPref("gfx.os2.font.hinting", &value);
-        if (NS_SUCCEEDED(rv) && value >= FC_HINT_NONE && value <= FC_HINT_FULL)
-            mHinting = value;
+    PRInt32 value;
+    nsresult rv = Preferences::GetInt("gfx.os2.font.hinting", &value);
+    if (NS_SUCCEEDED(rv) && value >= FC_HINT_NONE && value <= FC_HINT_FULL) {
+        mHinting = value;
+    }
 
-        PRBool enabled;
-        rv = prefbranch->GetBoolPref("gfx.os2.font.antialiasing", &enabled);
-        if (NS_SUCCEEDED(rv))
-            mAntialias = enabled;
-    }
+    mAntialias = Preferences::GetBool("gfx.os2.font.antialiasing", mAntialias);
+
 #ifdef DEBUG_thebes_2
     printf("  font display options: hinting=%d, antialiasing=%s\n",
            mHinting, mAntialias ? "on" : "off");
 #endif
 }
 
 gfxOS2Font::~gfxOS2Font()
 {
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -74,28 +74,27 @@
 #include "nsILocaleService.h"
 
 #include "nsWeakReference.h"
 
 #include "cairo.h"
 #include "qcms.h"
 
 #include "plstr.h"
-#include "nsIPrefService.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefBranch2.h"
-#include "nsIPrefLocalizedString.h"
 #include "nsCRT.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 
 #include "mozilla/FunctionTimer.h"
+#include "mozilla/Preferences.h"
 
 #include "nsIGfxInfo.h"
 
+using namespace mozilla;
+
 gfxPlatform *gPlatform = nsnull;
 static bool gEverInitialized = false;
 
 // These two may point to the same profile
 static qcms_profile *gCMSOutputProfile = nsnull;
 static qcms_profile *gCMSsRGBProfile = nsnull;
 
 static qcms_transform *gCMSRGBTransform = nsnull;
@@ -149,38 +148,42 @@ SRGBOverrideObserver::Observe(nsISupport
 }
 
 #define GFX_DOWNLOADABLE_FONTS_ENABLED "gfx.downloadable_fonts.enabled"
 #define GFX_DOWNLOADABLE_FONTS_SANITIZE "gfx.downloadable_fonts.sanitize"
 
 #define GFX_PREF_HARFBUZZ_SCRIPTS "gfx.font_rendering.harfbuzz.scripts"
 #define HARFBUZZ_SCRIPTS_DEFAULT  gfxUnicodeProperties::SHAPING_DEFAULT
 
+static const char* kObservedPrefs[] = {
+    "gfx.downloadable_fonts.",
+    "gfx.font_rendering.",
+    nsnull
+};
+
 class FontPrefsObserver : public nsIObserver
 {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
 NS_IMPL_ISUPPORTS1(FontPrefsObserver, nsIObserver)
 
 NS_IMETHODIMP
 FontPrefsObserver::Observe(nsISupports *aSubject,
                            const char *aTopic,
                            const PRUnichar *someData)
 {
-    nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(aSubject);
-    if (!branch || someData == nsnull) {
+    if (!someData) {
         NS_ERROR("font pref observer code broken");
         return NS_ERROR_UNEXPECTED;
     }
-    
-    gfxPlatform::GetPlatform()->FontsPrefsChanged(branch, 
-        NS_ConvertUTF16toUTF8(someData).get());
+    NS_ASSERTION(gfxPlatform::GetPlatform(), "the singleton instance has gone");
+    gfxPlatform::GetPlatform()->FontsPrefsChanged(NS_ConvertUTF16toUTF8(someData).get());
 
     return NS_OK;
 }
 
 
 
 // this needs to match the list of pref font.default.xx entries listed in all.js!
 // the order *must* match the order in eFontPrefLang
@@ -310,25 +313,21 @@ gfxPlatform::Init()
     if (NS_FAILED(rv)) {
         NS_RUNTIMEABORT("Could not initialize gfxTextRunCache");
     }
 
     /* Pref migration hook. */
     MigratePrefs();
 
     /* Create and register our CMS Override observer. */
-    gPlatform->overrideObserver = new SRGBOverrideObserver();
-    FontPrefsObserver *fontPrefObserver = new FontPrefsObserver();
+    gPlatform->mSRGBOverrideObserver = new SRGBOverrideObserver();
+    Preferences::AddWeakObserver(gPlatform->mSRGBOverrideObserver, CMForceSRGBPrefName);
 
-    nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs) {
-        prefs->AddObserver(CMForceSRGBPrefName, gPlatform->overrideObserver, PR_TRUE);
-        prefs->AddObserver("gfx.downloadable_fonts.", fontPrefObserver, PR_FALSE);
-        prefs->AddObserver("gfx.font_rendering.", fontPrefObserver, PR_FALSE);
-    }
+    gPlatform->mFontPrefsObserver = new FontPrefsObserver();
+    Preferences::AddStrongObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
 
     // Force registration of the gfx component, thus arranging for
     // ::Shutdown to be called.
     nsCOMPtr<nsISupports> forceReg
         = do_CreateInstance("@mozilla.org/gfx/init;1");
 }
 
 void
@@ -342,20 +341,28 @@ gfxPlatform::Shutdown()
     gfxFontGroup::Shutdown();
 #if defined(XP_MACOSX) || defined(XP_WIN) // temporary, until this is implemented on others
     gfxPlatformFontList::Shutdown();
 #endif
 
     // Free the various non-null transforms and loaded profiles
     ShutdownCMS();
 
-    /* Unregister our CMS Override callback. */
-    nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs)
-        prefs->RemoveObserver(CMForceSRGBPrefName, gPlatform->overrideObserver);
+    // In some cases, gPlatform may not be created but Shutdown() called,
+    // e.g., during xpcshell tests.
+    if (gPlatform) {
+        /* Unregister our CMS Override callback. */
+        NS_ASSERTION(gPlatform->mSRGBOverrideObserver, "mSRGBOverrideObserver has alreay gone");
+        Preferences::RemoveObserver(gPlatform->mSRGBOverrideObserver, CMForceSRGBPrefName);
+        gPlatform->mSRGBOverrideObserver = nsnull;
+
+        NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone");
+        Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
+        gPlatform->mFontPrefsObserver = nsnull;
+    }
 
     mozilla::gl::GLContextProvider::Shutdown();
 
     delete gPlatform;
     gPlatform = nsnull;
 }
 
 gfxPlatform::~gfxPlatform()
@@ -414,65 +421,43 @@ gfxPlatform::GetFontList(nsIAtom *aLangG
 }
 
 nsresult
 gfxPlatform::UpdateFontList()
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-PRBool 
-gfxPlatform::GetBoolPref(const char *aPref, PRBool aDefault)
-{
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs) {
-        PRBool allow;
-        nsresult rv = prefs->GetBoolPref(aPref, &allow);
-        if (NS_SUCCEEDED(rv))
-            return allow;
-    }
-
-    return aDefault;
-}
-
 PRBool
 gfxPlatform::DownloadableFontsEnabled()
 {
     if (mAllowDownloadableFonts == UNINITIALIZED_VALUE) {
         mAllowDownloadableFonts =
-            GetBoolPref(GFX_DOWNLOADABLE_FONTS_ENABLED, PR_FALSE);
+            Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_ENABLED, PR_FALSE);
     }
 
     return mAllowDownloadableFonts;
 }
 
 PRBool
 gfxPlatform::SanitizeDownloadedFonts()
 {
     if (mDownloadableFontsSanitize == UNINITIALIZED_VALUE) {
         mDownloadableFontsSanitize =
-            GetBoolPref(GFX_DOWNLOADABLE_FONTS_SANITIZE, PR_TRUE);
+            Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_SANITIZE, PR_TRUE);
     }
 
     return mDownloadableFontsSanitize;
 }
 
 PRBool
 gfxPlatform::UseHarfBuzzForScript(PRInt32 aScriptCode)
 {
     if (mUseHarfBuzzScripts == UNINITIALIZED_VALUE) {
-        mUseHarfBuzzScripts = HARFBUZZ_SCRIPTS_DEFAULT;
-        nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (prefs) {
-            PRInt32 scripts;
-            nsresult rv = prefs->GetIntPref(GFX_PREF_HARFBUZZ_SCRIPTS, &scripts);
-            if (NS_SUCCEEDED(rv)) {
-                mUseHarfBuzzScripts = scripts;
-            }
-        }
+        mUseHarfBuzzScripts = Preferences::GetInt(GFX_PREF_HARFBUZZ_SCRIPTS, HARFBUZZ_SCRIPTS_DEFAULT);
     }
 
     PRInt32 shapingType = gfxUnicodeProperties::ScriptShapingType(aScriptCode);
 
     return (mUseHarfBuzzScripts & shapingType) != 0;
 }
 
 gfxFontEntry*
@@ -489,110 +474,98 @@ gfxPlatform::MakePlatformFont(const gfxP
         NS_Free((void*)aFontData);
     }
     return nsnull;
 }
 
 static void
 AppendGenericFontFromPref(nsString& aFonts, nsIAtom *aLangGroup, const char *aGenericName)
 {
-    nsresult rv;
-
-    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-    if (!prefs)
-        return;
+    NS_ENSURE_TRUE(Preferences::GetRootBranch(), );
 
     nsCAutoString prefName, langGroupString;
-    nsXPIDLCString nameValue, nameListValue;
 
     aLangGroup->ToUTF8String(langGroupString);
 
     nsCAutoString genericDotLang;
     if (aGenericName) {
         genericDotLang.Assign(aGenericName);
     } else {
         prefName.AssignLiteral("font.default.");
         prefName.Append(langGroupString);
-        prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
+        genericDotLang = Preferences::GetCString(prefName.get());
     }
 
     genericDotLang.AppendLiteral(".");
     genericDotLang.Append(langGroupString);
 
     // fetch font.name.xxx value                   
     prefName.AssignLiteral("font.name.");
     prefName.Append(genericDotLang);
-    rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
-    if (NS_SUCCEEDED(rv)) {
+    nsAdoptingString nameValue = Preferences::GetString(prefName.get());
+    if (nameValue) {
         if (!aFonts.IsEmpty())
             aFonts.AppendLiteral(", ");
-        aFonts.Append(NS_ConvertUTF8toUTF16(nameValue));
+        aFonts += nameValue;
     }
 
     // fetch font.name-list.xxx value                   
     prefName.AssignLiteral("font.name-list.");
     prefName.Append(genericDotLang);
-    rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameListValue));
-    if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
+    nsAdoptingString nameListValue = Preferences::GetString(prefName.get());
+    if (nameListValue && !nameListValue.Equals(nameValue)) {
         if (!aFonts.IsEmpty())
             aFonts.AppendLiteral(", ");
-        aFonts.Append(NS_ConvertUTF8toUTF16(nameListValue));
+        aFonts += nameListValue;
     }
 }
 
 void
 gfxPlatform::GetPrefFonts(nsIAtom *aLanguage, nsString& aFonts, PRBool aAppendUnicode)
 {
     aFonts.Truncate();
 
     AppendGenericFontFromPref(aFonts, aLanguage, nsnull);
     if (aAppendUnicode)
         AppendGenericFontFromPref(aFonts, gfxAtoms::x_unicode, nsnull);
 }
 
 PRBool gfxPlatform::ForEachPrefFont(eFontPrefLang aLangArray[], PRUint32 aLangArrayLen, PrefFontCallback aCallback,
                                     void *aClosure)
 {
-    nsresult rv;
-
-    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-    if (!prefs)
-        return PR_FALSE;
+    NS_ENSURE_TRUE(Preferences::GetRootBranch(), PR_FALSE);
 
     PRUint32    i;
-    
     for (i = 0; i < aLangArrayLen; i++) {
         eFontPrefLang prefLang = aLangArray[i];
         const char *langGroup = GetPrefLangName(prefLang);
         
         nsCAutoString prefName;
-        nsXPIDLCString nameValue, nameListValue;
     
-        nsCAutoString genericDotLang;
         prefName.AssignLiteral("font.default.");
         prefName.Append(langGroup);
-        prefs->GetCharPref(prefName.get(), getter_Copies(genericDotLang));
+        nsAdoptingCString genericDotLang = Preferences::GetCString(prefName.get());
     
         genericDotLang.AppendLiteral(".");
         genericDotLang.Append(langGroup);
     
         // fetch font.name.xxx value                   
         prefName.AssignLiteral("font.name.");
         prefName.Append(genericDotLang);
-        rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameValue));
-        if (NS_SUCCEEDED(rv)) {
+        nsAdoptingCString nameValue = Preferences::GetCString(prefName.get());
+        if (nameValue) {
             if (!aCallback(prefLang, NS_ConvertUTF8toUTF16(nameValue), aClosure))
                 return PR_FALSE;
         }
     
         // fetch font.name-list.xxx value                   
         prefName.AssignLiteral("font.name-list.");
         prefName.Append(genericDotLang);
-        rv = prefs->GetCharPref(prefName.get(), getter_Copies(nameListValue));
-        if (NS_SUCCEEDED(rv) && !nameListValue.Equals(nameValue)) {
+        nsAdoptingCString nameListValue = Preferences::GetCString(prefName.get());
+        if (nameListValue && !nameListValue.Equals(nameValue)) {
             const char kComma = ',';
             const char *p, *p_end;
             nsCAutoString list(nameListValue);
             list.BeginReading(p);
             list.EndReading(p_end);
             while (p < p_end) {
                 while (nsCRT::IsAsciiSpace(*p)) {
                     if (++p == p_end)
@@ -708,45 +681,30 @@ gfxPlatform::GetLangPrefs(eFontPrefLang 
     }
 
     AppendPrefLang(aPrefLangs, aLen, eFontPrefLang_Others);
 }
 
 void
 gfxPlatform::AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang)
 {
-    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-
     // prefer the lang specified by the page *if* CJK
     if (IsLangCJK(aPageLang)) {
         AppendPrefLang(aPrefLangs, aLen, aPageLang);
     }
     
     // if not set up, set up the default CJK order, based on accept lang settings and locale
     if (mCJKPrefLangs.Length() == 0) {
     
         // temp array
         eFontPrefLang tempPrefLangs[kMaxLenPrefLangList];
         PRUint32 tempLen = 0;
         
         // Add the CJK pref fonts from accept languages, the order should be same order
-        nsCAutoString list;
-        if (prefs) {
-            nsCOMPtr<nsIPrefLocalizedString> prefString;
-            nsresult rv =
-                prefs->GetComplexValue("intl.accept_languages",
-                                       NS_GET_IID(nsIPrefLocalizedString),
-                                       getter_AddRefs(prefString));
-            if (NS_SUCCEEDED(rv) && prefString) {
-                nsAutoString temp;
-                prefString->ToString(getter_Copies(temp));
-                LossyCopyUTF16toASCII(temp, list);
-            }
-        }
-        
+        nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
         if (!list.IsEmpty()) {
             const char kComma = ',';
             const char *p, *p_end;
             list.BeginReading(p);
             list.EndReading(p_end);
             while (p < p_end) {
                 while (nsCRT::IsAsciiSpace(*p)) {
                     if (++p == p_end)
@@ -850,24 +808,20 @@ gfxPlatform::AppendPrefLang(eFontPrefLan
     }
 }
 
 eCMSMode
 gfxPlatform::GetCMSMode()
 {
     if (gCMSInitialized == PR_FALSE) {
         gCMSInitialized = PR_TRUE;
-        nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (prefs) {
-            PRInt32 mode;
-            nsresult rv =
-                prefs->GetIntPref(CMPrefName, &mode);
-            if (NS_SUCCEEDED(rv) && (mode >= 0) && (mode < eCMSMode_AllCount)) {
-                gCMSMode = static_cast<eCMSMode>(mode);
-            }
+        PRInt32 mode;
+        nsresult rv = Preferences::GetInt(CMPrefName, &mode);
+        if (NS_SUCCEEDED(rv) && (mode >= 0) && (mode < eCMSMode_AllCount)) {
+            gCMSMode = static_cast<eCMSMode>(mode);
         }
     }
     return gCMSMode;
 }
 
 /* Chris Murphy (CM consultant) suggests this as a default in the event that we
 cannot reproduce relative + Black Point Compensation.  BPC brings an
 unacceptable performance overhead, so we go with perceptual. */
@@ -876,35 +830,31 @@ unacceptable performance overhead, so we
 #define INTENT_MAX 3
 
 PRBool
 gfxPlatform::GetRenderingIntent()
 {
     if (gCMSIntent == -2) {
 
         /* Try to query the pref system for a rendering intent. */
-        nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (prefs) {
-            PRInt32 pIntent;
-            nsresult rv = prefs->GetIntPref(CMIntentPrefName, &pIntent);
-            if (NS_SUCCEEDED(rv)) {
-              
-                /* If the pref is within range, use it as an override. */
-                if ((pIntent >= INTENT_MIN) && (pIntent <= INTENT_MAX))
-                    gCMSIntent = pIntent;
-
-                /* If the pref is out of range, use embedded profile. */
-                else
-                    gCMSIntent = -1;
+        PRInt32 pIntent;
+        if (NS_SUCCEEDED(Preferences::GetInt(CMIntentPrefName, &pIntent))) {
+            /* If the pref is within range, use it as an override. */
+            if ((pIntent >= INTENT_MIN) && (pIntent <= INTENT_MAX)) {
+                gCMSIntent = pIntent;
+            }
+            /* If the pref is out of range, use embedded profile. */
+            else {
+                gCMSIntent = -1;
             }
         }
-
         /* If we didn't get a valid intent from prefs, use the default. */
-        if (gCMSIntent == -2) 
+        else {
             gCMSIntent = INTENT_DEFAULT;
+        }
     }
     return gCMSIntent;
 }
 
 void 
 gfxPlatform::TransformPixel(const gfxRGBA& in, gfxRGBA& out, qcms_transform *transform)
 {
 
@@ -941,41 +891,31 @@ gfxPlatform::GetPlatformCMSOutputProfile
 }
 
 qcms_profile *
 gfxPlatform::GetCMSOutputProfile()
 {
     if (!gCMSOutputProfile) {
         NS_TIME_FUNCTION;
 
-        nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (prefs) {
-
-            nsresult rv;
-
-            /* Determine if we're using the internal override to force sRGB as
-               an output profile for reftests. See Bug 452125.
+        /* Determine if we're using the internal override to force sRGB as
+           an output profile for reftests. See Bug 452125.
 
-               Note that we don't normally (outside of tests) set a
-               default value of this preference, which means GetBoolPref
-               will typically throw (and leave its out-param untouched).
-             */
-            PRBool doSRGBOverride;
-            rv = prefs->GetBoolPref(CMForceSRGBPrefName, &doSRGBOverride);
-            if (NS_SUCCEEDED(rv) && doSRGBOverride)
-                gCMSOutputProfile = GetCMSsRGBProfile();
+           Note that we don't normally (outside of tests) set a
+           default value of this preference, which means nsIPrefBranch::GetBoolPref
+           will typically throw (and leave its out-param untouched).
+         */
+        if (Preferences::GetBool(CMForceSRGBPrefName, PR_FALSE)) {
+            gCMSOutputProfile = GetCMSsRGBProfile();
+        }
 
-            if (!gCMSOutputProfile) {
-
-                nsXPIDLCString fname;
-                rv = prefs->GetCharPref(CMProfilePrefName,
-                                        getter_Copies(fname));
-                if (NS_SUCCEEDED(rv) && !fname.IsEmpty()) {
-                    gCMSOutputProfile = qcms_profile_from_path(fname);
-                }
+        if (!gCMSOutputProfile) {
+            nsAdoptingCString fname = Preferences::GetCString(CMProfilePrefName);
+            if (!fname.IsEmpty()) {
+                gCMSOutputProfile = qcms_profile_from_path(fname);
             }
         }
 
         if (!gCMSOutputProfile) {
             gCMSOutputProfile =
                 gfxPlatform::GetPlatform()->GetPlatformCMSOutputProfile();
         }
 
@@ -1099,36 +1039,24 @@ static void ShutdownCMS()
     // Reset the state variables
     gCMSIntent = -2;
     gCMSMode = eCMSMode_Off;
     gCMSInitialized = PR_FALSE;
 }
 
 static void MigratePrefs()
 {
-
-    /* Load the pref service. If we don't get it die quietly since this isn't
-       critical code. */
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!prefs)
-        return;
-
     /* Migrate from the boolean color_management.enabled pref - we now use
        color_management.mode. */
-    PRBool hasOldCMPref;
-    nsresult rv =
-        prefs->PrefHasUserValue(CMPrefNameOld, &hasOldCMPref);
-    if (NS_SUCCEEDED(rv) && (hasOldCMPref == PR_TRUE)) {
-        PRBool CMWasEnabled;
-        rv = prefs->GetBoolPref(CMPrefNameOld, &CMWasEnabled);
-        if (NS_SUCCEEDED(rv) && (CMWasEnabled == PR_TRUE))
-            prefs->SetIntPref(CMPrefName, eCMSMode_All);
-        prefs->ClearUserPref(CMPrefNameOld);
+    if (Preferences::HasUserValue(CMPrefNameOld)) {
+        if (Preferences::GetBool(CMPrefNameOld, PR_FALSE)) {
+            Preferences::SetInt(CMPrefName, static_cast<PRInt32>(eCMSMode_All));
+        }
+        Preferences::ClearUser(CMPrefNameOld);
     }
-
 }
 
 // default SetupClusterBoundaries, based on Unicode properties;
 // platform subclasses may override if they wish
 void
 gfxPlatform::SetupClusterBoundaries(gfxTextRun *aTextRun, const PRUnichar *aString)
 {
     if (aTextRun->GetFlags() & gfxTextRunFactory::TEXT_IS_8BIT) {
@@ -1239,17 +1167,17 @@ gfxPlatform::SetupClusterBoundaries(gfxT
             aTextRun->SetGlyphs(i, extendCluster, nsnull);
         }
 
         hangulState = hangulType;
     }
 }
 
 void
-gfxPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
+gfxPlatform::FontsPrefsChanged(const char *aPref)
 {
     NS_ASSERTION(aPref != nsnull, "null preference");
     if (!strcmp(GFX_DOWNLOADABLE_FONTS_ENABLED, aPref)) {
         mAllowDownloadableFonts = UNINITIALIZED_VALUE;
     } else if (!strcmp(GFX_DOWNLOADABLE_FONTS_SANITIZE, aPref)) {
         mDownloadableFontsSanitize = UNINITIALIZED_VALUE;
     } else if (!strcmp(GFX_PREF_HARFBUZZ_SCRIPTS, aPref)) {
         mUseHarfBuzzScripts = UNINITIALIZED_VALUE;
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -60,17 +60,16 @@ class gfxFontGroup;
 struct gfxFontStyle;
 class gfxUserFontSet;
 class gfxFontEntry;
 class gfxProxyFontEntry;
 class gfxPlatformFontList;
 class gfxTextRun;
 class nsIURI;
 class nsIAtom;
-class nsIPrefBranch;
 
 // pref lang id's for font prefs
 // !!! needs to match the list of pref font.default.xx entries listed in all.js !!!
 // !!! don't use as bit mask, this may grow larger !!!
 
 enum eFontPrefLang {
     eFontPrefLang_Western     =  0,
     eFontPrefLang_CentEuro    =  1,
@@ -345,17 +344,17 @@ public:
      */
     static qcms_transform* GetCMSInverseRGBTransform();
 
     /**
      * Return sRGBA -> output device transform.
      */
     static qcms_transform* GetCMSRGBATransform();
 
-    virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
+    virtual void FontsPrefsChanged(const char *aPref);
 
     /**
      * Returns a 1x1 surface that can be used to create graphics contexts
      * for measuring text etc as if they will be rendered to the screen
      */
     gfxASurface* ScreenReferenceSurface() { return mScreenReferenceSurface; }
 
     virtual gfxImageFormat GetOffscreenFormat()
@@ -365,28 +364,27 @@ public:
      * Returns a logger if one is available and logging is enabled
      */
     static PRLogModuleInfo* GetLog(eGfxLog aWhichLog);
 
 protected:
     gfxPlatform();
     virtual ~gfxPlatform();
 
-    static PRBool GetBoolPref(const char *aPref, PRBool aDefault);
-
     void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen, 
                             eFontPrefLang aCharLang, eFontPrefLang aPageLang);
                                                
     PRBool  mAllowDownloadableFonts;
     PRBool  mDownloadableFontsSanitize;
 
     // which scripts should be shaped with harfbuzz
     PRInt32 mUseHarfBuzzScripts;
 
 private:
     virtual qcms_profile* GetPlatformCMSOutputProfile();
 
     nsRefPtr<gfxASurface> mScreenReferenceSurface;
     nsTArray<PRUint32> mCJKPrefLangs;
-    nsCOMPtr<nsIObserver> overrideObserver;
+    nsCOMPtr<nsIObserver> mSRGBOverrideObserver;
+    nsCOMPtr<nsIObserver> mFontPrefsObserver;
 };
 
 #endif /* GFX_PLATFORM_H */
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -67,23 +67,24 @@
 #ifdef MOZ_LOGGING
 #define FORCE_PR_LOG /* Allow logging in the release build */
 #endif
 #include "prlog.h"
 
 #include "gfxPlatformFontList.h"
 #include "gfxTextRunWordCache.h"
 
-#include "nsIPrefService.h"
-#include "nsIPrefBranch2.h"  // for pref changes callback notification
-#include "nsServiceManagerUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsUnicodeRange.h"
 #include "gfxUnicodeProperties.h"
 
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
+
 // font info loader constants
 static const PRUint32 kDelayBeforeLoadingCmaps = 8 * 1000; // 8secs
 static const PRUint32 kIntervalBetweenLoadingCmaps = 150; // 150ms
 static const PRUint32 kNumFontsPerSlice = 10; // read in info 10 fonts at a time
 
 #ifdef PR_LOGGING
 
 #define LOG_FONTLIST(args) PR_LOG(gfxPlatform::GetLog(eGfxLog_fontlist), \
@@ -92,22 +93,31 @@ static const PRUint32 kNumFontsPerSlice 
                                    gfxPlatform::GetLog(eGfxLog_fontlist), \
                                    PR_LOG_DEBUG)
 
 #endif // PR_LOGGING
 
 gfxPlatformFontList *gfxPlatformFontList::sPlatformFontList = nsnull;
 
 
+static const char* kObservedPrefs[] = {
+    "font.",
+    "font.name-list.",
+    "intl.accept_languages",  // hmmmm...
+    nsnull
+};
+
 class gfxFontListPrefObserver : public nsIObserver {
 public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIOBSERVER
 };
 
+static gfxFontListPrefObserver* gFontListPrefObserver = nsnull;
+
 NS_IMPL_ISUPPORTS1(gfxFontListPrefObserver, nsIObserver)
 
 NS_IMETHODIMP
 gfxFontListPrefObserver::Observe(nsISupports     *aSubject,
                                  const char      *aTopic,
                                  const PRUnichar *aData)
 {
     NS_ASSERTION(!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), "invalid topic");
@@ -134,27 +144,28 @@ gfxPlatformFontList::gfxPlatformFontList
     mFaceNamesInitialized = PR_FALSE;
 
     mPrefFonts.Init(10);
 
     mBadUnderlineFamilyNames.Init(10);
     LoadBadUnderlineList();
 
     // pref changes notification setup
-    gfxFontListPrefObserver *observer = new gfxFontListPrefObserver();
-    if (observer) {
-        nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
-        if (pref) {
-            pref->AddObserver("font.", observer, PR_FALSE);
-            pref->AddObserver("font.name-list.", observer, PR_FALSE);
-            pref->AddObserver("intl.accept_languages", observer, PR_FALSE);  // hmmmm...
-        } else {
-            delete observer;
-        }
-    }
+    NS_ASSERTION(!gFontListPrefObserver,
+                 "There has been font list pref observer already");
+    gFontListPrefObserver = new gfxFontListPrefObserver();
+    NS_ADDREF(gFontListPrefObserver);
+    Preferences::AddStrongObservers(gFontListPrefObserver, kObservedPrefs);
+}
+
+gfxPlatformFontList::~gfxPlatformFontList()
+{
+    NS_ASSERTION(gFontListPrefObserver, "There is no font list pref observer");
+    Preferences::RemoveObservers(gFontListPrefObserver, kObservedPrefs);
+    NS_RELEASE(gFontListPrefObserver);
 }
 
 nsresult
 gfxPlatformFontList::InitFontList()
 {
     mFontFamilies.Clear();
     mOtherFamilyNames.Clear();
     mOtherFamilyNamesInitialized = PR_FALSE;
--- a/gfx/thebes/gfxPlatformFontList.h
+++ b/gfx/thebes/gfxPlatformFontList.h
@@ -74,16 +74,18 @@ public:
         return NS_OK;
     }
 
     static void Shutdown() {
         delete sPlatformFontList;
         sPlatformFontList = nsnull;
     }
 
+    virtual ~gfxPlatformFontList();
+
     // initialize font lists
     virtual nsresult InitFontList();
 
     void GetFontList (nsIAtom *aLangGroup,
                       const nsACString& aGenericFamily,
                       nsTArray<nsString>& aListOfFonts);
 
     virtual PRBool ResolveFontName(const nsAString& aFontName,
--- a/gfx/thebes/gfxPlatformMac.cpp
+++ b/gfx/thebes/gfxPlatformMac.cpp
@@ -42,28 +42,28 @@
 #include "gfxQuartzSurface.h"
 #include "gfxQuartzImageSurface.h"
 
 #include "gfxMacPlatformFontList.h"
 #include "gfxMacFont.h"
 #include "gfxCoreTextShaper.h"
 #include "gfxUserFontSet.h"
 
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
-#include "nsIPrefLocalizedString.h"
-#include "nsServiceManagerUtils.h"
 #include "nsCRT.h"
 #include "nsTArray.h"
 #include "nsUnicodeRange.h"
 
+#include "mozilla/Preferences.h"
+
 #include "qcms.h"
 
 #include <dlfcn.h>
 
+using namespace mozilla;
+
 // cribbed from CTFontManager.h
 enum {
    kAutoActivationDisabled = 1
 };
 typedef uint32_t AutoActivationSetting;
 
 // bug 567552 - disable auto-activation of fonts
 
@@ -265,27 +265,18 @@ gfxPlatformMac::OSXVersion()
 }
 
 PRUint32
 gfxPlatformMac::ReadAntiAliasingThreshold()
 {
     PRUint32 threshold = 0;  // default == no threshold
     
     // first read prefs flag to determine whether to use the setting or not
-    PRBool useAntiAliasingThreshold = PR_FALSE;
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs) {
-        PRBool enabled;
-        nsresult rv =
-            prefs->GetBoolPref("gfx.use_text_smoothing_setting", &enabled);
-        if (NS_SUCCEEDED(rv)) {
-            useAntiAliasingThreshold = enabled;
-        }
-    }
-    
+    PRBool useAntiAliasingThreshold = Preferences::GetBool("gfx.use_text_smoothing_setting", PR_FALSE);
+
     // if the pref setting is disabled, return 0 which effectively disables this feature
     if (!useAntiAliasingThreshold)
         return threshold;
         
     // value set via Appearance pref panel, "Turn off text smoothing for font sizes xxx and smaller"
     CFNumberRef prefValue = (CFNumberRef)CFPreferencesCopyAppValue(CFSTR("AppleAntiAliasingThreshold"), kCFPreferencesCurrentApplication);
 
     if (prefValue) {
--- a/gfx/thebes/gfxQtPlatform.cpp
+++ b/gfx/thebes/gfxQtPlatform.cpp
@@ -71,18 +71,19 @@
 
 #include "qcms.h"
 
 #ifndef MOZ_PANGO
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #endif
 
-#include "nsIPrefBranch.h"
-#include "nsIPrefService.h"
+#include "mozilla/Preferences.h"
+
+using namespace mozilla;
 
 #define DEFAULT_RENDER_MODE RENDER_DIRECT
 
 static QPaintEngine::Type sDefaultQtPaintEngineType = QPaintEngine::X11;
 gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nsnull;
 static cairo_user_data_key_t cairo_qt_pixmap_key;
 static void do_qt_pixmap_unref (void *data)
 {
@@ -118,25 +119,19 @@ gfxQtPlatform::gfxQtPlatform()
     gPlatformFontAliases->Init(100);
     gPrefFonts = new PrefFontTable();
     gPrefFonts->Init(100);
     gCodepointsWithNoFonts = new gfxSparseBitSet();
     UpdateFontList();
 #endif
 
     nsresult rv;
-    PRInt32 ival;
     // 0 - default gfxQPainterSurface
     // 1 - gfxImageSurface
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
-    if (prefs) {
-      rv = prefs->GetIntPref("mozilla.widget-qt.render-mode", &ival);
-      if (NS_FAILED(rv))
-          ival = DEFAULT_RENDER_MODE;
-    }
+    PRInt32 ival = Preferences::GetInt("mozilla.widget-qt.render-mode", DEFAULT_RENDER_MODE);
 
     const char *envTypeOverride = getenv("MOZ_QT_RENDER_TYPE");
     if (envTypeOverride)
         ival = atoi(envTypeOverride);
 
     switch (ival) {
         case 0:
             mRenderMode = RENDER_QPAINTER;
--- a/gfx/thebes/gfxTextRunWordCache.cpp
+++ b/gfx/thebes/gfxTextRunWordCache.cpp
@@ -36,32 +36,31 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "gfxTextRunWordCache.h"
 
 #include "nsWeakReference.h"
 #include "nsCRT.h"
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefBranch.h"
-#include "nsIPrefBranch2.h"
-#include "nsIPrefService.h"
 #include "nsIObserver.h"
 
 #include "nsBidiUtils.h"
+#include "mozilla/Preferences.h"
 
 #if defined(XP_UNIX)
 #include <stdint.h>
 #endif
 
 #ifdef DEBUG
 #include <stdio.h>
 #endif
 
+using namespace mozilla;
+
 /**
  * Cache individual "words" (strings delimited by white-space or white-space-like
  * characters that don't involve kerning or ligatures) in textruns.
  *  
  * The characters treated as word boundaries are defined by IsWordBoundary
  * below. The characters are: space, NBSP, and all the characters
  * defined by gfxFontGroup::IsInvalidChar. The latter are all converted
  * to invisible missing glyphs in this code. Thus, this class ensures
@@ -216,74 +215,59 @@ protected:
                        PRBool aSuccessful);
     void RemoveWord(gfxTextRun *aTextRun, PRUint32 aStart,
                     PRUint32 aEnd, PRUint32 aHash);
     void Uninit();
 
     nsTHashtable<CacheHashEntry> mCache;
 
     PRInt32 mBidiNumeral;
-    nsCOMPtr<nsIPrefBranch2> mPrefBranch;
-    nsCOMPtr<nsIPrefBranch2> mFontPrefBranch;
 
 #ifdef DEBUG
     static PLDHashOperator CacheDumpEntry(CacheHashEntry* aEntry, void* userArg);
 #endif
 };
 
 NS_IMPL_ISUPPORTS2(TextRunWordCache, nsIObserver, nsISupportsWeakReference)
 
 static TextRunWordCache *gTextRunWordCache = nsnull;
 
 static PRLogModuleInfo *gWordCacheLog = PR_NewLogModule("wordCache");
 
+static const char* kObservedPrefs[] = {
+    "bidi.",
+    "font.",
+    nsnull
+};
+
 void
 TextRunWordCache::Init()
 {
 #ifdef DEBUG
     mGeneration = 0;
 #endif
 
-    nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!prefService)
-        return;
-
-    nsCOMPtr<nsIPrefBranch> branch;
-    prefService->GetBranch("bidi.", getter_AddRefs(branch));
-    mPrefBranch = do_QueryInterface(branch);
-    if (!mPrefBranch)
-        return;
-
-    mPrefBranch->AddObserver("", this, PR_TRUE);
-    mPrefBranch->GetIntPref("numeral", &mBidiNumeral);
-
-    nsCOMPtr<nsIPrefBranch> fontBranch;
-    prefService->GetBranch("font.", getter_AddRefs(fontBranch));
-    mFontPrefBranch = do_QueryInterface(fontBranch);
-    if (mFontPrefBranch)
-      mFontPrefBranch->AddObserver("", this, PR_TRUE);
+    Preferences::AddWeakObservers(this, kObservedPrefs);
+    mBidiNumeral = Preferences::GetInt("bidi.numeral", mBidiNumeral);
 }
 
 void
 TextRunWordCache::Uninit()
 {
-    if (mPrefBranch)
-        mPrefBranch->RemoveObserver("", this);
-    if (mFontPrefBranch)
-        mFontPrefBranch->RemoveObserver("", this);
+    Preferences::RemoveObservers(this, kObservedPrefs);
 }
 
 NS_IMETHODIMP
 TextRunWordCache::Observe(nsISupports     *aSubject,
                           const char      *aTopic,
                           const PRUnichar *aData)
 {
     if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
-        if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("numeral").get())) {
-          mPrefBranch->GetIntPref("numeral", &mBidiNumeral);
+        if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("bidi.numeral").get())) {
+          mBidiNumeral = Preferences::GetInt("bidi.numeral", mBidiNumeral);
         }
         mCache.Clear();
         PR_LOG(gWordCacheLog, PR_LOG_DEBUG, ("flushing the textrun cache"));
 #ifdef DEBUG
         mGeneration++;
 #endif
     }
 
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -41,18 +41,17 @@
 #include "gfxWindowsPlatform.h"
 
 #include "gfxImageSurface.h"
 #include "gfxWindowsSurface.h"
 #include "gfxTextRunWordCache.h"
 
 #include "nsUnicharUtils.h"
 
-#include "nsIPrefService.h"
-#include "nsIPrefBranch2.h"
+#include "mozilla/Preferences.h"
 #include "nsServiceManagerUtils.h"
 #include "nsTArray.h"
 
 #include "nsIWindowsRegKey.h"
 #include "nsILocalFile.h"
 #include "plbase64.h"
 #include "nsIXULRuntime.h"
 
@@ -81,16 +80,18 @@
 #ifdef CAIRO_HAS_D2D_SURFACE
 #include "gfxD2DSurface.h"
 
 #include <d3d10_1.h>
 
 #include "nsIMemoryReporter.h"
 #include "nsMemory.h"
 
+using namespace mozilla;
+
 class D2DCacheReporter :
     public nsIMemoryReporter
 {
 public:
     D2DCacheReporter()
     { }
 
     NS_DECL_ISUPPORTS
@@ -278,28 +279,17 @@ gfxWindowsPlatform::UpdateRenderMode()
     ::GetVersionExA(&versionInfo);
     bool isVistaOrHigher = versionInfo.dwMajorVersion >= 6;
 
     PRBool safeMode = PR_FALSE;
     nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
     if (xr)
       xr->GetInSafeMode(&safeMode);
 
-    nsCOMPtr<nsIPrefBranch2> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    nsresult rv;
-
-    PRBool preferDirectWrite = PR_FALSE;
-
-    rv = pref->GetBoolPref(
-        "gfx.font_rendering.directwrite.enabled", &preferDirectWrite);
-    if (NS_FAILED(rv)) {
-        preferDirectWrite = PR_FALSE;
-    }
-
-    mUseDirectWrite = preferDirectWrite;
+    mUseDirectWrite = Preferences::GetBool("gfx.font_rendering.directwrite.enabled", PR_FALSE);
 
 #ifdef CAIRO_HAS_D2D_SURFACE
     PRBool d2dDisabled = PR_FALSE;
     PRBool d2dForceEnabled = PR_FALSE;
     PRBool d2dBlocked = PR_FALSE;
 
     nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
     if (gfxInfo) {
@@ -311,22 +301,18 @@ gfxWindowsPlatform::UpdateRenderMode()
                     status == nsIGfxInfo::FEATURE_BLOCKED_DEVICE)
                 {
                     d2dBlocked = PR_TRUE;
                 }
             }
         }
     }
 
-    rv = pref->GetBoolPref("gfx.direct2d.disabled", &d2dDisabled);
-    if (NS_FAILED(rv))
-        d2dDisabled = PR_FALSE;
-    rv = pref->GetBoolPref("gfx.direct2d.force-enabled", &d2dForceEnabled);
-    if (NS_FAILED(rv))
-        d2dForceEnabled = PR_FALSE;
+    d2dDisabled = Preferences::GetBool("gfx.direct2d.disabled", PR_FALSE);
+    d2dForceEnabled = Preferences::GetBool("gfx.direct2d.force-enabled", PR_FALSE);
 
     bool tryD2D = !d2dBlocked || d2dForceEnabled;
     
     // Do not ever try if d2d is explicitly disabled,
     // or if we're not using DWrite fonts.
     if (d2dDisabled || mUsingGDIFonts) {
         tryD2D = false;
     }
@@ -359,17 +345,17 @@ gfxWindowsPlatform::UpdateRenderMode()
             IDWriteFactory *factory;
             HRESULT hr = createDWriteFactory(
                 DWRITE_FACTORY_TYPE_SHARED,
                 __uuidof(IDWriteFactory),
                 reinterpret_cast<IUnknown**>(&factory));
             mDWriteFactory = factory;
             factory->Release();
 
-            SetupClearTypeParams(pref);
+            SetupClearTypeParams();
 
             if (hr == S_OK)
               reporter.SetSuccessful();
         }
     }
 #endif
 }
 
@@ -708,27 +694,27 @@ gfxWindowsPlatform::GetFTLibrary()
     return gPlatformFTLibrary;
 }
 #endif
 
 PRBool
 gfxWindowsPlatform::UseClearTypeForDownloadableFonts()
 {
     if (mUseClearTypeForDownloadableFonts == UNINITIALIZED_VALUE) {
-        mUseClearTypeForDownloadableFonts = GetBoolPref(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, PR_TRUE);
+        mUseClearTypeForDownloadableFonts = Preferences::GetBool(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, PR_TRUE);
     }
 
     return mUseClearTypeForDownloadableFonts;
 }
 
 PRBool
 gfxWindowsPlatform::UseClearTypeAlways()
 {
     if (mUseClearTypeAlways == UNINITIALIZED_VALUE) {
-        mUseClearTypeAlways = GetBoolPref(GFX_USE_CLEARTYPE_ALWAYS, PR_FALSE);
+        mUseClearTypeAlways = Preferences::GetBool(GFX_USE_CLEARTYPE_ALWAYS, PR_FALSE);
     }
 
     return mUseClearTypeAlways;
 }
 
 PRInt32
 gfxWindowsPlatform::WindowsOSVersion(PRInt32 *aBuildNum)
 {
@@ -886,87 +872,87 @@ gfxWindowsPlatform::GetCleartypeParams(n
             aParams.AppendElement(ctinfo);
         }
     }
 
     RegCloseKey(hKey);
 }
 
 void
-gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
+gfxWindowsPlatform::FontsPrefsChanged(const char *aPref)
 {
     PRBool clearTextFontCaches = PR_TRUE;
 
-    gfxPlatform::FontsPrefsChanged(aPrefBranch, aPref);
+    gfxPlatform::FontsPrefsChanged(aPref);
 
     if (!aPref) {
         mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
         mUseClearTypeAlways = UNINITIALIZED_VALUE;
     } else if (!strcmp(GFX_DOWNLOADABLE_FONTS_USE_CLEARTYPE, aPref)) {
         mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
     } else if (!strcmp(GFX_USE_CLEARTYPE_ALWAYS, aPref)) {
         mUseClearTypeAlways = UNINITIALIZED_VALUE;
     } else if (!strncmp(GFX_CLEARTYPE_PARAMS, aPref, strlen(GFX_CLEARTYPE_PARAMS))) {
-        SetupClearTypeParams(aPrefBranch);
+        SetupClearTypeParams();
     } else {
         clearTextFontCaches = PR_FALSE;
     }
 
     if (clearTextFontCaches) {    
         gfxFontCache *fc = gfxFontCache::GetCache();
         if (fc) {
             fc->Flush();
         }
         gfxTextRunWordCache::Flush();
     }
 }
 
 void
-gfxWindowsPlatform::SetupClearTypeParams(nsIPrefBranch *aPrefBranch)
+gfxWindowsPlatform::SetupClearTypeParams()
 {
 #if CAIRO_HAS_DWRITE_FONT
     if (GetDWriteFactory()) {
         // any missing prefs will default to invalid (-1) and be ignored;
         // out-of-range values will also be ignored
         FLOAT gamma = -1.0;
         FLOAT contrast = -1.0;
         FLOAT level = -1.0;
         int geometry = -1;
         int mode = -1;
         PRInt32 value;
-        if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_GAMMA,
-                                                 &value))) {
+        if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_GAMMA, &value))) {
             if (value >= 1000 && value <= 2200) {
                 gamma = FLOAT(value / 1000.0);
             }
         }
-        if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_CONTRAST,
-                                                 &value))) {
+
+        if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_CONTRAST, &value))) {
             if (value >= 0 && value <= 1000) {
                 contrast = FLOAT(value / 100.0);
             }
         }
-        if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_LEVEL,
-                                                 &value))) {
+
+        if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_LEVEL, &value))) {
             if (value >= 0 && value <= 100) {
                 level = FLOAT(value / 100.0);
             }
         }
-        if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_STRUCTURE,
-                                                 &value))) {
+
+        if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_STRUCTURE, &value))) {
             if (value >= 0 && value <= 2) {
                 geometry = value;
             }
         }
-        if (NS_SUCCEEDED(aPrefBranch->GetIntPref(GFX_CLEARTYPE_PARAMS_MODE,
-                                                 &value))) {
+
+        if (NS_SUCCEEDED(Preferences::GetInt(GFX_CLEARTYPE_PARAMS_MODE, &value))) {
             if (value >= 0 && value <= 5) {
                 mode = value;
             }
         }
+
         cairo_dwrite_set_cleartype_params(gamma, contrast, level, geometry, mode);
 
         switch (mode) {
         case DWRITE_RENDERING_MODE_ALIASED:
         case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC:
             mMeasuringMode = DWRITE_MEASURING_MODE_GDI_CLASSIC;
             break;
         case DWRITE_RENDERING_MODE_CLEARTYPE_GDI_NATURAL:
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -238,19 +238,19 @@ public:
 
     static PRInt32 WindowsOSVersion(PRInt32 *aBuildNum = nsnull);
 
     static void GetDLLVersion(const PRUnichar *aDLLPath, nsAString& aVersion);
 
     // returns ClearType tuning information for each display
     static void GetCleartypeParams(nsTArray<ClearTypeParameterInfo>& aParams);
 
-    virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
+    virtual void FontsPrefsChanged(const char *aPref);
 
-    void SetupClearTypeParams(nsIPrefBranch *aPrefBranch);
+    void SetupClearTypeParams();
 
 #ifdef CAIRO_HAS_DWRITE_FONT
     IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; }
     inline PRBool DWriteEnabled() { return mUseDirectWrite; }
     inline DWRITE_MEASURING_MODE DWriteMeasuringMode() { return mMeasuringMode; }
 #else
     inline PRBool DWriteEnabled() { return PR_FALSE; }
 #endif
--- a/gfx/thebes/gfxXlibSurface.cpp
+++ b/gfx/thebes/gfxXlibSurface.cpp
@@ -40,20 +40,21 @@
 
 #include "cairo.h"
 #include "cairo-xlib.h"
 #include "cairo-xlib-xrender.h"
 #include <X11/Xlibint.h>	/* For XESetCloseDisplay */
 
 #include "nsTArray.h"
 #include "nsAlgorithm.h"
-#include "nsServiceManagerUtils.h"
-#include "nsIPrefService.h"
+#include "mozilla/Preferences.h"
 #include "cairo-xlib-xrender.h"
 
+using namespace mozilla;
+
 // Although the dimension parameters in the xCreatePixmapReq wire protocol are
 // 16-bit unsigned integers, the server's CreatePixmap returns BadAlloc if
 // either dimension cannot be represented by a 16-bit *signed* integer.
 #define XLIB_IMAGE_SIDE_SIZE_LIMIT 0x7fff
 
 gfxXlibSurface::gfxXlibSurface(Display *dpy, Drawable drawable, Visual *visual)
     : mPixmapTaken(PR_FALSE), mDisplay(dpy), mDrawable(drawable)
 {
@@ -164,24 +165,17 @@ gfxXlibSurface::Create(Screen *screen, X
     if (result->CairoStatus() != 0)
         return nsnull;
 
     return result.forget();
 }
 
 static PRBool GetForce24bppPref()
 {
-    PRBool val = PR_FALSE; // default
-
-    nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (!prefs)
-        return val;
-
-    prefs->GetBoolPref("mozilla.widget.force-24bpp", &val);
-    return val;
+    return Preferences::GetBool("mozilla.widget.force-24bpp", PR_FALSE);
 }
 
 already_AddRefed<gfxASurface>
 gfxXlibSurface::CreateSimilarSurface(gfxContentType aContent,
                                      const gfxIntSize& aSize)
 {
     if (!mSurface || !mSurfaceValid) {
       return nsnull;