Bug 1616912 - Remove unused locale related code from nsChromeRegistry. r=jfkthame
authorZibi Braniecki <zbraniecki@mozilla.com>
Sat, 22 Feb 2020 00:20:03 +0000
changeset 2648956 2e9a6ba720996ec42d5b2cf7794b8ac6b01afc5a
parent 2648955 a1da47c3467ced1f9a4f35dfba28a972b7e46524
child 2648957 d67220ef9a916d94bd7a0423efab707775cbf93a
push id490874
push userdvarga@mozilla.com
push dateSat, 22 Feb 2020 10:42:44 +0000
treeherdertry@64a8e247759e [default view] [failures only]
reviewersjfkthame
bugs1616912
milestone75.0a1
Bug 1616912 - Remove unused locale related code from nsChromeRegistry. r=jfkthame Differential Revision: https://phabricator.services.mozilla.com/D63523
chrome/nsChromeRegistry.cpp
chrome/nsChromeRegistry.h
chrome/nsChromeRegistryChrome.cpp
chrome/nsChromeRegistryChrome.h
chrome/nsChromeRegistryContent.cpp
chrome/nsChromeRegistryContent.h
chrome/nsIChromeRegistry.idl
chrome/test/unit/test_bug848297.js
chrome/test/unit/xpcshell.ini
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -22,18 +22,16 @@
 #include "nsIScriptError.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/Printf.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/dom/Location.h"
 
-#include "unicode/uloc.h"
-
 nsChromeRegistry* nsChromeRegistry::gChromeRegistry;
 
 // DO NOT use namespace mozilla; it'll break due to a naming conflict between
 // mozilla::TextRange and a TextRange in OSX headers.
 using mozilla::PresShell;
 using mozilla::StyleSheet;
 using mozilla::dom::Document;
 using mozilla::dom::Location;
@@ -386,25 +384,8 @@ already_AddRefed<nsChromeRegistry> nsChr
     cr = new nsChromeRegistryContent();
   else
     cr = new nsChromeRegistryChrome();
 
   if (NS_FAILED(cr->Init())) return nullptr;
 
   return cr.forget();
 }
-
-void nsChromeRegistry::SanitizeForBCP47(nsACString& aLocale) {
-  // Currently, the only locale code we use that's not BCP47-conformant is
-  // "ja-JP-mac" on OS X, but let's try to be more general than just
-  // hard-coding that here.
-  const int32_t LANG_TAG_CAPACITY = 128;
-  char langTag[LANG_TAG_CAPACITY];
-  nsAutoCString locale(aLocale);
-  UErrorCode err = U_ZERO_ERROR;
-  // This is a fail-safe method that will set langTag to "und" if it cannot
-  // match any part of the input locale code.
-  int32_t len =
-      uloc_toLanguageTag(locale.get(), langTag, LANG_TAG_CAPACITY, false, &err);
-  if (U_SUCCESS(err) && len > 0) {
-    aLocale.Assign(langTag, len);
-  }
-}
--- a/chrome/nsChromeRegistry.h
+++ b/chrome/nsChromeRegistry.h
@@ -80,18 +80,16 @@ class nsChromeRegistry : public nsIToolk
                                         const nsCString& aPath) = 0;
   virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
                                        uint32_t* aFlags) = 0;
 
   static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow);
   static nsresult GetProviderAndPath(nsIURI* aChromeURL, nsACString& aProvider,
                                      nsACString& aPath);
 
