Line data Source code
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/. */
4 :
5 : #include "SpeechSynthesisParent.h"
6 : #include "nsSynthVoiceRegistry.h"
7 :
8 : namespace mozilla {
9 : namespace dom {
10 :
11 0 : SpeechSynthesisParent::SpeechSynthesisParent()
12 : {
13 0 : MOZ_COUNT_CTOR(SpeechSynthesisParent);
14 0 : }
15 :
16 0 : SpeechSynthesisParent::~SpeechSynthesisParent()
17 : {
18 0 : MOZ_COUNT_DTOR(SpeechSynthesisParent);
19 0 : }
20 :
21 : void
22 0 : SpeechSynthesisParent::ActorDestroy(ActorDestroyReason aWhy)
23 : {
24 : // Implement me! Bug 1005141
25 0 : }
26 :
27 : bool
28 0 : SpeechSynthesisParent::SendInit()
29 : {
30 0 : return nsSynthVoiceRegistry::GetInstance()->SendInitialVoicesAndState(this);
31 : }
32 :
33 : PSpeechSynthesisRequestParent*
34 0 : SpeechSynthesisParent::AllocPSpeechSynthesisRequestParent(const nsString& aText,
35 : const nsString& aLang,
36 : const nsString& aUri,
37 : const float& aVolume,
38 : const float& aRate,
39 : const float& aPitch)
40 : {
41 0 : RefPtr<SpeechTaskParent> task = new SpeechTaskParent(aVolume, aText);
42 0 : SpeechSynthesisRequestParent* actor = new SpeechSynthesisRequestParent(task);
43 0 : return actor;
44 : }
45 :
46 : bool
47 0 : SpeechSynthesisParent::DeallocPSpeechSynthesisRequestParent(PSpeechSynthesisRequestParent* aActor)
48 : {
49 0 : delete aActor;
50 0 : return true;
51 : }
52 :
53 : mozilla::ipc::IPCResult
54 0 : SpeechSynthesisParent::RecvPSpeechSynthesisRequestConstructor(PSpeechSynthesisRequestParent* aActor,
55 : const nsString& aText,
56 : const nsString& aLang,
57 : const nsString& aUri,
58 : const float& aVolume,
59 : const float& aRate,
60 : const float& aPitch)
61 : {
62 0 : MOZ_ASSERT(aActor);
63 : SpeechSynthesisRequestParent* actor =
64 0 : static_cast<SpeechSynthesisRequestParent*>(aActor);
65 0 : nsSynthVoiceRegistry::GetInstance()->Speak(aText, aLang, aUri, aVolume, aRate,
66 0 : aPitch, actor->mTask);
67 0 : return IPC_OK();
68 : }
69 :
70 : // SpeechSynthesisRequestParent
71 :
72 0 : SpeechSynthesisRequestParent::SpeechSynthesisRequestParent(SpeechTaskParent* aTask)
73 0 : : mTask(aTask)
74 : {
75 0 : mTask->mActor = this;
76 0 : MOZ_COUNT_CTOR(SpeechSynthesisRequestParent);
77 0 : }
78 :
79 0 : SpeechSynthesisRequestParent::~SpeechSynthesisRequestParent()
80 : {
81 0 : if (mTask) {
82 0 : mTask->mActor = nullptr;
83 : // If we still have a task, cancel it.
84 0 : mTask->Cancel();
85 : }
86 0 : MOZ_COUNT_DTOR(SpeechSynthesisRequestParent);
87 0 : }
88 :
89 : void
90 0 : SpeechSynthesisRequestParent::ActorDestroy(ActorDestroyReason aWhy)
91 : {
92 : // Implement me! Bug 1005141
93 0 : }
94 :
95 : mozilla::ipc::IPCResult
96 0 : SpeechSynthesisRequestParent::RecvPause()
97 : {
98 0 : MOZ_ASSERT(mTask);
99 0 : mTask->Pause();
100 0 : return IPC_OK();
101 : }
102 :
103 : mozilla::ipc::IPCResult
104 0 : SpeechSynthesisRequestParent::Recv__delete__()
105 : {
106 0 : MOZ_ASSERT(mTask);
107 0 : mTask->mActor = nullptr;
108 0 : mTask = nullptr;
109 0 : return IPC_OK();
110 : }
111 :
112 : mozilla::ipc::IPCResult
113 0 : SpeechSynthesisRequestParent::RecvResume()
114 : {
115 0 : MOZ_ASSERT(mTask);
116 0 : mTask->Resume();
117 0 : return IPC_OK();
118 : }
119 :
120 : mozilla::ipc::IPCResult
121 0 : SpeechSynthesisRequestParent::RecvCancel()
122 : {
123 0 : MOZ_ASSERT(mTask);
124 0 : mTask->Cancel();
125 0 : return IPC_OK();
126 : }
127 :
128 : mozilla::ipc::IPCResult
129 0 : SpeechSynthesisRequestParent::RecvForceEnd()
130 : {
131 0 : MOZ_ASSERT(mTask);
132 0 : mTask->ForceEnd();
133 0 : return IPC_OK();
134 : }
135 :
136 : mozilla::ipc::IPCResult
137 0 : SpeechSynthesisRequestParent::RecvSetAudioOutputVolume(const float& aVolume)
138 : {
139 0 : MOZ_ASSERT(mTask);
140 0 : mTask->SetAudioOutputVolume(aVolume);
141 0 : return IPC_OK();
142 : }
143 :
144 : // SpeechTaskParent
145 :
146 : nsresult
147 0 : SpeechTaskParent::DispatchStartImpl(const nsAString& aUri)
148 : {
149 0 : MOZ_ASSERT(mActor);
150 0 : if(NS_WARN_IF(!(mActor->SendOnStart(nsString(aUri))))) {
151 0 : return NS_ERROR_FAILURE;
152 : }
153 :
154 0 : return NS_OK;
155 : }
156 :
157 : nsresult
158 0 : SpeechTaskParent::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex)
159 : {
160 0 : if (!mActor) {
161 : // Child is already gone.
162 0 : return NS_OK;
163 : }
164 :
165 0 : if(NS_WARN_IF(!(mActor->SendOnEnd(false, aElapsedTime, aCharIndex)))) {
166 0 : return NS_ERROR_FAILURE;
167 : }
168 :
169 0 : return NS_OK;
170 : }
171 :
172 : nsresult
173 0 : SpeechTaskParent::DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex)
174 : {
175 0 : MOZ_ASSERT(mActor);
176 0 : if(NS_WARN_IF(!(mActor->SendOnPause(aElapsedTime, aCharIndex)))) {
177 0 : return NS_ERROR_FAILURE;
178 : }
179 :
180 0 : return NS_OK;
181 : }
182 :
183 : nsresult
184 0 : SpeechTaskParent::DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex)
185 : {
186 0 : MOZ_ASSERT(mActor);
187 0 : if(NS_WARN_IF(!(mActor->SendOnResume(aElapsedTime, aCharIndex)))) {
188 0 : return NS_ERROR_FAILURE;
189 : }
190 :
191 0 : return NS_OK;
192 : }
193 :
194 : nsresult
195 0 : SpeechTaskParent::DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex)
196 : {
197 0 : MOZ_ASSERT(mActor);
198 0 : if(NS_WARN_IF(!(mActor->SendOnEnd(true, aElapsedTime, aCharIndex)))) {
199 0 : return NS_ERROR_FAILURE;
200 : }
201 :
202 0 : return NS_OK;
203 : }
204 :
205 : nsresult
206 0 : SpeechTaskParent::DispatchBoundaryImpl(const nsAString& aName,
207 : float aElapsedTime, uint32_t aCharIndex,
208 : uint32_t aCharLength, uint8_t argc)
209 : {
210 0 : MOZ_ASSERT(mActor);
211 0 : if(NS_WARN_IF(!(mActor->SendOnBoundary(nsString(aName), aElapsedTime,
212 : aCharIndex, aCharLength, argc)))) {
213 0 : return NS_ERROR_FAILURE;
214 : }
215 :
216 0 : return NS_OK;
217 : }
218 :
219 : nsresult
220 0 : SpeechTaskParent::DispatchMarkImpl(const nsAString& aName,
221 : float aElapsedTime, uint32_t aCharIndex)
222 : {
223 0 : MOZ_ASSERT(mActor);
224 0 : if(NS_WARN_IF(!(mActor->SendOnMark(nsString(aName), aElapsedTime, aCharIndex)))) {
225 0 : return NS_ERROR_FAILURE;
226 : }
227 :
228 0 : return NS_OK;
229 : }
230 :
231 : } // namespace dom
232 : } // namespace mozilla
|