From 9ddabe806107298baf0fd3c066483f617b4be334 Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Thu, 26 Feb 2015 03:55:00 +0100 Subject: [PATCH] Bug 1059308 - Add Target.isTabActor to tell if the remote tab actor supports attach/detach requests. r=jryans --- .../devtools/debugger/debugger-controller.js | 4 +++- browser/devtools/debugger/test/head.js | 3 ++- browser/devtools/framework/connect/connect.js | 11 ++++++----- browser/devtools/framework/gDevTools.jsm | 3 ++- browser/devtools/framework/target.js | 18 ++++++++++++++++-- .../framework/toolbox-process-window.js | 7 ++++--- .../netmonitor/netmonitor-controller.js | 4 +++- browser/devtools/performance/modules/front.js | 11 +++-------- browser/devtools/profiler/utils/shared.js | 16 ++++++---------- browser/devtools/webconsole/webconsole.js | 2 +- 10 files changed, 46 insertions(+), 33 deletions(-) diff --git a/browser/devtools/debugger/debugger-controller.js b/browser/devtools/debugger/debugger-controller.js index 531d7df1a6a3..107cd8aa0e75 100644 --- a/browser/devtools/debugger/debugger-controller.js +++ b/browser/devtools/debugger/debugger-controller.js @@ -206,7 +206,9 @@ let DebuggerController = { if (target.isAddon) { yield this._startAddonDebugging(actor); - } else if (target.chrome) { + } else if (!target.isTabActor) { + // Some actors like AddonActor or RootActor for chrome debugging + // do not support attach/detach and can be used directly yield this._startChromeDebugging(chromeDebugger); } else { yield this._startDebuggingTab(); diff --git a/browser/devtools/debugger/test/head.js b/browser/devtools/debugger/test/head.js index f510a56f74a9..be82953e0649 100644 --- a/browser/devtools/debugger/test/head.js +++ b/browser/devtools/debugger/test/head.js @@ -581,7 +581,8 @@ AddonDebugger.prototype = { let targetOptions = { form: addonActor, client: this.client, - chrome: true + chrome: true, + isTabActor: false }; let toolboxOptions = { diff --git a/browser/devtools/framework/connect/connect.js b/browser/devtools/framework/connect/connect.js index c4cd31759d09..aa2d943735e0 100644 --- a/browser/devtools/framework/connect/connect.js +++ b/browser/devtools/framework/connect/connect.js @@ -162,7 +162,7 @@ let onConnectionReady = Task.async(function*(aType, aTraits) { function buildAddonLink(addon, parent) { let a = document.createElement("a"); a.onclick = function() { - openToolbox(addon, true, "jsdebugger"); + openToolbox(addon, true, "jsdebugger", false); } a.textContent = addon.name; @@ -221,11 +221,12 @@ function handleConnectionTimeout() { * The user clicked on one of the buttons. * Opens the toolbox. */ -function openToolbox(form, chrome=false, tool="webconsole") { +function openToolbox(form, chrome=false, tool="webconsole", isTabActor) { let options = { form: form, client: gClient, - chrome: chrome + chrome: chrome, + isTabActor: isTabActor }; devtools.TargetFactory.forRemoteTab(options).then((target) => { let hostType = devtools.Toolbox.HostType.WINDOW; @@ -233,7 +234,7 @@ function openToolbox(form, chrome=false, tool="webconsole") { toolbox.once("destroyed", function() { gClient.close(); }); - }); + }, console.error.bind(console)); window.close(); - }); + }, console.error.bind(console)); } diff --git a/browser/devtools/framework/gDevTools.jsm b/browser/devtools/framework/gDevTools.jsm index e32ec0f4086c..4c66b44bc282 100644 --- a/browser/devtools/framework/gDevTools.jsm +++ b/browser/devtools/framework/gDevTools.jsm @@ -718,7 +718,8 @@ let gDevToolsBrowser = { let options = { form: response.form, client: client, - chrome: true + chrome: true, + isTabActor: false }; return devtools.TargetFactory.forRemoteTab(options); }) diff --git a/browser/devtools/framework/target.js b/browser/devtools/framework/target.js index 50c7531dd589..4b5ab9f97f6b 100644 --- a/browser/devtools/framework/target.js +++ b/browser/devtools/framework/target.js @@ -175,6 +175,8 @@ function TabTarget(tab) { this._client = tab.client; this._chrome = tab.chrome; } + // Default isTabActor to true if not explicitely specified + this._isTabActor = typeof(tab.isTabActor) == "boolean" ? tab.isTabActor : true; } TabTarget.prototype = { @@ -315,10 +317,21 @@ TabTarget.prototype = { return this._client; }, + // Tells us if we are debugging content document + // or if we are debugging chrome stuff. + // Allows to controls which features are available against + // a chrome or a content document. get chrome() { return this._chrome; }, + // Tells us if the related actor implements TabActor interface + // and requires to call `attach` request before being used + // and `detach` during cleanup + get isTabActor() { + return this._isTabActor; + }, + get window() { // XXX - this is a footgun for e10s - there .contentWindow will be null, // and even though .contentWindowAsCPOW *might* work, it will not work @@ -436,12 +449,13 @@ TabTarget.prototype = { attachTab(); }); }); - } else if (!this.chrome) { + } else if (this.isTabActor) { // In the remote debugging case, the protocol connection will have been // already initialized in the connection screen code. attachTab(); } else { - // Remote chrome debugging doesn't need anything at this point. + // AddonActor and chrome debugging on RootActor doesn't inherits from TabActor and + // doesn't need to be attached. this._remote.resolve(null); } diff --git a/browser/devtools/framework/toolbox-process-window.js b/browser/devtools/framework/toolbox-process-window.js index 7cc5c9dff04e..8b80818f7199 100644 --- a/browser/devtools/framework/toolbox-process-window.js +++ b/browser/devtools/framework/toolbox-process-window.js @@ -38,7 +38,7 @@ let connect = Task.async(function*() { if (addonID) { gClient.listAddons(({addons}) => { let addonActor = addons.filter(addon => addon.id === addonID).pop(); - openToolbox(addonActor); + openToolbox({ form: addonActor, chrome: true, isTabActor: false }); }); } else { gClient.listTabs(openToolbox); @@ -65,11 +65,12 @@ function onCloseCommand(event) { window.close(); } -function openToolbox(form) { +function openToolbox({ form, chrome, isTabActor }) { let options = { form: form, client: gClient, - chrome: true + chrome: chrome, + isTabActor: isTabActor }; devtools.TargetFactory.forRemoteTab(options).then(target => { let frame = document.getElementById("toolbox-iframe"); diff --git a/browser/devtools/netmonitor/netmonitor-controller.js b/browser/devtools/netmonitor/netmonitor-controller.js index 19dc7fed97c5..76192807078d 100644 --- a/browser/devtools/netmonitor/netmonitor-controller.js +++ b/browser/devtools/netmonitor/netmonitor-controller.js @@ -211,7 +211,9 @@ let NetMonitorController = { let target = this._target; let { client, form } = target; - if (target.chrome) { + // 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); diff --git a/browser/devtools/performance/modules/front.js b/browser/devtools/performance/modules/front.js index 076d0de1a219..c28d3743f422 100644 --- a/browser/devtools/performance/modules/front.js +++ b/browser/devtools/performance/modules/front.js @@ -121,14 +121,9 @@ PerformanceActorsConnection.prototype = { * Initializes a connection to the profiler actor. */ _connectProfilerActor: Task.async(function*() { - // Chrome debugging targets have already obtained a reference - // to the profiler actor. - if (this._target.chrome) { - this._profiler = this._target.form.profilerActor; - } - // When we are debugging content processes, we already have the tab - // specific one. Use it immediately. - else if (this._target.form && this._target.form.profilerActor) { + // Chrome and content process targets already have obtained a reference + // to the profiler tab actor. Use it immediately. + if (this._target.form && this._target.form.profilerActor) { this._profiler = this._target.form.profilerActor; } // Check if we already have a grip to the `listTabs` response object diff --git a/browser/devtools/profiler/utils/shared.js b/browser/devtools/profiler/utils/shared.js index 429efa2e507a..29bc36c9ccfc 100644 --- a/browser/devtools/profiler/utils/shared.js +++ b/browser/devtools/profiler/utils/shared.js @@ -83,14 +83,9 @@ ProfilerConnection.prototype = { // Local debugging needs to make the target remote. yield this._target.makeRemote(); - // Chrome debugging targets have already obtained a reference - // to the profiler actor. - if (this._target.chrome) { - this._profiler = this._target.form.profilerActor; - } - // Or when we are debugging content processes, we already have the tab - // specific one. Use it immediately. - else if (this._target.form && this._target.form.profilerActor) { + // Chrome and content process targets already have obtained a reference + // to the profiler tab actor. Use it immediately. + if (this._target.form && this._target.form.profilerActor) { this._profiler = this._target.form.profilerActor; yield this._registerEventNotifications(); } @@ -100,8 +95,9 @@ ProfilerConnection.prototype = { this._profiler = this._target.root.profilerActor; yield this._registerEventNotifications(); } - // Otherwise, call `listTabs`. - else { + // Otherwise, call `listTabs`, but ensure not trying to fetch tab actors + // for AddonTarget that are chrome, but do not expose profile at all. + else if (!this._target.chrome) { this._profiler = (yield listTabs(this._client)).profilerActor; yield this._registerEventNotifications(); } diff --git a/browser/devtools/webconsole/webconsole.js b/browser/devtools/webconsole/webconsole.js index 6f52424298d1..e9816cea3512 100644 --- a/browser/devtools/webconsole/webconsole.js +++ b/browser/devtools/webconsole/webconsole.js @@ -5095,7 +5095,7 @@ WebConsoleConnectionProxy.prototype = { this.target.on("navigate", this._onTabNavigated); this._consoleActor = this.target.form.consoleActor; - if (!this.target.chrome) { + if (this.target.isTabActor) { let tab = this.target.form; this.owner.onLocationChange(tab.url, tab.title); }