nsresult nsAppShell::Init() { #ifdef PR_LOGGING if (!gWidgetLog) gWidgetLog = PR_NewLogModule("Widget"); #endif mObserversHash.Init(); nsresult rv = nsBaseAppShell::Init(); AndroidBridge* bridge = AndroidBridge::Bridge(); nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); if (obsServ) { obsServ->AddObserver(this, "xpcom-shutdown", false); } if (sPowerManagerService) sPowerManagerService->AddWakeLockListener(sWakeLockListener); if (!bridge) return rv; Preferences::AddStrongObservers(this, kObservedPrefs); bool match; rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match); NS_ENSURE_SUCCESS(rv, rv); if (match) { bridge->SetSelectedLocale(EmptyString()); return NS_OK; } nsAutoString locale; rv = Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale); if (NS_FAILED(rv)) { rv = Preferences::GetString(PREFNAME_UA_LOCALE, &locale); } bridge->SetSelectedLocale(locale); mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true); return rv; }
NS_IMETHODIMP nsAppShell::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData) { if (!strcmp(aTopic, "xpcom-shutdown")) { // We need to ensure no observers stick around after XPCOM shuts down // or we'll see crashes, as the app shell outlives XPConnect. mObserversHash.Clear(); return nsBaseAppShell::Observe(aSubject, aTopic, aData); } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && ( nsDependentString(aData).Equals( NS_LITERAL_STRING(PREFNAME_UA_LOCALE)) || nsDependentString(aData).Equals( NS_LITERAL_STRING(PREFNAME_COALESCE_TOUCHES)) || nsDependentString(aData).Equals( NS_LITERAL_STRING(PREFNAME_MATCH_OS)))) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return NS_OK; } bool match; nsresult rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match); NS_ENSURE_SUCCESS(rv, rv); if (match) { bridge->SetSelectedLocale(EmptyString()); return NS_OK; } nsAutoString locale; if (NS_FAILED(Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale))) { locale = Preferences::GetString(PREFNAME_UA_LOCALE); } bridge->SetSelectedLocale(locale); mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true); return NS_OK; } return NS_OK; }