Commit 0f09a67c authored by Paul Adenot's avatar Paul Adenot Committed by Pier Angelo Vendrame
Browse files

Bug 2021222 - Cancel SpeechSynthesis when the page navigates away. r=eeejay

Override DisconnectFromOwner, which is called during navigation, to cancel any
ongoing or queued speech utterances.

Differential Revision: https://phabricator.services.mozilla.com/D290201
parent fb292f93
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -273,6 +273,11 @@ void SpeechSynthesis::ForceEnd() {
  }
}

void SpeechSynthesis::DisconnectFromOwner() {
  Cancel();
  DOMEventTargetHelper::DisconnectFromOwner();
}

NS_IMETHODIMP
SpeechSynthesis::Observe(nsISupports* aSubject, const char* aTopic,
                         const char16_t* aData) {
+2 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ class SpeechSynthesis final : public DOMEventTargetHelper,

  void ForceEnd();

  void DisconnectFromOwner() override;

  IMPL_EVENT_HANDLER(voiceschanged)

 private:
+11 −0
Original line number Diff line number Diff line
<html>
<script>
  var u = new SpeechSynthesisUtterance("hello");
  u.lang = "it-IT-noend";
  u.addEventListener("start", function() {
    location = "file_speech_cancel_on_navigation_page2.html";
  });
  speechSynthesis.speak(u);
</script>
<body></body>
</html>
+13 −0
Original line number Diff line number Diff line
<html>
<script>
  window.ok = parent.ok;

  var u = new SpeechSynthesisUtterance("hi");
  u.addEventListener("end", function() {
    ok(true, "Speech in new page completed: previous speech was cancelled on navigation.");
    parent.onDone();
  });
  speechSynthesis.speak(u);
</script>
<body></body>
</html>
+4 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ support-files = [
  "file_global_queue_cancel.html",
  "file_global_queue_pause.html",
  "file_speech_repeating_utterance.html",
  "file_speech_cancel_on_navigation_page1.html",
  "file_speech_cancel_on_navigation_page2.html",
]

["test_bfcache.html"]
@@ -38,3 +40,5 @@ support-files = [
["test_speech_repeating_utterance.html"]

["test_speech_simple.html"]

["test_speech_cancel_on_navigation.html"]
Loading