Skip to content
Browse files

bug 642203 - Must treat locale pref as localized in multi-locale buil…

…ds r=blassey,dougt,gavin,mossop a=blocking-fennec
  • Loading branch information...
1 parent b65c6cf commit 7934260f8e7bb8e8cb079447ab768fccc90dfba5 @mfinkle mfinkle committed
View
23 toolkit/mozapps/extensions/XPIProvider.jsm
@@ -344,6 +344,9 @@ SafeInstallOperation.prototype = {
function getLocale() {
if (Prefs.getBoolPref(PREF_MATCH_OS_LOCALE, false))
return Services.locale.getLocaleComponentForUserAgent();
+ let locale = Prefs.getComplexPref(PREF_SELECTED_LOCALE, Ci.nsIPrefLocalizedString);
+ if (locale)
+ return locale;
return Prefs.getCharPref(PREF_SELECTED_LOCALE, "en-US");
}
@@ -1216,6 +1219,26 @@ var Prefs = {
},
/**
+ * Gets a complex preference.
+ *
+ * @param aName
+ * The name of the preference
+ * @param aType
+ * The interface type of the preference
+ * @param aDefaultValue
+ * A value to return if the preference does not exist
+ * @return the value of the preference or aDefaultValue if there is none
+ */
+ getComplexPref: function(aName, aType, aDefaultValue) {
+ try {
+ return Services.prefs.getComplexPref(aName, aType).data;
+ }
+ catch (e) {
+ }
+ return aDefaultValue;
+ },
+
+ /**
* Gets a boolean preference.
*
* @param aName
View
3 toolkit/mozapps/extensions/nsBlocklistService.js
@@ -246,7 +246,8 @@ function getLocale() {
try {
// Get the default branch
var defaultPrefs = gPref.getDefaultBranch(null);
- return defaultPrefs.getCharPref(PREF_GENERAL_USERAGENT_LOCALE);
+ return defaultPrefs.getComplexPref(PREF_GENERAL_USERAGENT_LOCALE,
+ Ci.nsIPrefLocalizedString).data;
} catch (e) {}
return gPref.getCharPref(PREF_GENERAL_USERAGENT_LOCALE);
View
5 widget/src/android/AndroidBridge.cpp
@@ -645,11 +645,10 @@ AndroidBridge::IsNetworkLinkKnown()
}
void
-AndroidBridge::SetSelectedLocale(const nsACString& aLocale)
+AndroidBridge::SetSelectedLocale(const nsAString& aLocale)
{
ALOG_BRIDGE("AndroidBridge::SetSelectedLocale");
- NS_ConvertUTF8toUTF16 wLocale(aLocale);
- jstring jLocale = GetJNIForThread()->NewString(wLocale.get(), wLocale.Length());
+ jstring jLocale = GetJNIForThread()->NewString(PromiseFlatString(aLocale).get(), aLocale.Length());
GetJNIForThread()->CallStaticVoidMethod(mGeckoAppShellClass, jSetSelectedLocale, jLocale);
}
View
2 widget/src/android/AndroidBridge.h
@@ -187,7 +187,7 @@ class AndroidBridge
bool IsNetworkLinkKnown();
- void SetSelectedLocale(const nsACString&);
+ void SetSelectedLocale(const nsAString&);
struct AutoLocalJNIFrame {
AutoLocalJNIFrame(int nEntries = 128) : mEntries(nEntries) {
View
78 widget/src/android/nsAppShell.cpp
@@ -44,6 +44,7 @@
#include "nsIAppStartup.h"
#include "nsIGeolocationProvider.h"
#include "nsIPrefService.h"
+#include "nsIPrefLocalizedString.h"
#include "mozilla/Services.h"
#include "mozilla/unused.h"
@@ -134,14 +135,35 @@ nsAppShell::Init()
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;
- nsCString locale;
- branch->GetBoolPref("intl.locale.matchOS", &match);
- if (!match ||
- NS_FAILED(branch->GetCharPref("general.useragent.locale", getter_Copies(locale))))
- bridge->SetSelectedLocale(EmptyCString());
- else
- bridge->SetSelectedLocale(locale);
+ rv = branch->GetBoolPref("intl.locale.matchOS", &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);
+ }
+
+ bridge->SetSelectedLocale(locale);
return rv;
}
@@ -155,21 +177,45 @@ nsAppShell::Observe(nsISupports* aSubject,
// 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) && (
- !wcscmp((const wchar_t*)aData, L"intl.locale.matchOS") ||
- !wcscmp((const wchar_t*)aData, L"general.useragent.locale"))) {
+ } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && (
+ nsDependentString(aData).Equals(
+ NS_LITERAL_STRING("general.useragent.locale")) ||
+ nsDependentString(aData).Equals(
+ NS_LITERAL_STRING("intl.locale.matchOS"))))
+ {
AndroidBridge* bridge = AndroidBridge::Bridge();
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
if (!prefs || !bridge)
return NS_OK;
+
+ nsString locale;
PRBool match = PR_FALSE;
- nsXPIDLCString locale;
+ nsresult rv = prefs->GetBoolPref("intl.locale.matchOS", &match);
+ NS_ENSURE_SUCCESS(rv, rv);
- if (!match && NS_SUCCEEDED(prefs->GetCharPref("general.useragent.locale",
- getter_Copies(locale))))
- bridge->SetSelectedLocale(locale);
- else
- bridge->SetSelectedLocale(EmptyCString());
+ 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);
+ }
+
+ bridge->SetSelectedLocale(locale);
return NS_OK;
}
return NS_OK;

0 comments on commit 7934260

Please sign in to comment.
Something went wrong with that request. Please try again.