Backed out 2 changesets (bug 1335983) for build bustage a=backout
authorWes Kocher <wkocher@mozilla.com>
Tue, 07 Feb 2017 12:34:30 -0800
changeset 374987 cddb9e197d816c2167bf49222e4b83745efce653
parent 374986 5a9559ded976666b28e3cbd28c5ca4d0ebf7cff0
child 374988 87d2810770f37202bca4c6934d1cd9a9d449e3e6
push idunknown
push userunknown
push dateunknown
reviewersbackout
bugs1335983
milestone54.0a1
backs out5a9559ded976666b28e3cbd28c5ca4d0ebf7cff0
de2b0d90e2dafb22885e63e58a498525e340badc
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/xul/templates/nsXULContentUtils.cpp
intl/locale/mac/nsCollationMacUC.cpp
intl/locale/mac/nsCollationMacUC.h
intl/locale/nsCollation.cpp
intl/locale/nsCollation.h
intl/locale/nsICollation.idl
intl/locale/tests/unit/test_collation_mac_icu.js
intl/locale/unix/nsCollationUnix.cpp
intl/locale/windows/nsCollationWin.cpp
js/xpconnect/src/XPCLocale.cpp
netwerk/base/nsDirectoryIndexStream.cpp
storage/mozStorageService.cpp
storage/test/unit/test_locale_collation.js
toolkit/components/places/nsNavHistory.cpp
toolkit/components/search/nsSearchService.js
--- a/dom/xslt/xslt/txXPathResultComparator.cpp
+++ b/dom/xslt/xslt/txXPathResultComparator.cpp
@@ -4,16 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/FloatingPoint.h"
 
 #include "txXPathResultComparator.h"
 #include "txExpr.h"
 #include "txCore.h"
 #include "nsCollationCID.h"
