mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 878958: Implement ChildDebuggerTransport, a debug protocol transport for communicating with content child processes via process message managers. r=dcamp
Transport classes (or prototypes?) should have a label that the requester telemetry stuff can cite, instead of that freaky check we have now.
This commit is contained in:
parent
62df5c4f44
commit
bbb754faad
@ -11,6 +11,8 @@ Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
* An adapter that handles data transfers between the debugger client and
|
||||
* server. It can work with both nsIPipe and nsIServerSocket transports so
|
||||
* long as the properly created input and output streams are specified.
|
||||
* (However, for intra-process connections, LocalDebuggerTransport, below,
|
||||
* is more efficient than using an nsIPipe pair with DebuggerTransport.)
|
||||
*
|
||||
* @param aInput nsIInputStream
|
||||
* The input stream.
|
||||
@ -20,12 +22,12 @@ Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
* Given a DebuggerTransport instance dt:
|
||||
* 1) Set dt.hooks to a packet handler object (described below).
|
||||
* 2) Call dt.ready() to begin watching for input packets.
|
||||
* 3) Send packets as you please, and handle incoming packets passed to
|
||||
* hook.onPacket.
|
||||
* 3) Call dt.send() to send packets as you please, and handle incoming
|
||||
* packets passed to hook.onPacket.
|
||||
* 4) Call dt.close() to close the connection, and disengage from the event
|
||||
* loop.
|
||||
*
|
||||
* A packet handler object is an object with two methods:
|
||||
* A packet handler is an object with two methods:
|
||||
*
|
||||
* - onPacket(packet) - called when we have received a complete packet.
|
||||
* |Packet| is the parsed form of the packet --- a JavaScript value, not
|
||||
@ -33,7 +35,7 @@ Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
*
|
||||
* - onClosed(status) - called when the connection is closed. |Status| is
|
||||
* an nsresult, of the sort passed to nsIRequestObserver.
|
||||
*
|
||||
*
|
||||
* Data is transferred as a JSON packet serialized into a string, with the
|
||||
* string length prepended to the packet, followed by a colon
|
||||
* ([length]:[packet]). The contents of the JSON packet are specified in
|
||||
@ -278,3 +280,50 @@ LocalDebuggerTransport.prototype = {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A transport for the debugging protocol that uses nsIMessageSenders to
|
||||
* exchange packets with servers running in child processes.
|
||||
*
|
||||
* In the parent process, |aSender| should be the nsIMessageSender for the
|
||||
* child process. In a child process, |aSender| should be the child process
|
||||
* message manager, which sends packets to the parent.
|
||||
*
|
||||
* aPrefix is a string included in the message names, to distinguish
|
||||
* multiple servers running in the same child process.
|
||||
*
|
||||
* This transport exchanges messages named 'debug:<prefix>:packet', where
|
||||
* <prefix> is |aPrefix|, whose data is the protocol packet.
|
||||
*/
|
||||
function ChildDebuggerTransport(aSender, aPrefix) {
|
||||
this._sender = aSender.QueryInterface(Components.interfaces.nsIMessageSender);
|
||||
this._messageName = "debug:" + aPrefix + ":packet";
|
||||
}
|
||||
|
||||
/*
|
||||
* To avoid confusion, we use 'message' to mean something that
|
||||
* nsIMessageSender conveys, and 'packet' to mean a remote debugging
|
||||
* protocol packet.
|
||||
*/
|
||||
ChildDebuggerTransport.prototype = {
|
||||
constructor: ChildDebuggerTransport,
|
||||
|
||||
hooks: null,
|
||||
|
||||
ready: function () {
|
||||
this._sender.addMessageListener(this._messageName, this);
|
||||
},
|
||||
|
||||
close: function () {
|
||||
this._sender.removeMessageListener(this._messageName, this);
|
||||
this.hooks.onClosed();
|
||||
},
|
||||
|
||||
receiveMessage: function ({data}) {
|
||||
this.hooks.onPacket(data);
|
||||
},
|
||||
|
||||
send: function (packet) {
|
||||
this._sender.sendAsyncMessage(this._messageName, packet);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user