Commit e17b3bbf authored by Minoru Chikamune's avatar Minoru Chikamune Committed by Commit Bot

Fix crash in SpeechSynthesisProxy::cancel and SpeechSynthesisProxy::pause

If ExecutionContext is destroyed, SpeechSynthesis should stop processing.

Bug: 1058076, 1095955, 1049056
Change-Id: I8a05a376f3c0472b3833bb9d1c57f89d0e7d8e05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2300905
Commit-Queue: Minoru Chikamune <chikamune@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789434}
parent cc665d85
...@@ -58,7 +58,7 @@ SpeechSynthesis* SpeechSynthesis::speechSynthesis(LocalDOMWindow& window) { ...@@ -58,7 +58,7 @@ SpeechSynthesis* SpeechSynthesis::speechSynthesis(LocalDOMWindow& window) {
// TODO(crbug/811929): Consider moving this logic into the Android- // TODO(crbug/811929): Consider moving this logic into the Android-
// specific backend implementation. // specific backend implementation.
#else #else
synthesis->InitializeMojomSynthesis(); ignore_result(synthesis->TryEnsureMojomSynthesis());
#endif #endif
} }
return synthesis; return synthesis;
...@@ -90,7 +90,7 @@ void SpeechSynthesis::OnSetVoiceList( ...@@ -90,7 +90,7 @@ void SpeechSynthesis::OnSetVoiceList(
const HeapVector<Member<SpeechSynthesisVoice>>& SpeechSynthesis::getVoices() { const HeapVector<Member<SpeechSynthesisVoice>>& SpeechSynthesis::getVoices() {
// Kick off initialization here to ensure voice list gets populated. // Kick off initialization here to ensure voice list gets populated.
InitializeMojomSynthesisIfNeeded(); ignore_result(TryEnsureMojomSynthesis());
return voice_list_; return voice_list_;
} }
...@@ -143,24 +143,27 @@ void SpeechSynthesis::cancel() { ...@@ -143,24 +143,27 @@ void SpeechSynthesis::cancel() {
// fire events on them asynchronously. // fire events on them asynchronously.
utterance_queue_.clear(); utterance_queue_.clear();
InitializeMojomSynthesisIfNeeded(); if (mojom::blink::SpeechSynthesis* mojom_synthesis =
mojom_synthesis_->Cancel(); TryEnsureMojomSynthesis())
mojom_synthesis->Cancel();
} }
void SpeechSynthesis::pause() { void SpeechSynthesis::pause() {
if (is_paused_) if (is_paused_)
return; return;
InitializeMojomSynthesisIfNeeded(); if (mojom::blink::SpeechSynthesis* mojom_synthesis =
mojom_synthesis_->Pause(); TryEnsureMojomSynthesis())
mojom_synthesis->Pause();
} }
void SpeechSynthesis::resume() { void SpeechSynthesis::resume() {
if (!CurrentSpeechUtterance()) if (!CurrentSpeechUtterance())
return; return;
InitializeMojomSynthesisIfNeeded(); if (mojom::blink::SpeechSynthesis* mojom_synthesis =
mojom_synthesis_->Resume(); TryEnsureMojomSynthesis())
mojom_synthesis->Resume();
} }
void SpeechSynthesis::DidStartSpeaking(SpeechSynthesisUtterance* utterance) { void SpeechSynthesis::DidStartSpeaking(SpeechSynthesisUtterance* utterance) {
...@@ -220,8 +223,8 @@ void SpeechSynthesis::StartSpeakingImmediately() { ...@@ -220,8 +223,8 @@ void SpeechSynthesis::StartSpeakingImmediately() {
utterance->SetStartTime(millis / 1000.0); utterance->SetStartTime(millis / 1000.0);
is_paused_ = false; is_paused_ = false;
InitializeMojomSynthesisIfNeeded(); if (TryEnsureMojomSynthesis())
utterance->Start(this); utterance->Start(this);
} }
void SpeechSynthesis::HandleSpeakingCompleted( void SpeechSynthesis::HandleSpeakingCompleted(
...@@ -339,21 +342,17 @@ void SpeechSynthesis::SetMojomSynthesisForTesting( ...@@ -339,21 +342,17 @@ void SpeechSynthesis::SetMojomSynthesisForTesting(
GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI))); GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI)));
} }
void SpeechSynthesis::InitializeMojomSynthesis() { mojom::blink::SpeechSynthesis* SpeechSynthesis::TryEnsureMojomSynthesis() {
DCHECK(!mojom_synthesis_.is_bound()); if (mojom_synthesis_.is_bound())
return mojom_synthesis_.get();
// The frame could be detached. In that case, calls on mojom_synthesis_ will // The frame could be detached. In that case, calls on mojom_synthesis_ will
// just get dropped. That's okay and is simpler than having to null-check // just get dropped. That's okay and is simpler than having to null-check
// mojom_synthesis_ before each use. // mojom_synthesis_ before each use.
ExecutionContext* context = GetExecutionContext(); ExecutionContext* context = GetExecutionContext();
if (!context) { if (!context)
// Mimic the LocalDOMWindow::GetTaskRunner code that uses the current return nullptr;
// task runner when frames are detached.
ignore_result(mojom_synthesis_.BindNewPipeAndPassReceiver(
Thread::Current()->GetTaskRunner()));
return;
}
auto receiver = mojom_synthesis_.BindNewPipeAndPassReceiver( auto receiver = mojom_synthesis_.BindNewPipeAndPassReceiver(
context->GetTaskRunner(TaskType::kMiscPlatformAPI)); context->GetTaskRunner(TaskType::kMiscPlatformAPI));
...@@ -362,11 +361,7 @@ void SpeechSynthesis::InitializeMojomSynthesis() { ...@@ -362,11 +361,7 @@ void SpeechSynthesis::InitializeMojomSynthesis() {
mojom_synthesis_->AddVoiceListObserver(receiver_.BindNewPipeAndPassRemote( mojom_synthesis_->AddVoiceListObserver(receiver_.BindNewPipeAndPassRemote(
context->GetTaskRunner(TaskType::kMiscPlatformAPI))); context->GetTaskRunner(TaskType::kMiscPlatformAPI)));
} return mojom_synthesis_.get();
void SpeechSynthesis::InitializeMojomSynthesisIfNeeded() {
if (!mojom_synthesis_.is_bound())
InitializeMojomSynthesis();
} }
const AtomicString& SpeechSynthesis::InterfaceName() const { const AtomicString& SpeechSynthesis::InterfaceName() const {
......
...@@ -125,8 +125,7 @@ class MODULES_EXPORT SpeechSynthesis final ...@@ -125,8 +125,7 @@ class MODULES_EXPORT SpeechSynthesis final
void SetMojomSynthesisForTesting( void SetMojomSynthesisForTesting(
mojo::PendingRemote<mojom::blink::SpeechSynthesis>); mojo::PendingRemote<mojom::blink::SpeechSynthesis>);
void InitializeMojomSynthesis(); mojom::blink::SpeechSynthesis* TryEnsureMojomSynthesis();
void InitializeMojomSynthesisIfNeeded();
HeapMojoReceiver<mojom::blink::SpeechSynthesisVoiceListObserver, HeapMojoReceiver<mojom::blink::SpeechSynthesisVoiceListObserver,
SpeechSynthesis> SpeechSynthesis>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment