mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1444132 - Remove the old proxy code. r=jryans
MozReview-Commit-ID: 33LcN5c5o4D --HG-- extra : rebase_source : fb2204f88d01a46e752809cf3175f9257627d065
This commit is contained in:
parent
0632dc4e55
commit
013d0c7338
@ -20,7 +20,6 @@ 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);
|
||||
@ -74,8 +73,6 @@ function WebConsoleActor(connection, parentActor) {
|
||||
|
||||
this.dbg = this.parentActor.makeDebugger();
|
||||
|
||||
this._netEvents = new Map();
|
||||
this._networkEventActorsByURL = new Map();
|
||||
this._gripDepth = 0;
|
||||
this._listeners = new Set();
|
||||
this._lastConsoleInputEvaluation = undefined;
|
||||
@ -130,25 +127,6 @@ WebConsoleActor.prototype =
|
||||
*/
|
||||
_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.
|
||||
*
|
||||
@ -395,7 +373,6 @@ WebConsoleActor.prototype =
|
||||
this._webConsoleCommandsCache = null;
|
||||
this._lastConsoleInputEvaluation = null;
|
||||
this._evalWindow = null;
|
||||
this._netEvents.clear();
|
||||
this.dbg.enabled = false;
|
||||
this.dbg = null;
|
||||
this.conn = null;
|
||||
@ -1736,58 +1713,6 @@ WebConsoleActor.prototype =
|
||||
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
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
"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");
|
||||
@ -1727,328 +1727,6 @@ NetworkMonitor.prototype = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user