From 1fd72cd0c4f5de06aaa042479def0c35313de3c1 Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Tue, 17 May 2022 13:12:08 +0000 Subject: [PATCH] Bug 1768209 - [devtools] Fix Disable Popup Auto-Hide + Browser Toolbox highlighters. r=emilio. Using insertAnonymousContent on a document where a XUL popup is displayed seems to hide/destroy it. This patch extends the current behaviour for XUL windows to Chrome windows: we add an iframe in the document which will contain the anonymous content. Differential Revision: https://phabricator.services.mozilla.com/D146036 --- .../actors/highlighters/utils/markup.js | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/devtools/server/actors/highlighters/utils/markup.js b/devtools/server/actors/highlighters/utils/markup.js index 34bebf8a7e6d..13f59895ff69 100644 --- a/devtools/server/actors/highlighters/utils/markup.js +++ b/devtools/server/actors/highlighters/utils/markup.js @@ -266,17 +266,21 @@ CanvasFrameAnonymousContentHelper.prototype = { // CanvasFrameAnonymousContentHelper was already destroyed. return; } - if (isXUL(this.highlighterEnv.window)) { + + const window = this.highlighterEnv.window; + const isXULWindow = isXUL(window); + const isChromeWindow = window.isChromeWindow; + + if (isXULWindow || isChromeWindow) { // In order to use anonymous content, we need to create and use an IFRAME // inside a XUL document first and use its window/document the same way we - // would normally use highlighter environment's window/document. See - // TODO: bug 1594587 for more details. - // - // Note: xul:window is not necessarily the top chrome window (as it's the - // case with about:devtools-toolbox). We need to ensure that we use the - // top chrome window to look up or create the iframe. + // would normally use highlighter environment's window/document. + // See Bug 1594587 for more details. + // For Chrome Windows, we also need to do it as the first call to insertAnonymousContent + // closes XUL popups even if ui.popup.disable_autohide is true (See Bug 1768896). + + const { documentElement } = window.document; if (!this._iframe) { - const { documentElement } = this.highlighterEnv.window.document; this._iframe = documentElement.querySelector( ":scope > .devtools-highlighter-renderer" ); @@ -286,19 +290,19 @@ CanvasFrameAnonymousContentHelper.prototype = { const numberOfHighlighters = parseInt(this._iframe.dataset.numberOfHighlighters, 10) + 1; this._iframe.dataset.numberOfHighlighters = numberOfHighlighters; - } else { - this._iframe = this.highlighterEnv.window.document.createElement( - "iframe" - ); - this._iframe.classList.add("devtools-highlighter-renderer"); - // If iframe is used for the first time, add ref count of one to its - // numberOfHighlighters data attribute. - this._iframe.dataset.numberOfHighlighters = 1; - documentElement.append(this._iframe); - loadSheet(this.highlighterEnv.window, XUL_HIGHLIGHTER_STYLES_SHEET); } } + if (!this._iframe) { + this._iframe = window.document.createElement("iframe"); + this._iframe.classList.add("devtools-highlighter-renderer"); + // If iframe is used for the first time, add ref count of one to its + // numberOfHighlighters data attribute. + this._iframe.dataset.numberOfHighlighters = 1; + documentElement.append(this._iframe); + loadSheet(window, XUL_HIGHLIGHTER_STYLES_SHEET); + } + if (this.waitForDocumentToLoad) { await waitForContentLoaded(this._iframe); }