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
This commit is contained in:
Nicolas Chevobbe 2022-05-17 13:12:08 +00:00
Родитель 2c889a3c67
Коммит 1fd72cd0c4
1 изменённых файлов: 22 добавлений и 18 удалений

Просмотреть файл

@ -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);
}