From eaa75cbe8cf9405617ea10431ed7d3a4df40dc2d Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Mon, 12 Jul 2021 13:50:03 +0000 Subject: [PATCH] Bug 1712750 - Make sure sanitize.xhtml gets to set its mozSubdialogReady. r=mtigley The mozSubdialogReady was being set inside of sanitize.xhtml in its load event handler, which would be scheduled to run AFTER the SubDialog _onLoad handler (which is what awaits mozSubdialogReady). The only reason this wasn't more obvious is because the first time the dialog is opened, the SubDialog _onLoad handler awaits translation of the document, which gives sanitize.xhtml a chance to run its load event handler and set the mozSubdialogReady. Subsequent opens of the dialog wouldn't need to re-run translation due to document caching, and so the mozSubdialogReady wouldn't be waited for, resulting in incorrect dialog layout. Depends on D119329 Differential Revision: https://phabricator.services.mozilla.com/D119330 --- browser/base/content/sanitize.xhtml | 3 +-- browser/base/content/sanitizeDialog.js | 29 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/browser/base/content/sanitize.xhtml b/browser/base/content/sanitize.xhtml index a4ec3b5ef9bb..763fb0b7fa9f 100644 --- a/browser/base/content/sanitize.xhtml +++ b/browser/base/content/sanitize.xhtml @@ -20,8 +20,7 @@ xmlns:html="http://www.w3.org/1999/xhtml" persist="lastSelected screenX screenY" data-l10n-id="dialog-title" - data-l10n-attrs="style" - onload="gSanitizePromptDialog.init();"> + data-l10n-attrs="style"> diff --git a/browser/base/content/sanitizeDialog.js b/browser/base/content/sanitizeDialog.js index 4f68bb230859..972befc210c7 100644 --- a/browser/base/content/sanitizeDialog.js +++ b/browser/base/content/sanitizeDialog.js @@ -30,7 +30,7 @@ var gSanitizePromptDialog = { return document.getElementById("sanitizeEverythingWarningBox"); }, - init() { + async init() { // This is used by selectByTimespan() to determine if the window has loaded. this._inited = true; this._dialog = document.querySelector("dialog"); @@ -53,13 +53,9 @@ var gSanitizePromptDialog = { ); let warningDesc = document.getElementById("sanitizeEverythingWarning"); // Ensure we've translated and sized the warning. - document.mozSubdialogReady = document.l10n - .translateFragment(warningDesc) - .then(() => { - // And then ensure we've run layout. - let rootWin = window.browsingContext.topChromeWindow; - return rootWin.promiseDocumentFlushed(() => {}); - }); + await document.l10n.translateFragment(warningDesc); + let rootWin = window.browsingContext.topChromeWindow; + await rootWin.promiseDocumentFlushed(() => {}); } else { this.warningBox.hidden = true; } @@ -221,3 +217,20 @@ var gSanitizePromptDialog = { } }, }; + +// We need to give the dialog an opportunity to set up the DOM +// before its measured for the SubDialog it will be embedded in. +// This is because the sanitizeEverythingWarningBox may or may +// not be visible, depending on whether "Everything" is the default +// choice in the menulist. +document.mozSubdialogReady = new Promise(resolve => { + window.addEventListener( + "load", + function() { + gSanitizePromptDialog.init().then(resolve); + }, + { + once: true, + } + ); +});