diff --git a/browser/devtools/framework/test/browser_toolbox_tabsswitch_shortcuts.js b/browser/devtools/framework/test/browser_toolbox_tabsswitch_shortcuts.js index 4e00336a0df..97a1c3e2508 100644 --- a/browser/devtools/framework/test/browser_toolbox_tabsswitch_shortcuts.js +++ b/browser/devtools/framework/test/browser_toolbox_tabsswitch_shortcuts.js @@ -11,12 +11,15 @@ function test() { addTab("about:blank", function() { let target = TargetFactory.forTab(gBrowser.selectedTab); - toolIDs = gDevTools.getToolDefinitionArray() - .filter(def => def.isTargetSupported(target)) - .map(def => def.id); idIndex = 0; - gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM) - .then(testShortcuts); + + target.makeRemote().then(() => { + toolIDs = gDevTools.getToolDefinitionArray() + .filter(def => def.isTargetSupported(target)) + .map(def => def.id); + gDevTools.showToolbox(target, toolIDs[0], Toolbox.HostType.BOTTOM) + .then(testShortcuts); + }); }); } diff --git a/browser/devtools/framework/test/browser_toolbox_tool_ready.js b/browser/devtools/framework/test/browser_toolbox_tool_ready.js index 1681608453f..155aa66af7a 100644 --- a/browser/devtools/framework/test/browser_toolbox_tool_ready.js +++ b/browser/devtools/framework/test/browser_toolbox_tool_ready.js @@ -3,6 +3,10 @@ function test() { addTab().then(function(data) { + data.target.makeRemote().then(performChecks.bind(null, data)); + }).then(null, console.error); + + function performChecks(data) { let toolIds = gDevTools.getToolDefinitionArray() .filter(def => def.isTargetSupported(data.target)) .map(def => def.id); @@ -32,5 +36,5 @@ function test() { }; open(0); - }).then(null, console.error); + } } diff --git a/browser/devtools/framework/toolbox.js b/browser/devtools/framework/toolbox.js index 56ce0598ee7..f803021a589 100644 --- a/browser/devtools/framework/toolbox.js +++ b/browser/devtools/framework/toolbox.js @@ -253,21 +253,20 @@ Toolbox.prototype = { this._addZoomKeys(); this._loadInitialZoom(); - // Load the toolbox-level actor fronts and utilities now - this._target.makeRemote().then(() => { - this._telemetry.toolOpened("toolbox"); + this._telemetry.toolOpened("toolbox"); - this.selectTool(this._defaultToolId).then(panel => { - this.emit("ready"); - deferred.resolve(); - }); + this.selectTool(this._defaultToolId).then(panel => { + this.emit("ready"); + deferred.resolve(); }); }; - iframe.setAttribute("src", this._URL); - - let domHelper = new DOMHelpers(iframe.contentWindow); - domHelper.onceDOMReady(domReady); + // Load the toolbox-level actor fronts and utilities now + this._target.makeRemote().then(() => { + iframe.setAttribute("src", this._URL); + let domHelper = new DOMHelpers(iframe.contentWindow); + domHelper.onceDOMReady(domReady); + }); return deferred.promise; }); diff --git a/browser/devtools/main.js b/browser/devtools/main.js index 6059a330a54..9f37ef853ea 100644 --- a/browser/devtools/main.js +++ b/browser/devtools/main.js @@ -239,7 +239,8 @@ Tools.netMonitor = { inMenu: true, isTargetSupported: function(target) { - return !target.isApp; + let root = target.client.mainRoot; + return root.traits.networkMonitor || !target.isApp; }, build: function(iframeWindow, toolbox) { diff --git a/browser/devtools/netmonitor/netmonitor-controller.js b/browser/devtools/netmonitor/netmonitor-controller.js index d418b30ea1c..48c0e6dc604 100644 --- a/browser/devtools/netmonitor/netmonitor-controller.js +++ b/browser/devtools/netmonitor/netmonitor-controller.js @@ -78,7 +78,11 @@ const EVENTS = { // Fired when charts have been displayed in the PerformanceStatisticsView. PLACEHOLDER_CHARTS_DISPLAYED: "NetMonitor:PlaceholderChartsDisplayed", PRIMED_CACHE_CHART_DISPLAYED: "NetMonitor:PrimedChartsDisplayed", - EMPTY_CACHE_CHART_DISPLAYED: "NetMonitor:EmptyChartsDisplayed" + EMPTY_CACHE_CHART_DISPLAYED: "NetMonitor:EmptyChartsDisplayed", + + // Fired once the NetMonitorController establishes a connection to the debug + // target. + CONNECTED: "connected", }; // Descriptions for what this frontend is currently doing. @@ -200,7 +204,10 @@ let NetMonitorController = { this._startMonitoringTab(client, form, deferred.resolve); } - return deferred.promise; + return deferred.promise.then((result) => { + window.emit(EVENTS.CONNECTED); + return result; + }); }, /** @@ -362,6 +369,25 @@ let NetMonitorController = { return promise.reject(new Error("Invalid activity type")); }, + /** + * Getter that tells if the server supports sending custom network requests. + * @type boolean + */ + get supportsCustomRequest() { + return this.webConsoleClient && + (this.webConsoleClient.traits.customNetworkRequest || + !this._target.isApp); + }, + + /** + * Getter that tells if the server can do network performance statistics. + * @type boolean + */ + get supportsPerfStats() { + return this.tabClient && + (this.tabClient.traits.reconfigure || !this._target.isApp); + }, + _startup: null, _shutdown: null, _connection: null, @@ -493,6 +519,11 @@ NetworkEventsHandler.prototype = { * The message received from the server. */ _onNetworkEvent: function(aType, aPacket) { + if (aPacket.from != this.webConsoleClient.actor) { + // Skip events from different console actors. + return; + } + let { actor, startedDateTime, method, url, isXHR } = aPacket.eventActor; NetMonitorView.RequestsMenu.addRequest(actor, startedDateTime, method, url, isXHR); window.emit(EVENTS.NETWORK_EVENT); @@ -508,6 +539,10 @@ NetworkEventsHandler.prototype = { */ _onNetworkEventUpdate: function(aType, aPacket) { let actor = aPacket.from; + if (!NetMonitorView.RequestsMenu.getItemByValue(actor)) { + // Skip events from unknown actors. + return; + } switch (aPacket.updateType) { case "requestHeaders": diff --git a/browser/devtools/netmonitor/netmonitor-view.js b/browser/devtools/netmonitor/netmonitor-view.js index 6be11f22010..261312c1ee1 100644 --- a/browser/devtools/netmonitor/netmonitor-view.js +++ b/browser/devtools/netmonitor/netmonitor-view.js @@ -374,16 +374,32 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { $("#request-menu-context-newtab").addEventListener("command", this._onContextNewTabCommand, false); $("#request-menu-context-copy-url").addEventListener("command", this._onContextCopyUrlCommand, false); $("#request-menu-context-copy-image-as-data-uri").addEventListener("command", this._onContextCopyImageAsDataUriCommand, false); - $("#request-menu-context-resend").addEventListener("command", this._onContextResendCommand, false); - $("#request-menu-context-perf").addEventListener("command", this._onContextPerfCommand, false); - $("#requests-menu-perf-notice-button").addEventListener("command", this._onContextPerfCommand, false); - $("#requests-menu-network-summary-button").addEventListener("command", this._onContextPerfCommand, false); - $("#requests-menu-network-summary-label").addEventListener("click", this._onContextPerfCommand, false); + window.once("connected", this._onConnect.bind(this)); + }, - $("#custom-request-send-button").addEventListener("click", this.sendCustomRequestEvent, false); - $("#custom-request-close-button").addEventListener("click", this.closeCustomRequestEvent, false); - $("#headers-summary-resend").addEventListener("click", this.cloneSelectedRequestEvent, false); + _onConnect: function() { + if (NetMonitorController.supportsCustomRequest) { + $("#request-menu-context-resend").addEventListener("command", this._onContextResendCommand, false); + $("#custom-request-send-button").addEventListener("click", this.sendCustomRequestEvent, false); + $("#custom-request-close-button").addEventListener("click", this.closeCustomRequestEvent, false); + $("#headers-summary-resend").addEventListener("click", this.cloneSelectedRequestEvent, false); + } else { + $("#request-menu-context-resend").hidden = true; + $("#headers-summary-resend").hidden = true; + } + + if (NetMonitorController.supportsPerfStats) { + $("#request-menu-context-perf").addEventListener("command", this._onContextPerfCommand, false); + $("#requests-menu-perf-notice-button").addEventListener("command", this._onContextPerfCommand, false); + $("#requests-menu-network-summary-button").addEventListener("command", this._onContextPerfCommand, false); + $("#requests-menu-network-summary-label").addEventListener("click", this._onContextPerfCommand, false); + } else { + $("#notice-perf-message").hidden = true; + $("#request-menu-context-perf").hidden = true; + $("#requests-menu-network-summary-button").hidden = true; + $("#requests-menu-network-summary-label").hidden = true; + } }, /** @@ -546,8 +562,12 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { */ sendCustomRequest: function() { let selected = this.selectedItem.attachment; - let data = Object.create(selected); + let data = { + method: selected.method, + url: selected.url, + httpVersion: selected.httpVersion, + }; if (selected.requestHeaders) { data.headers = selected.requestHeaders.headers; } @@ -1534,7 +1554,8 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, { let selectedItem = this.selectedItem; let resendElement = $("#request-menu-context-resend"); - resendElement.hidden = !selectedItem || selectedItem.attachment.isCustom; + resendElement.hidden = !NetMonitorController.supportsCustomRequest || + !selectedItem || selectedItem.attachment.isCustom; let copyUrlElement = $("#request-menu-context-copy-url"); copyUrlElement.hidden = !selectedItem; diff --git a/toolkit/devtools/webconsole/client.js b/toolkit/devtools/webconsole/client.js index 478eabc909b..b20df3d6451 100644 --- a/toolkit/devtools/webconsole/client.js +++ b/toolkit/devtools/webconsole/client.js @@ -30,6 +30,8 @@ exports.WebConsoleClient = WebConsoleClient; WebConsoleClient.prototype = { _longStrings: null, + get actor() { return this._actor; }, + /** * Retrieve the cached messages from the server. *