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