Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / media / webspeech / synth / ipc / SpeechSynthesisChild.cpp
blobff28d0c4183dd3e4fd9e8eedcd54281d971cd1e1
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,
22 aIsSpeaking);
23 return IPC_OK();
26 mozilla::ipc::IPCResult SpeechSynthesisChild::RecvVoiceAdded(
27 const RemoteVoice& aVoice) {
28 nsSynthVoiceRegistry::RecvAddVoice(aVoice);
29 return IPC_OK();
32 mozilla::ipc::IPCResult SpeechSynthesisChild::RecvVoiceRemoved(
33 const nsAString& aUri) {
34 nsSynthVoiceRegistry::RecvRemoveVoice(aUri);
35 return IPC_OK();
38 mozilla::ipc::IPCResult SpeechSynthesisChild::RecvSetDefaultVoice(
39 const nsAString& aUri, const bool& aIsDefault) {
40 nsSynthVoiceRegistry::RecvSetDefaultVoice(aUri, aIsDefault);
41 return IPC_OK();
44 mozilla::ipc::IPCResult SpeechSynthesisChild::RecvIsSpeakingChanged(
45 const bool& aIsSpeaking) {
46 nsSynthVoiceRegistry::RecvIsSpeakingChanged(aIsSpeaking);
47 return IPC_OK();
50 mozilla::ipc::IPCResult SpeechSynthesisChild::RecvNotifyVoicesChanged() {
51 nsSynthVoiceRegistry::RecvNotifyVoicesChanged();
52 return IPC_OK();
55 mozilla::ipc::IPCResult SpeechSynthesisChild::RecvNotifyVoicesError(
56 const nsAString& aError) {
57 nsSynthVoiceRegistry::RecvNotifyVoicesError(aError);
58 return IPC_OK();
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) {
71 delete aActor;
72 return true;
75 // SpeechSynthesisRequestChild
77 SpeechSynthesisRequestChild::SpeechSynthesisRequestChild(SpeechTaskChild* aTask)
78 : mTask(aTask) {
79 mTask->mActor = this;
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);
90 return IPC_OK();
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;
99 if (aIsError) {
100 mTask->DispatchErrorImpl(aElapsedTime, aCharIndex);
101 } else {
102 mTask->DispatchEndImpl(aElapsedTime, aCharIndex);
105 SpeechSynthesisRequestChild::Send__delete__(actor);
107 return IPC_OK();
110 mozilla::ipc::IPCResult SpeechSynthesisRequestChild::RecvOnPause(
111 const float& aElapsedTime, const uint32_t& aCharIndex) {
112 mTask->DispatchPauseImpl(aElapsedTime, aCharIndex);
113 return IPC_OK();
116 mozilla::ipc::IPCResult SpeechSynthesisRequestChild::RecvOnResume(
117 const float& aElapsedTime, const uint32_t& aCharIndex) {
118 mTask->DispatchResumeImpl(aElapsedTime, aCharIndex);
119 return IPC_OK();
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,
127 argc);
128 return IPC_OK();
131 mozilla::ipc::IPCResult SpeechSynthesisRequestChild::RecvOnMark(
132 const nsAString& aName, const float& aElapsedTime,
133 const uint32_t& aCharIndex) {
134 mTask->DispatchMarkImpl(aName, aElapsedTime, aCharIndex);
135 return IPC_OK();
138 // SpeechTaskChild
140 SpeechTaskChild::SpeechTaskChild(SpeechSynthesisUtterance* aUtterance,
141 bool aShouldResistFingerprinting)
142 : nsSpeechTask(aUtterance, aShouldResistFingerprinting), mActor(nullptr) {}
144 NS_IMETHODIMP
145 SpeechTaskChild::Setup(nsISpeechTaskCallback* aCallback) {
146 MOZ_CRASH("Should never be called from child");
149 void SpeechTaskChild::Pause() {
150 MOZ_ASSERT(mActor);
151 mActor->SendPause();
154 void SpeechTaskChild::Resume() {
155 MOZ_ASSERT(mActor);
156 mActor->SendResume();
159 void SpeechTaskChild::Cancel() {
160 MOZ_ASSERT(mActor);
161 mActor->SendCancel();
164 void SpeechTaskChild::ForceEnd() {
165 MOZ_ASSERT(mActor);
166 mActor->SendForceEnd();
169 void SpeechTaskChild::SetAudioOutputVolume(float aVolume) {
170 if (mActor) {
171 mActor->SendSetAudioOutputVolume(aVolume);
175 } // namespace mozilla::dom