Bug 1162692 - Add SpeechSynthesisUtterance.chosenVoiceURI for testing purposes. r=smaug
authorEitan Isaacson <eitan@monotonous.org>
Tue, 12 May 2015 13:24:58 -0700
changeset 243546 896c165d880b9d9da5268c6504056179a5dee491
parent 243545 763bd3743f94a390ba3281323ff4542642126b9e
child 243547 90e8896f13b731eeb09ef5bdc8fe22aff0588cba
push id59694
push usereisaacson@mozilla.com
push dateTue, 12 May 2015 20:25:03 +0000
treeherdermozilla-inbound@896c165d880b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1162692
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1162692 - Add SpeechSynthesisUtterance.chosenVoiceURI for testing purposes. r=smaug
dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp
dom/media/webspeech/synth/SpeechSynthesisUtterance.h
dom/media/webspeech/synth/ipc/PSpeechSynthesisRequest.ipdl
dom/media/webspeech/synth/ipc/SpeechSynthesisChild.cpp
dom/media/webspeech/synth/ipc/SpeechSynthesisChild.h
dom/media/webspeech/synth/ipc/SpeechSynthesisParent.cpp
dom/media/webspeech/synth/ipc/SpeechSynthesisParent.h
dom/media/webspeech/synth/nsSpeechTask.cpp
dom/media/webspeech/synth/nsSpeechTask.h
dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp
dom/webidl/SpeechSynthesisUtterance.webidl
--- a/dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp
+++ b/dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp
@@ -143,16 +143,22 @@ SpeechSynthesisUtterance::Pitch() const
 
 void
 SpeechSynthesisUtterance::SetPitch(float aPitch)
 {
   mPitch = aPitch;
 }
 
 void
+SpeechSynthesisUtterance::GetChosenVoiceURI(nsString& aResult) const
+{
+  aResult = mChosenVoiceURI;
+}
+
+void
 SpeechSynthesisUtterance::DispatchSpeechSynthesisEvent(const nsAString& aEventType,
                                                        uint32_t aCharIndex,
                                                        float aElapsedTime,
                                                        const nsAString& aName)
 {
   SpeechSynthesisEventInit init;
   init.mBubbles = false;
   init.mCancelable = false;
--- a/dom/media/webspeech/synth/SpeechSynthesisUtterance.h
+++ b/dom/media/webspeech/synth/SpeechSynthesisUtterance.h
@@ -66,16 +66,18 @@ public:
   float Rate() const;
 
   void SetRate(float aRate);
 
   float Pitch() const;
 
   void SetPitch(float aPitch);
 
+  void GetChosenVoiceURI(nsString& aResult) const;
+
   enum {
     STATE_NONE,
     STATE_PENDING,
     STATE_SPEAKING,
     STATE_ENDED
   };
 
   uint32_t GetState() { return mState; }
@@ -102,16 +104,18 @@ private:
   nsString mLang;
 
   float mVolume;
 
   float mRate;
 
   float mPitch;
 
+  nsString mChosenVoiceURI;
+
   uint32_t mState;
 
   bool mPaused;
 
   nsRefPtr<SpeechSynthesisVoice> mVoice;
 };
 
 } // namespace dom
--- a/dom/media/webspeech/synth/ipc/PSpeechSynthesisRequest.ipdl
+++ b/dom/media/webspeech/synth/ipc/PSpeechSynthesisRequest.ipdl
@@ -20,17 +20,17 @@ async protocol PSpeechSynthesisRequest
   Resume();
 
   Cancel();
 
  child:
 
   __delete__(bool aIsError, float aElapsedTime, uint32_t aCharIndex);
 
-  OnStart();
+  OnStart(nsString aUri);
 
   OnPause(float aElapsedTime, uint32_t aCharIndex);
 
   OnResume(float aElapsedTime, uint32_t aCharIndex);
 
   OnBoundary(nsString aName, float aElapsedTime, uint32_t aCharIndex);
 
   OnMark(nsString aName, float aElapsedTime, uint32_t aCharIndex);
