Backed out 7 changesets (bug 1839993) for causing build bustages on DecoderTemplate...
[gecko.git] / browser / actors / SpeechDispatcherParent.sys.mjs
blob40ddf0b3c4da837f57acc95b9e914ffc523ae510
1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 export class SpeechDispatcherParent extends JSWindowActorParent {
7   prefName() {
8     return "media.webspeech.synth.dont_notify_on_error";
9   }
11   disableNotification() {
12     Services.prefs.setBoolPref(this.prefName(), true);
13   }
15   async receiveMessage(aMessage) {
16     // The top level browsing context's embedding element should be a xul browser element.
17     let browser = this.browsingContext.top.embedderElement;
19     if (!browser) {
20       // We don't have a browser so bail!
21       return;
22     }
24     let notificationId;
26     if (Services.prefs.getBoolPref(this.prefName(), false)) {
27       console.info("Opted out from speech-dispatcher error notification");
28       return;
29     }
31     let messageId;
32     switch (aMessage.data) {
33       case "lib-missing":
34         messageId = "speech-dispatcher-lib-missing";
35         break;
37       case "lib-too-old":
38         messageId = "speech-dispatcher-lib-too-old";
39         break;
41       case "missing-symbol":
42         messageId = "speech-dispatcher-missing-symbol";
43         break;
45       case "open-fail":
46         messageId = "speech-dispatcher-open-fail";
47         break;
49       case "no-voices":
50         messageId = "speech-dispatcher-no-voices";
51         break;
53       default:
54         break;
55     }
57     let MozXULElement = browser.ownerGlobal.MozXULElement;
58     MozXULElement.insertFTLIfNeeded("browser/speechDispatcher.ftl");
60     // Now actually create the notification
61     let notificationBox = browser.getTabBrowser().getNotificationBox(browser);
62     if (notificationBox.getNotificationWithValue(notificationId)) {
63       return;
64     }
66     let buttons = [
67       {
68         supportPage: "speechd-setup",
69       },
70       {
71         "l10n-id": "speech-dispatcher-dismiss-button",
72         callback: () => {
73           this.disableNotification();
74         },
75       },
76     ];
78     let iconURL = "chrome://browser/skin/drm-icon.svg";
79     notificationBox.appendNotification(
80       notificationId,
81       {
82         label: { "l10n-id": messageId },
83         image: iconURL,
84         priority: notificationBox.PRIORITY_INFO_HIGH,
85         type: "warning",
86       },
87       buttons
88     );
89   }