Bug 1356503 - Part 1. Replace nsWin32Locale::GetXPLocale with LCIDToLocaleName (intl part). r=gandalf
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 27 Apr 2017 11:23:11 +0900
changeset 409182 0e10c59e3bb6a59605af70599628d7e68dda7af3
parent 409181 02d43f8e8686d0b754f15e1b409366c0378ad591
child 409183 b67da0f62ee1f188f33b35db05c36b2135ca1f0a
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgandalf
bugs1356503
milestone55.0a1
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
Bug 1356503 - Part 1. Replace nsWin32Locale::GetXPLocale with LCIDToLocaleName (intl part). r=gandalf Since our platform support is Windows 7+, we can replace nsWin32Locale::GetXPLocale with LCIDToLocaleName. LCIDToLocaleName has LOCALE_SYSTEM_DEFAULT and LOCALE_USER_DEFAULT, so we should it simply. MozReview-Commit-ID: 7JhhXayIK7S
intl/locale/windows/OSPreferences_win.cpp
--- a/intl/locale/windows/OSPreferences_win.cpp
+++ b/intl/locale/windows/OSPreferences_win.cpp
@@ -1,30 +1,32 @@
 /* -*- 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 "OSPreferences.h"
 #include "mozilla/intl/LocaleService.h"
-#include "nsWin32Locale.h"
 #include "nsReadableUtils.h"
 
+#include <windows.h>
+
 using namespace mozilla::intl;
 
 bool
 OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList)
 {
   MOZ_ASSERT(aLocaleList.IsEmpty());
 
-  nsAutoString locale;
-
-  LCID win_lcid = GetSystemDefaultLCID();
-  nsWin32Locale::GetXPLocale(win_lcid, locale);
+  WCHAR locale[LOCALE_NAME_MAX_LENGTH];
+  if (NS_WARN_IF(!LCIDToLocaleName(LOCALE_SYSTEM_DEFAULT, locale,
+                                   LOCALE_NAME_MAX_LENGTH, 0))) {
+    return false;
+  }
 
   NS_LossyConvertUTF16toASCII loc(locale);
 
   if (CanonicalizeLanguageTag(loc)) {
     aLocaleList.AppendElement(loc);
     return true;
   }
   return false;
@@ -34,21 +36,24 @@ OSPreferences::ReadSystemLocales(nsTArra
  * Windows distinguishes between System Locale (the locale OS is in), and
  * User Locale (the locale used for regional settings etc.).
  *
  * For DateTimePattern, we want to retrieve the User Locale.
  */
 static void
 ReadUserLocale(nsCString& aRetVal)
 {
-  nsAutoString locale;
-  LCID win_lcid = GetUserDefaultLCID();
-  nsWin32Locale::GetXPLocale(win_lcid, locale);
+  WCHAR locale[LOCALE_NAME_MAX_LENGTH];
+  if (NS_WARN_IF(!LCIDToLocaleName(LOCALE_USER_DEFAULT, locale,
+                                   LOCALE_NAME_MAX_LENGTH, 0))) {
+    aRetVal.Assign("en-US");
+    return;
+  }
 
-  aRetVal.AssignWithConversion(locale);
+  LossyCopyUTF16toASCII(locale, aRetVal);
 }
 
 static LCTYPE
 ToDateLCType(OSPreferences::DateTimeFormatStyle aFormatStyle)
 {
   switch (aFormatStyle) {
     case OSPreferences::DateTimeFormatStyle::None:
       return LOCALE_SLONGDATE;