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