+#include "nsILocale.h"
+#include "nsILocaleService.h"
 #include "nsIServiceManager.h"
 #include "prmem.h"
 
 #define kAscending (1<<0)
 #define kUpperFirst (1<<1)
 
 txResultStringComparator::txResultStringComparator(bool aAscending,
                                                    bool aUpperFirst,
@@ -28,26 +30,35 @@ txResultStringComparator::txResultString
     if (NS_FAILED(rv))
         NS_ERROR("Failed to initialize txResultStringComparator");
 }
 
 nsresult txResultStringComparator::init(const nsAFlatString& aLanguage)
 {
     nsresult rv;
 
+    nsCOMPtr<nsILocaleService> localeService =
+                    do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsILocale> locale;
+    if (!aLanguage.IsEmpty()) {
+        rv = localeService->NewLocale(aLanguage,
+                                      getter_AddRefs(locale));
+    }
+    else {
+        rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
+    }
+    NS_ENSURE_SUCCESS(rv, rv);
+
     nsCOMPtr<nsICollationFactory> 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;
 }
 
 nsresult
 txResultStringComparator::createSortableValue(Expr *aExpr,
                                               txIEvalContext *aContext,
--- a/dom/xul/templates/nsXULContentUtils.cpp
+++ b/dom/xul/templates/nsXULContentUtils.cpp
@@ -47,16 +47,18 @@
 #include "nsGkAtoms.h"
 #include "mozilla/Logging.h"
 #include "prtime.h"
 #include "rdf.h"
 #include "nsContentUtils.h"
 #include "nsIScriptableDateFormat.h"
 #include "nsICollation.h"
 #include "nsCollationCID.h"
+#include "nsILocale.h"
+#include "nsILocaleService.h"
 #include "nsIConsoleService.h"
 #include "nsEscape.h"
 
 using namespace mozilla;
 
 //------------------------------------------------------------------------
 
 nsIRDFService* nsXULContentUtils::gRDF;
@@ -118,24 +120,37 @@ nsXULContentUtils::Finish()
 
     return NS_OK;
 }
 
 nsICollation*
 nsXULContentUtils::GetCollation()
 {
     if (!gCollation) {
-        nsCOMPtr<nsICollationFactory> 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<nsILocaleService> localeService =
+            do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
+        if (NS_SUCCEEDED(rv)) {
+            nsCOMPtr<nsILocale> locale;
+            rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
+            if (NS_SUCCEEDED(rv) && locale) {
+                nsCOMPtr<nsICollationFactory> 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;
 }
 
 //------------------------------------------------------------------------
 
 nsresult
--- a/intl/locale/mac/nsCollationMacUC.cpp
+++ b/intl/locale/mac/nsCollationMacUC.cpp
@@ -1,36 +1,42 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsCollationMacUC.h"
+#include "nsILocaleService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIServiceManager.h"
 #include "prmem.h"
 #include "nsString.h"
 
 NS_IMPL_ISUPPORTS(nsCollationMacUC, nsICollation)
 
 nsCollationMacUC::nsCollationMacUC()
   : mInit(false)
   , mHasCollator(false)
+  , mLocaleICU(nullptr)
   , mLastStrength(-1)
   , mCollatorICU(nullptr)
 { }
 
 nsCollationMacUC::~nsCollationMacUC()
 {
 #ifdef DEBUG
   nsresult res =
 #endif
     CleanUpCollator();
   NS_ASSERTION(NS_SUCCEEDED(res), "CleanUpCollator failed");
+  if (mLocaleICU) {
+    free(mLocaleICU);
+    mLocaleICU = nullptr;
+  }
 }
 
 nsresult nsCollationMacUC::ConvertStrength(const int32_t aNSStrength,
                                            UCollationStrength* aICUStrength,
                                            UColAttributeValue* aCaseLevelOut)
 {
   NS_ENSURE_ARG_POINTER(aICUStrength);
   NS_ENSURE_TRUE((aNSStrength < 4), NS_ERROR_FAILURE);
@@ -57,29 +63,53 @@ nsresult nsCollationMacUC::ConvertStreng
   }
 
   *aICUStrength = strength;
   *aCaseLevelOut = caseLevel;
 
   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);
   if (mHasCollator && (mLastStrength == newStrength))
     return NS_OK;
 
   nsresult res;
   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;
   UColAttributeValue caseLevel;
   res = ConvertStrength(newStrength, &strength, &caseLevel);
   NS_ENSURE_SUCCESS(res, res);
 
   status = U_ZERO_ERROR;
@@ -107,22 +137,32 @@ nsresult nsCollationMacUC::CleanUpCollat
   if (mHasCollator) {
     ucol_close(mCollatorICU);
     mHasCollator = false;
   }
 
   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<nsILocale> appLocale;
 
-  mLocale = locale;
+  nsresult rv;
+  if (!locale) {
+    nsCOMPtr<nsILocaleService> 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;
 }
 
 NS_IMETHODIMP nsCollationMacUC::AllocateRawSortKey(int32_t strength, const nsAString& stringIn,
                                                    uint8_t** key, uint32_t* outLen)
 {
--- a/intl/locale/mac/nsCollationMacUC.h
+++ b/intl/locale/mac/nsCollationMacUC.h
@@ -1,20 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #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"
 
 class nsCollationMacUC final : public nsICollation {
 
 public:
   nsCollationMacUC();
 
@@ -22,23 +21,24 @@ public:
   NS_DECL_ISUPPORTS
 
   // nsICollation interface
   NS_DECL_NSICOLLATION
 
 protected:
   ~nsCollationMacUC();
 
+  nsresult ConvertLocaleICU(nsILocale* aNSLocale, char** aICULocale);
   nsresult ConvertStrength(const int32_t aStrength,
                            UCollationStrength* aStrengthOut,
                            UColAttributeValue* aCaseLevelOut);
   nsresult EnsureCollator(const int32_t newStrength);
   nsresult CleanUpCollator(void);
 
 private:
   bool mInit;
   bool mHasCollator;
-  nsCString mLocale;
+  char* mLocaleICU;
   int32_t mLastStrength;
   UCollator* mCollatorICU;
 };
 
 #endif  /* nsCollationMacUC_h_ */
--- a/intl/locale/nsCollation.cpp
+++ b/intl/locale/nsCollation.cpp
@@ -5,49 +5,38 @@
 
 #include "nsCollation.h"
 #include "nsCollationCID.h"
 #include "nsUnicharUtils.h"
 #include "prmem.h"
 #include "nsIUnicodeEncoder.h"
 #include "nsServiceManagerUtils.h"
 #include "mozilla/dom/EncodingUtils.h"
-#include "mozilla/intl/LocaleService.h"
 
 using mozilla::dom::EncodingUtils;
 
 ////////////////////////////////////////////////////////////////////////////////
 
 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;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 nsCollation::nsCollation()
--- a/intl/locale/nsCollation.h
+++ b/intl/locale/nsCollation.h
@@ -9,27 +9,26 @@
 
 
 #include "nsICollation.h"
 #include "nsCOMPtr.h"
 #include "mozilla/Attributes.h"
 
 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 {
 
   ~nsCollationFactory() {}
 
 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() {}
 };
 
 
 struct nsCollation {
 
 public: 
--- a/intl/locale/nsICollation.idl
+++ b/intl/locale/nsICollation.idl
@@ -6,28 +6,27 @@
 #include "nsILocale.idl"
 
 interface nsICollation;
 
 [scriptable, uuid(04971e14-d6b3-4ada-8cbb-c3a13842b349)]
 interface nsICollationFactory : nsISupports
 {
     /**
-     * Create a new collation for the current application locale.
+     * Create the 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 CreateCollation();
-
-    /**
-     * Create a new collation for a given locale.
-     *
-     * @return A new collation.
-     */
-    nsICollation CreateCollationForLocale(in ACString locale);
+    nsICollation CreateCollation(in nsILocale locale);
 };
 
 [scriptable, uuid(b0132cc0-3786-4557-9874-910d7def5f93)]
 interface nsICollation : nsISupports {
 
   // use the primary comparison for the given locale - no flags
   const long kCollationStrengthDefault = 0;
 
@@ -39,17 +38,17 @@ interface nsICollation : nsISupports {
 
   // case sensitive collation (default)
   const long kCollationCaseSensitive = kCollationStrengthDefault;
 
   // case insensitive collation
   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
   long compareString(in long strength, in AString string1, in AString string2);
 
   // allocate sort key from input string
   // returns newly allocated key, and its band its byte length
   [noscript] void allocateRawSortKey(in long strength, 
--- a/intl/locale/tests/unit/test_collation_mac_icu.js
+++ b/intl/locale/tests/unit/test_collation_mac_icu.js
@@ -15,19 +15,21 @@ function run_test()
     "¡viva España!",
     "Österreich",
     "中国",
     "日本",
     "한국",
   ];
 
   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);
   }
 
   // Locale en-US; default options.
   test("en-US", [
     "¡viva España!",
--- a/intl/locale/unix/nsCollationUnix.cpp
+++ b/intl/locale/unix/nsCollationUnix.cpp
@@ -3,16 +3,17 @@
  * 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/. */
 
 #include  <locale.h>
 #include "prmem.h"
 #include "nsCollationUnix.h"
 #include "nsIServiceManager.h"
 #include "nsIComponentManager.h"
+#include "nsILocaleService.h"
 #include "nsIPlatformCharset.h"
 #include "nsPosixLocale.h"
 #include "nsCOMPtr.h"
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 //#define DEBUG_UNIX_COLLATION
 
 inline void nsCollationUnix::DoSetLocale()
@@ -38,31 +39,65 @@ nsCollationUnix::nsCollationUnix() : mCo
 nsCollationUnix::~nsCollationUnix() 
 {
   if (mCollation)
     delete mCollation;
 }
 
 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");
 
   nsresult res;
 
   mCollation = new nsCollation;
 
-  nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
+  // 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<nsILocaleService> localeService = 
+             do_GetService(NS_LOCALESERVICE_CONTRACTID, &res);
+    if (NS_SUCCEEDED(res)) {
+      nsCOMPtr<nsILocale> 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)) {
-    nsAutoCString mappedCharset;
-    res = platformCharset->GetDefaultCharsetForLocale(NS_ConvertUTF8toUTF16(locale), mappedCharset);
+    // 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 <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &res);
     if (NS_SUCCEEDED(res)) {
-      mCollation->SetCharset(mappedCharset.get());
+      nsAutoCString mappedCharset;
+      res = platformCharset->GetDefaultCharsetForLocale(localeStr, mappedCharset);
+      if (NS_SUCCEEDED(res)) {
+        mCollation->SetCharset(mappedCharset.get());
+      }
     }
   }
 
   return NS_OK;
 }
 
 
 nsresult nsCollationUnix::CompareString(int32_t strength,
--- a/intl/locale/windows/nsCollationWin.cpp
+++ b/intl/locale/windows/nsCollationWin.cpp
@@ -2,16 +2,17 @@
 /* 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/. */
 
 
 #include "nsCollationWin.h"
 #include "nsIServiceManager.h"
 #include "nsIComponentManager.h"
+#include "nsILocaleService.h"
 #include "nsIPlatformCharset.h"
 #include "nsWin32Locale.h"
 #include "nsCOMPtr.h"
 #include "prmem.h"
 #include "plstr.h"
 #include <windows.h>
 
 #undef CompareString
@@ -24,41 +25,59 @@ nsCollationWin::nsCollationWin() : mColl
 }
 
 nsCollationWin::~nsCollationWin() 
 {
   if (mCollation)
     delete mCollation;
 }
 
-nsresult nsCollationWin::Initialize(const nsACString& locale)
+nsresult nsCollationWin::Initialize(nsILocale* locale) 
 {
   NS_ASSERTION(!mCollation, "Should only be initialized once.");
 
   nsresult res;
 
   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<nsILocaleService> localeService = 
+             do_GetService(NS_LOCALESERVICE_CONTRACTID);
+    if (localeService) {
+      nsCOMPtr<nsILocale> 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;
   }
 
   nsCOMPtr <nsIPlatformCharset> platformCharset = 
       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());
     }
   }
 
   return NS_OK;
 }
 
--- a/js/xpconnect/src/XPCLocale.cpp
+++ b/js/xpconnect/src/XPCLocale.cpp
@@ -121,21 +121,31 @@ private:
   }
 
   bool
   Compare(JSContext* cx, HandleString src1, HandleString src2, MutableHandleValue rval)
   {
     nsresult rv;
 
     if (!mCollation) {
-      nsCOMPtr<nsICollationFactory> colFactory =
-        do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv);
+      nsCOMPtr<nsILocaleService> localeService =
+        do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
 
       if (NS_SUCCEEDED(rv)) {
-        rv = colFactory->CreateCollation(getter_AddRefs(mCollation));
+        nsCOMPtr<nsILocale> locale;
+        rv = localeService->GetApplicationLocale(getter_AddRefs(locale));
+
+        if (NS_SUCCEEDED(rv)) {
+          nsCOMPtr<nsICollationFactory> colFactory =
+            do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID, &rv);
+
+          if (NS_SUCCEEDED(rv)) {
+            rv = colFactory->CreateCollation(locale, getter_AddRefs(mCollation));
+          }
+        }
       }
 
       if (NS_FAILED(rv)) {
         xpc::Throw(cx, rv);
         return false;
       }
     }
 
