Bug 1414186 - Use GetUserPreferredUILanguages for OSPreferences::SystemLocales. r=jfkthame
authorZibi Braniecki <zbraniecki@mozilla.com>
Fri, 03 Nov 2017 00:51:05 -0700
changeset 443372 591c22f2b3bb7ef4b933c876c8a53a92c597a301
parent 443371 c80acdea24c1c7954c4560c05d4625776ac09134
child 443373 c24b248d0cef4a14a2c31170bfa3c1dd4bad99c2
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1414186
milestone58.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 1414186 - Use GetUserPreferredUILanguages for OSPreferences::SystemLocales. r=jfkthame MozReview-Commit-ID: LId0mLIpfWQ
intl/locale/windows/OSPreferences_win.cpp
--- a/intl/locale/windows/OSPreferences_win.cpp
+++ b/intl/locale/windows/OSPreferences_win.cpp
@@ -12,28 +12,37 @@
 
 using namespace mozilla::intl;
 
 bool
 OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList)
 {
   MOZ_ASSERT(aLocaleList.IsEmpty());
 
-  WCHAR locale[LOCALE_NAME_MAX_LENGTH];
-  if (NS_WARN_IF(!LCIDToLocaleName(LOCALE_SYSTEM_DEFAULT, locale,
-                                   LOCALE_NAME_MAX_LENGTH, 0))) {
-    return false;
+  ULONG numLanguages = 0;
+  DWORD cchLanguagesBuffer = 0;
+  BOOL ok = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages,
+                                        nullptr, &cchLanguagesBuffer);
+  if (ok) {
+    AutoTArray<WCHAR, 64> locBuffer;
+    locBuffer.SetCapacity(cchLanguagesBuffer);
+    ok = GetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numLanguages,
+                                     locBuffer.Elements(), &cchLanguagesBuffer);
+    if (ok) {
+      NS_LossyConvertUTF16toASCII loc(locBuffer.Elements());
+
+      // We will only take the first locale from the returned list, because
+      // we do not support real fallback chains for RequestedLocales yet.
+      if (CanonicalizeLanguageTag(loc)) {
+        aLocaleList.AppendElement(loc);
+        return true;
+      }
+    }
   }
 
-  NS_LossyConvertUTF16toASCII loc(locale);
-
-  if (CanonicalizeLanguageTag(loc)) {
-    aLocaleList.AppendElement(loc);
-    return true;
-  }
   return false;
 }
 
 bool
 OSPreferences::ReadRegionalPrefsLocales(nsTArray<nsCString>& aLocaleList)
 {
   MOZ_ASSERT(aLocaleList.IsEmpty());