Bug 661101 widget should use mozilla::Preferences r=roc

This commit is contained in:
Masayuki Nakano 2011-06-07 16:38:00 +09:00
Родитель 35529b1111
Коммит 58feee75ac
12 изменённых файлов: 87 добавлений и 122 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -327,6 +327,10 @@ private:
// broken image and loading image icons
public:
IconLoad();
~IconLoad()
{
Shutdown();
}
void Shutdown();
@ -359,6 +363,7 @@ private:
nsCOMPtr<imgIRequest> mBrokenImage;
PRPackedBool mPrefForceInlineAltText;
PRPackedBool mPrefShowPlaceholders;
PRPackedBool mHasShutdown;
};
public:

Просмотреть файл

@ -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<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);
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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 <android/log.h>
#include <pthread.h>
#include "nsIPrefBranch2.h"
#include <wchar.h>
#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<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);
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<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);
@ -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<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);
@ -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<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs)
nsIPrefService* prefs = Preferences::GetService();
if (prefs) {
prefs->SavePrefFile(nsnull);
}
break;
}

Просмотреть файл

@ -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<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;
}
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<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;
@ -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;

Просмотреть файл

@ -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<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;
}
}

Просмотреть файл

@ -56,8 +56,6 @@
#include "nsDeviceContextSpecQt.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "prenv.h" /* for PR_GetEnv */
#include "nsPrintfCString.h"

Просмотреть файл

@ -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<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;
}
@ -3047,11 +3040,8 @@ nsWindow::SetInputMode(const IMEContext& aContext)
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;

Просмотреть файл

@ -52,7 +52,6 @@
#include "nsExceptionHandler.h"
#include "nsICrashReporter.h"
#define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
#include "nsIPrefService.h"
#endif