SpeechSynthesisVoice.cpp (2594B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "SpeechSynthesis.h" 8 #include "mozilla/dom/SpeechSynthesisVoiceBinding.h" 9 #include "nsSynthVoiceRegistry.h" 10 11 namespace mozilla::dom { 12 13 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SpeechSynthesisVoice, mParent) 14 NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechSynthesisVoice) 15 NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechSynthesisVoice) 16 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechSynthesisVoice) 17 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 18 NS_INTERFACE_MAP_ENTRY(nsISupports) 19 NS_INTERFACE_MAP_END 20 21 SpeechSynthesisVoice::SpeechSynthesisVoice(nsISupports* aParent, 22 const nsAString& aUri) 23 : mParent(aParent), mUri(aUri) {} 24 25 SpeechSynthesisVoice::~SpeechSynthesisVoice() = default; 26 27 JSObject* SpeechSynthesisVoice::WrapObject(JSContext* aCx, 28 JS::Handle<JSObject*> aGivenProto) { 29 return SpeechSynthesisVoice_Binding::Wrap(aCx, this, aGivenProto); 30 } 31 32 nsISupports* SpeechSynthesisVoice::GetParentObject() const { return mParent; } 33 34 void SpeechSynthesisVoice::GetVoiceURI(nsString& aRetval) const { 35 aRetval = mUri; 36 } 37 38 void SpeechSynthesisVoice::GetName(nsString& aRetval) const { 39 DebugOnly<nsresult> rv = 40 nsSynthVoiceRegistry::GetInstance()->GetVoiceName(mUri, aRetval); 41 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), 42 "Failed to get SpeechSynthesisVoice.name"); 43 } 44 45 void SpeechSynthesisVoice::GetLang(nsString& aRetval) const { 46 DebugOnly<nsresult> rv = 47 nsSynthVoiceRegistry::GetInstance()->GetVoiceLang(mUri, aRetval); 48 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), 49 "Failed to get SpeechSynthesisVoice.lang"); 50 } 51 52 bool SpeechSynthesisVoice::LocalService() const { 53 bool isLocal; 54 DebugOnly<nsresult> rv = 55 nsSynthVoiceRegistry::GetInstance()->IsLocalVoice(mUri, &isLocal); 56 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), 57 "Failed to get SpeechSynthesisVoice.localService"); 58 59 return isLocal; 60 } 61 62 bool SpeechSynthesisVoice::Default() const { 63 bool isDefault; 64 DebugOnly<nsresult> rv = 65 nsSynthVoiceRegistry::GetInstance()->IsDefaultVoice(mUri, &isDefault); 66 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), 67 "Failed to get SpeechSynthesisVoice.default"); 68 69 return isDefault; 70 } 71 72 } // namespace mozilla::dom