From c286b2ef873cc53760708cebcbf487e71e98b039 Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Wed, 8 Feb 2017 12:31:06 -0800 Subject: [PATCH] Bug 1337551: Migrate Services.jsm to use LocaleService. r=mossop MozReview-Commit-ID: G0HFXfg4r6Y --HG-- extra : rebase_source : 2217abbb1371132b82574be690f9fab5c1b64fb7 --- addon-sdk/source/test/test-l10n-locale.js | 3 +-- browser/modules/DirectoryLinksProvider.jsm | 3 ++- toolkit/components/telemetry/TelemetryEnvironment.jsm | 8 ++++---- toolkit/modules/Locale.jsm | 7 +++++-- toolkit/modules/Services.jsm | 2 +- toolkit/modules/tests/xpcshell/test_Services.js | 2 +- toolkit/mozapps/extensions/AddonManager.jsm | 7 +++++-- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/addon-sdk/source/test/test-l10n-locale.js b/addon-sdk/source/test/test-l10n-locale.js index 564abbf1be6f..dba64d2d52e0 100644 --- a/addon-sdk/source/test/test-l10n-locale.js +++ b/addon-sdk/source/test/test-l10n-locale.js @@ -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 diff --git a/browser/modules/DirectoryLinksProvider.jsm b/browser/modules/DirectoryLinksProvider.jsm index 5fe9f9fce06f..d9f44e82dee7 100644 --- a/browser/modules/DirectoryLinksProvider.jsm +++ b/browser/modules/DirectoryLinksProvider.jsm @@ -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 { diff --git a/toolkit/components/telemetry/TelemetryEnvironment.jsm b/toolkit/components/telemetry/TelemetryEnvironment.jsm index fdaf93fa69a8..9d0e737b300b 100644 --- a/toolkit/components/telemetry/TelemetryEnvironment.jsm +++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm @@ -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; } diff --git a/toolkit/modules/Locale.jsm b/toolkit/modules/Locale.jsm index fab39df0abb3..1066835cc639 100644 --- a/toolkit/modules/Locale.jsm +++ b/toolkit/modules/Locale.jsm @@ -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) diff --git a/toolkit/modules/Services.jsm b/toolkit/modules/Services.jsm index 759427052d47..a9e7b719e30c 100644 --- a/toolkit/modules/Services.jsm +++ b/toolkit/modules/Services.jsm @@ -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"], diff --git a/toolkit/modules/tests/xpcshell/test_Services.js b/toolkit/modules/tests/xpcshell/test_Services.js index 81b8757cb0cd..325d6cb42c50 100644 --- a/toolkit/modules/tests/xpcshell/test_Services.js +++ b/toolkit/modules/tests/xpcshell/test_Services.js @@ -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); diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 21d4b40a161a..dd50c1b6590d 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.jsm @@ -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 {