diff --git a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm b/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm index bbda2d925328..87e8ca9cb517 100644 --- a/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm +++ b/dom/media/webspeech/synth/cocoa/OSXSpeechSynthesizerService.mm @@ -35,7 +35,6 @@ public: : mTask(aTask) , mSpeechSynthesizer(aSynth) , mOffsets(aOffsets) - , mCanceled(false) { mStartingTime = TimeStamp::Now(); } @@ -62,7 +61,6 @@ private: TimeStamp mStartingTime; uint32_t mCurrentIndex; nsTArray mOffsets; - bool mCanceled; }; NS_IMPL_CYCLE_COLLECTION(SpeechTaskCallback, mTask); @@ -80,7 +78,6 @@ SpeechTaskCallback::OnCancel() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; - mCanceled = true; [mSpeechSynthesizer stopSpeaking]; return NS_OK; @@ -166,12 +163,7 @@ SpeechTaskCallback::OnError(uint32_t aIndex) void SpeechTaskCallback::OnDidFinishSpeaking() { - if (mCanceled) { - mTask->DispatchError(GetTimeDurationFromStart(), mCurrentIndex, - uint32_t(dom::SpeechSynthesisErrorCode::Interrupted)); - } else { - mTask->DispatchEnd(GetTimeDurationFromStart(), mCurrentIndex); - } + mTask->DispatchEnd(GetTimeDurationFromStart(), mCurrentIndex); // no longer needed [mSpeechSynthesizer setDelegate:nil]; mTask = nullptr; diff --git a/dom/media/webspeech/synth/nsSpeechTask.cpp b/dom/media/webspeech/synth/nsSpeechTask.cpp index ac7734bd96d8..c664c5b9c708 100644 --- a/dom/media/webspeech/synth/nsSpeechTask.cpp +++ b/dom/media/webspeech/synth/nsSpeechTask.cpp @@ -411,7 +411,7 @@ nsSpeechTask::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex) DestroyAudioChannelAgent(); MOZ_ASSERT(mUtterance); - if(NS_WARN_IF(mUtterance->mState != SpeechSynthesisUtterance::STATE_SPEAKING)) { + if(NS_WARN_IF(mUtterance->mState == SpeechSynthesisUtterance::STATE_ENDED)) { return NS_ERROR_NOT_AVAILABLE; } @@ -426,10 +426,14 @@ nsSpeechTask::DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex) mSpeechSynthesis->OnEnd(this); } - utterance->mState = SpeechSynthesisUtterance::STATE_ENDED; - utterance->DispatchSpeechSynthesisEvent(NS_LITERAL_STRING("end"), - aCharIndex, aElapsedTime, - EmptyString()); + if (utterance->mState == SpeechSynthesisUtterance::STATE_PENDING) { + utterance->mState = SpeechSynthesisUtterance::STATE_NONE; + } else { + utterance->mState = SpeechSynthesisUtterance::STATE_ENDED; + utterance->DispatchSpeechSynthesisEvent(NS_LITERAL_STRING("end"), + aCharIndex, aElapsedTime, + EmptyString()); + } return NS_OK; } @@ -509,12 +513,6 @@ nsSpeechTask::DispatchError(float aElapsedTime, uint32_t aCharIndex, uint32_t aE return NS_ERROR_FAILURE; } - return DispatchErrorInner(aElapsedTime, aCharIndex, aError); -} - -nsresult -nsSpeechTask::DispatchErrorInner(float aElapsedTime, uint32_t aCharIndex, uint32_t aError) -{ if (!mPreCanceled) { nsSynthVoiceRegistry::GetInstance()->SpeakNext(); } @@ -534,12 +532,9 @@ nsSpeechTask::DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex, uint32_ mSpeechSynthesis->OnEnd(this); } - RefPtr utterance = mUtterance; - utterance->mState = (utterance->mState == SpeechSynthesisUtterance::STATE_SPEAKING) ? - SpeechSynthesisUtterance::STATE_ENDED : SpeechSynthesisUtterance::STATE_NONE; - utterance->DispatchSpeechSynthesisErrorEvent(aCharIndex, aElapsedTime, - SpeechSynthesisErrorCode(aError)); - + mUtterance->mState = SpeechSynthesisUtterance::STATE_ENDED; + mUtterance->DispatchSpeechSynthesisErrorEvent(aCharIndex, aElapsedTime, + SpeechSynthesisErrorCode(aError)); return NS_OK; } @@ -665,8 +660,7 @@ nsSpeechTask::Cancel() } if (!mIndirectAudio) { - DispatchErrorInner(GetCurrentTime(), GetCurrentCharOffset(), - uint32_t(SpeechSynthesisErrorCode::Interrupted)); + DispatchEndInner(GetCurrentTime(), GetCurrentCharOffset()); } } diff --git a/dom/media/webspeech/synth/nsSpeechTask.h b/dom/media/webspeech/synth/nsSpeechTask.h index 31d479e51ab5..adc336f604e3 100644 --- a/dom/media/webspeech/synth/nsSpeechTask.h +++ b/dom/media/webspeech/synth/nsSpeechTask.h @@ -109,8 +109,6 @@ private: nsresult DispatchEndInner(float aElapsedTime, uint32_t aCharIndex); - nsresult DispatchErrorInner(float aElapsedTime, uint32_t aCharIndex, uint32_t aError); - void CreateAudioChannelAgent(); void DestroyAudioChannelAgent(); diff --git a/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp b/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp index b864c161c9bd..47154df34677 100644 --- a/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp +++ b/dom/media/webspeech/synth/speechd/SpeechDispatcherService.cpp @@ -8,7 +8,6 @@ #include "mozilla/dom/nsSpeechTask.h" #include "mozilla/dom/nsSynthVoiceRegistry.h" -#include "mozilla/dom/SpeechSynthesisErrorEvent.h" #include "mozilla/Preferences.h" #include "nsEscape.h" #include "nsISupports.h" @@ -252,11 +251,6 @@ SpeechDispatcherCallback::OnSpeechEvent(SPDNotificationType state) break; case SPD_EVENT_CANCEL: - mTask->DispatchError((TimeStamp::Now() - mStartTime).ToSeconds(), 0, - uint32_t(SpeechSynthesisErrorCode::Interrupted)); - remove = true; - break; - case SPD_EVENT_END: mTask->DispatchEnd((TimeStamp::Now() - mStartTime).ToSeconds(), 0); remove = true; diff --git a/dom/media/webspeech/synth/test/file_global_queue_cancel.html b/dom/media/webspeech/synth/test/file_global_queue_cancel.html index b73e91894c7e..03b77ba2fc6d 100644 --- a/dom/media/webspeech/synth/test/file_global_queue_cancel.html +++ b/dom/media/webspeech/synth/test/file_global_queue_cancel.html @@ -41,7 +41,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1188099 var utterance5 = new win2.SpeechSynthesisUtterance("u5: hello, losers too"); utterance5.lang = 'it-IT-noend'; - var eventOrder = ['start1', 'end1', 'start2', 'error2']; + var eventOrder = ['start1', 'end1', 'start2', 'end2']; utterance1.addEventListener('start', function(e) { is(eventOrder.shift(), 'start1', 'start1'); testSynthState(win1, { speaking: true, pending: true }); @@ -61,8 +61,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1188099 testSynthState(win2, { speaking: true, pending: false }); win1.speechSynthesis.cancel(); }); - utterance2.addEventListener('error', function(e) { - is(eventOrder.shift(), 'error2', 'error2'); + utterance2.addEventListener('end', function(e) { + is(eventOrder.shift(), 'end2', 'end2'); testSynthState(win1, { speaking: false, pending: false }); testSynthState(win2, { speaking: false, pending: false }); SimpleTest.finish(); diff --git a/dom/media/webspeech/synth/test/file_indirect_service_events.html b/dom/media/webspeech/synth/test/file_indirect_service_events.html index 10cc3fc74476..fb4e31244449 100644 --- a/dom/media/webspeech/synth/test/file_indirect_service_events.html +++ b/dom/media/webspeech/synth/test/file_indirect_service_events.html @@ -50,7 +50,7 @@ function testFunc(done_cb) { speechSynthesis.cancel(); }); - utterance.addEventListener('error', function(e) { + utterance.addEventListener('end', function(e) { ok(e.charIndex, 1, 'resume event charIndex matches service arguments'); ok(e.elapsedTime, 1.5, 'end event elapsedTime matches service arguments'); test_no_events(); diff --git a/dom/media/webspeech/synth/test/file_speech_cancel.html b/dom/media/webspeech/synth/test/file_speech_cancel.html index ff8980afb434..2ab0e1d0a87f 100644 --- a/dom/media/webspeech/synth/test/file_speech_cancel.html +++ b/dom/media/webspeech/synth/test/file_speech_cancel.html @@ -27,7 +27,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1150315 /** Test for Bug 1150315 **/ function testFunc(done_cb) { - var gotErrorEvent = false; + var gotEndEvent = false; // A long utterance that we will interrupt. var utterance = new SpeechSynthesisUtterance("Donec ac nunc feugiat, posuere " + "mauris id, pharetra velit. Donec fermentum orci nunc, sit amet maximus" + @@ -63,14 +63,13 @@ function testFunc(done_cb) { speechSynthesis.cancel(); speechSynthesis.speak(utterance3); }); - utterance2.addEventListener('error', function(e) { - gotErrorEvent = true; - is(e.error, "interrupted", "Error event is has right error.") + utterance2.addEventListener('end', function(e) { + gotEndEvent = true; }); var utterance3 = new SpeechSynthesisUtterance("Hello, world 3!"); utterance3.addEventListener('start', function() { - ok(gotErrorEvent, "didn't get error event for previous utterance"); + ok(gotEndEvent, "didn't get start event for this utterance"); }); utterance3.addEventListener('end', done_cb); diff --git a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp index 3c60c387c989..f1a677039247 100644 --- a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp +++ b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp @@ -90,8 +90,7 @@ public: NS_IMETHOD OnCancel() override { if (mTask) { - mTask->DispatchError(1.5, 1, - uint32_t(SpeechSynthesisErrorCode::Interrupted)); + mTask->DispatchEnd(1.5, 1); } return NS_OK; diff --git a/dom/media/webspeech/synth/windows/SapiService.cpp b/dom/media/webspeech/synth/windows/SapiService.cpp index 3bdd55a350ff..c368ad1157c4 100644 --- a/dom/media/webspeech/synth/windows/SapiService.cpp +++ b/dom/media/webspeech/synth/windows/SapiService.cpp @@ -13,7 +13,6 @@ #include "mozilla/dom/nsSynthVoiceRegistry.h" #include "mozilla/dom/nsSpeechTask.h" -#include "mozilla/dom/SpeechSynthesisErrorEvent.h" #include "mozilla/Preferences.h" namespace mozilla { @@ -132,13 +131,9 @@ SapiCallback::OnSpeechEvent(const SPEVENT& speechEvent) break; case SPEI_END_INPUT_STREAM: if (mSpeakTextLen) { - // mSpeakTextLen will be > 0 on any utterance except a cancel utterance. mCurrentIndex = mSpeakTextLen; - mTask->DispatchEnd(GetTickCount() - mStartingTime, mCurrentIndex); - } else { - mTask->DispatchError(GetTickCount() - mStartingTime, mCurrentIndex, - uint32_t(SpeechSynthesisErrorCode::Interrupted)); } + mTask->DispatchEnd(GetTickCount() - mStartingTime, mCurrentIndex); mTask = nullptr; break; case SPEI_TTS_BOOKMARK: