Bug 1356503 - Part 2. Replace nsWin32Locale::GetXPLocale with LCIDToLocaleName (webspeech part). r=eeejay
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Thu, 27 Apr 2017 12:40:30 +0900
changeset 409183 b67da0f62ee1f188f33b35db05c36b2135ca1f0a
parent 409182 0e10c59e3bb6a59605af70599628d7e68dda7af3
child 409184 51dc277d8fe873657308e91a6852ec8b52f7e5e1
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)
reviewerseeejay
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 2. Replace nsWin32Locale::GetXPLocale with LCIDToLocaleName (webspeech part). r=eeejay Since our platform support is Windows 7+, we can replace nsWin32Locale::GetXPLocale with LCIDToLocaleName. MozReview-Commit-ID: Tboh4P6cLc
dom/media/webspeech/synth/windows/SapiService.cpp
--- a/dom/media/webspeech/synth/windows/SapiService.cpp
+++ b/dom/media/webspeech/synth/windows/SapiService.cpp
@@ -2,17 +2,16 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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 "nsISupports.h"
 #include "SapiService.h"
 #include "nsServiceManagerUtils.h"
-#include "nsWin32Locale.h"
 #include "GeckoProfiler.h"
 #include "nsEscape.h"
 
 #include "mozilla/dom/nsSynthVoiceRegistry.h"
 #include "mozilla/dom/nsSpeechTask.h"
 #include "mozilla/Preferences.h"
 
 namespace mozilla {
@@ -271,16 +270,17 @@ SapiService::RegisterVoices()
   }
 
   RefPtr<IEnumSpObjectTokens> voiceTokens;
   if (FAILED(category->EnumTokens(nullptr, nullptr,
                                   getter_AddRefs(voiceTokens)))) {
     return false;
   }
 
+  WCHAR locale[LOCALE_NAME_MAX_LENGTH];
   while (true) {
     RefPtr<ISpObjectToken> voiceToken;
     if (voiceTokens->Next(1, getter_AddRefs(voiceToken), nullptr) != S_OK) {
       break;
     }
 
     RefPtr<ISpDataKey> attributes;
     if (FAILED(voiceToken->OpenKey(L"Attributes",
@@ -293,34 +293,37 @@ SapiService::RegisterVoices()
       continue;
     }
 
     // Language attribute is LCID by hex.  So we need convert to locale
     // name.
     nsAutoString hexLcid;
     LCID lcid = wcstol(language, nullptr, 16);
     CoTaskMemFree(language);
-    nsAutoString locale;
-    nsWin32Locale::GetXPLocale(lcid, locale);
+    if (NS_WARN_IF(!LCIDToLocaleName(lcid, locale,
+                                     LOCALE_NAME_MAX_LENGTH, 0))) {
+      continue;
+    }
 
     WCHAR* description = nullptr;
     if (FAILED(voiceToken->GetStringValue(nullptr, &description))) {
       continue;
     }
 
     nsAutoString uri;
     uri.AssignLiteral("urn:moz-tts:sapi:");
     uri.Append(description);
     uri.AppendLiteral("?");
     uri.Append(locale);
 
     // This service can only speak one utterance at a time, se we set
     // aQueuesUtterances to true in order to track global state and schedule
     // access to this service.
-    rv = registry->AddVoice(this, uri, nsDependentString(description), locale,
+    rv = registry->AddVoice(this, uri, nsDependentString(description),
+                            nsDependentString(locale),
                             true, true);
     CoTaskMemFree(description);
     if (NS_FAILED(rv)) {
       continue;
     }
 
     mVoices.Put(uri, voiceToken);
   }