tor-browser

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

js-window-actor-transport.js (1902B)


      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 /**
      8 * DevTools transport relying on JS Window Actors. This is an experimental
      9 * transport. It is only used when using the JS Window Actor based frame
     10 * connector. In that case this transport will be used to communicate between
     11 * the DevToolsServer living in the parent process and the DevToolsServer
     12 * living in the process of the target frame.
     13 *
     14 * This is intended to be a replacement for child-transport.js which is a
     15 * message-manager based transport.
     16 */
     17 class JsWindowActorTransport {
     18  constructor(jsWindowActor, prefix) {
     19    this.hooks = null;
     20    this._jsWindowActor = jsWindowActor;
     21    this._prefix = prefix;
     22 
     23    this._onPacketReceived = this._onPacketReceived.bind(this);
     24  }
     25 
     26  _addListener() {
     27    this._jsWindowActor.on("packet-received", this._onPacketReceived);
     28  }
     29 
     30  _removeListener() {
     31    this._jsWindowActor.off("packet-received", this._onPacketReceived);
     32  }
     33 
     34  ready() {
     35    this._addListener();
     36  }
     37 
     38  /**
     39   * @param {object} options
     40   * @param {boolean} options.isModeSwitching
     41   *        true when this is called as the result of a change to the devtools.browsertoolbox.scope pref
     42   */
     43  close(options) {
     44    this._removeListener();
     45    if (this.hooks.onTransportClosed) {
     46      this.hooks.onTransportClosed(null, options);
     47    }
     48  }
     49 
     50  _onPacketReceived(eventName, { data }) {
     51    const { prefix, packet } = data;
     52    if (prefix === this._prefix) {
     53      this.hooks.onPacket(packet);
     54    }
     55  }
     56 
     57  send(packet) {
     58    this._jsWindowActor.sendPacket(packet, this._prefix);
     59  }
     60 
     61  startBulkSend() {
     62    throw new Error("startBulkSend not implemented for JsWindowActorTransport");
     63  }
     64 }
     65 
     66 exports.JsWindowActorTransport = JsWindowActorTransport;