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/. */
7 #include "SpeechSynthesis.h"
8 #include "nsSynthVoiceRegistry.h"
9 #include "mozilla/dom/SpeechSynthesisVoiceBinding.h"
11 namespace mozilla::dom
{
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
)
21 SpeechSynthesisVoice::SpeechSynthesisVoice(nsISupports
* aParent
,
22 const nsAString
& aUri
)
23 : mParent(aParent
), mUri(aUri
) {}
25 SpeechSynthesisVoice::~SpeechSynthesisVoice() = default;
27 JSObject
* SpeechSynthesisVoice::WrapObject(JSContext
* aCx
,
28 JS::Handle
<JSObject
*> aGivenProto
) {
29 return SpeechSynthesisVoice_Binding::Wrap(aCx
, this, aGivenProto
);
32 nsISupports
* SpeechSynthesisVoice::GetParentObject() const { return mParent
; }
34 void SpeechSynthesisVoice::GetVoiceURI(nsString
& aRetval
) const {
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");
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");
52 bool SpeechSynthesisVoice::LocalService() const {
54 DebugOnly
<nsresult
> rv
=
55 nsSynthVoiceRegistry::GetInstance()->IsLocalVoice(mUri
, &isLocal
);
56 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv
),
57 "Failed to get SpeechSynthesisVoice.localService");
62 bool SpeechSynthesisVoice::Default() const {
64 DebugOnly
<nsresult
> rv
=
65 nsSynthVoiceRegistry::GetInstance()->IsDefaultVoice(mUri
, &isDefault
);
66 NS_WARNING_ASSERTION(NS_SUCCEEDED(rv
),
67 "Failed to get SpeechSynthesisVoice.default");
72 } // namespace mozilla::dom