--- a/dom/media/webspeech/synth/ipc/SpeechSynthesisChild.cpp
+++ b/dom/media/webspeech/synth/ipc/SpeechSynthesisChild.cpp
@@ -68,19 +68,19 @@ SpeechSynthesisRequestChild::SpeechSynth
 }
 
 SpeechSynthesisRequestChild::~SpeechSynthesisRequestChild()
 {
   MOZ_COUNT_DTOR(SpeechSynthesisRequestChild);
 }
 
 bool
-SpeechSynthesisRequestChild::RecvOnStart()
+SpeechSynthesisRequestChild::RecvOnStart(const nsString& aUri)
 {
-  mTask->DispatchStartImpl();
+  mTask->DispatchStartImpl(aUri);
   return true;
 }
 
 bool
 SpeechSynthesisRequestChild::Recv__delete__(const bool& aIsError,
                                             const float& aElapsedTime,
                                             const uint32_t& aCharIndex)
 {
--- a/dom/media/webspeech/synth/ipc/SpeechSynthesisChild.h
+++ b/dom/media/webspeech/synth/ipc/SpeechSynthesisChild.h
@@ -43,17 +43,17 @@ protected:
 
 class SpeechSynthesisRequestChild : public PSpeechSynthesisRequestChild
 {
 public:
   explicit SpeechSynthesisRequestChild(SpeechTaskChild* aTask);
   virtual ~SpeechSynthesisRequestChild();
 
 protected:
-  virtual bool RecvOnStart() override;
+  virtual bool RecvOnStart(const nsString& aUri) override;
 
   virtual bool Recv__delete__(const bool& aIsError,
                               const float& aElapsedTime,
                               const uint32_t& aCharIndex) override;
 
   virtual bool RecvOnPause(const float& aElapsedTime, const uint32_t& aCharIndex) override;
 
   virtual bool RecvOnResume(const float& aElapsedTime, const uint32_t& aCharIndex) override;
--- a/dom/media/webspeech/synth/ipc/SpeechSynthesisParent.cpp
+++ b/dom/media/webspeech/synth/ipc/SpeechSynthesisParent.cpp
@@ -115,20 +115,20 @@ SpeechSynthesisRequestParent::RecvCancel
   MOZ_ASSERT(mTask);
   mTask->Cancel();
   return true;
 }
 
 // SpeechTaskParent
 
 nsresult
-SpeechTaskParent::DispatchStartImpl()
+SpeechTaskParent::DispatchStartImpl(const nsAString& aUri)
 {
   MOZ_ASSERT(mActor);
-  NS_ENSURE_TRUE(mActor->SendOnStart(), NS_ERROR_FAILURE);
+  NS_ENSURE_TRUE(mActor->SendOnStart(nsString(aUri)), NS_ERROR_FAILURE);
 
   return NS_OK;
 }
 
 nsresult
 SpeechTaskParent::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex)
 {
   MOZ_ASSERT(mActor);
--- a/dom/media/webspeech/synth/ipc/SpeechSynthesisParent.h
+++ b/dom/media/webspeech/synth/ipc/SpeechSynthesisParent.h
@@ -70,17 +70,17 @@ protected:
 
 class SpeechTaskParent : public nsSpeechTask
 {
   friend class SpeechSynthesisRequestParent;
 public:
   SpeechTaskParent(float aVolume, const nsAString& aUtterance)
     : nsSpeechTask(aVolume, aUtterance) {}
 
-  virtual nsresult DispatchStartImpl();
+  virtual nsresult DispatchStartImpl(const nsAString& aUri);
 
   virtual nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex);
 
   virtual nsresult DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex);
 
   virtual nsresult DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex);
 
   virtual nsresult DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex);
--- a/dom/media/webspeech/synth/nsSpeechTask.cpp
+++ b/dom/media/webspeech/synth/nsSpeechTask.cpp
@@ -135,16 +135,22 @@ nsSpeechTask::~nsSpeechTask()
 
 void
 nsSpeechTask::BindStream(ProcessedMediaStream* aStream)
 {
   mStream = MediaStreamGraph::GetInstance()->CreateSourceStream(nullptr);
   mPort = aStream->AllocateInputPort(mStream, 0);
 }
 
