From 146c4b948859170b180fb2f887541612fd7538ca Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Tue, 7 Feb 2017 12:52:03 -0800 Subject: [PATCH] Bug 1335983 - Migrate nsCollation::CreateCollection to use LocaleService::GetAppLocale. r=jfkthame MozReview-Commit-ID: 5GEnL7Kihpj --- dom/xslt/xslt/txXPathResultComparator.cpp | 23 +++------- dom/xul/templates/nsXULContentUtils.cpp | 29 +++--------- intl/locale/mac/nsCollationMacUC.cpp | 46 ++----------------- intl/locale/mac/nsCollationMacUC.h | 6 +-- intl/locale/nsCollation.cpp | 15 +++++- intl/locale/nsCollation.h | 5 +- intl/locale/nsICollation.idl | 19 ++++---- .../tests/unit/test_collation_mac_icu.js | 4 +- intl/locale/unix/nsCollationUnix.cpp | 45 ++---------------- intl/locale/windows/nsCollationWin.cpp | 29 ++---------- js/xpconnect/src/XPCLocale.cpp | 16 ++----- netwerk/base/nsDirectoryIndexStream.cpp | 12 +---- storage/mozStorageService.cpp | 17 +------ storage/test/unit/test_locale_collation.js | 4 +- toolkit/components/places/nsNavHistory.cpp | 10 +--- toolkit/components/search/nsSearchService.js | 5 +- 16 files changed, 64 insertions(+), 221 deletions(-) diff --git a/dom/xslt/xslt/txXPathResultComparator.cpp b/dom/xslt/xslt/txXPathResultComparator.cpp index 5403089206b5b..25bc57d4f9319 100644 --- a/dom/xslt/xslt/txXPathResultComparator.cpp +++ b/dom/xslt/xslt/txXPathResultComparator.cpp @@ -9,8 +9,6 @@ #include "txExpr.h" #include "txCore.h" #include "nsCollationCID.h" -#include "nsILocale.h" -#include "nsILocaleService.h" #include "nsIServiceManager.h" #include "prmem.h" @@ -35,25 +33,16 @@ nsresult txResultStringComparator::init(const nsAFlatString& aLanguage) { nsresult rv; - nsCOMPtr localeService = - do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr locale; - if (!aLanguage.IsEmpty()) { - rv = localeService->NewLocale(aLanguage, - getter_AddRefs(locale)); - } - else { - rv = localeService->GetApplicationLocale(getter_AddRefs(locale)); - } - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr colFactory = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - rv = colFactory->CreateCollation(locale, getter_AddRefs(mCollation)); + if (aLanguage.IsEmpty()) { + rv = colFactory->CreateCollation(getter_AddRefs(mCollation)); + } else { + rv = colFactory->CreateCollationForLocale(NS_ConvertUTF16toUTF8(aLanguage), getter_AddRefs(mCollation)); + } + NS_ENSURE_SUCCESS(rv, rv); return NS_OK; diff --git a/dom/xul/templates/nsXULContentUtils.cpp b/dom/xul/templates/nsXULContentUtils.cpp index a5f00473c9a1b..a30f64a1b6205 100644 --- a/dom/xul/templates/nsXULContentUtils.cpp +++ b/dom/xul/templates/nsXULContentUtils.cpp @@ -52,8 +52,6 @@ #include "nsIScriptableDateFormat.h" #include "nsICollation.h" #include "nsCollationCID.h" -#include "nsILocale.h" -#include "nsILocaleService.h" #include "nsIConsoleService.h" #include "nsEscape.h" @@ -125,27 +123,14 @@ nsICollation* nsXULContentUtils::GetCollation() { if (!gCollation) { - nsresult rv; - - // get a locale service - nsCOMPtr localeService = - do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr locale; - rv = localeService->GetApplicationLocale(getter_AddRefs(locale)); - if (NS_SUCCEEDED(rv) && locale) { - nsCOMPtr colFactory = - do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID); - if (colFactory) { - rv = colFactory->CreateCollation(locale, &gCollation); - NS_ASSERTION(NS_SUCCEEDED(rv), - "couldn't create collation instance"); - } else - NS_ERROR("couldn't create instance of collation factory"); - } else - NS_ERROR("unable to get application locale"); + nsCOMPtr colFactory = + do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID); + if (colFactory) { + DebugOnly rv = colFactory->CreateCollation(&gCollation); + NS_ASSERTION(NS_SUCCEEDED(rv), + "couldn't create collation instance"); } else - NS_ERROR("couldn't get locale factory"); + NS_ERROR("couldn't create instance of collation factory"); } return gCollation; diff --git a/intl/locale/mac/nsCollationMacUC.cpp b/intl/locale/mac/nsCollationMacUC.cpp index d230f4d771956..b32154453a693 100644 --- a/intl/locale/mac/nsCollationMacUC.cpp +++ b/intl/locale/mac/nsCollationMacUC.cpp @@ -4,7 +4,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsCollationMacUC.h" -#include "nsILocaleService.h" #include "nsIPrefBranch.h" #include "nsIPrefService.h" #include "nsIServiceManager.h" @@ -16,7 +15,6 @@ NS_IMPL_ISUPPORTS(nsCollationMacUC, nsICollation) nsCollationMacUC::nsCollationMacUC() : mInit(false) , mHasCollator(false) - , mLocaleICU(nullptr) , mLastStrength(-1) , mCollatorICU(nullptr) { } @@ -28,10 +26,6 @@ nsCollationMacUC::~nsCollationMacUC() #endif CleanUpCollator(); NS_ASSERTION(NS_SUCCEEDED(res), "CleanUpCollator failed"); - if (mLocaleICU) { - free(mLocaleICU); - mLocaleICU = nullptr; - } } nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength, @@ -68,28 +62,6 @@ nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength, return NS_OK; } -nsresult nsCollationMacUC::ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale) -{ - NS_ENSURE_ARG_POINTER(aNSLocale); - NS_ENSURE_ARG_POINTER(aICULocale); - - nsAutoString localeString; - nsresult res = aNSLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), localeString); - NS_ENSURE_TRUE(NS_SUCCEEDED(res) && !localeString.IsEmpty(), - NS_ERROR_FAILURE); - NS_LossyConvertUTF16toASCII tmp(localeString); - tmp.ReplaceChar('-', '_'); - char* locale = (char*)malloc(tmp.Length() + 1); - if (!locale) { - return NS_ERROR_OUT_OF_MEMORY; - } - strcpy(locale, tmp.get()); - - *aICULocale = locale; - - return NS_OK; -} - nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength) { NS_ENSURE_TRUE(mInit, NS_ERROR_NOT_INITIALIZED); @@ -100,11 +72,9 @@ nsresult nsCollationMacUC::EnsureCollator(const int32_t newStrength) res = CleanUpCollator(); NS_ENSURE_SUCCESS(res, res); - NS_ENSURE_TRUE(mLocaleICU, NS_ERROR_NOT_INITIALIZED); - UErrorCode status; status = U_ZERO_ERROR; - mCollatorICU = ucol_open(mLocaleICU, &status); + mCollatorICU = ucol_open(mLocale.get(), &status); NS_ENSURE_TRUE(U_SUCCESS(status), NS_ERROR_FAILURE); UCollationStrength strength; @@ -142,22 +112,12 @@ nsresult nsCollationMacUC::CleanUpCollator(void) return NS_OK; } -NS_IMETHODIMP nsCollationMacUC::Initialize(nsILocale* locale) +NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale) { NS_ENSURE_TRUE((!mInit), NS_ERROR_ALREADY_INITIALIZED); nsCOMPtr appLocale; - nsresult rv; - if (!locale) { - nsCOMPtr localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - rv = localeService->GetApplicationLocale(getter_AddRefs(appLocale)); - NS_ENSURE_SUCCESS(rv, rv); - locale = appLocale; - } - - rv = ConvertLocaleICU(locale, &mLocaleICU); - NS_ENSURE_SUCCESS(rv, rv); + mLocale = locale; mInit = true; return NS_OK; diff --git a/intl/locale/mac/nsCollationMacUC.h b/intl/locale/mac/nsCollationMacUC.h index 46bb0145de723..c234ff4eee502 100644 --- a/intl/locale/mac/nsCollationMacUC.h +++ b/intl/locale/mac/nsCollationMacUC.h @@ -6,9 +6,10 @@ #ifndef nsCollationMacUC_h_ #define nsCollationMacUC_h_ +#include "mozilla/Attributes.h" #include "nsICollation.h" #include "nsCollation.h" -#include "mozilla/Attributes.h" +#include "nsString.h" #include "unicode/ucol.h" @@ -26,7 +27,6 @@ class nsCollationMacUC final : public nsICollation { protected: ~nsCollationMacUC(); - nsresult ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale); nsresult ConvertStrength(const int32_t aStrength, UCollationStrength* aStrengthOut, UColAttributeValue* aCaseLevelOut); @@ -36,7 +36,7 @@ class nsCollationMacUC final : public nsICollation { private: bool mInit; bool mHasCollator; - char* mLocaleICU; + nsCString mLocale; int32_t mLastStrength; UCollator* mCollatorICU; }; diff --git a/intl/locale/nsCollation.cpp b/intl/locale/nsCollation.cpp index f6fa544715fcd..51f7b337a0906 100644 --- a/intl/locale/nsCollation.cpp +++ b/intl/locale/nsCollation.cpp @@ -10,6 +10,7 @@ #include "nsIUnicodeEncoder.h" #include "nsServiceManagerUtils.h" #include "mozilla/dom/EncodingUtils.h" +#include "mozilla/intl/LocaleService.h" using mozilla::dom::EncodingUtils; @@ -19,19 +20,29 @@ NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID); NS_IMPL_ISUPPORTS(nsCollationFactory, nsICollationFactory) -nsresult nsCollationFactory::CreateCollation(nsILocale* locale, nsICollation** instancePtr) +nsresult nsCollationFactory::CreateCollation(nsICollation** instancePtr) +{ + nsAutoCString appLocale; + mozilla::intl::LocaleService::GetInstance()->GetAppLocale(appLocale); + + return CreateCollationForLocale(appLocale, instancePtr); +} + +nsresult +nsCollationFactory::CreateCollationForLocale(const nsACString& locale, nsICollation** instancePtr) { // Create a collation interface instance. // nsICollation *inst; nsresult res; - + res = CallCreateInstance(kCollationCID, &inst); if (NS_FAILED(res)) { return res; } inst->Initialize(locale); + *instancePtr = inst; return res; diff --git a/intl/locale/nsCollation.h b/intl/locale/nsCollation.h index 4d936682261f3..bec27b89fd1c0 100644 --- a/intl/locale/nsCollation.h +++ b/intl/locale/nsCollation.h @@ -14,7 +14,7 @@ class nsIUnicodeEncoder; -// Create a collation interface for an input locale. +// Create a collation interface for the current app's locale. // class nsCollationFactory final : public nsICollationFactory { @@ -23,7 +23,8 @@ class nsCollationFactory final : public nsICollationFactory { public: NS_DECL_ISUPPORTS - NS_IMETHOD CreateCollation(nsILocale* locale, nsICollation** instancePtr) override; + NS_IMETHOD CreateCollation(nsICollation** instancePtr) override; + NS_IMETHOD CreateCollationForLocale(const nsACString& locale, nsICollation** instancePtr) override; nsCollationFactory() {} }; diff --git a/intl/locale/nsICollation.idl b/intl/locale/nsICollation.idl index bbcfb395bb6ca..ad52d0b6ae970 100644 --- a/intl/locale/nsICollation.idl +++ b/intl/locale/nsICollation.idl @@ -11,17 +11,18 @@ interface nsICollation; interface nsICollationFactory : nsISupports { /** - * Create the collation for a given locale. + * Create a new collation for the current application locale. * - * Use NULL as the locale parameter to use the user's locale preference - * from the operating system. + * @return A new collation. + */ + nsICollation CreateCollation(); + + /** + * Create a new collation for a given locale. * - * @param locale - * The locale for which to create the collation or null to use - * user preference. - * @return A collation for the given locale. + * @return A new collation. */ - nsICollation CreateCollation(in nsILocale locale); + nsICollation CreateCollationForLocale(in ACString locale); }; [scriptable, uuid(b0132cc0-3786-4557-9874-910d7def5f93)] @@ -43,7 +44,7 @@ interface nsICollation : nsISupports { const long kCollationCaseInSensitive = (kCollationCaseInsensitiveAscii | kCollationAccentInsenstive); // init this interface to a specified locale (should only be called by collation factory) - void initialize(in nsILocale locale); + void initialize(in ACString locale); // compare two strings // result is same as strcmp diff --git a/intl/locale/tests/unit/test_collation_mac_icu.js b/intl/locale/tests/unit/test_collation_mac_icu.js index 32ebc60ebccae..221d1c8f68470 100644 --- a/intl/locale/tests/unit/test_collation_mac_icu.js +++ b/intl/locale/tests/unit/test_collation_mac_icu.js @@ -20,11 +20,9 @@ function run_test() ]; function test(locale, expected) { - var localeSvc = Cc["@mozilla.org/intl/nslocaleservice;1"]. - getService(Ci.nsILocaleService); var collator = Cc["@mozilla.org/intl/collation-factory;1"]. createInstance(Ci.nsICollationFactory). - CreateCollation(localeSvc.newLocale(locale)); + CreateCollationForLocale(locale); var strength = Ci.nsICollation.kCollationStrengthDefault; var actual = input.sort((x, y) => collator.compareString(strength, x,y)); deepEqual(actual, expected, locale); diff --git a/intl/locale/unix/nsCollationUnix.cpp b/intl/locale/unix/nsCollationUnix.cpp index 3bc5a731c17fe..409e5894bfc5e 100644 --- a/intl/locale/unix/nsCollationUnix.cpp +++ b/intl/locale/unix/nsCollationUnix.cpp @@ -8,7 +8,6 @@ #include "nsCollationUnix.h" #include "nsIServiceManager.h" #include "nsIComponentManager.h" -#include "nsILocaleService.h" #include "nsIPlatformCharset.h" #include "nsPosixLocale.h" #include "nsCOMPtr.h" @@ -44,7 +43,7 @@ nsCollationUnix::~nsCollationUnix() NS_IMPL_ISUPPORTS(nsCollationUnix, nsICollation) -nsresult nsCollationUnix::Initialize(nsILocale* locale) +nsresult nsCollationUnix::Initialize(const nsACString& locale) { #define kPlatformLocaleLength 64 NS_ASSERTION(!mCollation, "Should only be initialized once"); @@ -53,46 +52,12 @@ nsresult nsCollationUnix::Initialize(nsILocale* locale) mCollation = new nsCollation; - // default platform locale - mLocale.Assign('C'); - - nsAutoString localeStr; - NS_NAMED_LITERAL_STRING(aCategory, "NSILOCALE_COLLATE##PLATFORM"); - - // get locale string, use app default if no locale specified - if (locale == nullptr) { - nsCOMPtr localeService = - do_GetService(NS_LOCALESERVICE_CONTRACTID, &res); - if (NS_SUCCEEDED(res)) { - nsCOMPtr appLocale; - res = localeService->GetApplicationLocale(getter_AddRefs(appLocale)); - if (NS_SUCCEEDED(res)) { - res = appLocale->GetCategory(aCategory, localeStr); - NS_ASSERTION(NS_SUCCEEDED(res), "failed to get app locale info"); - } - } - } - else { - res = locale->GetCategory(aCategory, localeStr); - NS_ASSERTION(NS_SUCCEEDED(res), "failed to get locale info"); - } - - // Get platform locale and charset name from locale, if available + nsCOMPtr platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res); if (NS_SUCCEEDED(res)) { - // keep the same behavior as 4.x as well as avoiding Linux collation key problem - if (localeStr.LowerCaseEqualsLiteral("en_us")) { // note: locale is in platform format - localeStr.Assign('C'); - } - - nsPosixLocale::GetPlatformLocale(localeStr, mLocale); - - nsCOMPtr platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res); + nsAutoCString mappedCharset; + res = platformCharset->GetDefaultCharsetForLocale(NS_ConvertUTF8toUTF16(locale), mappedCharset); if (NS_SUCCEEDED(res)) { - nsAutoCString mappedCharset; - res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset); - if (NS_SUCCEEDED(res)) { - mCollation->SetCharset(mappedCharset.get()); - } + mCollation->SetCharset(mappedCharset.get()); } } diff --git a/intl/locale/windows/nsCollationWin.cpp b/intl/locale/windows/nsCollationWin.cpp index 8dcdb8f071abc..76bc8a2d48c88 100644 --- a/intl/locale/windows/nsCollationWin.cpp +++ b/intl/locale/windows/nsCollationWin.cpp @@ -7,7 +7,6 @@ #include "nsCollationWin.h" #include "nsIServiceManager.h" #include "nsIComponentManager.h" -#include "nsILocaleService.h" #include "nsIPlatformCharset.h" #include "nsWin32Locale.h" #include "nsCOMPtr.h" @@ -30,7 +29,7 @@ nsCollationWin::~nsCollationWin() delete mCollation; } -nsresult nsCollationWin::Initialize(nsILocale* locale) +nsresult nsCollationWin::Initialize(const nsACString& locale) { NS_ASSERTION(!mCollation, "Should only be initialized once."); @@ -38,32 +37,14 @@ nsresult nsCollationWin::Initialize(nsILocale* locale) mCollation = new nsCollation; + NS_ConvertASCIItoUTF16 wideLocale(locale); + // default LCID (en-US) mLCID = 1033; - nsAutoString localeStr; - - // get locale string, use app default if no locale specified - if (!locale) { - nsCOMPtr localeService = - do_GetService(NS_LOCALESERVICE_CONTRACTID); - if (localeService) { - nsCOMPtr appLocale; - res = localeService->GetApplicationLocale(getter_AddRefs(appLocale)); - if (NS_SUCCEEDED(res)) { - res = appLocale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), - localeStr); - } - } - } - else { - res = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_COLLATE"), - localeStr); - } - // Get LCID and charset name from locale, if available LCID lcid; - res = nsWin32Locale::GetPlatformLocale(localeStr, &lcid); + res = nsWin32Locale::GetPlatformLocale(wideLocale, &lcid); if (NS_SUCCEEDED(res)) { mLCID = lcid; } @@ -72,7 +53,7 @@ nsresult nsCollationWin::Initialize(nsILocale* locale) do_GetService(NS_PLATFORMCHARSET_CONTRACTID); if (platformCharset) { nsAutoCString mappedCharset; - res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset); + res = platformCharset->GetDefaultCharsetForLocale(wideLocale, mappedCharset); if (NS_SUCCEEDED(res)) { mCollation->SetCharset(mappedCharset.get()); } diff --git a/js/xpconnect/src/XPCLocale.cpp b/js/xpconnect/src/XPCLocale.cpp index 2fe78cb7554ad..c98a51dc1a064 100644 --- a/js/xpconnect/src/XPCLocale.cpp +++ b/js/xpconnect/src/XPCLocale.cpp @@ -126,21 +126,11 @@ struct XPCLocaleCallbacks : public JSLocaleCallbacks nsresult rv; if (!mCollation) { - nsCOMPtr localeService = - do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); + nsCOMPtr colFactory = + do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { - nsCOMPtr locale; - rv = localeService->GetApplicationLocale(getter_AddRefs(locale)); - - if (NS_SUCCEEDED(rv)) { - nsCOMPtr colFactory = - do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv); - - if (NS_SUCCEEDED(rv)) { - rv = colFactory->CreateCollation(locale, getter_AddRefs(mCollation)); - } - } + rv = colFactory->CreateCollation(getter_AddRefs(mCollation)); } if (NS_FAILED(rv)) { diff --git a/netwerk/base/nsDirectoryIndexStream.cpp b/netwerk/base/nsDirectoryIndexStream.cpp index 87a57fd579c27..3e57d1a253383 100644 --- a/netwerk/base/nsDirectoryIndexStream.cpp +++ b/netwerk/base/nsDirectoryIndexStream.cpp @@ -22,8 +22,6 @@ #ifdef THREADSAFE_I18N #include "nsCollationCID.h" #include "nsICollation.h" -#include "nsILocale.h" -#include "nsILocaleService.h" #endif #include "nsIFile.h" #include "nsURLHelper.h" @@ -120,20 +118,12 @@ nsDirectoryIndexStream::Init(nsIFile* aDir) } #ifdef THREADSAFE_I18N - nsCOMPtr ls = do_GetService(NS_LOCALESERVICE_CONTRACTID, - &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr locale; - rv = ls->GetApplicationLocale(getter_AddRefs(locale)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr cf = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr coll; - rv = cf->CreateCollation(locale, getter_AddRefs(coll)); + rv = cf->CreateCollation(getter_AddRefs(coll)); if (NS_FAILED(rv)) return rv; mArray.Sort(compare, coll); diff --git a/storage/mozStorageService.cpp b/storage/mozStorageService.cpp index 38e81fd4d0c56..e315b92ccca7d 100644 --- a/storage/mozStorageService.cpp +++ b/storage/mozStorageService.cpp @@ -14,8 +14,6 @@ #include "nsEmbedCID.h" #include "nsThreadUtils.h" #include "mozStoragePrivateHelpers.h" -#include "nsILocale.h" -#include "nsILocaleService.h" #include "nsIXPConnect.h" #include "nsIObserverService.h" #include "nsIPropertyBag2.h" @@ -608,19 +606,6 @@ Service::getLocaleCollation() if (mLocaleCollation) return mLocaleCollation; - nsCOMPtr svc(do_GetService(NS_LOCALESERVICE_CONTRACTID)); - if (!svc) { - NS_WARNING("Could not get locale service"); - return nullptr; - } - - nsCOMPtr appLocale; - nsresult rv = svc->GetApplicationLocale(getter_AddRefs(appLocale)); - if (NS_FAILED(rv)) { - NS_WARNING("Could not get application locale"); - return nullptr; - } - nsCOMPtr collFact = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID); if (!collFact) { @@ -628,7 +613,7 @@ Service::getLocaleCollation() return nullptr; } - rv = collFact->CreateCollation(appLocale, getter_AddRefs(mLocaleCollation)); + nsresult rv = collFact->CreateCollation(getter_AddRefs(mLocaleCollation)); if (NS_FAILED(rv)) { NS_WARNING("Could not create collation"); return nullptr; diff --git a/storage/test/unit/test_locale_collation.js b/storage/test/unit/test_locale_collation.js index 7855ec8d2fcf8..fa7a1989e3aec 100644 --- a/storage/test/unit/test_locale_collation.js +++ b/storage/test/unit/test_locale_collation.js @@ -232,11 +232,9 @@ function setup() { gUtf16Conn = createUtf16Database(); initTableWithStrings(gStrings, gUtf16Conn); - let localeSvc = Cc["@mozilla.org/intl/nslocaleservice;1"]. - getService(Ci.nsILocaleService); let collFact = Cc["@mozilla.org/intl/collation-factory;1"]. createInstance(Ci.nsICollationFactory); - gLocaleCollation = collFact.CreateCollation(localeSvc.getApplicationLocale()); + gLocaleCollation = collFact.CreateCollation(); } // Test Runs diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index 996073bf6185b..4d7c2acda14cd 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -20,7 +20,6 @@ #include "nsTArray.h" #include "nsCollationCID.h" -#include "nsILocaleService.h" #include "nsNetUtil.h" #include "nsPrintfCString.h" #include "nsPromiseFlatString.h" @@ -4479,18 +4478,11 @@ nsNavHistory::GetCollation() if (mCollation) return mCollation; - // locale - nsCOMPtr locale; - nsCOMPtr ls(do_GetService(NS_LOCALESERVICE_CONTRACTID)); - NS_ENSURE_TRUE(ls, nullptr); - nsresult rv = ls->GetApplicationLocale(getter_AddRefs(locale)); - NS_ENSURE_SUCCESS(rv, nullptr); - // collation nsCOMPtr cfact = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID); NS_ENSURE_TRUE(cfact, nullptr); - rv = cfact->CreateCollation(locale, getter_AddRefs(mCollation)); + nsresult rv = cfact->CreateCollation(getter_AddRefs(mCollation)); NS_ENSURE_SUCCESS(rv, nullptr); return mCollation; diff --git a/toolkit/components/search/nsSearchService.js b/toolkit/components/search/nsSearchService.js index f9eb7799e691b..d60476f34b12b 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -3868,12 +3868,9 @@ SearchService.prototype = { alphaEngines.push(this._engines[engine.name]); } - let locale = Cc["@mozilla.org/intl/nslocaleservice;1"] - .getService(Ci.nsILocaleService) - .newLocale(getLocale()); let collation = Cc["@mozilla.org/intl/collation-factory;1"] .createInstance(Ci.nsICollationFactory) - .CreateCollation(locale); + .CreateCollation(); const strength = Ci.nsICollation.kCollationCaseInsensitiveAscii; let comparator = (a, b) => collation.compareString(strength, a.name, b.name); alphaEngines.sort(comparator);