Bug 1162692 - Add SpeechSynthesisUtterance.chosenVoiceURI for testing purposes. r=smaug
☠☠ backed out by 05e4643b27ec ☠ ☠
authorEitan Isaacson <eitan@monotonous.org>
Fri, 08 May 2015 10:32:12 -0700
changeset 242951 3466be6fd32ca5189d9d785f036382763b3175b7
parent 242950 4f21884b0c36b5a3e136991d515cbb33f9da621f
child 242952 4ff5e8facd3751b864104efa120a918643553bf4
push id59561
push usereisaacson@mozilla.com
push dateFri, 08 May 2015 17:32:17 +0000
treeherdermozilla-inbound@3466be6fd32c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1162692
milestone40.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
@@ -556,16 +556,18 @@ nsSynthVoiceRegistry::Speak(const nsAStr
 {
   LOG(PR_LOG_DEBUG,
       ("nsSynthVoiceRegistry::Speak text='%s' lang='%s' uri='%s' rate=%f pitch=%f",
        NS_ConvertUTF16toUTF8(aText).get(), NS_ConvertUTF16toUTF8(aLang).get(),
        NS_ConvertUTF16toUTF8(aUri).get(), aRate, aPitch));
 
   VoiceData* voice = FindBestMatch(aUri, aLang);
 
+  aTask->SetChosenVoiceURI(voice->mUri);
+
   if (!voice) {
     NS_WARNING("No voices found.");
     aTask->DispatchError(0, 0);
     return;
   }
 
   LOG(PR_LOG_DEBUG, ("nsSynthVoiceRegistry::Speak - Using voice URI: %s",
                      NS_ConvertUTF16toUTF8(voice->mUri).get()));
--- 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;
 };