+void
+nsSpeechTask::SetChosenVoiceURI(const nsAString& aUri)
+{
+  mChosenVoiceURI = aUri;
+}
+
 NS_IMETHODIMP
 nsSpeechTask::Setup(nsISpeechTaskCallback* aCallback,
                     uint32_t aChannels, uint32_t aRate, uint8_t argc)
 {
   MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
 
   LOG(PR_LOG_DEBUG, ("nsSpeechTask::Setup"));
 
@@ -277,23 +283,30 @@ nsSpeechTask::DispatchStart()
   }
 
   return DispatchStartImpl();
 }
 
 nsresult
 nsSpeechTask::DispatchStartImpl()
 {
+  return DispatchStartImpl(mChosenVoiceURI);
+}
+
+nsresult
+nsSpeechTask::DispatchStartImpl(const nsAString& aUri)
+{
   LOG(PR_LOG_DEBUG, ("nsSpeechTask::DispatchStart"));
 
   MOZ_ASSERT(mUtterance);
   NS_ENSURE_TRUE(mUtterance->mState == SpeechSynthesisUtterance::STATE_PENDING,
                  NS_ERROR_NOT_AVAILABLE);
 
   mUtterance->mState = SpeechSynthesisUtterance::STATE_SPEAKING;
+  mUtterance->mChosenVoiceURI = aUri;
   mUtterance->DispatchSpeechSynthesisEvent(NS_LITERAL_STRING("start"), 0, 0,
                                            NS_LITERAL_STRING(""));
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSpeechTask::DispatchEnd(float aElapsedTime, uint32_t aCharIndex)
--- a/dom/media/webspeech/synth/nsSpeechTask.h
+++ b/dom/media/webspeech/synth/nsSpeechTask.h
@@ -42,20 +42,24 @@ public:
   uint32_t GetCurrentCharOffset();
 
   void SetSpeechSynthesis(SpeechSynthesis* aSpeechSynthesis);
 
   void SetIndirectAudio(bool aIndirectAudio) { mIndirectAudio = aIndirectAudio; }
 
   void BindStream(ProcessedMediaStream* aStream);
 
+  void SetChosenVoiceURI(const nsAString& aUri);
+
 protected:
   virtual ~nsSpeechTask();
 
-  virtual nsresult DispatchStartImpl();
+  nsresult DispatchStartImpl();
+
+  virtual nsresult DispatchStartImpl(const nsAString& aUri);
 
   virtual nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex);
 
   virtual nsresult DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex);
 
   virtual nsresult DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex);
 
   virtual nsresult DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex);
@@ -84,14 +88,16 @@ private:
 
   nsCOMPtr<nsISpeechTaskCallback> mCallback;
 
   uint32_t mChannels;
 
   nsRefPtr<SpeechSynthesis> mSpeechSynthesis;
 
   bool mIndirectAudio;
+
+  nsString mChosenVoiceURI;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp
+++ b/dom/media/webspeech/synth/nsSynthVoiceRegistry.cpp
@@ -562,16 +562,18 @@ nsSynthVoiceRegistry::Speak(const nsAStr
   VoiceData* voice = FindBestMatch(aUri, aLang);
 
   if (!voice) {
     NS_WARNING("No voices found.");
     aTask->DispatchError(0, 0);
     return;
   }
 
+  aTask->SetChosenVoiceURI(voice->mUri);
+
   LOG(PR_LOG_DEBUG, ("nsSynthVoiceRegistry::Speak - Using voice URI: %s",
                      NS_ConvertUTF16toUTF8(voice->mUri).get()));
 
   SpeechServiceType serviceType;
 
   DebugOnly<nsresult> rv = voice->mService->GetServiceType(&serviceType);
   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get speech service type");
 
--- a/dom/webidl/SpeechSynthesisUtterance.webidl
+++ b/dom/webidl/SpeechSynthesisUtterance.webidl
@@ -23,9 +23,12 @@ interface SpeechSynthesisUtterance : Eve
 
   attribute EventHandler onstart;
   attribute EventHandler onend;
   attribute EventHandler onerror;
   attribute EventHandler onpause;
   attribute EventHandler onresume;
   attribute EventHandler onmark;
   attribute EventHandler onboundary;
+
+  [ChromeOnly]
+  readonly attribute DOMString chosenVoiceURI;
 };