tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SpeechSynthesisChild.cpp (5108B)


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