-  void SanitizeForBCP47(nsACString& aLocale);
-
  public:
   static already_AddRefed<nsChromeRegistry> GetSingleton();
 
   struct ManifestProcessingContext {
     ManifestProcessingContext(NSLocationType aType,
                               mozilla::FileLocation& aFile)
         : mType(aType), mFile(aFile) {}
 
--- a/chrome/nsChromeRegistryChrome.cpp
+++ b/chrome/nsChromeRegistryChrome.cpp
@@ -126,32 +126,31 @@ nsChromeRegistryChrome::GetLocalesForPac
   return rv;
 }
 
 NS_IMETHODIMP
 nsChromeRegistryChrome::IsLocaleRTL(const nsACString& package, bool* aResult) {
   *aResult = false;
 
   nsAutoCString locale;
-  GetSelectedLocale(package, false, locale);
+  GetSelectedLocale(package, locale);
   if (locale.Length() < 2) return NS_OK;
 
   *aResult = LocaleService::IsLocaleRTL(locale);
   return NS_OK;
 }
 
 /**
  * This method negotiates only between the app locale and the available
  * chrome packages.
  *
  * If you want to get the current application's UI locale, please use
  * LocaleService::GetAppLocaleAsBCP47.
  */
 nsresult nsChromeRegistryChrome::GetSelectedLocale(const nsACString& aPackage,
-                                                   bool aAsBCP47,
                                                    nsACString& aLocale) {
   nsAutoCString reqLocale;
   if (aPackage.EqualsLiteral("global")) {
     LocaleService::GetInstance()->GetAppLocaleAsBCP47(reqLocale);
   } else {
     AutoTArray<nsCString, 10> requestedLocales;
     LocaleService::GetInstance()->GetRequestedLocales(requestedLocales);
     reqLocale.Assign(requestedLocales[0]);
@@ -161,20 +160,16 @@ nsresult nsChromeRegistryChrome::GetSele
   nsresult rv = OverrideLocalePackage(aPackage, realpackage);
   if (NS_FAILED(rv)) return rv;
   PackageEntry* entry;
   if (!mPackagesHash.Get(realpackage, &entry)) return NS_ERROR_FILE_NOT_FOUND;
 
   aLocale = entry->locales.GetSelected(reqLocale, nsProviderArray::LOCALE);
   if (aLocale.IsEmpty()) return NS_ERROR_FAILURE;
 
-  if (aAsBCP47) {
-    SanitizeForBCP47(aLocale);
-  }
-
   return NS_OK;
 }
 
 nsresult nsChromeRegistryChrome::OverrideLocalePackage(
     const nsACString& aPackage, nsACString& aOverride) {
   const nsACString& pref =
       NS_LITERAL_CSTRING(PACKAGE_OVERRIDE_BRANCH) + aPackage;
   nsAutoCString override;
--- a/chrome/nsChromeRegistryChrome.h
+++ b/chrome/nsChromeRegistryChrome.h
@@ -28,18 +28,17 @@ class nsChromeRegistryChrome : public ns
   ~nsChromeRegistryChrome();
 
   nsresult Init() override;
 
   NS_IMETHOD CheckForNewChrome() override;
   NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage,
                                   nsIUTF8StringEnumerator** aResult) override;
   NS_IMETHOD IsLocaleRTL(const nsACString& package, bool* aResult) override;
-  NS_IMETHOD GetSelectedLocale(const nsACString& aPackage, bool aAsBCP47,
-                               nsACString& aLocale) override;
+  nsresult GetSelectedLocale(const nsACString& aPackage, nsACString& aLocale);
   NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
                      const char16_t* someData) override;
 
   // If aChild is non-null then it is a new child to notify. If aChild is
   // null, then we have installed new chrome and we are resetting all of our
   // children's registered chrome.
   void SendRegisteredChrome(mozilla::dom::PContentParent* aChild);
 
--- a/chrome/nsChromeRegistryContent.cpp
+++ b/chrome/nsChromeRegistryContent.cpp
@@ -155,30 +155,16 @@ nsChromeRegistryContent::CheckForNewChro
 NS_IMETHODIMP
 nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
                                      bool* aResult) {
   *aResult = mozilla::intl::LocaleService::IsLocaleRTL(mLocale);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage,
-                                           bool aAsBCP47, nsACString& aLocale) {
-  if (aPackage != nsDependentCString("global")) {
-    NS_ERROR("Uh-oh, caller wanted something other than 'some local'");
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-  aLocale = mLocale;
-  if (aAsBCP47) {
-    SanitizeForBCP47(aLocale);
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic,
                                  const char16_t* aData) {
   CONTENT_NOT_IMPLEMENTED();
 }
 
 void nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx,
                                               int lineno, char* const* argv,
                                               int flags) {
--- a/chrome/nsChromeRegistryContent.h
+++ b/chrome/nsChromeRegistryContent.h
@@ -23,18 +23,16 @@ class nsChromeRegistryContent : public n
                             const nsACString& aLocale, bool aReset);
 
   NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage,
                                   nsIUTF8StringEnumerator** aResult) override;
   NS_IMETHOD CheckForNewChrome() override;
   NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
                      const char16_t* aData) override;
   NS_IMETHOD IsLocaleRTL(const nsACString& package, bool* aResult) override;
