Bug 1616912 - Remove unused locale related code from nsChromeRegistry. r=jfkthame
Differential Revision: https://phabricator.services.mozilla.com/D63523
This commit is contained in:
@@ -27,8 +27,6 @@
|
||||
#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
|
||||
@@ -391,20 +389,3 @@ already_AddRefed<nsChromeRegistry> nsChromeRegistry::GetSingleton() {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +85,6 @@ class nsChromeRegistry : public nsIToolkitChromeRegistry,
|
||||
static nsresult GetProviderAndPath(nsIURI* aChromeURL, nsACString& aProvider,
|
||||
nsACString& aPath);
|
||||
|
||||
void SanitizeForBCP47(nsACString& aLocale);
|
||||
|
||||
public:
|
||||
static already_AddRefed<nsChromeRegistry> GetSingleton();
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ 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);
|
||||
@@ -146,7 +146,6 @@ nsChromeRegistryChrome::IsLocaleRTL(const nsACString& package, bool* aResult) {
|
||||
* LocaleService::GetAppLocaleAsBCP47.
|
||||
*/
|
||||
nsresult nsChromeRegistryChrome::GetSelectedLocale(const nsACString& aPackage,
|
||||
bool aAsBCP47,
|
||||
nsACString& aLocale) {
|
||||
nsAutoCString reqLocale;
|
||||
if (aPackage.EqualsLiteral("global")) {
|
||||
@@ -166,10 +165,6 @@ nsresult nsChromeRegistryChrome::GetSelectedLocale(const nsACString& aPackage,
|
||||
aLocale = entry->locales.GetSelected(reqLocale, nsProviderArray::LOCALE);
|
||||
if (aLocale.IsEmpty()) return NS_ERROR_FAILURE;
|
||||
|
||||
if (aAsBCP47) {
|
||||
SanitizeForBCP47(aLocale);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,7 @@ class nsChromeRegistryChrome : public nsChromeRegistry {
|
||||
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;
|
||||
|
||||
|
||||
@@ -159,20 +159,6 @@ nsChromeRegistryContent::IsLocaleRTL(const nsACString& aPackage,
|
||||
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) {
|
||||
|
||||
@@ -28,8 +28,6 @@ class nsChromeRegistryContent : public nsChromeRegistry {
|
||||
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);
|
||||
|
||||
@@ -43,13 +43,6 @@ interface nsIChromeRegistry : nsISupports
|
||||
[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);
|
||||
|
||||
@@ -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",
|
||||
]);
|
||||
}
|
||||
@@ -11,7 +11,6 @@ support-files = data/**
|
||||
[test_bug415367.js]
|
||||
[test_bug564667.js]
|
||||
tags = addons
|
||||
[test_bug848297.js]
|
||||
[test_crlf.js]
|
||||
[test_data_protocol_registration.js]
|
||||
[test_no_remote_registration.js]
|
||||
|
||||
Reference in New Issue
Block a user