1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "SpeechSynthesisChild.h"
6 #include "nsSynthVoiceRegistry.h"
8 namespace mozilla::dom
{
10 SpeechSynthesisChild::SpeechSynthesisChild() {
11 MOZ_COUNT_CTOR(SpeechSynthesisChild
);
14 SpeechSynthesisChild::~SpeechSynthesisChild() {
15 MOZ_COUNT_DTOR(SpeechSynthesisChild
);
18 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvInitialVoicesAndState(
19 nsTArray
<RemoteVoice
>&& aVoices
, nsTArray
<nsString
>&& aDefaults
,
20 const bool& aIsSpeaking
) {
21 nsSynthVoiceRegistry::RecvInitialVoicesAndState(aVoices
, aDefaults
,
26 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvVoiceAdded(
27 const RemoteVoice
& aVoice
) {
28 nsSynthVoiceRegistry::RecvAddVoice(aVoice
);
32 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvVoiceRemoved(
33 const nsAString
& aUri
) {
34 nsSynthVoiceRegistry::RecvRemoveVoice(aUri
);
38 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvSetDefaultVoice(
39 const nsAString
& aUri
, const bool& aIsDefault
) {
40 nsSynthVoiceRegistry::RecvSetDefaultVoice(aUri
, aIsDefault
);
44 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvIsSpeakingChanged(
45 const bool& aIsSpeaking
) {
46 nsSynthVoiceRegistry::RecvIsSpeakingChanged(aIsSpeaking
);
50 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvNotifyVoicesChanged() {
51 nsSynthVoiceRegistry::RecvNotifyVoicesChanged();
55 mozilla::ipc::IPCResult
SpeechSynthesisChild::RecvNotifyVoicesError(
56 const nsAString
& aError
) {
57 nsSynthVoiceRegistry::RecvNotifyVoicesError(aError
);
61 PSpeechSynthesisRequestChild
*
62 SpeechSynthesisChild::AllocPSpeechSynthesisRequestChild(
63 const nsAString
& aText
, const nsAString
& aLang
, const nsAString
& aUri
,
64 const float& aVolume
, const float& aRate
, const float& aPitch
,
65 const bool& aShouldResistFingerprinting
) {
66 MOZ_CRASH("Caller is supposed to manually construct a request!");
69 bool SpeechSynthesisChild::DeallocPSpeechSynthesisRequestChild(
70 PSpeechSynthesisRequestChild
* aActor
) {
75 // SpeechSynthesisRequestChild
77 SpeechSynthesisRequestChild::SpeechSynthesisRequestChild(SpeechTaskChild
* aTask
)
80 MOZ_COUNT_CTOR(SpeechSynthesisRequestChild
);
83 SpeechSynthesisRequestChild::~SpeechSynthesisRequestChild() {
84 MOZ_COUNT_DTOR(SpeechSynthesisRequestChild
);
87 mozilla::ipc::IPCResult
SpeechSynthesisRequestChild::RecvOnStart(
88 const nsAString
& aUri
) {
89 mTask
->DispatchStartImpl(aUri
);
93 mozilla::ipc::IPCResult
SpeechSynthesisRequestChild::RecvOnEnd(
94 const bool& aIsError
, const float& aElapsedTime
,
95 const uint32_t& aCharIndex
) {
96 SpeechSynthesisRequestChild
* actor
= mTask
->mActor
;
97 mTask
->mActor
= nullptr;
100 mTask
->DispatchErrorImpl(aElapsedTime
, aCharIndex
);
102 mTask
->DispatchEndImpl(aElapsedTime
, aCharIndex
);
105 SpeechSynthesisRequestChild::Send__delete__(actor
);
110 mozilla::ipc::IPCResult
SpeechSynthesisRequestChild::RecvOnPause(
111 const float& aElapsedTime
, const uint32_t& aCharIndex
) {
112 mTask
->DispatchPauseImpl(aElapsedTime
, aCharIndex
);
116 mozilla::ipc::IPCResult
SpeechSynthesisRequestChild::RecvOnResume(
117 const float& aElapsedTime
, const uint32_t& aCharIndex
) {
118 mTask
->DispatchResumeImpl(aElapsedTime
, aCharIndex
);
122 mozilla::ipc::IPCResult
SpeechSynthesisRequestChild::RecvOnBoundary(
123 const nsAString
& aName
, const float& aElapsedTime
,
124 const uint32_t& aCharIndex
, const uint32_t& aCharLength
,
125 const uint8_t& argc
) {
126 mTask
->DispatchBoundaryImpl(aName
, aElapsedTime
, aCharIndex
, aCharLength
,
131 mozilla::ipc::IPCResult
SpeechSynthesisRequestChild::RecvOnMark(
132 const nsAString
& aName
, const float& aElapsedTime
,
133 const uint32_t& aCharIndex
) {
134 mTask
->DispatchMarkImpl(aName
, aElapsedTime
, aCharIndex
);
140 SpeechTaskChild::SpeechTaskChild(SpeechSynthesisUtterance
* aUtterance
,
141 bool aShouldResistFingerprinting
)
142 : nsSpeechTask(aUtterance
, aShouldResistFingerprinting
), mActor(nullptr) {}
145 SpeechTaskChild::Setup(nsISpeechTaskCallback
* aCallback
) {
146 MOZ_CRASH("Should never be called from child");
149 void SpeechTaskChild::Pause() {
154 void SpeechTaskChild::Resume() {
156 mActor
->SendResume();
159 void SpeechTaskChild::Cancel() {
161 mActor
->SendCancel();
164 void SpeechTaskChild::ForceEnd() {
166 mActor
->SendForceEnd();
169 void SpeechTaskChild::SetAudioOutputVolume(float aVolume
) {
171 mActor
->SendSetAudioOutputVolume(aVolume
);
175 } // namespace mozilla::dom