1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webspeech/synth/ipc/SpeechSynthesisParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,184 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "SpeechSynthesisParent.h" 1.9 +#include "nsSynthVoiceRegistry.h" 1.10 + 1.11 +namespace mozilla { 1.12 +namespace dom { 1.13 + 1.14 +SpeechSynthesisParent::SpeechSynthesisParent() 1.15 +{ 1.16 + MOZ_COUNT_CTOR(SpeechSynthesisParent); 1.17 +} 1.18 + 1.19 +SpeechSynthesisParent::~SpeechSynthesisParent() 1.20 +{ 1.21 + MOZ_COUNT_DTOR(SpeechSynthesisParent); 1.22 +} 1.23 + 1.24 +bool 1.25 +SpeechSynthesisParent::RecvReadVoiceList(InfallibleTArray<RemoteVoice>* aVoices, 1.26 + InfallibleTArray<nsString>* aDefaults) 1.27 +{ 1.28 + nsSynthVoiceRegistry::GetInstance()->SendVoices(aVoices, aDefaults); 1.29 + return true; 1.30 +} 1.31 + 1.32 +PSpeechSynthesisRequestParent* 1.33 +SpeechSynthesisParent::AllocPSpeechSynthesisRequestParent(const nsString& aText, 1.34 + const nsString& aLang, 1.35 + const nsString& aUri, 1.36 + const float& aVolume, 1.37 + const float& aRate, 1.38 + const float& aPitch) 1.39 +{ 1.40 + nsRefPtr<SpeechTaskParent> task = new SpeechTaskParent(aVolume, aText); 1.41 + SpeechSynthesisRequestParent* actor = new SpeechSynthesisRequestParent(task); 1.42 + return actor; 1.43 +} 1.44 + 1.45 +bool 1.46 +SpeechSynthesisParent::DeallocPSpeechSynthesisRequestParent(PSpeechSynthesisRequestParent* aActor) 1.47 +{ 1.48 + delete aActor; 1.49 + return true; 1.50 +} 1.51 + 1.52 +bool 1.53 +SpeechSynthesisParent::RecvPSpeechSynthesisRequestConstructor(PSpeechSynthesisRequestParent* aActor, 1.54 + const nsString& aText, 1.55 + const nsString& aLang, 1.56 + const nsString& aUri, 1.57 + const float& aVolume, 1.58 + const float& aRate, 1.59 + const float& aPitch) 1.60 +{ 1.61 + MOZ_ASSERT(aActor); 1.62 + SpeechSynthesisRequestParent* actor = 1.63 + static_cast<SpeechSynthesisRequestParent*>(aActor); 1.64 + nsSynthVoiceRegistry::GetInstance()->Speak(aText, aLang, aUri, aRate, 1.65 + aPitch, actor->mTask); 1.66 + return true; 1.67 +} 1.68 + 1.69 +// SpeechSynthesisRequestParent 1.70 + 1.71 +SpeechSynthesisRequestParent::SpeechSynthesisRequestParent(SpeechTaskParent* aTask) 1.72 + : mTask(aTask) 1.73 +{ 1.74 + mTask->mActor = this; 1.75 + MOZ_COUNT_CTOR(SpeechSynthesisRequestParent); 1.76 +} 1.77 + 1.78 +SpeechSynthesisRequestParent::~SpeechSynthesisRequestParent() 1.79 +{ 1.80 + if (mTask && mTask->mActor) { 1.81 + mTask->mActor = nullptr; 1.82 + } 1.83 + 1.84 + MOZ_COUNT_DTOR(SpeechSynthesisRequestParent); 1.85 +} 1.86 + 1.87 +bool 1.88 +SpeechSynthesisRequestParent::RecvPause() 1.89 +{ 1.90 + MOZ_ASSERT(mTask); 1.91 + mTask->Pause(); 1.92 + return true; 1.93 +} 1.94 + 1.95 +bool 1.96 +SpeechSynthesisRequestParent::RecvResume() 1.97 +{ 1.98 + MOZ_ASSERT(mTask); 1.99 + mTask->Resume(); 1.100 + return true; 1.101 +} 1.102 + 1.103 +bool 1.104 +SpeechSynthesisRequestParent::RecvCancel() 1.105 +{ 1.106 + MOZ_ASSERT(mTask); 1.107 + mTask->Cancel(); 1.108 + return true; 1.109 +} 1.110 + 1.111 +// SpeechTaskParent 1.112 + 1.113 +nsresult 1.114 +SpeechTaskParent::DispatchStartImpl() 1.115 +{ 1.116 + MOZ_ASSERT(mActor); 1.117 + NS_ENSURE_TRUE(mActor->SendOnStart(), NS_ERROR_FAILURE); 1.118 + 1.119 + return NS_OK; 1.120 +} 1.121 + 1.122 +nsresult 1.123 +SpeechTaskParent::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex) 1.124 +{ 1.125 + MOZ_ASSERT(mActor); 1.126 + SpeechSynthesisRequestParent* actor = mActor; 1.127 + mActor = nullptr; 1.128 + NS_ENSURE_TRUE(actor->Send__delete__(actor, false, aElapsedTime, aCharIndex), 1.129 + NS_ERROR_FAILURE); 1.130 + 1.131 + return NS_OK; 1.132 +} 1.133 + 1.134 +nsresult 1.135 +SpeechTaskParent::DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex) 1.136 +{ 1.137 + MOZ_ASSERT(mActor); 1.138 + NS_ENSURE_TRUE(mActor->SendOnPause(aElapsedTime, aCharIndex), NS_ERROR_FAILURE); 1.139 + 1.140 + return NS_OK; 1.141 +} 1.142 + 1.143 +nsresult 1.144 +SpeechTaskParent::DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex) 1.145 +{ 1.146 + MOZ_ASSERT(mActor); 1.147 + NS_ENSURE_TRUE(mActor->SendOnResume(aElapsedTime, aCharIndex), NS_ERROR_FAILURE); 1.148 + 1.149 + return NS_OK; 1.150 +} 1.151 + 1.152 +nsresult 1.153 +SpeechTaskParent::DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex) 1.154 +{ 1.155 + MOZ_ASSERT(mActor); 1.156 + SpeechSynthesisRequestParent* actor = mActor; 1.157 + mActor = nullptr; 1.158 + NS_ENSURE_TRUE(actor->Send__delete__(actor, true, aElapsedTime, aCharIndex), 1.159 + NS_ERROR_FAILURE); 1.160 + 1.161 + return NS_OK; 1.162 +} 1.163 + 1.164 +nsresult 1.165 +SpeechTaskParent::DispatchBoundaryImpl(const nsAString& aName, 1.166 + float aElapsedTime, uint32_t aCharIndex) 1.167 +{ 1.168 + MOZ_ASSERT(mActor); 1.169 + NS_ENSURE_TRUE(mActor->SendOnBoundary(nsString(aName), aElapsedTime, aCharIndex), 1.170 + NS_ERROR_FAILURE); 1.171 + 1.172 + return NS_OK; 1.173 +} 1.174 + 1.175 +nsresult 1.176 +SpeechTaskParent::DispatchMarkImpl(const nsAString& aName, 1.177 + float aElapsedTime, uint32_t aCharIndex) 1.178 +{ 1.179 + MOZ_ASSERT(mActor); 1.180 + NS_ENSURE_TRUE(mActor->SendOnMark(nsString(aName), aElapsedTime, aCharIndex), 1.181 + NS_ERROR_FAILURE); 1.182 + 1.183 + return NS_OK; 1.184 +} 1.185 + 1.186 +} // namespace dom 1.187 +} // namespace mozilla