-  NS_IMETHOD GetSelectedLocale(const nsACString& aPackage, bool aAsBCP47,
-                               nsACString& aLocale) override;
 
   void RegisterPackage(const ChromePackage& aPackage);
   void RegisterOverride(const OverrideMapping& aOverride);
   void RegisterSubstitution(const SubstitutionMapping& aResource);
 
  private:
   struct PackageEntry {
     PackageEntry() : flags(0) {}
--- a/chrome/nsIChromeRegistry.idl
+++ b/chrome/nsIChromeRegistry.idl
@@ -38,23 +38,16 @@ interface nsIChromeRegistry : nsISupport
    * refresh the chrome list at runtime, looking for new packages/etc
    */
   void checkForNewChrome();
 };
 
 [scriptable, uuid(93251ddf-5e85-4172-ac2a-31780562974f)]
 interface nsIXULChromeRegistry : nsIChromeRegistry
 {
-  // If the optional asBCP47 parameter is true, the locale code will be
-  // converted to a BCP47 language tag; in particular, this means that
-  // "ja-JP-mac" will be returned as "ja-JP-x-lvariant-mac", which can be
-  // passed to ECMA402 Intl API methods without throwing a RangeError.
-  ACString getSelectedLocale(in ACString packageName,
-                             [optional] in boolean asBCP47);
-
   // Get whether the default writing direction of the locale is RTL
   // (or may be overridden by intl.uidirection pref)
   boolean isLocaleRTL(in ACString package);
 
   /**
    * Installable skin XBL is not always granted the same privileges as other
    * chrome. This asks the chrome registry whether scripts are allowed to be
    * run for a particular chrome URI. Do not pass non-chrome URIs to this
deleted file mode 100644
--- a/chrome/test/unit/test_bug848297.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-var MANIFESTS = [do_get_file("data/test_bug848297.manifest")];
-
-// Stub in the locale service so we can control what gets returned as the OS locale setting
-
-registerManifests(MANIFESTS);
-
-var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
-  .getService(Ci.nsIXULChromeRegistry)
-  .QueryInterface(Ci.nsIToolkitChromeRegistry);
-chromeReg.checkForNewChrome();
-
-function enum_to_array(strings) {
-  return Array.from(strings).sort();
-}
-
-function run_test() {
-  // without override
-  Services.locale.requestedLocales = ["de"];
-  Assert.equal(chromeReg.getSelectedLocale("basepack"), "en-US");
-  Assert.equal(chromeReg.getSelectedLocale("overpack"), "de");
-  Assert.deepEqual(enum_to_array(chromeReg.getLocalesForPackage("basepack")), [
-    "en-US",
-    "fr",
-  ]);
-
-  // with override
-  Services.prefs.setCharPref("chrome.override_package.basepack", "overpack");
-  Assert.equal(chromeReg.getSelectedLocale("basepack"), "de");
-  Assert.deepEqual(enum_to_array(chromeReg.getLocalesForPackage("basepack")), [
-    "de",
-    "en-US",
-  ]);
-}
--- a/chrome/test/unit/xpcshell.ini
+++ b/chrome/test/unit/xpcshell.ini
@@ -6,13 +6,12 @@ support-files = data/**
 [test_bug292789.js]
 [test_bug380398.js]
 [test_bug397073.js]
 [test_bug399707.js]
 [test_bug401153.js]
 [test_bug415367.js]
 [test_bug564667.js]
 tags = addons
-[test_bug848297.js]
 [test_crlf.js]
 [test_data_protocol_registration.js]
 [test_no_remote_registration.js]
 [test_resolve_uris.js]