--- a/netwerk/base/nsDirectoryIndexStream.cpp
+++ b/netwerk/base/nsDirectoryIndexStream.cpp
@@ -17,16 +17,18 @@
 #include "nsEscape.h"
 #include "nsDirectoryIndexStream.h"
 #include "mozilla/Logging.h"
 #include "prtime.h"
 #include "nsISimpleEnumerator.h"
 #ifdef THREADSAFE_I18N
 #include "nsCollationCID.h"
 #include "nsICollation.h"
+#include "nsILocale.h"
+#include "nsILocaleService.h"
 #endif
 #include "nsIFile.h"
 #include "nsURLHelper.h"
 #include "nsNativeCharsetUtils.h"
 
 // NOTE: This runs on the _file transport_ thread.
 // The problem is that now that we're actually doing something with the data,
 // we want to do stuff like i18n sorting. However, none of the collation stuff
@@ -113,22 +115,30 @@ nsDirectoryIndexStream::Init(nsIFile* aD
         if (NS_SUCCEEDED(rv)) {
             nsCOMPtr<nsIFile> file = do_QueryInterface(elem);
             if (file)
                 mArray.AppendObject(file); // addrefs
         }
     }
 
 #ifdef THREADSAFE_I18N
+    nsCOMPtr<nsILocaleService> ls = do_GetService(NS_LOCALESERVICE_CONTRACTID,
+                                                  &rv);
+    if (NS_FAILED(rv)) return rv;
+
+    nsCOMPtr<nsILocale> locale;
+    rv = ls->GetApplicationLocale(getter_AddRefs(locale));
+    if (NS_FAILED(rv)) return rv;
+    
     nsCOMPtr<nsICollationFactory> cf = do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID,
                                                          &rv);
     if (NS_FAILED(rv)) return rv;
 
     nsCOMPtr<nsICollation> coll;
