Bug 1437332 - Stop narration on unload. r=Gijs
authorEitan Isaacson <eitan@monotonous.org>
Mon, 26 Feb 2018 16:08:00 +0200
changeset 405609 c394578ac6678d28269709790c4f572cd017e0cb
parent 405608 c0a9a2976d793e09d46d48c1d050de16dc118348
child 405610 8a60cb3337c129909bf4c62b27a3720ffef7e46f
push id100263
push userbtara@mozilla.com
push dateWed, 28 Feb 2018 04:58:12 +0000
treeherdermozilla-inbound@1e97b5ef21b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1437332
milestone60.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 1437332 - Stop narration on unload. r=Gijs
toolkit/components/narrate/NarrateControls.jsm
--- a/toolkit/components/narrate/NarrateControls.jsm
+++ b/toolkit/components/narrate/NarrateControls.jsm
@@ -142,19 +142,17 @@ NarrateControls.prototype = {
         break;
       case "click":
         this._onButtonClick(evt);
         break;
       case "voiceschanged":
         this._setupVoices();
         break;
       case "unload":
-        if (this.narrator.speaking) {
-          TelemetryStopwatch.finish("NARRATE_CONTENT_SPEAKTIME_MS", this);
-        }
+        this.narrator.stop();
         break;
     }
   },
 
   /**
    * Returns true if synth voices are available.
    */
   _setupVoices() {
@@ -236,44 +234,44 @@ NarrateControls.prototype = {
       this.narrator.skipPrevious();
     } else if (classList.contains("narrate-skip-next")) {
       this.narrator.skipNext();
     } else if (classList.contains("narrate-start-stop")) {
       if (this.narrator.speaking) {
         this.narrator.stop();
       } else {
         this._updateSpeechControls(true);
+        TelemetryStopwatch.start("NARRATE_CONTENT_SPEAKTIME_MS", this);
         let options = { rate: this.rate, voice: this.voice };
-        this.narrator.start(options).then(() => {
+        this.narrator.start(options).catch(err => {
+          Cu.reportError(`Narrate failed: ${err}.`);
+        }).then(() => {
           this._updateSpeechControls(false);
-        }, err => {
-          Cu.reportError(`Narrate failed: ${err}.`);
-          this._updateSpeechControls(false);
+          TelemetryStopwatch.finish("NARRATE_CONTENT_SPEAKTIME_MS", this);
         });
       }
     }
   },
 
   _updateSpeechControls(speaking) {
     let dropdown = this._doc.querySelector(".narrate-dropdown");
+    if (!dropdown) {
+      // Elements got destroyed, but window lingers on for a bit.
+      return;
+    }
+
     dropdown.classList.toggle("keep-open", speaking);
     dropdown.classList.toggle("speaking", speaking);
 
     let startStopButton = this._doc.querySelector(".narrate-start-stop");
     startStopButton.title =
       gStrings.GetStringFromName(speaking ? "stop" : "start");
 
     this._doc.querySelector(".narrate-skip-previous").disabled = !speaking;
     this._doc.querySelector(".narrate-skip-next").disabled = !speaking;
-
-    if (speaking) {
-      TelemetryStopwatch.start("NARRATE_CONTENT_SPEAKTIME_MS", this);
-    } else {
-      TelemetryStopwatch.finish("NARRATE_CONTENT_SPEAKTIME_MS", this);
-    }
   },
 
   _createVoiceLabel(voice) {
     // This is a highly imperfect method of making human-readable labels
     // for system voices. Because each platform has a different naming scheme
     // for voices, we use a different method for each platform.
     switch (Services.appinfo.OS) {
       case "WINNT":