Bug 1859954 - Use XP_DARWIN rather than XP_MACOS in PHC r=glandium
[gecko.git] / devtools / shared / transport / js-window-actor-transport.js
blob9f0fb82497c3650b2863ec184601f5ca8f7d4245
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/. */
5 "use strict";
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;
23     this._onPacketReceived = this._onPacketReceived.bind(this);
24   }
26   _addListener() {
27     this._jsWindowActor.on("packet-received", this._onPacketReceived);
28   }
30   _removeListener() {
31     this._jsWindowActor.off("packet-received", this._onPacketReceived);
32   }
34   ready() {
35     this._addListener();
36   }
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   }
50   _onPacketReceived(eventName, { data }) {
51     const { prefix, packet } = data;
52     if (prefix === this._prefix) {
53       this.hooks.onPacket(packet);
54     }
55   }
57   send(packet) {
58     this._jsWindowActor.sendPacket(packet, this._prefix);
59   }
61   startBulkSend() {
62     throw new Error("startBulkSend not implemented for JsWindowActorTransport");
63   }
66 exports.JsWindowActorTransport = JsWindowActorTransport;