-    rv = cf->CreateCollation(getter_AddRefs(coll));
+    rv = cf->CreateCollation(locale, getter_AddRefs(coll));
     if (NS_FAILED(rv)) return rv;
 
     mArray.Sort(compare, coll);
 #else
     mArray.Sort(compare, nullptr);
 #endif
 
     mBuf.AppendLiteral("300: ");
--- a/storage/mozStorageService.cpp
+++ b/storage/mozStorageService.cpp
@@ -9,16 +9,18 @@
 
 #include "mozStorageService.h"
 #include "mozStorageConnection.h"
 #include "nsAutoPtr.h"
 #include "nsCollationCID.h"
 #include "nsEmbedCID.h"
 #include "nsThreadUtils.h"
 #include "mozStoragePrivateHelpers.h"
+#include "nsILocale.h"
+#include "nsILocaleService.h"
 #include "nsIXPConnect.h"
 #include "nsIObserverService.h"
 #include "nsIPropertyBag2.h"
 #include "mozilla/Services.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/LateWriteChecks.h"
 #include "mozIStorageCompletionCallback.h"
 #include "mozIStoragePendingStatement.h"
@@ -601,24 +603,37 @@ Service::localeCompareStrings(const nsAS
 nsICollation *
 Service::getLocaleCollation()
 {
   mMutex.AssertCurrentThreadOwns();
 
   if (mLocaleCollation)
     return mLocaleCollation;
 
+  nsCOMPtr<nsILocaleService> svc(do_GetService(NS_LOCALESERVICE_CONTRACTID));
+  if (!svc) {
+    NS_WARNING("Could not get locale service");
+    return nullptr;
+  }
+
+  nsCOMPtr<nsILocale> appLocale;
+  nsresult rv = svc->GetApplicationLocale(getter_AddRefs(appLocale));
+  if (NS_FAILED(rv)) {
+    NS_WARNING("Could not get application locale");
+    return nullptr;
+  }
+
   nsCOMPtr<nsICollationFactory> collFact =
     do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
   if (!collFact) {
     NS_WARNING("Could not create collation factory");
     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;
   }
 
   return mLocaleCollation;
 }
 
--- a/storage/test/unit/test_locale_collation.js
+++ b/storage/test/unit/test_locale_collation.js
@@ -227,19 +227,21 @@ function setup() {
 
   gStrings = readTestData();
 
   initTableWithStrings(gStrings, getOpenedDatabase());
 
   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
 
 var gTests = [
   {
     desc: "Case and accent sensitive UTF-8",
     run:   () => runUtf8Test("locale_case_accent_sensitive")
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -15,16 +15,17 @@
 #include "nsAnnotationService.h"
 #include "nsFaviconService.h"
 #include "nsPlacesMacros.h"
 #include "History.h"
 #include "Helpers.h"
 
 #include "nsTArray.h"
 #include "nsCollationCID.h"
+#include "nsILocaleService.h"
 #include "nsNetUtil.h"
 #include "nsPrintfCString.h"
 #include "nsPromiseFlatString.h"
 #include "nsString.h"
 #include "nsUnicharUtils.h"
 #include "prsystem.h"
 #include "prtime.h"
 #include "nsEscape.h"
@@ -4473,21 +4474,28 @@ nsNavHistory::AutoCompleteFeedback(int32
 
 
 nsICollation *
 nsNavHistory::GetCollation()
 {
   if (mCollation)
     return mCollation;
 
+  // locale
+  nsCOMPtr<nsILocale> locale;
+  nsCOMPtr<nsILocaleService> 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<nsICollationFactory> 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;
 }
 
 nsIStringBundle *
 nsNavHistory::GetBundle()
 {
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -3863,19 +3863,22 @@ SearchService.prototype = {
     let alphaEngines = [];
 
     for (let name in this._engines) {
       let engine = this._engines[name];
       if (!(engine.name in addedEngines))
         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);
     return this.__sortedEngines = this.__sortedEngines.concat(alphaEngines);
   },
 
   /**
    * Get a sorted array of engines.