From 0c01c764aa3786cf0201c14d67143711eb49ea5e Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Thu, 31 Jan 2019 18:08:19 +0000 Subject: [PATCH] Bug 1521440: Avoid to move to about:blank after destroying. r=ochameau,jdescottes Differential Revision: https://phabricator.services.mozilla.com/D17795 --HG-- extra : moz-landing-system : lando --- .../client/framework/toolbox-host-manager.js | 7 +++-- devtools/client/framework/toolbox-hosts.js | 31 ++++++++++++++++++- devtools/client/framework/toolbox-init.js | 2 +- devtools/client/framework/toolbox.js | 16 +++++++++- toolkit/components/telemetry/Events.yaml | 2 +- toolkit/components/telemetry/Histograms.json | 2 +- 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/devtools/client/framework/toolbox-host-manager.js b/devtools/client/framework/toolbox-host-manager.js index e0fcb858715e..af5f1c3900be 100644 --- a/devtools/client/framework/toolbox-host-manager.js +++ b/devtools/client/framework/toolbox-host-manager.js @@ -104,6 +104,7 @@ ToolboxHostManager.prototype = { this.hostType === Toolbox.HostType.RIGHT) { this.host.frame.minWidth = WIDTH_CHEVRON_AND_MEATBALL_AND_CLOSE * zoomValue; } else if (this.hostType === Toolbox.HostType.WINDOW || + this.hostType === Toolbox.HostType.PAGE || this.hostType === Toolbox.HostType.CUSTOM) { this.host.frame.minWidth = WIDTH_CHEVRON_AND_MEATBALL * zoomValue; } @@ -215,7 +216,8 @@ ToolboxHostManager.prototype = { this.destroyHost(); - if (this.hostType != Toolbox.HostType.CUSTOM) { + if (this.hostType !== Toolbox.HostType.CUSTOM && + this.hostType !== Toolbox.HostType.PAGE) { Services.prefs.setCharPref(PREVIOUS_HOST, this.hostType); } @@ -227,7 +229,8 @@ ToolboxHostManager.prototype = { this.setMinWidthWithZoom(); - if (hostType != Toolbox.HostType.CUSTOM) { + if (hostType !== Toolbox.HostType.CUSTOM && + hostType !== Toolbox.HostType.PAGE) { Services.prefs.setCharPref(LAST_HOST, hostType); } diff --git a/devtools/client/framework/toolbox-hosts.js b/devtools/client/framework/toolbox-hosts.js index b0094bd34d6f..c49d1cb67b3a 100644 --- a/devtools/client/framework/toolbox-hosts.js +++ b/devtools/client/framework/toolbox-hosts.js @@ -370,6 +370,35 @@ CustomHost.prototype = { }, }; +/** + * Host object for the toolbox as a page. + * This is typically used by `about:debugging`, when opening toolbox in a new tab, + * via `about:devtools-toolbox` URLs. + * The `iframe` ends up being the tab's browser element. + */ +function PageHost(hostTab, options) { + this.frame = options.customIframe; +} + +PageHost.prototype = { + type: "page", + + create: function() { + return promise.resolve(this.frame); + }, + + // Do nothing. + raise: function() {}, + + // Do nothing. + setTitle: function(title) {}, + + // Do nothing. + destroy: function() { + return promise.resolve(null); + }, +}; + /** * Switch to the given tab in a browser and focus the browser window */ @@ -385,5 +414,5 @@ exports.Hosts = { "right": RightHost, "window": WindowHost, "custom": CustomHost, + "page": PageHost, }; - diff --git a/devtools/client/framework/toolbox-init.js b/devtools/client/framework/toolbox-init.js index 1be60e3b0337..13d4b8fd37b4 100644 --- a/devtools/client/framework/toolbox-init.js +++ b/devtools/client/framework/toolbox-init.js @@ -77,7 +77,7 @@ if (url.search.length > 1) { target = await targetFromURL(url); } const options = { customIframe: host }; - await gDevTools.showToolbox(target, tool, Toolbox.HostType.CUSTOM, options); + await gDevTools.showToolbox(target, tool, Toolbox.HostType.PAGE, options); })().catch(error => { console.error("Exception while loading the toolbox", error); }); diff --git a/devtools/client/framework/toolbox.js b/devtools/client/framework/toolbox.js index f2848bf404b2..29df65e789f5 100644 --- a/devtools/client/framework/toolbox.js +++ b/devtools/client/framework/toolbox.js @@ -220,6 +220,9 @@ Toolbox.HostType = { LEFT: "left", WINDOW: "window", CUSTOM: "custom", + // This is typically used by `about:debugging`, when opening toolbox in a new tab, + // via `about:devtools-toolbox` URLs. + PAGE: "page", }; Toolbox.prototype = { @@ -435,7 +438,9 @@ Toolbox.prototype = { if (isToolboxURL) { // Update the URL so that onceDOMReady watch for the right url. this._URL = this.win.location.href; + } + if (this.hostType === Toolbox.HostType.PAGE) { // Displays DebugTargetInfo which shows the basic information of debug target, // if `about:devtools-toolbox` URL opens directly. // DebugTargetInfo requires this._deviceDescription to be populated @@ -727,6 +732,7 @@ Toolbox.prototype = { case Toolbox.HostType.WINDOW: return 2; case Toolbox.HostType.CUSTOM: return 3; case Toolbox.HostType.LEFT: return 4; + case Toolbox.HostType.PAGE: return 5; default: return 9; } }, @@ -738,6 +744,7 @@ Toolbox.prototype = { case Toolbox.HostType.LEFT: return "left"; case Toolbox.HostType.RIGHT: return "right"; case Toolbox.HostType.WINDOW: return "window"; + case Toolbox.HostType.PAGE: return "page"; case Toolbox.HostType.CUSTOM: return "other"; default: return "bottom"; } @@ -1105,6 +1112,7 @@ Toolbox.prototype = { for (const type in Toolbox.HostType) { const position = Toolbox.HostType[type]; if (position == Toolbox.HostType.CUSTOM || + position == Toolbox.HostType.PAGE || (!sideEnabled && (position == Toolbox.HostType.LEFT || position == Toolbox.HostType.RIGHT))) { continue; @@ -2981,7 +2989,13 @@ Toolbox.prototype = { // target attribute to be still // defined. try { - win.location.replace("about:blank"); + // If this toolbox displayed as a page, avoid to move to `about:blank`. + // For example in case of reloading, when the thread of processing of + // destroying the toolbox arrives at here after starting reloading process, + // although we should display same page, `about:blank` will display. + if (this.hostType !== Toolbox.HostType.PAGE) { + win.location.replace("about:blank"); + } } catch (e) { // Do nothing; } diff --git a/toolkit/components/telemetry/Events.yaml b/toolkit/components/telemetry/Events.yaml index a7c8fd539844..8ade74d3ee52 100644 --- a/toolkit/components/telemetry/Events.yaml +++ b/toolkit/components/telemetry/Events.yaml @@ -281,7 +281,7 @@ devtools.main: release_channel_collection: opt-out expiry_version: never extra_keys: - host: "Toolbox host (positioning): bottom, side, window or other." + host: "Toolbox host (positioning): bottom, left, right, window, page or other." width: Toolbox width rounded up to the nearest 50px. session_id: The start time of the session in milliseconds since epoch (Unix Timestamp) e.g. 1396381378123. add_breakpoint: diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index f39c6b545392..ae77746a8d9a 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -10493,7 +10493,7 @@ "bug_numbers": [1205845, 1389995], "n_values": 9, "releaseChannelCollection": "opt-out", - "description": "Records DevTools toolbox host each time the toolbox is opened and when the host is changed (0:Bottom, 1:Side, 2:Window, 3:Custom, 9:Unknown)." + "description": "Records DevTools toolbox host each time the toolbox is opened and when the host is changed (0:Bottom, 1:RIGHT, 2:WINDOW, 3:CUSTOM, 4:LEFT, 5:PAGE, 9:Unknown)." }, "DEVTOOLS_NUMBER_OF_CSS_GRIDS_IN_A_PAGE": { "record_in_processes": ["main", "content"],