From a9ce32d9a5a872be8217499b6b0be64d7c06d255 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Tue, 7 Feb 2017 12:34:30 -0800 Subject: [PATCH] Backed out 2 changesets (bug 1335983) for build bustage a=backout Backed out changeset 5a9559ded976 (bug 1335983) Backed out changeset de2b0d90e2da (bug 1335983) MozReview-Commit-ID: 377KQDU1QqJ --- 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 | 47 ++++++++++++++++--- 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, 222 insertions(+), 65 deletions(-) diff --git a/dom/xslt/xslt/txXPathResultComparator.cpp b/dom/xslt/xslt/txXPathResultComparator.cpp index 25bc57d4f931..5403089206b5 100644 --- a/dom/xslt/xslt/txXPathResultComparator.cpp +++ b/dom/xslt/xslt/txXPathResultComparator.cpp @@ -9,6 +9,8 @@ #include "txExpr.h" #include "txCore.h" #include "nsCollationCID.h" +#include "nsILocale.h" +#include "nsILocaleService.h" #include "nsIServiceManager.h" #include "prmem.h" @@ -33,16 +35,25 @@ 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); - if (aLanguage.IsEmpty()) { - rv = colFactory->CreateCollation(getter_AddRefs(mCollation)); - } else { - rv = colFactory->CreateCollationForLocale(NS_ConvertUTF16toUTF8(aLanguage), getter_AddRefs(mCollation)); - } - + rv = colFactory->CreateCollation(locale, 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 edad6b0d1028..a5f00473c9a1 100644 --- a/dom/xul/templates/nsXULContentUtils.cpp +++ b/dom/xul/templates/nsXULContentUtils.cpp @@ -52,6 +52,8 @@ #include "nsIScriptableDateFormat.h" #include "nsICollation.h" #include "nsCollationCID.h" +#include "nsILocale.h" +#include "nsILocaleService.h" #include "nsIConsoleService.h" #include "nsEscape.h" @@ -123,14 +125,27 @@ nsICollation* nsXULContentUtils::GetCollation() { if (!gCollation) { - nsCOMPtr colFactory = - do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID); - if (colFactory) { - rv = colFactory->CreateCollation(&gCollation); - NS_ASSERTION(NS_SUCCEEDED(rv), - "couldn't create collation instance"); + 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"); } else - NS_ERROR("couldn't create instance of collation factory"); + NS_ERROR("couldn't get locale factory"); } return gCollation; diff --git a/intl/locale/mac/nsCollationMacUC.cpp b/intl/locale/mac/nsCollationMacUC.cpp index b32154453a69..d230f4d77195 100644 --- a/intl/locale/mac/nsCollationMacUC.cpp +++ b/intl/locale/mac/nsCollationMacUC.cpp @@ -4,6 +4,7 @@ * 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" @@ -15,6 +16,7 @@ NS_IMPL_ISUPPORTS(nsCollationMacUC, nsICollation) nsCollationMacUC::nsCollationMacUC() : mInit(false) , mHasCollator(false) + , mLocaleICU(nullptr) , mLastStrength(-1) , mCollatorICU(nullptr) { } @@ -26,6 +28,10 @@ nsCollationMacUC::~nsCollationMacUC() #endif CleanUpCollator(); NS_ASSERTION(NS_SUCCEEDED(res), "CleanUpCollator failed"); + if (mLocaleICU) { + free(mLocaleICU); + mLocaleICU = nullptr; + } } nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength, @@ -62,6 +68,28 @@ 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); @@ -72,9 +100,11 @@ 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(mLocale.get(), &status); + mCollatorICU = ucol_open(mLocaleICU, &status); NS_ENSURE_TRUE(U_SUCCESS(status), NS_ERROR_FAILURE); UCollationStrength strength; @@ -112,12 +142,22 @@ nsresult nsCollationMacUC::CleanUpCollator(void) return NS_OK; } -NS_IMETHODIMP nsCollationMacUC::Initialize(const nsACString& locale) +NS_IMETHODIMP nsCollationMacUC::Initialize(nsILocale* locale) { NS_ENSURE_TRUE((!mInit), NS_ERROR_ALREADY_INITIALIZED); nsCOMPtr appLocale; - mLocale = locale; + 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); mInit = true; return NS_OK; diff --git a/intl/locale/mac/nsCollationMacUC.h b/intl/locale/mac/nsCollationMacUC.h index c234ff4eee50..46bb0145de72 100644 --- a/intl/locale/mac/nsCollationMacUC.h +++ b/intl/locale/mac/nsCollationMacUC.h @@ -6,10 +6,9 @@ #ifndef nsCollationMacUC_h_ #define nsCollationMacUC_h_ -#include "mozilla/Attributes.h" #include "nsICollation.h" #include "nsCollation.h" -#include "nsString.h" +#include "mozilla/Attributes.h" #include "unicode/ucol.h" @@ -27,6 +26,7 @@ public: protected: ~nsCollationMacUC(); + nsresult ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale); nsresult ConvertStrength(const int32_t aStrength, UCollationStrength* aStrengthOut, UColAttributeValue* aCaseLevelOut); @@ -36,7 +36,7 @@ protected: private: bool mInit; bool mHasCollator; - nsCString mLocale; + char* mLocaleICU; int32_t mLastStrength; UCollator* mCollatorICU; }; diff --git a/intl/locale/nsCollation.cpp b/intl/locale/nsCollation.cpp index 51f7b337a090..f6fa544715fc 100644 --- a/intl/locale/nsCollation.cpp +++ b/intl/locale/nsCollation.cpp @@ -10,7 +10,6 @@ #include "nsIUnicodeEncoder.h" #include "nsServiceManagerUtils.h" #include "mozilla/dom/EncodingUtils.h" -#include "mozilla/intl/LocaleService.h" using mozilla::dom::EncodingUtils; @@ -20,29 +19,19 @@ NS_DEFINE_CID(kCollationCID, NS_COLLATION_CID); NS_IMPL_ISUPPORTS(nsCollationFactory, nsICollationFactory) -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) +nsresult nsCollationFactory::CreateCollation(nsILocale* 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 bec27b89fd1c..4d936682261f 100644 --- a/intl/locale/nsCollation.h +++ b/intl/locale/nsCollation.h @@ -14,7 +14,7 @@ class nsIUnicodeEncoder; -// Create a collation interface for the current app's locale. +// Create a collation interface for an input locale. // class nsCollationFactory final : public nsICollationFactory { @@ -23,8 +23,7 @@ class nsCollationFactory final : public nsICollationFactory { public: NS_DECL_ISUPPORTS - NS_IMETHOD CreateCollation(nsICollation** instancePtr) override; - NS_IMETHOD CreateCollationForLocale(const nsACString& locale, nsICollation** instancePtr) override; + NS_IMETHOD CreateCollation(nsILocale* locale, nsICollation** instancePtr) override; nsCollationFactory() {} }; diff --git a/intl/locale/nsICollation.idl b/intl/locale/nsICollation.idl index ad52d0b6ae97..bbcfb395bb6c 100644 --- a/intl/locale/nsICollation.idl +++ b/intl/locale/nsICollation.idl @@ -11,18 +11,17 @@ interface nsICollation; interface nsICollationFactory : nsISupports { /** - * Create a new collation for the current application locale. + * Create the collation for a given locale. * - * @return A new collation. - */ - nsICollation CreateCollation(); - - /** - * Create a new collation for a given locale. + * Use NULL as the locale parameter to use the user's locale preference + * from the operating system. * - * @return A new collation. + * @param locale + * The locale for which to create the collation or null to use + * user preference. + * @return A collation for the given locale. */ - nsICollation CreateCollationForLocale(in ACString locale); + nsICollation CreateCollation(in nsILocale locale); }; [scriptable, uuid(b0132cc0-3786-4557-9874-910d7def5f93)] @@ -44,7 +43,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 ACString locale); + void initialize(in nsILocale 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 221d1c8f6847..32ebc60ebcca 100644 --- a/intl/locale/tests/unit/test_collation_mac_icu.js +++ b/intl/locale/tests/unit/test_collation_mac_icu.js @@ -20,9 +20,11 @@ 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). - CreateCollationForLocale(locale); + CreateCollation(localeSvc.newLocale(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 409e5894bfc5..3bc5a731c17f 100644 --- a/intl/locale/unix/nsCollationUnix.cpp +++ b/intl/locale/unix/nsCollationUnix.cpp @@ -8,6 +8,7 @@ #include "nsCollationUnix.h" #include "nsIServiceManager.h" #include "nsIComponentManager.h" +#include "nsILocaleService.h" #include "nsIPlatformCharset.h" #include "nsPosixLocale.h" #include "nsCOMPtr.h" @@ -43,7 +44,7 @@ nsCollationUnix::~nsCollationUnix() NS_IMPL_ISUPPORTS(nsCollationUnix, nsICollation) -nsresult nsCollationUnix::Initialize(const nsACString& locale) +nsresult nsCollationUnix::Initialize(nsILocale* locale) { #define kPlatformLocaleLength 64 NS_ASSERTION(!mCollation, "Should only be initialized once"); @@ -52,12 +53,46 @@ nsresult nsCollationUnix::Initialize(const nsACString& locale) mCollation = new nsCollation; - nsCOMPtr platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res); - if (NS_SUCCEEDED(res)) { - nsAutoCString mappedCharset; - res = platformCharset->GetDefaultCharsetForLocale(NS_ConvertUTF8toUTF16(locale), mappedCharset); + // 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)) { - mCollation->SetCharset(mappedCharset.get()); + 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 + 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); + if (NS_SUCCEEDED(res)) { + nsAutoCString mappedCharset; + res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset); + if (NS_SUCCEEDED(res)) { + mCollation->SetCharset(mappedCharset.get()); + } } } diff --git a/intl/locale/windows/nsCollationWin.cpp b/intl/locale/windows/nsCollationWin.cpp index 76bc8a2d48c8..8dcdb8f071ab 100644 --- a/intl/locale/windows/nsCollationWin.cpp +++ b/intl/locale/windows/nsCollationWin.cpp @@ -7,6 +7,7 @@ #include "nsCollationWin.h" #include "nsIServiceManager.h" #include "nsIComponentManager.h" +#include "nsILocaleService.h" #include "nsIPlatformCharset.h" #include "nsWin32Locale.h" #include "nsCOMPtr.h" @@ -29,7 +30,7 @@ nsCollationWin::~nsCollationWin() delete mCollation; } -nsresult nsCollationWin::Initialize(const nsACString& locale) +nsresult nsCollationWin::Initialize(nsILocale* locale) { NS_ASSERTION(!mCollation, "Should only be initialized once."); @@ -37,14 +38,32 @@ nsresult nsCollationWin::Initialize(const nsACString& 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(wideLocale, &lcid); + res = nsWin32Locale::GetPlatformLocale(localeStr, &lcid); if (NS_SUCCEEDED(res)) { mLCID = lcid; } @@ -53,7 +72,7 @@ nsresult nsCollationWin::Initialize(const nsACString& locale) do_GetService(NS_PLATFORMCHARSET_CONTRACTID); if (platformCharset) { nsAutoCString mappedCharset; - res = platformCharset->GetDefaultCharsetForLocale(wideLocale, mappedCharset); + res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset); if (NS_SUCCEEDED(res)) { mCollation->SetCharset(mappedCharset.get()); } diff --git a/js/xpconnect/src/XPCLocale.cpp b/js/xpconnect/src/XPCLocale.cpp index c98a51dc1a06..2fe78cb7554a 100644 --- a/js/xpconnect/src/XPCLocale.cpp +++ b/js/xpconnect/src/XPCLocale.cpp @@ -126,11 +126,21 @@ private: nsresult rv; if (!mCollation) { - nsCOMPtr colFactory = - do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv); + nsCOMPtr localeService = + do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { - rv = colFactory->CreateCollation(getter_AddRefs(mCollation)); + 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)); + } + } } if (NS_FAILED(rv)) { diff --git a/netwerk/base/nsDirectoryIndexStream.cpp b/netwerk/base/nsDirectoryIndexStream.cpp index 3e57d1a25338..87a57fd579c2 100644 --- a/netwerk/base/nsDirectoryIndexStream.cpp +++ b/netwerk/base/nsDirectoryIndexStream.cpp @@ -22,6 +22,8 @@ #ifdef THREADSAFE_I18N #include "nsCollationCID.h" #include "nsICollation.h" +#include "nsILocale.h" +#include "nsILocaleService.h" #endif #include "nsIFile.h" #include "nsURLHelper.h" @@ -118,12 +120,20 @@ 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(getter_AddRefs(coll)); + rv = cf->CreateCollation(locale, getter_AddRefs(coll)); if (NS_FAILED(rv)) return rv; mArray.Sort(compare, coll); diff --git a/storage/mozStorageService.cpp b/storage/mozStorageService.cpp index e315b92ccca7..38e81fd4d0c5 100644 --- a/storage/mozStorageService.cpp +++ b/storage/mozStorageService.cpp @@ -14,6 +14,8 @@ #include "nsEmbedCID.h" #include "nsThreadUtils.h" #include "mozStoragePrivateHelpers.h" +#include "nsILocale.h" +#include "nsILocaleService.h" #include "nsIXPConnect.h" #include "nsIObserverService.h" #include "nsIPropertyBag2.h" @@ -606,6 +608,19 @@ 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) { @@ -613,7 +628,7 @@ Service::getLocaleCollation() return nullptr; } - nsresult rv = collFact->CreateCollation(getter_AddRefs(mLocaleCollation)); + rv = collFact->CreateCollation(appLocale, 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 fa7a1989e3ae..7855ec8d2fcf 100644 --- a/storage/test/unit/test_locale_collation.js +++ b/storage/test/unit/test_locale_collation.js @@ -232,9 +232,11 @@ 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(); + gLocaleCollation = collFact.CreateCollation(localeSvc.getApplicationLocale()); } // Test Runs diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index 4d7c2acda14c..996073bf6185 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -20,6 +20,7 @@ #include "nsTArray.h" #include "nsCollationCID.h" +#include "nsILocaleService.h" #include "nsNetUtil.h" #include "nsPrintfCString.h" #include "nsPromiseFlatString.h" @@ -4478,11 +4479,18 @@ 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); - nsresult rv = cfact->CreateCollation(getter_AddRefs(mCollation)); + rv = cfact->CreateCollation(locale, 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 d60476f34b12..f9eb7799e691 100644 --- a/toolkit/components/search/nsSearchService.js +++ b/toolkit/components/search/nsSearchService.js @@ -3868,9 +3868,12 @@ 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(); + .CreateCollation(locale); const strength = Ci.nsICollation.kCollationCaseInsensitiveAscii; let comparator = (a, b) => collation.compareString(strength, a.name, b.name); alphaEngines.sort(comparator);