Bug 1317413 - Separate net monitor messages by RDP prefix. r=tromey a=jcristau
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 17 Nov 2016 18:06:13 -0600
changeset 352661 bafd3cf3970490e029351e6befa56667f568f85f
parent 352660 a7c5e5d204bdf11a3aa6d44cc0b08fd7a770344f
child 352662 d87b17a47f600b30cad7e7a48dfaa42d3faa7678
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstromey, jcristau
bugs1317413
milestone52.0a2
Bug 1317413 - Separate net monitor messages by RDP prefix. r=tromey a=jcristau In RDM, we use one net monitor RDP connection to set throttling values from the UI and the toolbox uses a second connection to display requests. When passing data across processes, we need to include the RDP connection prefix in the name to ensure it's routed properly to the right RDP connection. MozReview-Commit-ID: 56fP9d4xj66
devtools/shared/webconsole/network-monitor.js
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -1516,16 +1516,17 @@ function NetworkMonitorChild(appId, oute
   this.appId = appId;
   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 = {
   appId: null,
   owner: null,
   _netEvents: null,
@@ -1534,51 +1535,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, {
       appId: this.appId,
       outerWindowID: this.outerWindowID,
       action: "start",
     });
   },
 
   _onNewEvent: DevToolsUtils.makeInfallible(function _onNewEvent(msg) {
     let {id, event} = msg.data;
@@ -1593,35 +1592,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();
@@ -1640,28 +1636,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 = {
@@ -1671,17 +1670,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 () {
@@ -1719,38 +1718,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.
@@ -1795,17 +1795,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;