tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SpeechDispatcherParent.sys.mjs (2364B)


      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/. */
      5 
      6 export class SpeechDispatcherParent extends JSWindowActorParent {
      7  prefName() {
      8    return "media.webspeech.synth.dont_notify_on_error";
      9  }
     10 
     11  disableNotification() {
     12    Services.prefs.setBoolPref(this.prefName(), true);
     13  }
     14 
     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;
     18 
     19    if (!browser) {
     20      // We don't have a browser so bail!
     21      return;
     22    }
     23 
     24    let notificationId;
     25 
     26    if (Services.prefs.getBoolPref(this.prefName(), false)) {
     27      console.info("Opted out from speech-dispatcher error notification");
     28      return;
     29    }
     30 
     31    let messageId;
     32    switch (aMessage.data) {
     33      case "lib-missing":
     34        messageId = "speech-dispatcher-lib-missing";
     35        break;
     36 
     37      case "lib-too-old":
     38        messageId = "speech-dispatcher-lib-too-old";
     39        break;
     40 
     41      case "missing-symbol":
     42        messageId = "speech-dispatcher-missing-symbol";
     43        break;
     44 
     45      case "open-fail":
     46        messageId = "speech-dispatcher-open-fail";
     47        break;
     48 
     49      case "no-voices":
     50        messageId = "speech-dispatcher-no-voices";
     51        break;
     52 
     53      default:
     54        break;
     55    }
     56 
     57    let MozXULElement = browser.ownerGlobal.MozXULElement;
     58    MozXULElement.insertFTLIfNeeded("browser/speechDispatcher.ftl");
     59 
     60    // Now actually create the notification
     61    let notificationBox = browser.getTabBrowser().getNotificationBox(browser);
     62    if (notificationBox.getNotificationWithValue(notificationId)) {
     63      return;
     64    }
     65 
     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    ];
     77 
     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  }
     90 }