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) {
// TODO(crbug/811929): Consider moving this logic into the Android-
// specific backend implementation.
#else
synthesis->InitializeMojomSynthesis();
ignore_result(synthesis->TryEnsureMojomSynthesis());
#endif
}
return synthesis;
......@@ -90,7 +90,7 @@ void SpeechSynthesis::OnSetVoiceList(
const HeapVector<Member<SpeechSynthesisVoice>>& SpeechSynthesis::getVoices() {
// Kick off initialization here to ensure voice list gets populated.
InitializeMojomSynthesisIfNeeded();
ignore_result(TryEnsureMojomSynthesis());
return voice_list_;
}
......@@ -143,24 +143,27 @@ void SpeechSynthesis::cancel() {
// fire events on them asynchronously.
utterance_queue_.clear();
InitializeMojomSynthesisIfNeeded();
mojom_synthesis_->Cancel();
if (mojom::blink::SpeechSynthesis* mojom_synthesis =
TryEnsureMojomSynthesis())
mojom_synthesis->Cancel();
}
void SpeechSynthesis::pause() {
if (is_paused_)
return;
InitializeMojomSynthesisIfNeeded();
mojom_synthesis_->Pause();
if (mojom::blink::SpeechSynthesis* mojom_synthesis =
TryEnsureMojomSynthesis())
mojom_synthesis->Pause();
}
void SpeechSynthesis::resume() {
if (!CurrentSpeechUtterance())
return;
InitializeMojomSynthesisIfNeeded();
mojom_synthesis_->Resume();
if (mojom::blink::SpeechSynthesis* mojom_synthesis =
TryEnsureMojomSynthesis())
mojom_synthesis->Resume();
}
void SpeechSynthesis::DidStartSpeaking(SpeechSynthesisUtterance* utterance) {
......@@ -220,8 +223,8 @@ void SpeechSynthesis::StartSpeakingImmediately() {
utterance->SetStartTime(millis / 1000.0);
is_paused_ = false;
InitializeMojomSynthesisIfNeeded();
utterance->Start(this);
if (TryEnsureMojomSynthesis())
utterance->Start(this);
}
void SpeechSynthesis::HandleSpeakingCompleted(
......@@ -339,21 +342,17 @@ void SpeechSynthesis::SetMojomSynthesisForTesting(
GetExecutionContext()->GetTaskRunner(TaskType::kMiscPlatformAPI)));
}
void SpeechSynthesis::InitializeMojomSynthesis() {
DCHECK(!mojom_synthesis_.is_bound());
mojom::blink::SpeechSynthesis* SpeechSynthesis::TryEnsureMojomSynthesis() {
if (mojom_synthesis_.is_bound())
return mojom_synthesis_.get();
// 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
// mojom_synthesis_ before each use.
ExecutionContext* context = GetExecutionContext();
if (!context) {
// Mimic the LocalDOMWindow::GetTaskRunner code that uses the current
// task runner when frames are detached.
ignore_result(mojom_synthesis_.BindNewPipeAndPassReceiver(
Thread::Current()->GetTaskRunner()));
return;
}
if (!context)
return nullptr;
auto receiver = mojom_synthesis_.BindNewPipeAndPassReceiver(
context->GetTaskRunner(TaskType::kMiscPlatformAPI));
......@@ -362,11 +361,7 @@ void SpeechSynthesis::InitializeMojomSynthesis() {
mojom_synthesis_->AddVoiceListObserver(receiver_.BindNewPipeAndPassRemote(
context->GetTaskRunner(TaskType::kMiscPlatformAPI)));
}
void SpeechSynthesis::InitializeMojomSynthesisIfNeeded() {
if (!mojom_synthesis_.is_bound())
InitializeMojomSynthesis();
return mojom_synthesis_.get();
}
const AtomicString& SpeechSynthesis::InterfaceName() const {
......
......@@ -125,8 +125,7 @@ class MODULES_EXPORT SpeechSynthesis final
void SetMojomSynthesisForTesting(
mojo::PendingRemote<mojom::blink::SpeechSynthesis>);
void InitializeMojomSynthesis();
void InitializeMojomSynthesisIfNeeded();
mojom::blink::SpeechSynthesis* TryEnsureMojomSynthesis();
HeapMojoReceiver<mojom::blink::SpeechSynthesisVoiceListObserver,
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