Bug 1337551: Migrate Services.jsm to use LocaleService. r=mossop

MozReview-Commit-ID: G0HFXfg4r6Y

--HG--
extra : rebase_source : 2217abbb1371132b82574be690f9fab5c1b64fb7
This commit is contained in:
Zibi Braniecki 2017-02-08 12:31:06 -08:00
parent 78a1fe605c
commit c286b2ef87
7 changed files with 19 additions and 13 deletions

View File

@ -110,8 +110,7 @@ exports.testPreferedOsLocale = function(assert) {
prefs.set(PREF_SELECTED_LOCALE, "");
prefs.set(PREF_ACCEPT_LANGUAGES, "");
let expectedLocale = Services.locale.getLocaleComponentForUserAgent().
toLowerCase();
let expectedLocale = Services.locale.getAppLocale().toLowerCase();
let expectedLocaleList = [expectedLocale];
// Add default "en-us" fallback if the main language is not already en-us

View File

@ -194,7 +194,8 @@ var DirectoryLinksProvider = {
} catch (e) {}
if (matchOS) {
return Services.locale.getLocaleComponentForUserAgent();
return Cc["@mozilla.org/intl/ospreferences;1"].
getService(Ci.mozIOSPreferences).getSystemLocale();
}
try {

View File

@ -230,9 +230,7 @@ function enforceBoolean(aValue) {
*/
function getBrowserLocale() {
try {
return Cc["@mozilla.org/chrome/chrome-registry;1"].
getService(Ci.nsIXULChromeRegistry).
getSelectedLocale("global");
return Services.locale.getAppLocale();
} catch (e) {
return null;
}
@ -244,7 +242,9 @@ function getBrowserLocale() {
*/
function getSystemLocale() {
try {
return Services.locale.getLocaleComponentForUserAgent();
return Cc["@mozilla.org/intl/ospreferences;1"].
getService(Ci.mozIOSPreferences).
getSystemLocale();
} catch (e) {
return null;
}

View File

@ -18,8 +18,11 @@ this.Locale = {
* @return the selected locale or "en-US" if none is selected
*/
getLocale() {
if (Preferences.get(PREF_MATCH_OS_LOCALE, false))
return Services.locale.getLocaleComponentForUserAgent();
if (Preferences.get(PREF_MATCH_OS_LOCALE, false)) {
const osPrefs =
Cc["@mozilla.org/intl/ospreferences;1"].getService(Ci.mozIOSPreferences);
return osPrefs.getSystemLocale();
}
try {
let locale = Preferences.get(PREF_SELECTED_LOCALE, null, Ci.nsIPrefLocalizedString);
if (locale)

View File

@ -75,7 +75,7 @@ var initTable = [
["els", "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService"],
["eTLD", "@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"],
["io", "@mozilla.org/network/io-service;1", "nsIIOService2"],
["locale", "@mozilla.org/intl/nslocaleservice;1", "nsILocaleService"],
["locale", "@mozilla.org/intl/localeservice;1", "mozILocaleService"],
["logins", "@mozilla.org/login-manager;1", "nsILoginManager"],
["obs", "@mozilla.org/observer-service;1", "nsIObserverService"],
["perms", "@mozilla.org/permissionmanager;1", "nsIPermissionManager"],

View File

@ -45,7 +45,7 @@ function run_test() {
checkService("focus", Ci.nsIFocusManager);
checkService("io", Ci.nsIIOService);
checkService("io", Ci.nsIIOService2);
checkService("locale", Ci.nsILocaleService);
checkService("locale", Ci.mozILocaleService);
checkService("logins", Ci.nsILoginManager);
checkService("obs", Ci.nsIObserverService);
checkService("perms", Ci.nsIPermissionManager);

View File

@ -329,8 +329,11 @@ function promiseCallProvider(aProvider, aMethod, ...aArgs) {
*/
function getLocale() {
try {
if (Services.prefs.getBoolPref(PREF_MATCH_OS_LOCALE))
return Services.locale.getLocaleComponentForUserAgent();
if (Services.prefs.getBoolPref(PREF_MATCH_OS_LOCALE)) {
const osPrefs =
Cc["@mozilla.org/intl/ospreferences;1"].getService(Ci.mozIOSPreferences);
return osPrefs.getSystemLocale();
}
} catch (e) { }
try {