--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -1520,16 +1520,17 @@ NetworkMonitor.prototype = {
function NetworkMonitorChild(outerWindowID, messageManager, conn, owner) {
this.outerWindowID = outerWindowID;
this.conn = conn;
this.owner = owner;
this._messageManager = messageManager;
this._onNewEvent = this._onNewEvent.bind(this);
this._onUpdateEvent = this._onUpdateEvent.bind(this);
this._netEvents = new Map();
+ this._msgName = `debug:${this.conn.prefix}netmonitor`;
}
exports.NetworkMonitorChild = NetworkMonitorChild;
NetworkMonitorChild.prototype = {
owner: null,
_netEvents: null,
_saveRequestAndResponseBodies: true,
@@ -1537,51 +1538,49 @@ NetworkMonitorChild.prototype = {
get saveRequestAndResponseBodies() {
return this._saveRequestAndResponseBodies;
},
set saveRequestAndResponseBodies(val) {
this._saveRequestAndResponseBodies = val;
- this._messageManager.sendAsyncMessage("debug:netmonitor", {
+ this._messageManager.sendAsyncMessage(this._msgName, {
action: "setPreferences",
preferences: {
saveRequestAndResponseBodies: this._saveRequestAndResponseBodies,
},
});
},
get throttleData() {
return this._throttleData;
},
set throttleData(val) {
this._throttleData = val;
- this._messageManager.sendAsyncMessage("debug:netmonitor", {
+ this._messageManager.sendAsyncMessage(this._msgName, {
action: "setPreferences",
preferences: {
throttleData: this._throttleData,
},
});
},
init: function () {
this.conn.setupInParent({
module: "devtools/shared/webconsole/network-monitor",
setupParent: "setupParentProcess"
});
let mm = this._messageManager;
- mm.addMessageListener("debug:netmonitor:newEvent",
- this._onNewEvent);
- mm.addMessageListener("debug:netmonitor:updateEvent",
- this._onUpdateEvent);
- mm.sendAsyncMessage("debug:netmonitor", {
+ mm.addMessageListener(`${this._msgName}:newEvent`, this._onNewEvent);
+ mm.addMessageListener(`${this._msgName}:updateEvent`, this._onUpdateEvent);
+ mm.sendAsyncMessage(this._msgName, {
outerWindowID: this.outerWindowID,
action: "start",
});
},
_onNewEvent: DevToolsUtils.makeInfallible(function _onNewEvent(msg) {
let {id, event} = msg.data;
@@ -1595,35 +1594,32 @@ NetworkMonitorChild.prototype = {
this._netEvents.set(id, Cu.getWeakReference(actor));
}),
_onUpdateEvent: DevToolsUtils.makeInfallible(function _onUpdateEvent(msg) {
let {id, method, args} = msg.data;
let weakActor = this._netEvents.get(id);
let actor = weakActor ? weakActor.get() : null;
if (!actor) {
- console.error("Received debug:netmonitor:updateEvent for unknown " +
- "event ID: " + id);
+ console.error(`Received ${this._msgName}:updateEvent for unknown event ID: ${id}`);
return;
}
if (!(method in actor)) {
- console.error("Received debug:netmonitor:updateEvent unsupported " +
- "method: " + method);
+ console.error(`Received ${this._msgName}:updateEvent unsupported ` +
+ `method: ${method}`);
return;
}
actor[method].apply(actor, args);
}),
destroy: function () {
let mm = this._messageManager;
try {
- mm.removeMessageListener("debug:netmonitor:newEvent",
- this._onNewEvent);
- mm.removeMessageListener("debug:netmonitor:updateEvent",
- this._onUpdateEvent);
+ mm.removeMessageListener(`${this._msgName}:newEvent`, this._onNewEvent);
+ mm.removeMessageListener(`${this._msgName}:updateEvent`, this._onUpdateEvent);
} catch (e) {
// On b2g, when registered to a new root docshell,
// all message manager functions throw when trying to call them during
// message-manager-disconnect event.
// As there is no attribute/method on message manager to know
// if they are still usable or not, we can only catch the exception...
}
this._netEvents.clear();
@@ -1642,28 +1638,31 @@ NetworkMonitorChild.prototype = {
* The child process has a NetworkMonitorChild instance that is listening for
* all network logging from the main process. The net monitor shim is used to
* proxy the data to the WebConsoleActor instance of the child process.
*
* @constructor
* @param nsIMessageManager messageManager
* The message manager for the child app process. This is used for
* communication with the NetworkMonitorChild instance of the process.
+ * @param string msgName
+ * The message name to be used for this connection.
*/
-function NetworkEventActorProxy(messageManager) {
+function NetworkEventActorProxy(messageManager, msgName) {
this.id = gSequenceId();
this.messageManager = messageManager;
+ this._msgName = msgName;
}
exports.NetworkEventActorProxy = NetworkEventActorProxy;
NetworkEventActorProxy.methodFactory = function (method) {
return DevToolsUtils.makeInfallible(function () {
let args = Array.slice(arguments);
let mm = this.messageManager;
- mm.sendAsyncMessage("debug:netmonitor:updateEvent", {
+ mm.sendAsyncMessage(`${this._msgName}:updateEvent`, {
id: this.id,
method: method,
args: args,
});
}, "NetworkEventActorProxy." + method);
};
NetworkEventActorProxy.prototype = {
@@ -1673,17 +1672,17 @@ NetworkEventActorProxy.prototype = {
*
* @param object event
* Object describing the network request.
* @return object
* This object.
*/
init: DevToolsUtils.makeInfallible(function (event) {
let mm = this.messageManager;
- mm.sendAsyncMessage("debug:netmonitor:newEvent", {
+ mm.sendAsyncMessage(`${this._msgName}:newEvent`, {
id: this.id,
event: event,
});
return this;
}),
};
(function () {
@@ -1721,38 +1720,39 @@ exports.setupParentProcess = setupParent
* monitor needs to run there when debugging tabs that are in the child.
*
* @param nsIMessageManager mm
* The message manager for the browser we're filtering on.
* @param string prefix
* The RDP connection prefix that uniquely identifies the connection.
*/
function NetworkMonitorParent(mm, prefix) {
+ this._msgName = `debug:${prefix}netmonitor`;
this.onNetMonitorMessage = this.onNetMonitorMessage.bind(this);
this.onNetworkEvent = this.onNetworkEvent.bind(this);
this.setMessageManager(mm);
}
NetworkMonitorParent.prototype = {
netMonitor: null,
messageManager: null,
setMessageManager(mm) {
if (this.messageManager) {
let oldMM = this.messageManager;
- oldMM.removeMessageListener("debug:netmonitor", this.onNetMonitorMessage);
+ oldMM.removeMessageListener(this._msgName, this.onNetMonitorMessage);
}
this.messageManager = mm;
if (mm) {
- mm.addMessageListener("debug:netmonitor", this.onNetMonitorMessage);
+ mm.addMessageListener(this._msgName, this.onNetMonitorMessage);
}
},
/**
- * Handler for "debug:netmonitor" messages received through the message manager
+ * Handler for `debug:${prefix}netmonitor` messages received through the message manager
* from the content process.
*
* @param object msg
* Message from the content.
*/
onNetMonitorMessage: DevToolsUtils.makeInfallible(function (msg) {
let {action} = msg.json;
// Pipe network monitor data from parent to child via the message manager.
@@ -1797,17 +1797,17 @@ NetworkMonitorParent.prototype = {
*
* @param object event
* Object describing the network request.
* @return object
* A NetworkEventActorProxy instance which is notified when further
* data about the request is available.
*/
onNetworkEvent: DevToolsUtils.makeInfallible(function (event) {
- return new NetworkEventActorProxy(this.messageManager).init(event);
+ return new NetworkEventActorProxy(this.messageManager, this._msgName).init(event);
}),
destroy: function () {
this.setMessageManager(null);
if (this.netMonitor) {
this.netMonitor.destroy();
this.netMonitor = null;