diff --git a/intl/locale/LocaleService.cpp b/intl/locale/LocaleService.cpp index f33ba24360ad..b0ecef85f4d7 100644 --- a/intl/locale/LocaleService.cpp +++ b/intl/locale/LocaleService.cpp @@ -19,6 +19,8 @@ #include "unicode/uloc.h" +#define INTL_SYSTEM_LOCALES_CHANGED "intl:system-locales-changed" + #define MATCH_OS_LOCALE_PREF "intl.locale.matchOS" #define SELECTED_LOCALE_PREF "general.useragent.locale" @@ -175,6 +177,11 @@ LocaleService::GetInstance() // from prefs. DebugOnly rv = Preferences::AddWeakObservers(sInstance, kObservedPrefs); MOZ_ASSERT(NS_SUCCEEDED(rv), "Adding observers failed."); + + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (obs) { + obs->AddObserver(sInstance, INTL_SYSTEM_LOCALES_CHANGED, false); + } } ClearOnShutdown(&sInstance); } @@ -185,6 +192,11 @@ LocaleService::~LocaleService() { if (mIsServer) { Preferences::RemoveObservers(this, kObservedPrefs); + + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (obs) { + obs->RemoveObserver(static_cast(this), INTL_SYSTEM_LOCALES_CHANGED); + } } } @@ -519,19 +531,24 @@ LocaleService::Observe(nsISupports *aSubject, const char *aTopic, { MOZ_ASSERT(mIsServer, "This should only be called in the server mode."); - NS_ConvertUTF16toUTF8 pref(aData); - - // This is a temporary solution until we get bug 1337078 landed. - if (pref.EqualsLiteral(ANDROID_OS_LOCALE_PREF)) { - OSPreferences::GetInstance()->Refresh(); - } - // At the moment the only thing we're observing are settings indicating - // user requested locales. - if (pref.EqualsLiteral(MATCH_OS_LOCALE_PREF) || - pref.EqualsLiteral(SELECTED_LOCALE_PREF) || - pref.EqualsLiteral(ANDROID_OS_LOCALE_PREF)) { + if (!strcmp(aTopic, INTL_SYSTEM_LOCALES_CHANGED)) { OnRequestedLocalesChanged(); + } else { + NS_ConvertUTF16toUTF8 pref(aData); + + // This is a temporary solution until we get bug 1337078 landed. + if (pref.EqualsLiteral(ANDROID_OS_LOCALE_PREF)) { + OSPreferences::GetInstance()->Refresh(); + } + // At the moment the only thing we're observing are settings indicating + // user requested locales. + if (pref.EqualsLiteral(MATCH_OS_LOCALE_PREF) || + pref.EqualsLiteral(SELECTED_LOCALE_PREF) || + pref.EqualsLiteral(ANDROID_OS_LOCALE_PREF)) { + OnRequestedLocalesChanged(); + } } + return NS_OK; }