Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
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 "SpeechSynthesisParent.h"
6 #include "nsSynthVoiceRegistry.h"
8 namespace mozilla {
9 namespace dom {
11 SpeechSynthesisParent::SpeechSynthesisParent()
12 {
13 MOZ_COUNT_CTOR(SpeechSynthesisParent);
14 }
16 SpeechSynthesisParent::~SpeechSynthesisParent()
17 {
18 MOZ_COUNT_DTOR(SpeechSynthesisParent);
19 }
21 bool
22 SpeechSynthesisParent::RecvReadVoiceList(InfallibleTArray<RemoteVoice>* aVoices,
23 InfallibleTArray<nsString>* aDefaults)
24 {
25 nsSynthVoiceRegistry::GetInstance()->SendVoices(aVoices, aDefaults);
26 return true;
27 }
29 PSpeechSynthesisRequestParent*
30 SpeechSynthesisParent::AllocPSpeechSynthesisRequestParent(const nsString& aText,
31 const nsString& aLang,
32 const nsString& aUri,
33 const float& aVolume,
34 const float& aRate,
35 const float& aPitch)
36 {
37 nsRefPtr<SpeechTaskParent> task = new SpeechTaskParent(aVolume, aText);
38 SpeechSynthesisRequestParent* actor = new SpeechSynthesisRequestParent(task);
39 return actor;
40 }
42 bool
43 SpeechSynthesisParent::DeallocPSpeechSynthesisRequestParent(PSpeechSynthesisRequestParent* aActor)
44 {
45 delete aActor;
46 return true;
47 }
49 bool
50 SpeechSynthesisParent::RecvPSpeechSynthesisRequestConstructor(PSpeechSynthesisRequestParent* aActor,
51 const nsString& aText,
52 const nsString& aLang,
53 const nsString& aUri,
54 const float& aVolume,
55 const float& aRate,
56 const float& aPitch)
57 {
58 MOZ_ASSERT(aActor);
59 SpeechSynthesisRequestParent* actor =
60 static_cast<SpeechSynthesisRequestParent*>(aActor);
61 nsSynthVoiceRegistry::GetInstance()->Speak(aText, aLang, aUri, aRate,
62 aPitch, actor->mTask);
63 return true;
64 }
66 // SpeechSynthesisRequestParent
68 SpeechSynthesisRequestParent::SpeechSynthesisRequestParent(SpeechTaskParent* aTask)
69 : mTask(aTask)
70 {
71 mTask->mActor = this;
72 MOZ_COUNT_CTOR(SpeechSynthesisRequestParent);
73 }
75 SpeechSynthesisRequestParent::~SpeechSynthesisRequestParent()
76 {
77 if (mTask && mTask->mActor) {
78 mTask->mActor = nullptr;
79 }
81 MOZ_COUNT_DTOR(SpeechSynthesisRequestParent);
82 }
84 bool
85 SpeechSynthesisRequestParent::RecvPause()
86 {
87 MOZ_ASSERT(mTask);
88 mTask->Pause();
89 return true;
90 }
92 bool
93 SpeechSynthesisRequestParent::RecvResume()
94 {
95 MOZ_ASSERT(mTask);
96 mTask->Resume();
97 return true;
98 }
100 bool
101 SpeechSynthesisRequestParent::RecvCancel()
102 {
103 MOZ_ASSERT(mTask);
104 mTask->Cancel();
105 return true;
106 }
108 // SpeechTaskParent
110 nsresult
111 SpeechTaskParent::DispatchStartImpl()
112 {
113 MOZ_ASSERT(mActor);
114 NS_ENSURE_TRUE(mActor->SendOnStart(), NS_ERROR_FAILURE);
116 return NS_OK;
117 }
119 nsresult
120 SpeechTaskParent::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex)
121 {
122 MOZ_ASSERT(mActor);
123 SpeechSynthesisRequestParent* actor = mActor;
124 mActor = nullptr;
125 NS_ENSURE_TRUE(actor->Send__delete__(actor, false, aElapsedTime, aCharIndex),
126 NS_ERROR_FAILURE);
128 return NS_OK;
129 }
131 nsresult
132 SpeechTaskParent::DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex)
133 {
134 MOZ_ASSERT(mActor);
135 NS_ENSURE_TRUE(mActor->SendOnPause(aElapsedTime, aCharIndex), NS_ERROR_FAILURE);
137 return NS_OK;
138 }
140 nsresult
141 SpeechTaskParent::DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex)
142 {
143 MOZ_ASSERT(mActor);
144 NS_ENSURE_TRUE(mActor->SendOnResume(aElapsedTime, aCharIndex), NS_ERROR_FAILURE);
146 return NS_OK;
147 }
149 nsresult
150 SpeechTaskParent::DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex)
151 {
152 MOZ_ASSERT(mActor);
153 SpeechSynthesisRequestParent* actor = mActor;
154 mActor = nullptr;
155 NS_ENSURE_TRUE(actor->Send__delete__(actor, true, aElapsedTime, aCharIndex),
156 NS_ERROR_FAILURE);
158 return NS_OK;
159 }
161 nsresult
162 SpeechTaskParent::DispatchBoundaryImpl(const nsAString& aName,
163 float aElapsedTime, uint32_t aCharIndex)
164 {
165 MOZ_ASSERT(mActor);
166 NS_ENSURE_TRUE(mActor->SendOnBoundary(nsString(aName), aElapsedTime, aCharIndex),
167 NS_ERROR_FAILURE);
169 return NS_OK;
170 }
172 nsresult
173 SpeechTaskParent::DispatchMarkImpl(const nsAString& aName,
174 float aElapsedTime, uint32_t aCharIndex)
175 {
176 MOZ_ASSERT(mActor);
177 NS_ENSURE_TRUE(mActor->SendOnMark(nsString(aName), aElapsedTime, aCharIndex),
178 NS_ERROR_FAILURE);
180 return NS_OK;
181 }
183 } // namespace dom
184 } // namespace mozilla