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 #ifndef mozilla_dom_SpeechSynthesisParent_h
6 #define mozilla_dom_SpeechSynthesisParent_h
7 
8 #include "mozilla/dom/PSpeechSynthesisParent.h"
9 #include "mozilla/dom/PSpeechSynthesisRequestParent.h"
10 #include "nsSpeechTask.h"
11 
12 namespace mozilla {
13 namespace dom {
14 
15 class ContentParent;
16 class SpeechTaskParent;
17 class SpeechSynthesisRequestParent;
18 
19 class SpeechSynthesisParent : public PSpeechSynthesisParent {
20   friend class ContentParent;
21   friend class SpeechSynthesisRequestParent;
22   friend class PSpeechSynthesisParent;
23 
24  public:
25   void ActorDestroy(ActorDestroyReason aWhy) override;
26 
27   bool SendInit();
28 
29  protected:
30   SpeechSynthesisParent();
31   virtual ~SpeechSynthesisParent();
32   PSpeechSynthesisRequestParent* AllocPSpeechSynthesisRequestParent(
33       const nsString& aText, const nsString& aLang, const nsString& aUri,
34       const float& aVolume, const float& aRate, const float& aPitch,
35       const bool& aIsChrome);
36 
37   bool DeallocPSpeechSynthesisRequestParent(
38       PSpeechSynthesisRequestParent* aActor);
39 
40   mozilla::ipc::IPCResult RecvPSpeechSynthesisRequestConstructor(
41       PSpeechSynthesisRequestParent* aActor, const nsString& aText,
42       const nsString& aLang, const nsString& aUri, const float& aVolume,
43       const float& aRate, const float& aPitch, const bool& aIsChrome) override;
44 };
45 
46 class SpeechSynthesisRequestParent : public PSpeechSynthesisRequestParent {
47  public:
48   explicit SpeechSynthesisRequestParent(SpeechTaskParent* aTask);
49   virtual ~SpeechSynthesisRequestParent();
50 
51   RefPtr<SpeechTaskParent> mTask;
52 
53  protected:
54   void ActorDestroy(ActorDestroyReason aWhy) override;
55 
56   mozilla::ipc::IPCResult RecvPause() override;
57 
58   mozilla::ipc::IPCResult RecvResume() override;
59 
60   mozilla::ipc::IPCResult RecvCancel() override;
61 
62   mozilla::ipc::IPCResult RecvForceEnd() override;
63 
64   mozilla::ipc::IPCResult RecvSetAudioOutputVolume(
65       const float& aVolume) override;
66 
67   mozilla::ipc::IPCResult Recv__delete__() override;
68 };
69 
70 class SpeechTaskParent : public nsSpeechTask {
71   friend class SpeechSynthesisRequestParent;
72 
73  public:
SpeechTaskParent(float aVolume,const nsAString & aUtterance,bool aIsChrome)74   SpeechTaskParent(float aVolume, const nsAString& aUtterance, bool aIsChrome)
75       : nsSpeechTask(aVolume, aUtterance, aIsChrome), mActor(nullptr) {}
76 
77   nsresult DispatchStartImpl(const nsAString& aUri) override;
78 
79   nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex) override;
80 
81   nsresult DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex) override;
82 
83   nsresult DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex) override;
84 
85   nsresult DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex) override;
86 
87   nsresult DispatchBoundaryImpl(const nsAString& aName, float aElapsedTime,
88                                 uint32_t aCharIndex, uint32_t aCharLength,
89                                 uint8_t argc) override;
90 
91   nsresult DispatchMarkImpl(const nsAString& aName, float aElapsedTime,
92                             uint32_t aCharIndex) override;
93 
94  private:
95   SpeechSynthesisRequestParent* mActor;
96 };
97 
98 }  // namespace dom
99 }  // namespace mozilla
100 
101 #endif
102