diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp index 4f16814699c1..9441ddccfe1a 100644 --- a/layout/generic/nsImageFrame.cpp +++ b/layout/generic/nsImageFrame.cpp @@ -1887,6 +1887,7 @@ static const char* kIconLoadPrefs[] = { nsImageFrame::IconLoad::IconLoad() { + mHasShutdown = PR_FALSE; // register observers Preferences::AddStrongObservers(this, kIconLoadPrefs); GetPrefs(); @@ -1895,6 +1896,10 @@ nsImageFrame::IconLoad::IconLoad() void nsImageFrame::IconLoad::Shutdown() { + if (mHasShutdown) { + return; + } + mHasShutdown = PR_TRUE; Preferences::RemoveObservers(this, kIconLoadPrefs); // in case the pref service releases us later if (mLoadingImage) { diff --git a/layout/generic/nsImageFrame.h b/layout/generic/nsImageFrame.h index 75bac2b3a85e..cde8ca12cfc4 100644 --- a/layout/generic/nsImageFrame.h +++ b/layout/generic/nsImageFrame.h @@ -327,6 +327,10 @@ private: // broken image and loading image icons public: IconLoad(); + ~IconLoad() + { + Shutdown(); + } void Shutdown(); @@ -359,6 +363,7 @@ private: nsCOMPtr mBrokenImage; PRPackedBool mPrefForceInlineAltText; PRPackedBool mPrefShowPlaceholders; + PRPackedBool mHasShutdown; }; public: diff --git a/widget/src/android/AndroidBridge.cpp b/widget/src/android/AndroidBridge.cpp index 3d1ab067b556..0c381da11672 100644 --- a/widget/src/android/AndroidBridge.cpp +++ b/widget/src/android/AndroidBridge.cpp @@ -45,8 +45,8 @@ #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) @@ -249,29 +249,26 @@ AndroidBridge::NotifyIMEEnabled(int aState, const nsAString& aTypeHint, args[1].l = JNI()->NewString(typeHint.get(), typeHint.Length()); args[2].l = JNI()->NewString(actionHint.get(), actionHint.Length()); args[3].z = false; - nsCOMPtr 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); } diff --git a/widget/src/android/GfxInfo.cpp b/widget/src/android/GfxInfo.cpp index 8a0638bba856..f6385656c61b 100644 --- a/widget/src/android/GfxInfo.cpp +++ b/widget/src/android/GfxInfo.cpp @@ -47,7 +47,6 @@ #include "nsExceptionHandler.h" #include "nsICrashReporter.h" #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1" -#include "nsIPrefService.h" #endif using namespace mozilla::widget; diff --git a/widget/src/android/nsAppShell.cpp b/widget/src/android/nsAppShell.cpp index 3334f07bb92b..7f6c3be70a10 100644 --- a/widget/src/android/nsAppShell.cpp +++ b/widget/src/android/nsAppShell.cpp @@ -43,18 +43,16 @@ #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 #include -#include "nsIPrefBranch2.h" #include #ifdef MOZ_LOGGING @@ -102,6 +100,14 @@ nsAppShell::NotifyNativeEvent() 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() { @@ -126,36 +132,21 @@ nsAppShell::Init() if (!bridge) return rv; - nsCOMPtr 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); - - nsString locale; - PRBool match = PR_FALSE; - rv = branch->GetBoolPref("intl.locale.matchOS", &match); + Preferences::AddStrongObservers(this, kObservedPrefs); + PRBool match; + rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match); NS_ENSURE_SUCCESS(rv, rv); if (match) { bridge->SetSelectedLocale(EmptyString()); return NS_OK; } - nsCOMPtr 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); @@ -174,40 +165,27 @@ nsAppShell::Observe(nsISupports* aSubject, 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 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 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); @@ -362,9 +340,10 @@ nsAppShell::ProcessNextNativeEvent(PRBool mayWait) // 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 prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefs) + nsIPrefService* prefs = Preferences::GetService(); + if (prefs) { prefs->SavePrefFile(nsnull); + } break; } diff --git a/widget/src/android/nsWindow.cpp b/widget/src/android/nsWindow.cpp index 48ad135c0a2f..f60b8417b464 100644 --- a/widget/src/android/nsWindow.cpp +++ b/widget/src/android/nsWindow.cpp @@ -43,6 +43,7 @@ #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; @@ -52,7 +53,6 @@ using mozilla::unused; #include "nsIdleService.h" #include "nsWindow.h" #include "nsIObserverService.h" -#include "nsIPrefService.h" #include "nsRenderingContext.h" #include "nsIDOMSimpleGestureEvent.h" @@ -1749,14 +1749,10 @@ nsWindow::SetInputMode(const IMEContext& aContext) // IMEContext depending on the content.ime.strict.policy pref if (aContext.mStatus != nsIWidget::IME_STATUS_DISABLED && aContext.mStatus != nsIWidget::IME_STATUS_PLUGIN) { - nsCOMPtr 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; } } diff --git a/widget/src/cocoa/GfxInfo.mm b/widget/src/cocoa/GfxInfo.mm index 83e7bbc7711d..913a6599c21c 100644 --- a/widget/src/cocoa/GfxInfo.mm +++ b/widget/src/cocoa/GfxInfo.mm @@ -48,7 +48,6 @@ #include "nsExceptionHandler.h" #include "nsICrashReporter.h" #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1" -#include "nsIPrefService.h" #endif using namespace mozilla::widget; diff --git a/widget/src/os2/nsDeviceContextSpecOS2.cpp b/widget/src/os2/nsDeviceContextSpecOS2.cpp index 856ac94a5066..e9e17ab3b835 100644 --- a/widget/src/os2/nsDeviceContextSpecOS2.cpp +++ b/widget/src/os2/nsDeviceContextSpecOS2.cpp @@ -44,8 +44,6 @@ #include "nsReadableUtils.h" #include "nsTArray.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "prenv.h" /* for PR_GetEnv */ #include "prtime.h" @@ -64,6 +62,10 @@ #include "gfxOS2Surface.h" #include "nsIPrintSettingsService.h" +#include "mozilla/Preferences.h" + +using namespace mozilla; + PRINTDLG nsDeviceContextSpecOS2::PrnDlg; //---------------------------------------------------------------------------------- @@ -657,9 +659,8 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () if (!mGlobalPrinterList) return NS_ERROR_OUT_OF_MEMORY; - nsresult rv; - nsCOMPtr 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; @@ -667,8 +668,8 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () 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 @@ -678,10 +679,10 @@ nsresult GlobalPrinters::InitializeGlobalPrinters () 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; diff --git a/widget/src/os2/nsWindow.cpp b/widget/src/os2/nsWindow.cpp index f78ff92b496c..74b2d83e4cc2 100644 --- a/widget/src/os2/nsWindow.cpp +++ b/widget/src/os2/nsWindow.cpp @@ -75,7 +75,6 @@ #include "nsGfxCIID.h" #include "nsHashKeys.h" #include "nsIMenuRollup.h" -#include "nsIPrefService.h" #include "nsIRollupListener.h" #include "nsIScreenManager.h" #include "nsOS2Uni.h" @@ -84,6 +83,10 @@ #include "nsWidgetAtoms.h" #include "wdgtos2rc.h" +#include "mozilla/Preferences.h" + +using namespace mozilla; + //============================================================================= // Macros //============================================================================= @@ -309,14 +312,8 @@ void nsWindow::InitGlobals() // 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 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; } } diff --git a/widget/src/qt/nsDeviceContextSpecQt.cpp b/widget/src/qt/nsDeviceContextSpecQt.cpp index d3aba4cede36..6a9605d55887 100644 --- a/widget/src/qt/nsDeviceContextSpecQt.cpp +++ b/widget/src/qt/nsDeviceContextSpecQt.cpp @@ -56,8 +56,6 @@ #include "nsDeviceContextSpecQt.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "prenv.h" /* for PR_GetEnv */ #include "nsPrintfCString.h" diff --git a/widget/src/qt/nsWindow.cpp b/widget/src/qt/nsWindow.cpp index 5c988a6c49bd..2fb711bafeec 100644 --- a/widget/src/qt/nsWindow.cpp +++ b/widget/src/qt/nsWindow.cpp @@ -102,9 +102,8 @@ using namespace QtMobility; #include "nsWidgetsCID.h" #include "nsQtKeyUtils.h" #include "mozilla/Services.h" +#include "mozilla/Preferences.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "nsIStringBundle.h" #include "nsGfxCIID.h" @@ -2497,15 +2496,9 @@ nsresult initialize_prefs(void) { // check to see if we should set our raise pref - nsCOMPtr 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; } @@ -3047,11 +3040,8 @@ nsWindow::SetInputMode(const IMEContext& aContext) case nsIWidget::IME_STATUS_ENABLED: case nsIWidget::IME_STATUS_PASSWORD: { - PRInt32 openDelay = 200; - nsCOMPtr 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; diff --git a/widget/src/windows/GfxInfo.cpp b/widget/src/windows/GfxInfo.cpp index 9e91ab027116..aebb4c21ae37 100644 --- a/widget/src/windows/GfxInfo.cpp +++ b/widget/src/windows/GfxInfo.cpp @@ -52,7 +52,6 @@ #include "nsExceptionHandler.h" #include "nsICrashReporter.h" #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1" -#include "nsIPrefService.h" #endif