Bug 1178738 - Update narrator to use error events when narration is stopped. r?Gijs draft
authorEitan Isaacson <eitan@monotonous.org>
Wed, 18 May 2016 09:50:04 -0700
changeset 374472 b04352fe7f621105c8a27627760610753bab0b5c
parent 374471 4ff825245d66df4696225136148e7a824ce1e2c4
child 522644 1920009a41e4375597254d30ffbbf9663ef6de55
push id20034
push userbmo:eitan@monotonous.org
push dateThu, 02 Jun 2016 16:08:31 +0000
reviewersGijs
bugs1178738
milestone49.0a1
Bug 1178738 - Update narrator to use error events when narration is stopped. r?Gijs MozReview-Commit-ID: L9Bd2WDdlMp
toolkit/components/narrate/Narrator.jsm
--- a/toolkit/components/narrate/Narrator.jsm
+++ b/toolkit/components/narrate/Narrator.jsm
@@ -172,39 +172,44 @@ Narrator.prototype = {
           this._sendTestEvent("paragraphstart", {
             voice: utterance.chosenVoiceURI,
             rate: utterance.rate,
             paragraph: paragraph.textContent
           });
         }
       });
 
-      utterance.addEventListener("end", () => {
+      let onDone = (e) => {
         if (!this._win) {
           // page got unloaded, don't do anything.
           return;
         }
 
+        if (e.type == "error" &&
+            !(['interrupted', 'canceled'].includes(e.error))) {
+          reject("speech synthesis failed");
+          return;
+        }
+
         paragraph.classList.remove("narrating");
         this._startTime = 0;
         if (this._inTest) {
           this._sendTestEvent("paragraphend", {});
         }
 
         if (this._stopped) {
           // User pressed stopped.
           resolve();
         } else {
           this._speakInner().then(resolve, reject);
         }
-      });
+      };
 
-      utterance.addEventListener("error", () => {
-        reject("speech synthesis failed");
-      });
+      utterance.addEventListener("end", onDone);
+      utterance.addEventListener("error", onDone);
 
       this._win.speechSynthesis.speak(utterance);
     });
   },
 
   start: function(speechOptions) {
     this._speechOptions = {
       rate: speechOptions.rate,