michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "SpeechSynthesisChild.h" michael@0: #include "nsSynthVoiceRegistry.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: SpeechSynthesisChild::SpeechSynthesisChild() michael@0: { michael@0: MOZ_COUNT_CTOR(SpeechSynthesisChild); michael@0: } michael@0: michael@0: SpeechSynthesisChild::~SpeechSynthesisChild() michael@0: { michael@0: MOZ_COUNT_DTOR(SpeechSynthesisChild); michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisChild::RecvVoiceAdded(const RemoteVoice& aVoice) michael@0: { michael@0: nsSynthVoiceRegistry::RecvAddVoice(aVoice); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisChild::RecvVoiceRemoved(const nsString& aUri) michael@0: { michael@0: nsSynthVoiceRegistry::RecvRemoveVoice(aUri); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisChild::RecvSetDefaultVoice(const nsString& aUri, michael@0: const bool& aIsDefault) michael@0: { michael@0: nsSynthVoiceRegistry::RecvSetDefaultVoice(aUri, aIsDefault); michael@0: return true; michael@0: } michael@0: michael@0: PSpeechSynthesisRequestChild* michael@0: SpeechSynthesisChild::AllocPSpeechSynthesisRequestChild(const nsString& aText, michael@0: const nsString& aLang, michael@0: const nsString& aUri, michael@0: const float& aVolume, michael@0: const float& aRate, michael@0: const float& aPitch) michael@0: { michael@0: MOZ_CRASH("Caller is supposed to manually construct a request!"); michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisChild::DeallocPSpeechSynthesisRequestChild(PSpeechSynthesisRequestChild* aActor) michael@0: { michael@0: delete aActor; michael@0: return true; michael@0: } michael@0: michael@0: // SpeechSynthesisRequestChild michael@0: michael@0: SpeechSynthesisRequestChild::SpeechSynthesisRequestChild(SpeechTaskChild* aTask) michael@0: : mTask(aTask) michael@0: { michael@0: mTask->mActor = this; michael@0: MOZ_COUNT_CTOR(SpeechSynthesisRequestChild); michael@0: } michael@0: michael@0: SpeechSynthesisRequestChild::~SpeechSynthesisRequestChild() michael@0: { michael@0: MOZ_COUNT_DTOR(SpeechSynthesisRequestChild); michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisRequestChild::RecvOnStart() michael@0: { michael@0: mTask->DispatchStartImpl(); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisRequestChild::Recv__delete__(const bool& aIsError, michael@0: const float& aElapsedTime, michael@0: const uint32_t& aCharIndex) michael@0: { michael@0: mTask->mActor = nullptr; michael@0: michael@0: if (aIsError) { michael@0: mTask->DispatchErrorImpl(aElapsedTime, aCharIndex); michael@0: } else { michael@0: mTask->DispatchEndImpl(aElapsedTime, aCharIndex); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisRequestChild::RecvOnPause(const float& aElapsedTime, michael@0: const uint32_t& aCharIndex) michael@0: { michael@0: mTask->DispatchPauseImpl(aElapsedTime, aCharIndex); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisRequestChild::RecvOnResume(const float& aElapsedTime, michael@0: const uint32_t& aCharIndex) michael@0: { michael@0: mTask->DispatchResumeImpl(aElapsedTime, aCharIndex); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisRequestChild::RecvOnBoundary(const nsString& aName, michael@0: const float& aElapsedTime, michael@0: const uint32_t& aCharIndex) michael@0: { michael@0: mTask->DispatchBoundaryImpl(aName, aElapsedTime, aCharIndex); michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: SpeechSynthesisRequestChild::RecvOnMark(const nsString& aName, michael@0: const float& aElapsedTime, michael@0: const uint32_t& aCharIndex) michael@0: { michael@0: mTask->DispatchMarkImpl(aName, aElapsedTime, aCharIndex); michael@0: return true; michael@0: } michael@0: michael@0: // SpeechTaskChild michael@0: michael@0: SpeechTaskChild::SpeechTaskChild(SpeechSynthesisUtterance* aUtterance) michael@0: : nsSpeechTask(aUtterance) michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SpeechTaskChild::Setup(nsISpeechTaskCallback* aCallback, michael@0: uint32_t aChannels, uint32_t aRate, uint8_t argc) michael@0: { michael@0: MOZ_CRASH("Should never be called from child"); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SpeechTaskChild::SendAudio(JS::Handle aData, JS::Handle aLandmarks, michael@0: JSContext* aCx) michael@0: { michael@0: MOZ_CRASH("Should never be called from child"); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: SpeechTaskChild::SendAudioNative(int16_t* aData, uint32_t aDataLen) michael@0: { michael@0: MOZ_CRASH("Should never be called from child"); michael@0: } michael@0: michael@0: void michael@0: SpeechTaskChild::Pause() michael@0: { michael@0: MOZ_ASSERT(mActor); michael@0: mActor->SendPause(); michael@0: } michael@0: michael@0: void michael@0: SpeechTaskChild::Resume() michael@0: { michael@0: MOZ_ASSERT(mActor); michael@0: mActor->SendResume(); michael@0: } michael@0: michael@0: void michael@0: SpeechTaskChild::Cancel() michael@0: { michael@0: MOZ_ASSERT(mActor); michael@0: mActor->SendCancel(); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla