tor-browser

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

accessibility.js (3728B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const { Actor } = require("resource://devtools/shared/protocol.js");
      8 const {
      9  accessibilitySpec,
     10 } = require("resource://devtools/shared/specs/accessibility.js");
     11 
     12 loader.lazyRequireGetter(
     13  this,
     14  "AccessibleWalkerActor",
     15  "resource://devtools/server/actors/accessibility/walker.js",
     16  true
     17 );
     18 loader.lazyRequireGetter(
     19  this,
     20  "SimulatorActor",
     21  "resource://devtools/server/actors/accessibility/simulator.js",
     22  true
     23 );
     24 
     25 /**
     26 * The AccessibilityActor is a top level container actor that initializes
     27 * accessible walker and is the top-most point of interaction for accessibility
     28 * tools UI for a top level content process.
     29 */
     30 class AccessibilityActor extends Actor {
     31  constructor(conn, targetActor) {
     32    super(conn, accessibilitySpec);
     33    // This event is fired when accessibility service is initialized or shut
     34    // down. "init" and "shutdown" events are only relayed when the enabled
     35    // state matches the event (e.g. the event came from the same process as
     36    // the actor).
     37    Services.obs.addObserver(this, "a11y-init-or-shutdown");
     38    this.targetActor = targetActor;
     39  }
     40 
     41  getTraits() {
     42    // The traits are used to know if accessibility actors support particular
     43    // API on the server side.
     44    return {
     45      // @backward-compat { version 84 } Fixed on the server by Bug 1654956.
     46      tabbingOrder: true,
     47    };
     48  }
     49 
     50  bootstrap() {
     51    return {
     52      enabled: this.enabled,
     53    };
     54  }
     55 
     56  get enabled() {
     57    return Services.appinfo.accessibilityEnabled;
     58  }
     59 
     60  /**
     61   * Observe Accessibility service init and shutdown events. It relays these
     62   * events to AccessibilityFront if the event is fired for the a11y service
     63   * that lives in the same process.
     64   *
     65   * @param  {null} subject
     66   *         Not used.
     67   * @param  {string} topic
     68   *         Name of the a11y service event: "a11y-init-or-shutdown".
     69   * @param  {string} data
     70   *         "0" corresponds to shutdown and "1" to init.
     71   */
     72  observe(subject, topic, data) {
     73    const enabled = data === "1";
     74    if (enabled && this.enabled) {
     75      this.emit("init");
     76    } else if (!enabled && !this.enabled) {
     77      if (this.walker) {
     78        this.walker.reset();
     79      }
     80 
     81      this.emit("shutdown");
     82    }
     83  }
     84 
     85  /**
     86   * Get or create AccessibilityWalker actor, similar to WalkerActor.
     87   *
     88   * @return {object}
     89   *         AccessibleWalkerActor for the current tab.
     90   */
     91  getWalker() {
     92    if (!this.walker) {
     93      this.walker = new AccessibleWalkerActor(this.conn, this.targetActor);
     94      this.manage(this.walker);
     95    }
     96    return this.walker;
     97  }
     98 
     99  /**
    100   * Get or create Simulator actor, managed by AccessibilityActor,
    101   * only if webrender is enabled. Simulator applies color filters on an entire
    102   * viewport. This needs to be done using webrender and not an SVG
    103   * <feColorMatrix> since it is accelerated and scrolling with filter applied
    104   * needs to be smooth (Bug1431466).
    105   *
    106   * @return {object | null}
    107   *         SimulatorActor for the current tab.
    108   */
    109  getSimulator() {
    110    if (!this.simulator) {
    111      this.simulator = new SimulatorActor(this.conn, this.targetActor);
    112      this.manage(this.simulator);
    113    }
    114 
    115    return this.simulator;
    116  }
    117 
    118  /**
    119   * Destroy accessibility actor. This method also shutsdown accessibility
    120   * service if possible.
    121   */
    122  async destroy() {
    123    super.destroy();
    124    Services.obs.removeObserver(this, "a11y-init-or-shutdown");
    125    this.walker = null;
    126    this.targetActor = null;
    127  }
    128 }
    129 
    130 exports.AccessibilityActor = AccessibilityActor;