Bug 1444132 - Remove the old proxy code. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 17 Jul 2018 02:23:49 -0700
changeset 826064 48ac26a8a15c762c558bc8037a159a1ac647d370
parent 826063 ace2f8e7a9c99077a49327c206cb6d8e96173e1e
child 826065 c993f615d1e6985369bccb2433fcb174181618bf
push id118238
push userbmo:mh+mozilla@glandium.org
push dateThu, 02 Aug 2018 22:02:22 +0000
reviewersjryans
bugs1444132
milestone63.0a1
Bug 1444132 - Remove the old proxy code. r=jryans MozReview-Commit-ID: 33LcN5c5o4D
devtools/server/actors/webconsole.js
devtools/shared/webconsole/network-monitor.js
--- a/devtools/server/actors/webconsole.js
+++ b/devtools/server/actors/webconsole.js
@@ -15,17 +15,16 @@ const { ActorPool } = require("devtools/
 const { ThreadActor } = require("devtools/server/actors/thread");
 const { ObjectActor } = require("devtools/server/actors/object");
 const { LongStringActor } = require("devtools/server/actors/object/long-string");
 const { createValueGrip, stringIsLong } = require("devtools/server/actors/object/utils");
 const DevToolsUtils = require("devtools/shared/DevToolsUtils");
 const ErrorDocs = require("devtools/server/actors/errordocs");
 
 loader.lazyRequireGetter(this, "NetworkMonitorActor", "devtools/server/actors/network-monitor", true);
-loader.lazyRequireGetter(this, "NetworkEventActor", "devtools/server/actors/network-event", true);
 loader.lazyRequireGetter(this, "ConsoleProgressListener", "devtools/shared/webconsole/network-monitor", true);
 loader.lazyRequireGetter(this, "StackTraceCollector", "devtools/shared/webconsole/network-monitor", true);
 loader.lazyRequireGetter(this, "JSPropertyProvider", "devtools/shared/webconsole/js-property-provider", true);
 loader.lazyRequireGetter(this, "Parser", "resource://devtools/shared/Parser.jsm", true);
 loader.lazyRequireGetter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm", true);
 loader.lazyRequireGetter(this, "WebConsoleCommands", "devtools/server/actors/webconsole/utils", true);
 loader.lazyRequireGetter(this, "addWebConsoleCommands", "devtools/server/actors/webconsole/utils", true);
 loader.lazyRequireGetter(this, "formatCommand", "devtools/server/actors/webconsole/commands", true);
@@ -69,18 +68,16 @@ function WebConsoleActor(connection, par
 
   this._actorPool = new ActorPool(this.conn);
   this.conn.addActorPool(this._actorPool);
 
   this._prefs = {};
 
   this.dbg = this.parentActor.makeDebugger();
 
-  this._netEvents = new Map();
-  this._networkEventActorsByURL = new Map();
   this._gripDepth = 0;
   this._listeners = new Set();
   this._lastConsoleInputEvaluation = undefined;
 
   this.objectGrip = this.objectGrip.bind(this);
   this._onWillNavigate = this._onWillNavigate.bind(this);
   this._onChangedToplevelDocument = this._onChangedToplevelDocument.bind(this);
   EventEmitter.on(this.parentActor, "changed-toplevel-document",
@@ -126,35 +123,16 @@ WebConsoleActor.prototype =
   /**
    * Web Console-related preferences.
    * @private
    * @type object
    */
   _prefs: null,
 
   /**
-   * Holds a map between nsIChannel objects and NetworkEventActors for requests
-   * created with sendHTTPRequest or found via the network listener.
-   *
-   * @private
-   * @type Map
-   */
-  _netEvents: null,
-
-  /**
-   * Holds a map from URL to NetworkEventActors for requests noticed by the network
-   * listener.  Requests are added when they start, so the actor might not yet have all
-   * data for the request until it has completed.
-   *
-   * @private
-   * @type Map
-   */
-  _networkEventActorsByURL: null,
-
-  /**
    * Holds a set of all currently registered listeners.
    *
    * @private
    * @type Set
    */
   _listeners: null,
 
   /**
@@ -390,17 +368,16 @@ WebConsoleActor.prototype =
       Services.obs.removeObserver(this._onObserverNotification,
                                   "last-pb-context-exited");
     }
 
     this._actorPool = null;
     this._webConsoleCommandsCache = null;
     this._lastConsoleInputEvaluation = null;
     this._evalWindow = null;
-    this._netEvents.clear();
     this.dbg.enabled = false;
     this.dbg = null;
     this.conn = null;
   },
 
   /**
    * Create and return an environment actor that corresponds to the provided
    * Debugger.Environment. This is a straightforward clone of the ThreadActor's
@@ -1731,68 +1708,16 @@ WebConsoleActor.prototype =
       from: this.actorID,
       type: "consoleAPICall",
       message: this.prepareConsoleMessageForRemote(message),
     };
     this.conn.send(packet);
   },
 
   /**
-   * Handler for network events. This method is invoked when a new network event
-   * is about to be recorded.
-   *
-   * @see NetworkEventActor
-   * @see NetworkMonitor from webconsole/utils.js
-   *
-   * @param object event
-   *        The initial network request event information.
-   * @return object
-   *         A new NetworkEventActor is returned. This is used for tracking the
-   *         network request and response.
-   */
-  onNetworkEvent: function(event) {
-    const actor = this.getNetworkEventActor(event.channelId);
-    actor.init(event);
-
-    this._networkEventActorsByURL.set(actor._request.url, actor);
-
-    const packet = {
-      from: this.actorID,
-      type: "networkEvent",
-      eventActor: actor.form()
-    };
-
-    this.conn.send(packet);
-
-    return actor;
-  },
-
-  /**
-   * Get the NetworkEventActor for a nsIHttpChannel, if it exists,
-   * otherwise create a new one.
-   *
-   * @param string channelId
-   *        The id of the channel for the network event.
-   * @return object
-   *         The NetworkEventActor for the given channel.
-   */
-  getNetworkEventActor: function(channelId) {
-    let actor = this._netEvents.get(channelId);
-    if (actor) {
-      // delete from map as we should only need to do this check once
-      this._netEvents.delete(channelId);
-      return actor;
-    }
-
-    actor = new NetworkEventActor(this);
-    this._actorPool.addActor(actor);
-    return actor;
-  },
-
-  /**
    * Get the NetworkEventActor for a given URL that may have been noticed by the network
    * listener.  Requests are added when they start, so the actor might not yet have all
    * data for the request until it has completed.
    *
    * @param string url
    *        The URL of the request to search for.
    */
   getRequestContentForURL(url) {
--- a/devtools/shared/webconsole/network-monitor.js
+++ b/devtools/shared/webconsole/network-monitor.js
@@ -1,17 +1,17 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft= javascript ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-const {Cc, Ci, Cm, Cu, Cr, components} = require("chrome");
+const {Cc, Ci, Cm, Cr, components} = require("chrome");
 const ChromeUtils = require("ChromeUtils");
 const Services = require("Services");
 const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
 
 loader.lazyRequireGetter(this, "NetworkHelper",
                          "devtools/shared/webconsole/network-helper");
 loader.lazyRequireGetter(this, "DevToolsUtils",
                          "devtools/shared/DevToolsUtils");
@@ -1722,338 +1722,16 @@ NetworkMonitor.prototype = {
     this.openResponses.clear();
     this.owner = null;
     this.filters = null;
     this._throttler = null;
   },
 };
 
 /**
- * The NetworkMonitorChild is used to proxy all of the network activity of the
- * child app process from the main process. The child WebConsoleActor creates an
- * instance of this object.
- *
- * Network requests for apps happen in the main process. As such,
- * a NetworkMonitor instance is used by the WebappsActor in the main process to
- * log the network requests for this child process.
- *
- * The main process creates NetworkEventActorProxy instances per request. These
- * send the data to this object using the nsIMessageManager. Here we proxy the
- * data to the WebConsoleActor or to a NetworkEventActor.
- *
- * @constructor
- * @param number outerWindowID
- *        The outerWindowID of the target actor's main window.
- * @param nsIMessageManager messageManager
- *        The nsIMessageManager to use to communicate with the parent process.
- * @param object DebuggerServerConnection
- *        The RDP connection to the client.
- * @param object owner
- *        The WebConsoleActor that is listening for the network requests.
- */
-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,
-  _throttleData: null,
-
-  get saveRequestAndResponseBodies() {
-    return this._saveRequestAndResponseBodies;
-  },
-
-  set saveRequestAndResponseBodies(val) {
-    this._saveRequestAndResponseBodies = val;
-
-    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(this._msgName, {
-      action: "setPreferences",
-      preferences: {
-        throttleData: this._throttleData,
-      },
-    });
-  },
-
-  init: function() {
-    this.conn.setupInParent({
-      module: "devtools/shared/webconsole/network-monitor",
-      setupParent: "setupParentProcess"
-    });
-
-    const mm = this._messageManager;
-    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) {
-    const {id, event} = msg.data;
-
-    // Try to add stack trace to the event data received from parent
-    if (this.owner.stackTraceCollector) {
-      event.cause.stacktrace =
-        this.owner.stackTraceCollector.getStackTrace(event.channelId);
-    }
-
-    const actor = this.owner.onNetworkEvent(event);
-    this._netEvents.set(id, Cu.getWeakReference(actor));
-  }),
-
-  _onUpdateEvent: DevToolsUtils.makeInfallible(function _onUpdateEvent(msg) {
-    const {id, method, args} = msg.data;
-    const weakActor = this._netEvents.get(id);
-    const actor = weakActor ? weakActor.get() : null;
-    if (!actor) {
-      console.error(`Received ${this._msgName}:updateEvent for unknown event ID: ${id}`);
-      return;
-    }
-    if (!(method in actor)) {
-      console.error(`Received ${this._msgName}:updateEvent unsupported ` +
-                    `method: ${method}`);
-      return;
-    }
-    actor[method].apply(actor, args);
-  }),
-
-  destroy: function() {
-    const mm = this._messageManager;
-    try {
-      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();
-    this._messageManager = null;
-    this.conn = null;
-    this.owner = null;
-  },
-};
-
-/**
- * The NetworkEventActorProxy is used to send network request information from
- * the main process to the child app process. One proxy is used per request.
- * Similarly, one NetworkEventActor in the child app process is used per
- * request. The client receives all network logs from the child actors.
- *
- * 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, msgName) {
-  this.id = gSequenceId();
-  this.messageManager = messageManager;
-  this._msgName = msgName;
-}
-exports.NetworkEventActorProxy = NetworkEventActorProxy;
-
-NetworkEventActorProxy.methodFactory = function(method) {
-  return DevToolsUtils.makeInfallible(function() {
-    const args = Array.slice(arguments);
-    const mm = this.messageManager;
-    mm.sendAsyncMessage(`${this._msgName}:updateEvent`, {
-      id: this.id,
-      method: method,
-      args: args,
-    });
-  }, "NetworkEventActorProxy." + method);
-};
-
-NetworkEventActorProxy.prototype = {
-  /**
-   * Initialize the network event. This method sends the network request event
-   * to the content process.
-   *
-   * @param object event
-   *        Object describing the network request.
-   * @return object
-   *         This object.
-   */
-  init: DevToolsUtils.makeInfallible(function(event) {
-    const mm = this.messageManager;
-    mm.sendAsyncMessage(`${this._msgName}:newEvent`, {
-      id: this.id,
-      event: event,
-    });
-    return this;
-  }),
-};
-
-(function() {
-  // Listeners for new network event data coming from the NetworkMonitor.
-  const methods = ["addRequestHeaders", "addRequestCookies", "addRequestPostData",
-                   "addResponseStart", "addSecurityInfo", "addResponseHeaders",
-                   "addResponseCookies", "addResponseContent", "addResponseCache",
-                   "addEventTimings"];
-  const factory = NetworkEventActorProxy.methodFactory;
-  for (const method of methods) {
-    NetworkEventActorProxy.prototype[method] = factory(method);
-  }
-})();
-
-/**
- * This is triggered by the child calling `setupInParent` when the child's network monitor
- * is starting up.  This initializes the parent process side of the monitoring.
- */
-function setupParentProcess({ mm, prefix }) {
-  let networkMonitor = new NetworkMonitorParent(mm, prefix);
-  return {
-    onBrowserSwap: newMM => networkMonitor.setMessageManager(newMM),
-    onDisconnected: () => {
-      networkMonitor.destroy();
-      networkMonitor = null;
-    }
-  };
-}
-
-exports.setupParentProcess = setupParentProcess;
-
-/**
- * The NetworkMonitorParent runs in the parent process and uses the message manager to
- * listen for requests from the child process to start/stop the network monitor.  Most
- * request data is only available from the parent process, so that's why the network
- * 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) {
-      const oldMM = this.messageManager;
-      oldMM.removeMessageListener(this._msgName, this.onNetMonitorMessage);
-    }
-    this.messageManager = mm;
-    if (mm) {
-      mm.addMessageListener(this._msgName, this.onNetMonitorMessage);
-    }
-  },
-
-  /**
-   * 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) {
-    const {action} = msg.json;
-    // Pipe network monitor data from parent to child via the message manager.
-    switch (action) {
-      case "start":
-        if (!this.netMonitor) {
-          const {appId, outerWindowID} = msg.json;
-          this.netMonitor = new NetworkMonitor({
-            outerWindowID,
-            appId,
-          }, this);
-          this.netMonitor.init();
-        }
-        break;
-      case "setPreferences": {
-        const {preferences} = msg.json;
-        for (const key of Object.keys(preferences)) {
-          if ((key == "saveRequestAndResponseBodies" ||
-               key == "throttleData") && this.netMonitor) {
-            this.netMonitor[key] = preferences[key];
-          }
-        }
-        break;
-      }
-
-      case "stop":
-        if (this.netMonitor) {
-          this.netMonitor.destroy();
-          this.netMonitor = null;
-        }
-        break;
-
-      case "disconnect":
-        this.destroy();
-        break;
-    }
-  }),
-
-  /**
-   * Handler for new network requests. This method is invoked by the current
-   * NetworkMonitor instance.
-   *
-   * @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, this._msgName).init(event);
-  }),
-
-  destroy: function() {
-    this.setMessageManager(null);
-
-    if (this.netMonitor) {
-      this.netMonitor.destroy();
-      this.netMonitor = null;
-    }
-  },
-};
-
-/**
  * A WebProgressListener that listens for location changes.
  *
  * This progress listener is used to track file loads and other kinds of
  * location changes.
  *
  * @constructor
  * @param object window
  *        The window for which we need to track location changes.