diff --git a/devtools/client/webconsole/browser-console.js b/devtools/client/webconsole/browser-console.js index 8805e24b33b2..38c72ad91fe1 100644 --- a/devtools/client/webconsole/browser-console.js +++ b/devtools/client/webconsole/browser-console.js @@ -38,18 +38,13 @@ class BrowserConsole extends WebConsole { * @param Boolean fissionSupport */ constructor(target, iframeWindow, chromeWindow, fissionSupport = false) { - super(null, iframeWindow, chromeWindow, true, fissionSupport); + super(target, iframeWindow, chromeWindow, true, fissionSupport); - this._browserConsoleTarget = target; this._telemetry = new Telemetry(); this._bcInitializer = null; this._bcDestroyer = null; } - get currentTarget() { - return this._browserConsoleTarget; - } - /** * Initialize the Browser Console instance. * @@ -101,7 +96,7 @@ class BrowserConsole extends WebConsole { this._telemetry.toolClosed("browserconsole", -1, this); await super.destroy(); - await this.currentTarget.destroy(); + await this.target.destroy(); this.chromeWindow.close(); })(); diff --git a/devtools/client/webconsole/panel.js b/devtools/client/webconsole/panel.js index f456e77501ba..23d033e7e16b 100644 --- a/devtools/client/webconsole/panel.js +++ b/devtools/client/webconsole/panel.js @@ -65,11 +65,7 @@ WebConsolePanel.prototype = { const chromeWindow = iframe.ownerDocument.defaultView; // Open the Web Console. - this.hud = new WebConsole( - this._toolbox, - webConsoleUIWindow, - chromeWindow - ); + this.hud = new WebConsole(this.target, webConsoleUIWindow, chromeWindow); await this.hud.init(); // Pipe 'reloaded' event from WebConsoleUI to WebConsolePanel. @@ -89,7 +85,7 @@ WebConsolePanel.prototype = { return this; }, - get currentTarget() { + get target() { return this._toolbox.target; }, diff --git a/devtools/client/webconsole/test/browser/browser_console_devtools_loader_exception.js b/devtools/client/webconsole/test/browser/browser_console_devtools_loader_exception.js index 33ed776761b6..046e30cb8655 100644 --- a/devtools/client/webconsole/test/browser/browser_console_devtools_loader_exception.js +++ b/devtools/client/webconsole/test/browser/browser_console_devtools_loader_exception.js @@ -17,7 +17,7 @@ add_task(async function() { ok(bcHud, "browser console opened"); // Cause an exception in a script loaded with the DevTools loader. - const toolbox = wcHud.toolbox; + const toolbox = gDevTools.getToolbox(wcHud.target); const oldPanels = toolbox._toolPanels; // non-iterable toolbox._toolPanels = {}; diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_click_function_to_source.js b/devtools/client/webconsole/test/browser/browser_webconsole_click_function_to_source.js index c74ebc5fa6aa..4572c561e215 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_click_function_to_source.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_click_function_to_source.js @@ -38,7 +38,7 @@ add_task(async function() { info("Click on the jump to definition button."); jumpIcon.click(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); await waitForSelectedSource(dbg, TEST_SCRIPT_URI); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_errors_after_page_reload.js b/devtools/client/webconsole/test/browser/browser_webconsole_errors_after_page_reload.js index bc7712517734..2699b40ccffa 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_errors_after_page_reload.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_errors_after_page_reload.js @@ -15,7 +15,7 @@ add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); info("Reload the content window"); - const onNavigate = hud.currentTarget.once("navigate"); + const onNavigate = hud.target.once("navigate"); ContentTask.spawn(gBrowser.selectedBrowser, null, () => { content.wrappedJSObject.location.reload(); }); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe.js b/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe.js index 93b0202a89b5..ebc0f51d38f6 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe.js @@ -30,7 +30,7 @@ add_task(async function() { info("Open the debugger and then select the console again"); await openDebugger(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); await openConsole(); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe2.js b/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe2.js index 359575224929..d313d4efed0d 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe2.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_eval_in_debugger_stackframe2.js @@ -18,7 +18,7 @@ add_task(async function() { info("open the debugger"); await openDebugger(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); // firstCall calls secondCall, which has a debugger statement, so we'll be paused. diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_location_logpoint_debugger_link.js b/devtools/client/webconsole/test/browser/browser_webconsole_location_logpoint_debugger_link.js index 0fc4a6e05397..fab84b120d76 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_location_logpoint_debugger_link.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_location_logpoint_debugger_link.js @@ -25,7 +25,7 @@ add_task(async function() { info("Open the Debugger panel"); await openDebugger(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); await selectSource(dbg, "test-location-debugger-link-logpoint-1.js"); @@ -111,7 +111,7 @@ add_task(async function() { info("Open the Debugger panel"); await openDebugger(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); info("Add a logpoint to the first file"); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js b/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js index 944a71294972..6d9d2b1afb69 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_multiple_windows_and_tabs.js @@ -37,7 +37,7 @@ add_task(async function() { for (const tab of tabs) { // Open the console in tab${i}. const hud = await openConsole(tab); - const browser = hud.currentTarget.tab.linkedBrowser; + const browser = hud.target.tab.linkedBrowser; const message = "message for tab " + tabs.indexOf(tab); // Log a message in the newly opened console. diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_nodes_highlight.js b/devtools/client/webconsole/test/browser/browser_webconsole_nodes_highlight.js index d57cbd56f42b..3b147604eedb 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_nodes_highlight.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_nodes_highlight.js @@ -29,7 +29,7 @@ Services.scriptloader.loadSubScript( add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); await registerTestActor(toolbox.target.client); const testActor = await getTestActor(toolbox); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_nodes_select.js b/devtools/client/webconsole/test/browser/browser_webconsole_nodes_select.js index 4b874acdd0d6..207f9f575733 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_nodes_select.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_nodes_select.js @@ -23,7 +23,7 @@ const TEST_URI = "data:text/html;charset=utf-8," + encodeURI(HTML); add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); // Loading the inspector panel at first, to make it possible to listen for // new node selections diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_optimized_out_vars.js b/devtools/client/webconsole/test/browser/browser_webconsole_optimized_out_vars.js index f5769da23776..cc191c31079d 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_optimized_out_vars.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_optimized_out_vars.js @@ -16,7 +16,7 @@ add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); await openDebugger(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); await selectSource(dbg, "test-closure-optimized-out.html"); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_timestamps.js b/devtools/client/webconsole/test/browser/browser_webconsole_timestamps.js index 6987bad59d54..78b49406ad26 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_timestamps.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_timestamps.js @@ -31,7 +31,7 @@ add_task(async function() { info("Open the settings panel"); const observer = new PrefObserver(""); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const { panelDoc, panelWin } = await toolbox.selectTool("options"); info("Change Timestamp preference"); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_visibility_messages.js b/devtools/client/webconsole/test/browser/browser_webconsole_visibility_messages.js index 042eb765fbbd..3089882202ba 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_visibility_messages.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_visibility_messages.js @@ -25,7 +25,7 @@ const MESSAGES_COUNT = 10; add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); info("Log one message in the console"); ContentTask.spawn(gBrowser.selectedBrowser, null, () => { @@ -85,7 +85,7 @@ add_task(async function() { // Here, the messages should still be logged. add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); info("Log one message in the console"); ContentTask.spawn(gBrowser.selectedBrowser, null, () => { diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_warning_groups_toggle.js b/devtools/client/webconsole/test/browser/browser_webconsole_warning_groups_toggle.js index 37d467e90d26..446b19edd021 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_warning_groups_toggle.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_warning_groups_toggle.js @@ -278,7 +278,7 @@ async function toggleWarningGroupPreference(hud, fromUI = true) { info("Open the settings panel"); const observer = new PrefObserver(""); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const { panelDoc, panelWin } = await toolbox.selectTool("options"); info("Change warning preference"); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_worker_evaluate.js b/devtools/client/webconsole/test/browser/browser_webconsole_worker_evaluate.js index 27b0bf3dc1d2..87b19f8de9d5 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_worker_evaluate.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_worker_evaluate.js @@ -14,7 +14,7 @@ add_task(async function() { const hud = await openNewTabAndConsole(TEST_URI); await openDebugger(); - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const dbg = createDebuggerContext(toolbox); execute(hud, "pauseInWorker(42)"); diff --git a/devtools/client/webconsole/test/browser/head.js b/devtools/client/webconsole/test/browser/head.js index aab923238e51..bfba769a56f0 100644 --- a/devtools/client/webconsole/test/browser/head.js +++ b/devtools/client/webconsole/test/browser/head.js @@ -350,7 +350,7 @@ function hideContextMenu(hud) { } function _getContextMenu(hud) { - const toolbox = hud.toolbox; + const toolbox = gDevTools.getToolbox(hud.target); const doc = toolbox ? toolbox.topWindow.document : hud.chromeWindow.document; return doc.getElementById("webconsole-menu"); } diff --git a/devtools/client/webconsole/webconsole-connection-proxy.js b/devtools/client/webconsole/webconsole-connection-proxy.js index 8873933550fe..d992cc3dfb2b 100644 --- a/devtools/client/webconsole/webconsole-connection-proxy.js +++ b/devtools/client/webconsole/webconsole-connection-proxy.js @@ -23,10 +23,19 @@ class WebConsoleConnectionProxy { * @param RemoteTarget target * The target that the console will connect to. */ - constructor(webConsoleUI, target) { + constructor(webConsoleUI, target, isBrowserConsole, fissionSupport) { this.webConsoleUI = webConsoleUI; this.target = target; - this.fissionSupport = this.webConsoleUI.fissionSupport; + this.isBrowserConsole = isBrowserConsole; + this.fissionSupport = fissionSupport; + + /** + * The DebuggerClient object. + * + * @see DebuggerClient + * @type object + */ + this.client = target.client; this._connecter = null; @@ -59,7 +68,6 @@ class WebConsoleConnectionProxy { this.target.on("navigate", this._onTabNavigated); const connection = (async () => { - this.client = this.target.client; this.webConsoleClient = await this.target.getFront("console"); this._addWebConsoleClientEventListeners(); await this._attachConsole(); @@ -376,6 +384,7 @@ class WebConsoleConnectionProxy { this.client = null; this.webConsoleClient = null; + this.target = null; this.webConsoleUI = null; } } diff --git a/devtools/client/webconsole/webconsole-ui.js b/devtools/client/webconsole/webconsole-ui.js index 7d78d324d78d..0d02681f7620 100644 --- a/devtools/client/webconsole/webconsole-ui.js +++ b/devtools/client/webconsole/webconsole-ui.js @@ -7,6 +7,7 @@ const { Utils: WebConsoleUtils } = require("devtools/client/webconsole/utils"); const EventEmitter = require("devtools/shared/event-emitter"); const Services = require("Services"); +const { gDevTools } = require("devtools/client/framework/devtools"); const { WebConsoleConnectionProxy, } = require("devtools/client/webconsole/webconsole-connection-proxy"); @@ -142,21 +143,20 @@ class WebConsoleUI { this.wrapper.destroy(); } - const toolbox = this.hud.toolbox; + const toolbox = gDevTools.getToolbox(this.hud.target); if (toolbox) { toolbox.off("webconsole-selected", this._onPanelSelected); toolbox.off("split-console", this._onChangeSplitConsoleState); toolbox.off("select", this._onChangeSplitConsoleState); } + this.window = this.hud = this.wrapper = null; + for (const proxy of this.getAllProxies()) { proxy.disconnect(); } this.proxy = null; this.additionalProxies = null; - - // Nullify `hud` last as it nullify also target which is used on destroy - this.window = this.hud = this.wrapper = null; } /** @@ -222,7 +222,7 @@ class WebConsoleUI { } logWarningAboutReplacedAPI() { - return this.hud.currentTarget.logWarningInPage( + return this.hud.target.logWarningInPage( l10n.getStr("ConsoleAPIDisabled"), "ConsoleAPIDisabled" ); @@ -257,11 +257,19 @@ class WebConsoleUI { * A promise object that is resolved/reject based on the proxies connections. */ async _initConnection() { - this.proxy = new WebConsoleConnectionProxy(this, this.hud.currentTarget); + this.proxy = new WebConsoleConnectionProxy( + this, + this.hud.target, + this.isBrowserConsole, + this.fissionSupport + ); - const target = this.hud.currentTarget; - if (this.fissionSupport && target.chrome && !target.isAddon) { - const { mainRoot } = target.client; + if ( + this.fissionSupport && + this.hud.target.chrome && + !this.hud.target.isAddon + ) { + const { mainRoot } = this.hud.target.client; const { processes } = await mainRoot.listProcesses(); this.additionalProxies = []; @@ -270,7 +278,7 @@ class WebConsoleUI { // Don't create a proxy for the "main" target, // as we already created it in this.proxy. - if (targetFront === target) { + if (targetFront === this.hud.target) { continue; } @@ -283,7 +291,12 @@ class WebConsoleUI { } this.additionalProxies.push( - new WebConsoleConnectionProxy(this, targetFront) + new WebConsoleConnectionProxy( + this, + targetFront, + this.isBrowserConsole, + this.fissionSupport + ) ); } } @@ -297,7 +310,7 @@ class WebConsoleUI { this.outputNode = this.document.getElementById("app-wrapper"); - const toolbox = this.hud.toolbox; + const toolbox = gDevTools.getToolbox(this.hud.target); // Initialize module loader and load all the WebConsoleWrapper. The entire code-base // doesn't need any extra privileges and runs entirely in content scope. diff --git a/devtools/client/webconsole/webconsole-wrapper.js b/devtools/client/webconsole/webconsole-wrapper.js index 26c3569e3f3a..fd97c59be227 100644 --- a/devtools/client/webconsole/webconsole-wrapper.js +++ b/devtools/client/webconsole/webconsole-wrapper.js @@ -84,9 +84,9 @@ class WebConsoleWrapper { this.webConsoleUI[id] = node; }; const { webConsoleUI } = this; - const debuggerClient = this.hud.currentTarget.client; + const debuggerClient = this.hud.target.client; - const webConsoleClient = await this.hud.currentTarget.getFront("console"); + const webConsoleClient = await this.hud.target.getFront("console"); this.networkDataProvider = new DataProvider({ actions: { updateRequest: (id, data) => { @@ -114,15 +114,23 @@ class WebConsoleWrapper { webConsoleUI.hud.openLink(url, e); }, canRewind: () => { - const target = webConsoleUI.hud && webConsoleUI.hud.currentTarget; - const traits = target && target.traits; - return traits && traits.canRewind; + if ( + !( + webConsoleUI.hud && + webConsoleUI.hud.target && + webConsoleUI.hud.target.traits + ) + ) { + return false; + } + + return webConsoleUI.hud.target.traits.canRewind; }, createElement: nodename => { return this.document.createElement(nodename); }, fetchObjectProperties: async (grip, ignoreNonIndexedProperties) => { - const client = new ObjectClient(this.hud.currentTarget.client, grip); + const client = new ObjectClient(this.hud.target.client, grip); const { iterator } = await client.enumProperties({ ignoreNonIndexedProperties, }); @@ -130,7 +138,7 @@ class WebConsoleWrapper { return ownProperties; }, fetchObjectEntries: async grip => { - const client = new ObjectClient(this.hud.currentTarget.client, grip); + const client = new ObjectClient(this.hud.target.client, grip); const { iterator } = await client.enumEntries(); const { ownProperties } = await iterator.slice(0, iterator.count); return ownProperties; diff --git a/devtools/client/webconsole/webconsole.js b/devtools/client/webconsole/webconsole.js index 01f6a0be09ac..a4280640c763 100644 --- a/devtools/client/webconsole/webconsole.js +++ b/devtools/client/webconsole/webconsole.js @@ -51,8 +51,8 @@ const isMacOS = Services.appinfo.OS === "Darwin"; class WebConsole { /* * @constructor - * @param object toolbox - * The toolbox where the web console is displayed. + * @param object target + * The target that the web console will connect to. * @param nsIDOMWindow iframeWindow * The window where the web console UI is already loaded. * @param nsIDOMWindow chromeWindow @@ -60,16 +60,16 @@ class WebConsole { * @param bool isBrowserConsole */ constructor( - toolbox, + target, iframeWindow, chromeWindow, isBrowserConsole = false, fissionSupport = false ) { - this.toolbox = toolbox; this.iframeWindow = iframeWindow; this.chromeWindow = chromeWindow; this.hudId = "hud_" + ++gHudId; + this.target = target; this.browserWindow = this.chromeWindow.top; this.isBrowserConsole = isBrowserConsole; this.fissionSupport = fissionSupport; @@ -86,10 +86,6 @@ class WebConsole { EventEmitter.decorate(this); } - get currentTarget() { - return this.toolbox.target; - } - /** * Getter for the window that can provide various utilities that the web * console makes use of, like opening links, managing popups, etc. In @@ -197,7 +193,7 @@ class WebConsole { * The line number which you want to place the caret. */ viewSourceInStyleEditor(sourceURL, sourceLine) { - const toolbox = this.toolbox; + const toolbox = gDevTools.getToolbox(this.target); if (!toolbox) { this.viewSource(sourceURL, sourceLine); return; @@ -220,7 +216,7 @@ class WebConsole { * The column number which you want to place the caret. */ viewSourceInDebugger(sourceURL, sourceLine, sourceColumn) { - const toolbox = this.toolbox; + const toolbox = gDevTools.getToolbox(this.target); if (!toolbox) { this.viewSource(sourceURL, sourceLine, sourceColumn); return; @@ -257,7 +253,7 @@ class WebConsole { * returned. */ getDebuggerFrames() { - const toolbox = this.toolbox; + const toolbox = gDevTools.getToolbox(this.target); if (!toolbox) { return null; } @@ -286,7 +282,7 @@ class WebConsole { * `originalExpression`. */ getMappedExpression(expression) { - const toolbox = this.toolbox; + const toolbox = gDevTools.getToolbox(this.target); // We need to check if the debugger is open, since it may perform a variable name // substitution for sourcemapped script (i.e. evaluated `myVar.trim()` might need to @@ -341,7 +337,7 @@ class WebConsole { * then |null| is returned. */ getInspectorSelection() { - const toolbox = this.toolbox; + const toolbox = gDevTools.getToolbox(this.target); if (!toolbox) { return null; }