content/media/webspeech/synth/ipc/SpeechSynthesisChild.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webspeech/synth/ipc/SpeechSynthesisChild.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     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 "SpeechSynthesisChild.h"
     1.9 +#include "nsSynthVoiceRegistry.h"
    1.10 +
    1.11 +namespace mozilla {
    1.12 +namespace dom {
    1.13 +
    1.14 +SpeechSynthesisChild::SpeechSynthesisChild()
    1.15 +{
    1.16 +  MOZ_COUNT_CTOR(SpeechSynthesisChild);
    1.17 +}
    1.18 +
    1.19 +SpeechSynthesisChild::~SpeechSynthesisChild()
    1.20 +{
    1.21 +  MOZ_COUNT_DTOR(SpeechSynthesisChild);
    1.22 +}
    1.23 +
    1.24 +bool
    1.25 +SpeechSynthesisChild::RecvVoiceAdded(const RemoteVoice& aVoice)
    1.26 +{
    1.27 +  nsSynthVoiceRegistry::RecvAddVoice(aVoice);
    1.28 +  return true;
    1.29 +}
    1.30 +
    1.31 +bool
    1.32 +SpeechSynthesisChild::RecvVoiceRemoved(const nsString& aUri)
    1.33 +{
    1.34 +  nsSynthVoiceRegistry::RecvRemoveVoice(aUri);
    1.35 +  return true;
    1.36 +}
    1.37 +
    1.38 +bool
    1.39 +SpeechSynthesisChild::RecvSetDefaultVoice(const nsString& aUri,
    1.40 +                                          const bool& aIsDefault)
    1.41 +{
    1.42 +  nsSynthVoiceRegistry::RecvSetDefaultVoice(aUri, aIsDefault);
    1.43 +  return true;
    1.44 +}
    1.45 +
    1.46 +PSpeechSynthesisRequestChild*
    1.47 +SpeechSynthesisChild::AllocPSpeechSynthesisRequestChild(const nsString& aText,
    1.48 +                                                        const nsString& aLang,
    1.49 +                                                        const nsString& aUri,
    1.50 +                                                        const float& aVolume,
    1.51 +                                                        const float& aRate,
    1.52 +                                                        const float& aPitch)
    1.53 +{
    1.54 +  MOZ_CRASH("Caller is supposed to manually construct a request!");
    1.55 +}
    1.56 +
    1.57 +bool
    1.58 +SpeechSynthesisChild::DeallocPSpeechSynthesisRequestChild(PSpeechSynthesisRequestChild* aActor)
    1.59 +{
    1.60 +  delete aActor;
    1.61 +  return true;
    1.62 +}
    1.63 +
    1.64 +// SpeechSynthesisRequestChild
    1.65 +
    1.66 +SpeechSynthesisRequestChild::SpeechSynthesisRequestChild(SpeechTaskChild* aTask)
    1.67 +  : mTask(aTask)
    1.68 +{
    1.69 +  mTask->mActor = this;
    1.70 +  MOZ_COUNT_CTOR(SpeechSynthesisRequestChild);
    1.71 +}
    1.72 +
    1.73 +SpeechSynthesisRequestChild::~SpeechSynthesisRequestChild()
    1.74 +{
    1.75 +  MOZ_COUNT_DTOR(SpeechSynthesisRequestChild);
    1.76 +}
    1.77 +
    1.78 +bool
    1.79 +SpeechSynthesisRequestChild::RecvOnStart()
    1.80 +{
    1.81 +  mTask->DispatchStartImpl();
    1.82 +  return true;
    1.83 +}
    1.84 +
    1.85 +bool
    1.86 +SpeechSynthesisRequestChild::Recv__delete__(const bool& aIsError,
    1.87 +                                            const float& aElapsedTime,
    1.88 +                                            const uint32_t& aCharIndex)
    1.89 +{
    1.90 +  mTask->mActor = nullptr;
    1.91 +
    1.92 +  if (aIsError) {
    1.93 +    mTask->DispatchErrorImpl(aElapsedTime, aCharIndex);
    1.94 +  } else {
    1.95 +    mTask->DispatchEndImpl(aElapsedTime, aCharIndex);
    1.96 +  }
    1.97 +
    1.98 +  return true;
    1.99 +}
   1.100 +
   1.101 +bool
   1.102 +SpeechSynthesisRequestChild::RecvOnPause(const float& aElapsedTime,
   1.103 +                                         const uint32_t& aCharIndex)
   1.104 +{
   1.105 +  mTask->DispatchPauseImpl(aElapsedTime, aCharIndex);
   1.106 +  return true;
   1.107 +}
   1.108 +
   1.109 +bool
   1.110 +SpeechSynthesisRequestChild::RecvOnResume(const float& aElapsedTime,
   1.111 +                                          const uint32_t& aCharIndex)
   1.112 +{
   1.113 +  mTask->DispatchResumeImpl(aElapsedTime, aCharIndex);
   1.114 +  return true;
   1.115 +}
   1.116 +
   1.117 +bool
   1.118 +SpeechSynthesisRequestChild::RecvOnBoundary(const nsString& aName,
   1.119 +                                            const float& aElapsedTime,
   1.120 +                                            const uint32_t& aCharIndex)
   1.121 +{
   1.122 +  mTask->DispatchBoundaryImpl(aName, aElapsedTime, aCharIndex);
   1.123 +  return true;
   1.124 +}
   1.125 +
   1.126 +bool
   1.127 +SpeechSynthesisRequestChild::RecvOnMark(const nsString& aName,
   1.128 +                                        const float& aElapsedTime,
   1.129 +                                        const uint32_t& aCharIndex)
   1.130 +{
   1.131 +  mTask->DispatchMarkImpl(aName, aElapsedTime, aCharIndex);
   1.132 +  return true;
   1.133 +}
   1.134 +
   1.135 +// SpeechTaskChild
   1.136 +
   1.137 +SpeechTaskChild::SpeechTaskChild(SpeechSynthesisUtterance* aUtterance)
   1.138 +  : nsSpeechTask(aUtterance)
   1.139 +{
   1.140 +}
   1.141 +
   1.142 +NS_IMETHODIMP
   1.143 +SpeechTaskChild::Setup(nsISpeechTaskCallback* aCallback,
   1.144 +                       uint32_t aChannels, uint32_t aRate, uint8_t argc)
   1.145 +{
   1.146 +  MOZ_CRASH("Should never be called from child");
   1.147 +}
   1.148 +
   1.149 +NS_IMETHODIMP
   1.150 +SpeechTaskChild::SendAudio(JS::Handle<JS::Value> aData, JS::Handle<JS::Value> aLandmarks,
   1.151 +                           JSContext* aCx)
   1.152 +{
   1.153 +  MOZ_CRASH("Should never be called from child");
   1.154 +}
   1.155 +
   1.156 +NS_IMETHODIMP
   1.157 +SpeechTaskChild::SendAudioNative(int16_t* aData, uint32_t aDataLen)
   1.158 +{
   1.159 +  MOZ_CRASH("Should never be called from child");
   1.160 +}
   1.161 +
   1.162 +void
   1.163 +SpeechTaskChild::Pause()
   1.164 +{
   1.165 +  MOZ_ASSERT(mActor);
   1.166 +  mActor->SendPause();
   1.167 +}
   1.168 +
   1.169 +void
   1.170 +SpeechTaskChild::Resume()
   1.171 +{
   1.172 +  MOZ_ASSERT(mActor);
   1.173 +  mActor->SendResume();
   1.174 +}
   1.175 +
   1.176 +void
   1.177 +SpeechTaskChild::Cancel()
   1.178 +{
   1.179 +  MOZ_ASSERT(mActor);
   1.180 +  mActor->SendCancel();
   1.181 +}
   1.182 +
   1.183 +} // namespace dom
   1.184 +} // namespace mozilla

mercurial