Bug 862341 Part 4: Start recording network requests when the toolbox opens. r=vporof

This commit is contained in:
Panos Astithas 2015-05-04 13:58:25 +03:00
Родитель 42164a66ce
Коммит 0ad1685cde
5 изменённых файлов: 45 добавлений и 98 удалений

Просмотреть файл

@ -165,6 +165,7 @@ function TabTarget(tab) {
this._handleThreadState = this._handleThreadState.bind(this);
this.on("thread-resumed", this._handleThreadState);
this.on("thread-paused", this._handleThreadState);
this.activeTab = this.activeConsole = null;
// Only real tabs need initialization here. Placeholder objects for remote
// targets will be initialized after a makeRemote method call.
if (tab && !["client", "form", "chrome"].every(tab.hasOwnProperty, tab)) {
@ -420,6 +421,19 @@ TabTarget.prototype = {
}
this.activeTab = aTabClient;
this.threadActor = aResponse.threadActor;
attachConsole();
});
};
let attachConsole = () => {
this._client.attachConsole(this._form.consoleActor,
[ "NetworkActivity" ],
(aResponse, aWebConsoleClient) => {
if (!aWebConsoleClient) {
this._remote.reject("Unable to attach to the console");
return;
}
this.activeConsole = aWebConsoleClient;
this._remote.resolve(null);
});
};
@ -439,7 +453,7 @@ TabTarget.prototype = {
} else {
// AddonActor and chrome debugging on RootActor doesn't inherits from TabActor and
// doesn't need to be attached.
this._remote.resolve(null);
attachConsole();
}
return this._remote.promise;
@ -593,11 +607,10 @@ TabTarget.prototype = {
// We started with a local tab and created the client ourselves, so we
// should close it.
this._client.close(cleanupAndResolve);
} else {
} else if (this.activeTab) {
// The client was handed to us, so we are not responsible for closing
// it. We just need to detach from the tab, if already attached.
if (this.activeTab) {
// |detach| may fail if the connection is already dead, so proceed
// |detach| may fail if the connection is already dead, so proceed with
// cleanup directly after this.
this.activeTab.detach();
cleanupAndResolve();
@ -605,7 +618,6 @@ TabTarget.prototype = {
cleanupAndResolve();
}
}
}
return this._destroyer.promise;
},
@ -620,6 +632,7 @@ TabTarget.prototype = {
promiseTargets.delete(this._form);
}
this.activeTab = null;
this.activeConsole = null;
this._client = null;
this._tab = null;
this._form = null;

Просмотреть файл

@ -110,6 +110,9 @@ function Toolbox(target, selectedTool, hostType, hostOptions) {
this._toolPanels = new Map();
this._telemetry = new Telemetry();
this._initInspector = null;
this._inspector = null;
this._toolRegistered = this._toolRegistered.bind(this);
this._toolUnregistered = this._toolUnregistered.bind(this);
this._refreshHostTitle = this._refreshHostTitle.bind(this);
@ -367,7 +370,7 @@ Toolbox.prototype = {
this._pingTelemetry();
let panel = yield this.selectTool(this._defaultToolId);
yield this.selectTool(this._defaultToolId);
// Wait until the original tool is selected so that the split
// console input will receive focus.

Просмотреть файл

@ -196,7 +196,9 @@ let NetMonitorController = {
/**
* Initiates remote or chrome network monitoring based on the current target,
* wiring event handlers as necessary.
* wiring event handlers as necessary. Since the TabTarget will have already
* started listening to network requests by now, this is largely
* netmonitor-specific initialization.
*
* @return object
* A promise that is resolved when the monitor finishes connecting.
@ -209,15 +211,18 @@ let NetMonitorController = {
let deferred = promise.defer();
this._connection = deferred.promise;
let target = this._target;
let { client, form } = target;
this.client = this._target.client;
// Some actors like AddonActor or RootActor for chrome debugging
// do not support attach/detach and can be used directly
if (!target.isTabActor) {
this._startChromeMonitoring(client, form.consoleActor, deferred.resolve);
} else {
this._startMonitoringTab(client, form, deferred.resolve);
// aren't actual tabs.
if (this._target.isTabActor) {
this.tabClient = this._target.activeTab;
}
this.webConsoleClient = this._target.activeConsole;
this.webConsoleClient.setPreferences(NET_PREFS, () => {
this.TargetEventsHandler.connect();
this.NetworkEventsHandler.connect();
deferred.resolve();
});
yield deferred.promise;
window.emit(EVENTS.CONNECTED);
@ -243,82 +248,6 @@ let NetMonitorController = {
return !!this.client;
},
/**
* Sets up a monitoring session.
*
* @param DebuggerClient aClient
* The debugger client.
* @param object aTabGrip
* The remote protocol grip of the tab.
* @param function aCallback
* A function to invoke once the client attached to the console client.
*/
_startMonitoringTab: function(aClient, aTabGrip, aCallback) {
if (!aClient) {
Cu.reportError("No client found!");
return;
}
this.client = aClient;
aClient.attachTab(aTabGrip.actor, (aResponse, aTabClient) => {
if (!aTabClient) {
Cu.reportError("No tab client found!");
return;
}
this.tabClient = aTabClient;
aClient.attachConsole(aTabGrip.consoleActor, LISTENERS, (aResponse, aWebConsoleClient) => {
if (!aWebConsoleClient) {
Cu.reportError("Couldn't attach to console: " + aResponse.error);
return;
}
this.webConsoleClient = aWebConsoleClient;
this.webConsoleClient.setPreferences(NET_PREFS, () => {
this.TargetEventsHandler.connect();
this.NetworkEventsHandler.connect();
if (aCallback) {
aCallback();
}
});
});
});
},
/**
* Sets up a chrome monitoring session.
*
* @param DebuggerClient aClient
* The debugger client.
* @param object aConsoleActor
* The remote protocol grip of the chrome debugger.
* @param function aCallback
* A function to invoke once the client attached to the console client.
*/
_startChromeMonitoring: function(aClient, aConsoleActor, aCallback) {
if (!aClient) {
Cu.reportError("No client found!");
return;
}
this.client = aClient;
aClient.attachConsole(aConsoleActor, LISTENERS, (aResponse, aWebConsoleClient) => {
if (!aWebConsoleClient) {
Cu.reportError("Couldn't attach to console: " + aResponse.error);
return;
}
this.webConsoleClient = aWebConsoleClient;
this.webConsoleClient.setPreferences(NET_PREFS, () => {
this.TargetEventsHandler.connect();
this.NetworkEventsHandler.connect();
if (aCallback) {
aCallback();
}
});
});
},
/**
* Gets the activity currently performed by the frontend.
* @return number

Просмотреть файл

@ -15,9 +15,6 @@ function test() {
let { RequestsMenu } = NetMonitorView;
reqMenu = RequestsMenu;
is(reqMenu.itemCount, 0,
"The request menu should empty before reloading");
let button = document.querySelector("#requests-menu-reload-notice-button");
button.click();
})

Просмотреть файл

@ -147,6 +147,11 @@ function initNetMonitor(aUrl, aWindow, aEnableCache) {
if(!aEnableCache) {
yield toggleCache(target, true);
info("Cache disabled when the current and all future toolboxes are open.");
// Remove any requests generated by the reload while toggling the cache to
// avoid interfering with the test.
isnot([...target.activeConsole.getNetworkEvents()].length, 0,
"Request to reconfigure the tab was recorded.");
target.activeConsole.clearNetworkRequests();
}
let toolbox = yield gDevTools.showToolbox(target, "netmonitor");