|
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 "SpeechSynthesisChild.h" |
|
6 #include "nsSynthVoiceRegistry.h" |
|
7 |
|
8 namespace mozilla { |
|
9 namespace dom { |
|
10 |
|
11 SpeechSynthesisChild::SpeechSynthesisChild() |
|
12 { |
|
13 MOZ_COUNT_CTOR(SpeechSynthesisChild); |
|
14 } |
|
15 |
|
16 SpeechSynthesisChild::~SpeechSynthesisChild() |
|
17 { |
|
18 MOZ_COUNT_DTOR(SpeechSynthesisChild); |
|
19 } |
|
20 |
|
21 bool |
|
22 SpeechSynthesisChild::RecvVoiceAdded(const RemoteVoice& aVoice) |
|
23 { |
|
24 nsSynthVoiceRegistry::RecvAddVoice(aVoice); |
|
25 return true; |
|
26 } |
|
27 |
|
28 bool |
|
29 SpeechSynthesisChild::RecvVoiceRemoved(const nsString& aUri) |
|
30 { |
|
31 nsSynthVoiceRegistry::RecvRemoveVoice(aUri); |
|
32 return true; |
|
33 } |
|
34 |
|
35 bool |
|
36 SpeechSynthesisChild::RecvSetDefaultVoice(const nsString& aUri, |
|
37 const bool& aIsDefault) |
|
38 { |
|
39 nsSynthVoiceRegistry::RecvSetDefaultVoice(aUri, aIsDefault); |
|
40 return true; |
|
41 } |
|
42 |
|
43 PSpeechSynthesisRequestChild* |
|
44 SpeechSynthesisChild::AllocPSpeechSynthesisRequestChild(const nsString& aText, |
|
45 const nsString& aLang, |
|
46 const nsString& aUri, |
|
47 const float& aVolume, |
|
48 const float& aRate, |
|
49 const float& aPitch) |
|
50 { |
|
51 MOZ_CRASH("Caller is supposed to manually construct a request!"); |
|
52 } |
|
53 |
|
54 bool |
|
55 SpeechSynthesisChild::DeallocPSpeechSynthesisRequestChild(PSpeechSynthesisRequestChild* aActor) |
|
56 { |
|
57 delete aActor; |
|
58 return true; |
|
59 } |
|
60 |
|
61 // SpeechSynthesisRequestChild |
|
62 |
|
63 SpeechSynthesisRequestChild::SpeechSynthesisRequestChild(SpeechTaskChild* aTask) |
|
64 : mTask(aTask) |
|
65 { |
|
66 mTask->mActor = this; |
|
67 MOZ_COUNT_CTOR(SpeechSynthesisRequestChild); |
|
68 } |
|
69 |
|
70 SpeechSynthesisRequestChild::~SpeechSynthesisRequestChild() |
|
71 { |
|
72 MOZ_COUNT_DTOR(SpeechSynthesisRequestChild); |
|
73 } |
|
74 |
|
75 bool |
|
76 SpeechSynthesisRequestChild::RecvOnStart() |
|
77 { |
|
78 mTask->DispatchStartImpl(); |
|
79 return true; |
|
80 } |
|
81 |
|
82 bool |
|
83 SpeechSynthesisRequestChild::Recv__delete__(const bool& aIsError, |
|
84 const float& aElapsedTime, |
|
85 const uint32_t& aCharIndex) |
|
86 { |
|
87 mTask->mActor = nullptr; |
|
88 |
|
89 if (aIsError) { |
|
90 mTask->DispatchErrorImpl(aElapsedTime, aCharIndex); |
|
91 } else { |
|
92 mTask->DispatchEndImpl(aElapsedTime, aCharIndex); |
|
93 } |
|
94 |
|
95 return true; |
|
96 } |
|
97 |
|
98 bool |
|
99 SpeechSynthesisRequestChild::RecvOnPause(const float& aElapsedTime, |
|
100 const uint32_t& aCharIndex) |
|
101 { |
|
102 mTask->DispatchPauseImpl(aElapsedTime, aCharIndex); |
|
103 return true; |
|
104 } |
|
105 |
|
106 bool |
|
107 SpeechSynthesisRequestChild::RecvOnResume(const float& aElapsedTime, |
|
108 const uint32_t& aCharIndex) |
|
109 { |
|
110 mTask->DispatchResumeImpl(aElapsedTime, aCharIndex); |
|
111 return true; |
|
112 } |
|
113 |
|
114 bool |
|
115 SpeechSynthesisRequestChild::RecvOnBoundary(const nsString& aName, |
|
116 const float& aElapsedTime, |
|
117 const uint32_t& aCharIndex) |
|
118 { |
|
119 mTask->DispatchBoundaryImpl(aName, aElapsedTime, aCharIndex); |
|
120 return true; |
|
121 } |
|
122 |
|
123 bool |
|
124 SpeechSynthesisRequestChild::RecvOnMark(const nsString& aName, |
|
125 const float& aElapsedTime, |
|
126 const uint32_t& aCharIndex) |
|
127 { |
|
128 mTask->DispatchMarkImpl(aName, aElapsedTime, aCharIndex); |
|
129 return true; |
|
130 } |
|
131 |
|
132 // SpeechTaskChild |
|
133 |
|
134 SpeechTaskChild::SpeechTaskChild(SpeechSynthesisUtterance* aUtterance) |
|
135 : nsSpeechTask(aUtterance) |
|
136 { |
|
137 } |
|
138 |
|
139 NS_IMETHODIMP |
|
140 SpeechTaskChild::Setup(nsISpeechTaskCallback* aCallback, |
|
141 uint32_t aChannels, uint32_t aRate, uint8_t argc) |
|
142 { |
|
143 MOZ_CRASH("Should never be called from child"); |
|
144 } |
|
145 |
|
146 NS_IMETHODIMP |
|
147 SpeechTaskChild::SendAudio(JS::Handle<JS::Value> aData, JS::Handle<JS::Value> aLandmarks, |
|
148 JSContext* aCx) |
|
149 { |
|
150 MOZ_CRASH("Should never be called from child"); |
|
151 } |
|
152 |
|
153 NS_IMETHODIMP |
|
154 SpeechTaskChild::SendAudioNative(int16_t* aData, uint32_t aDataLen) |
|
155 { |
|
156 MOZ_CRASH("Should never be called from child"); |
|
157 } |
|
158 |
|
159 void |
|
160 SpeechTaskChild::Pause() |
|
161 { |
|
162 MOZ_ASSERT(mActor); |
|
163 mActor->SendPause(); |
|
164 } |
|
165 |
|
166 void |
|
167 SpeechTaskChild::Resume() |
|
168 { |
|
169 MOZ_ASSERT(mActor); |
|
170 mActor->SendResume(); |
|
171 } |
|
172 |
|
173 void |
|
174 SpeechTaskChild::Cancel() |
|
175 { |
|
176 MOZ_ASSERT(mActor); |
|
177 mActor->SendCancel(); |
|
178 } |
|
179 |
|
180 } // namespace dom |
|
181 } // namespace mozilla |