From 0ad1685cde273d21ce3558cae02130968c4ad0b1 Mon Sep 17 00:00:00 2001 From: Panos Astithas Date: Mon, 4 May 2015 13:58:25 +0300 Subject: [PATCH] Bug 862341 Part 4: Start recording network requests when the toolbox opens. r=vporof --- browser/devtools/framework/target.js | 33 +++++-- browser/devtools/framework/toolbox.js | 5 +- .../netmonitor/netmonitor-controller.js | 97 +++---------------- .../test/browser_net_reload-button.js | 3 - browser/devtools/netmonitor/test/head.js | 5 + 5 files changed, 45 insertions(+), 98 deletions(-) diff --git a/browser/devtools/framework/target.js b/browser/devtools/framework/target.js index 2daf18fc1a50..ee9cb1ac0b12 100644 --- a/browser/devtools/framework/target.js +++ b/browser/devtools/framework/target.js @@ -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,17 +607,15 @@ 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 - // cleanup directly after this. - this.activeTab.detach(); - cleanupAndResolve(); - } else { - cleanupAndResolve(); - } + // |detach| may fail if the connection is already dead, so proceed with + // cleanup directly after this. + this.activeTab.detach(); + cleanupAndResolve(); + } else { + cleanupAndResolve(); } } @@ -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; diff --git a/browser/devtools/framework/toolbox.js b/browser/devtools/framework/toolbox.js index dab515ac7c8b..81547cac2884 100644 --- a/browser/devtools/framework/toolbox.js +++ b/browser/devtools/framework/toolbox.js @@ -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. diff --git a/browser/devtools/netmonitor/netmonitor-controller.js b/browser/devtools/netmonitor/netmonitor-controller.js index fd41ba18cd49..ad936af9ab73 100644 --- a/browser/devtools/netmonitor/netmonitor-controller.js +++ b/browser/devtools/netmonitor/netmonitor-controller.js @@ -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 diff --git a/browser/devtools/netmonitor/test/browser_net_reload-button.js b/browser/devtools/netmonitor/test/browser_net_reload-button.js index ab551b124454..bc350d0d3fae 100644 --- a/browser/devtools/netmonitor/test/browser_net_reload-button.js +++ b/browser/devtools/netmonitor/test/browser_net_reload-button.js @@ -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(); }) diff --git a/browser/devtools/netmonitor/test/head.js b/browser/devtools/netmonitor/test/head.js index b3271ac1ec96..3ed0add19742 100644 --- a/browser/devtools/netmonitor/test/head.js +++ b/browser/devtools/netmonitor/test/head.js @@ -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");