Bug 1585482 - Restructure all <xul:dialog> usages such that they are not the top level element r=bgrins
authorKirk Steuber <ksteuber@mozilla.com>
Tue, 10 Dec 2019 18:25:59 +0000
changeset 506294 db3709c80ad1540170537a0a986642038ffad410
parent 506293 88b25807638231dcf403d8f0b597fc770f1d24a4
child 506295 9ed1b123250d4c9f616532a80f54b00099cf34b6
push id36902
push useraciure@mozilla.com
push dateWed, 11 Dec 2019 03:34:51 +0000
treeherdermozilla-central@7635669b8d72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1585482
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1585482 - Restructure all <xul:dialog> usages such that they are not the top level element r=bgrins This patch also includes necessary JS changes to support this. Most commonly, the dialog was accessed with document.documentElement, which needed to be changed now that the dialog is not the top level element. Differential Revision: https://phabricator.services.mozilla.com/D52411
browser/base/content/safeMode.js
browser/base/content/safeMode.xul
browser/base/content/sanitize.xul
browser/base/content/sanitizeDialog.js
browser/components/places/content/bookmarkProperties.js
browser/components/places/content/bookmarkProperties.xul
browser/components/preferences/applicationManager.xhtml
browser/components/preferences/browserLanguages.js
browser/components/preferences/browserLanguages.xhtml
browser/components/preferences/colors.js
browser/components/preferences/colors.xhtml
browser/components/preferences/connection.js
browser/components/preferences/connection.xhtml
browser/components/preferences/fonts.js
browser/components/preferences/fonts.xhtml
browser/components/preferences/in-content/subdialogs.js
browser/components/preferences/in-content/syncChooseWhatToSync.js
browser/components/preferences/in-content/syncChooseWhatToSync.xhtml
browser/components/preferences/languages.js
browser/components/preferences/languages.xhtml
browser/components/preferences/sanitize.js
browser/components/preferences/sanitize.xhtml
browser/components/preferences/selectBookmark.js
browser/components/preferences/selectBookmark.xhtml
browser/components/preferences/siteDataRemoveSelected.xhtml
browser/components/shell/content/setDesktopBackground.js
browser/components/shell/content/setDesktopBackground.xul
browser/extensions/formautofill/skin/linux/editDialog.css
browser/extensions/formautofill/skin/shared/editAddress.css
browser/extensions/formautofill/skin/shared/editDialog-shared.css
browser/themes/linux/preferences/in-content/dialog.css
browser/themes/osx/preferences/in-content/dialog.css
browser/themes/windows/preferences/in-content/dialog.css
security/manager/pki/resources/content/certManager.xhtml
security/manager/pki/resources/content/certViewer.xhtml
security/manager/pki/resources/content/changepassword.js
security/manager/pki/resources/content/changepassword.xhtml
security/manager/pki/resources/content/clientauthask.xhtml
security/manager/pki/resources/content/deletecert.xhtml
security/manager/pki/resources/content/device_manager.xhtml
security/manager/pki/resources/content/downloadcert.xhtml
security/manager/pki/resources/content/editcacert.xhtml
security/manager/pki/resources/content/exceptionDialog.js
security/manager/pki/resources/content/exceptionDialog.xhtml
security/manager/pki/resources/content/load_device.xhtml
security/manager/pki/resources/content/resetpassword.xhtml
security/manager/pki/resources/content/setp12password.js
security/manager/pki/resources/content/setp12password.xhtml
toolkit/components/apppicker/content/appPicker.xul
toolkit/components/printing/content/printPageSetup.xul
toolkit/components/printing/content/printPreviewProgress.xul
toolkit/components/printing/content/printProgress.xul
toolkit/components/prompts/content/commonDialog.js
toolkit/components/prompts/content/commonDialog.xul
toolkit/components/prompts/content/selectDialog.xul
toolkit/content/preferencesBindings.js
toolkit/content/resetProfile.xul
toolkit/content/widgets/dialog.js
toolkit/content/xul.css
toolkit/mozapps/downloads/HelperAppDlg.jsm
toolkit/mozapps/downloads/content/unknownContentType.xul
toolkit/mozapps/extensions/content/blocklist.js
toolkit/mozapps/extensions/content/blocklist.xul
toolkit/mozapps/handling/content/dialog.js
toolkit/mozapps/handling/content/dialog.xul
toolkit/mozapps/preferences/changemp.js
toolkit/mozapps/preferences/changemp.xhtml
toolkit/mozapps/preferences/removemp.js
toolkit/mozapps/preferences/removemp.xhtml
toolkit/mozapps/update/content/history.js
toolkit/mozapps/update/content/history.xhtml
toolkit/mozapps/update/content/updateElevation.xul
toolkit/profile/content/profileDowngrade.xul
toolkit/profile/content/profileSelection.js
toolkit/profile/content/profileSelection.xul
--- a/browser/base/content/safeMode.js
+++ b/browser/base/content/safeMode.js
@@ -64,26 +64,27 @@ function onExtra1() {
     // Continue in safe mode
     window.close();
   }
   // The reset dialog will handle starting the reset process if the user confirms.
   showResetDialog();
 }
 
 function onLoad() {
+  const dialog = document.getElementById("safeModeDialog");
   if (appStartup.automaticSafeModeNecessary) {
     document.getElementById("autoSafeMode").hidden = false;
     document.getElementById("safeMode").hidden = true;
     if (ResetProfile.resetSupported()) {
       document.getElementById("resetProfile").hidden = false;
     } else {
       // Hide the reset button is it's not supported.
-      document.documentElement.getButton("extra1").hidden = true;
+      dialog.getButton("extra1").hidden = true;
     }
   } else if (!ResetProfile.resetSupported()) {
     // Hide the reset button and text if it's not supported.
-    document.documentElement.getButton("extra1").hidden = true;
+    dialog.getButton("extra1").hidden = true;
     document.getElementById("resetProfileInstead").hidden = true;
   }
   document.addEventListener("dialogaccept", onDefaultButton);
   document.addEventListener("dialogcancel", onCancel);
   document.addEventListener("dialogextra1", onExtra1);
 }
--- a/browser/base/content/safeMode.xul
+++ b/browser/base/content/safeMode.xul
@@ -2,25 +2,25 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/content/safeMode.css"?>
 
-<dialog id="safeModeDialog"
-            xmlns:html="http://www.w3.org/1999/xhtml"
+<window xmlns:html="http://www.w3.org/1999/xhtml"
             xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
             data-l10n-id="safe-mode-window"
             data-l10n-attrs="title,style"
+            onload="onLoad()">
+<dialog id="safeModeDialog"
             buttons="accept,extra1"
             buttonidaccept="start-safe-mode"
-            buttonidextra1="refresh-profile"
-            onload="onLoad()">
+            buttonidextra1="refresh-profile">
 
   <linkset>
     <html:link rel="localization" href="branding/brand.ftl"/>
     <html:link rel="localization" href="browser/safeMode.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/safeMode.js"/>
 
@@ -38,8 +38,9 @@
   </vbox>
 
   <vbox id="resetProfile" hidden="true">
     <label data-l10n-id="refresh-profile-instead" />
   </vbox>
 
   <separator class="thin"/>
 </dialog>
+</window>
--- a/browser/base/content/sanitize.xul
+++ b/browser/base/content/sanitize.xul
@@ -7,27 +7,27 @@
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 <?xml-stylesheet href="chrome://browser/skin/sanitizeDialog.css"?>
 
 
 <?xml-stylesheet href="chrome://browser/content/sanitizeDialog.css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
-<dialog id="SanitizeDialog" type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        buttons="accept,cancel"
         persist="lastSelected screenX screenY"
-        role="dialog"
         data-l10n-id="dialog-title"
         data-l10n-attrs="style"
         onload="gSanitizePromptDialog.init();">
+<dialog id="SanitizeDialog"
+        buttons="accept,cancel">
 
   <linkset>
     <html:link rel="localization" href="browser/sanitize.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/preferencesBindings.js"/>
   <script src="chrome://browser/content/sanitizeDialog.js"/>
 
@@ -96,8 +96,9 @@
       </vbox>
       <vbox flex="1">
         <checkbox data-l10n-id="item-offline-apps"
                   preference="privacy.cpd.offlineApps"/>
       </vbox>
     </hbox>
   </groupbox>
 </dialog>
+</window>
--- a/browser/base/content/sanitizeDialog.js
+++ b/browser/base/content/sanitizeDialog.js
@@ -28,18 +28,19 @@ var gSanitizePromptDialog = {
 
   get warningBox() {
     return document.getElementById("sanitizeEverythingWarningBox");
   },
 
   init() {
     // This is used by selectByTimespan() to determine if the window has loaded.
     this._inited = true;
+    this._dialog = document.getElementById("SanitizeDialog");
 
-    let OKButton = document.documentElement.getButton("accept");
+    let OKButton = this._dialog.getButton("accept");
     document.l10n.setAttributes(OKButton, "sanitize-button-ok");
 
     document.addEventListener("dialogaccept", function(e) {
       gSanitizePromptDialog.sanitize(e);
     });
 
     this.registerSyncFromPrefListeners();
 
@@ -109,21 +110,20 @@ var gSanitizePromptDialog = {
   sanitize(event) {
     // Update pref values before handing off to the sanitizer (bug 453440)
     this.updatePrefs();
 
     // As the sanitize is async, we disable the buttons, update the label on
     // the 'accept' button to indicate things are happening and return false -
     // once the async operation completes (either with or without errors)
     // we close the window.
-    let docElt = document.documentElement;
-    let acceptButton = docElt.getButton("accept");
+    let acceptButton = this._dialog.getButton("accept");
     acceptButton.disabled = true;
     document.l10n.setAttributes(acceptButton, "sanitize-button-clearing");
-    docElt.getButton("cancel").disabled = true;
+    this._dialog.getButton("cancel").disabled = true;
 
     try {
       let range = Sanitizer.getClearRange(this.selectedTimespan);
       let options = {
         ignoreTimespan: !range,
         range,
       };
       Sanitizer.sanitize(null, options)
@@ -170,17 +170,17 @@ var gSanitizePromptDialog = {
   onReadGeneric() {
     // Find any other pref that's checked and enabled (except for
     // privacy.sanitize.timeSpan, which doesn't affect the button's status).
     var found = this._getItemPrefs().some(
       pref => !!pref.value && !pref.disabled
     );
 
     try {
-      document.documentElement.getButton("accept").disabled = !found;
+      this._dialog.getButton("accept").disabled = !found;
     } catch (e) {}
 
     // Update the warning prompt if needed
     this.prepareWarning();
 
     return undefined;
   },
 
--- a/browser/components/places/content/bookmarkProperties.js
+++ b/browser/components/places/content/bookmarkProperties.js
@@ -242,32 +242,36 @@ var BookmarkPropertiesPanel = {
     document.addEventListener("dialogaccept", function() {
       BookmarkPropertiesPanel.onDialogAccept();
     });
     document.addEventListener("dialogcancel", function() {
       BookmarkPropertiesPanel.onDialogCancel();
     });
 
     // Disable the buttons until we have all the information required.
-    let acceptButton = document.documentElement.getButton("accept");
+    let acceptButton = document
+      .getElementById("bookmarkproperties")
+      .getButton("accept");
     acceptButton.disabled = true;
 
     // Allow initialization to complete in a truely async manner so that we're
     // not blocking the main thread.
     this._initDialog().catch(ex => {
       Cu.reportError(`Failed to initialize dialog: ${ex}`);
     });
   },
 
   /**
    * Initializes the dialog, gathering the required bookmark data. This function
    * will enable the accept button (if appropraite) when it is complete.
    */
   async _initDialog() {
-    let acceptButton = document.documentElement.getButton("accept");
+    let acceptButton = document
+      .getElementById("bookmarkproperties")
+      .getButton("accept");
     acceptButton.label = this._getAcceptLabel();
     let acceptButtonDisabled = false;
 
     // Do not use sizeToContent, otherwise, due to bug 90276, the dialog will
     // grow at every opening.
     // Since elements can be uncollapsed asynchronously, we must observe their
     // mutations and resize the dialog using a cached element size.
     this._height = window.outerHeight;
@@ -359,19 +363,19 @@ var BookmarkPropertiesPanel = {
     var target = aEvent.target;
     switch (aEvent.type) {
       case "input":
         if (
           target.id == "editBMPanel_locationField" ||
           target.id == "editBMPanel_keywordField"
         ) {
           // Check uri fields to enable accept button if input is valid
-          document.documentElement.getButton(
-            "accept"
-          ).disabled = !this._inputIsValid();
+          document
+            .getElementById("bookmarkproperties")
+            .getButton("accept").disabled = !this._inputIsValid();
         }
         break;
       case "resize":
         for (let [id, oldHeight] of elementsHeight) {
           let newHeight = document.getElementById(id).getBoundingClientRect()
             .height;
           this._height += -oldHeight + newHeight;
           elementsHeight.set(id, newHeight);
--- a/browser/components/places/content/bookmarkProperties.xul
+++ b/browser/components/places/content/bookmarkProperties.xul
@@ -4,38 +4,39 @@
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/places/editBookmark.css"?>
 <?xml-stylesheet href="chrome://browser/skin/places/tree-icons.css"?>
 <?xml-stylesheet href="chrome://browser/content/places/places.css"?>
 
-<!DOCTYPE dialog [
+<!DOCTYPE window [
   <!ENTITY % editBookmarkOverlayDTD SYSTEM "chrome://browser/locale/places/editBookmarkOverlay.dtd">
   %editBookmarkOverlayDTD;
 ]>
 
-<dialog id="bookmarkproperties"
-        buttons="accept, cancel"
-        buttoniconaccept="save"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         onload="BookmarkPropertiesPanel.onDialogLoad();"
         onunload="BookmarkPropertiesPanel.onDialogUnload();"
         style="min-width: 30em;"
         persist="screenX screenY width">
+<dialog id="bookmarkproperties"
+        buttons="accept, cancel"
+        buttoniconaccept="save">
 
   <stringbundleset id="stringbundleset">
     <stringbundle id="stringBundle"
                   src="chrome://browser/locale/places/bookmarkProperties.properties"/>
   </stringbundleset>
 
   <script src="chrome://browser/content/places/editBookmark.js"/>
   <script src="chrome://browser/content/places/bookmarkProperties.js"/>
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
   <script src="chrome://browser/content/utilityOverlay.js"/>
   <script src="chrome://browser/content/places/places-tree.js"/>
 
 #include editBookmarkPanel.inc.xhtml
 
 </dialog>
+</window>
--- a/browser/components/preferences/applicationManager.xhtml
+++ b/browser/components/preferences/applicationManager.xhtml
@@ -1,24 +1,24 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/applications.css"?>
 
-<dialog id="appManager"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        buttons="accept,cancel"
         onload="gAppManagerDialog.onLoad();"
         data-l10n-id="app-manager-window"
         data-l10n-attrs="title, style"
         persist="screenX screenY">
+<dialog id="appManager"
+        buttons="accept,cancel">
 
   <linkset>
     <html:link rel="localization" href="browser/preferences/applicationManager.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/utilityOverlay.js"/>
   <script src="chrome://global/content/preferencesBindings.js"/>
   <script src="chrome://browser/content/preferences/applicationManager.js"/>
@@ -45,8 +45,9 @@
     </vbox>
   </hbox>
   <vbox id="appDetails">
     <separator class="thin"/>
     <label id="appType"/>
     <html:input type="text" id="appLocation" readonly="readonly" style="margin-inline: 0;"/>
   </vbox>
 </dialog>
+</window>
--- a/browser/components/preferences/browserLanguages.js
+++ b/browser/components/preferences/browserLanguages.js
@@ -25,20 +25,19 @@ ChromeUtils.defineModuleGetter(
   "resource://services-settings/remote-settings.js"
 );
 ChromeUtils.defineModuleGetter(
   this,
   "SelectionChangedMenulist",
   "resource:///modules/SelectionChangedMenulist.jsm"
 );
 
-document.documentElement.addEventListener(
-  "dialoghelp",
-  window.top.openPrefsHelp
-);
+document
+  .getElementById("BrowserLanguagesDialog")
+  .addEventListener("dialoghelp", window.top.openPrefsHelp);
 
 /* This dialog provides an interface for managing what language the browser is
  * displayed in.
  *
  * There is a list of "requested" locales and a list of "available" locales. The
  * requested locales must be installed and enabled. Available locales could be
  * installed and enabled, or fetched from the AMO language tools API.
  *
@@ -379,19 +378,19 @@ var gBrowserLanguagesDialog = {
   },
 
   beforeAccept() {
     this.selected = this.getSelectedLocales();
     this.accepted = true;
   },
 
   async onLoad() {
-    document.documentElement.addEventListener("beforeaccept", () =>
-      this.beforeAccept()
-    );
+    document
+      .getElementById("BrowserLanguagesDialog")
+      .addEventListener("beforeaccept", () => this.beforeAccept());
     // Maintain the previously selected locales even if we cancel out.
     let { telemetryId, selected, search } = window.arguments[0];
     this.telemetryId = telemetryId;
     this.selectedLocales = selected;
 
     // This is a list of available locales that the user selected. It's more
     // restricted than the Intl notion of `requested` as it only contains
     // locale codes for which we have matching locales available.
--- a/browser/components/preferences/browserLanguages.xhtml
+++ b/browser/components/preferences/browserLanguages.xhtml
@@ -2,25 +2,25 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 
-<dialog id="BrowserLanguagesDialog" type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="browser-languages-window"
         data-l10n-attrs="title, style"
+        persist="screenX screenY"
+        onload="gBrowserLanguagesDialog.onLoad();">
+<dialog id="BrowserLanguagesDialog"
         buttons="accept,cancel,help"
-        persist="screenX screenY"
-        role="dialog"
-        onload="gBrowserLanguagesDialog.onLoad();"
         helpTopic="change-language">
 
   <linkset>
     <html:link rel="localization" href="branding/brand.ftl"/>
     <html:link rel="localization" href="browser/preferences/languages.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/utilityOverlay.js"/>
@@ -48,8 +48,9 @@
             data-l10n-id="languages-customize-add"
             disabled="true"/>
   </box>
   <hbox id="warning-message" class="message-bar message-bar-warning" hidden="true">
     <image class="message-bar-icon"/>
     <description class="message-bar-description" data-l10n-id="browser-languages-error"/>
   </hbox>
 </dialog>
+</window>
--- a/browser/components/preferences/colors.js
+++ b/browser/components/preferences/colors.js
@@ -1,18 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../../toolkit/content/preferencesBindings.js */
 
-document.documentElement.addEventListener(
-  "dialoghelp",
-  window.top.openPrefsHelp
-);
+document
+  .getElementById("ColorsDialog")
+  .addEventListener("dialoghelp", window.top.openPrefsHelp);
 
 Preferences.addAll([
   { id: "browser.display.document_color_use", type: "int" },
   { id: "browser.anchor_color", type: "string" },
   { id: "browser.visited_color", type: "string" },
   { id: "browser.underline_anchors", type: "bool" },
   { id: "browser.display.foreground_color", type: "string" },
   { id: "browser.display.background_color", type: "string" },
--- a/browser/components/preferences/colors.xhtml
+++ b/browser/components/preferences/colors.xhtml
@@ -3,24 +3,24 @@
 <!-- -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -->
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 
-<dialog id="ColorsDialog" type="child" class="prefwindow"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="colors-window"
         data-l10n-attrs="title, style"
+        persist="lastSelected screenX screenY">
+<dialog id="ColorsDialog"
         buttons="accept,cancel,help"
-        persist="lastSelected screenX screenY"
-        role="dialog"
         helpTopic="prefs-fonts-and-colors">
 
   <linkset>
     <html:link rel="localization" href="browser/preferences/colors.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/utilityOverlay.js"/>
   <script src="chrome://global/content/preferencesBindings.js"/>
@@ -85,8 +85,9 @@
                   value="1" id="documentColorNever"/>
       </menupopup>
     </menulist>
   </hbox>
 
   <!-- Load the script after the elements for layout issues (bug 1501755). -->
   <script src="chrome://browser/content/preferences/colors.js"/>
 </dialog>
+</window>
--- a/browser/components/preferences/connection.js
+++ b/browser/components/preferences/connection.js
@@ -2,20 +2,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../base/content/utilityOverlay.js */
 /* import-globals-from ../../../toolkit/content/preferencesBindings.js */
 /* import-globals-from in-content/extensionControlled.js */
 
-document.documentElement.addEventListener(
-  "dialoghelp",
-  window.top.openPrefsHelp
-);
+document
+  .getElementById("ConnectionsDialog")
+  .addEventListener("dialoghelp", window.top.openPrefsHelp);
 
 Preferences.addAll([
   // Add network.proxy.autoconfig_url before network.proxy.type so they're
   // both initialized when network.proxy.type initialization triggers a call to
   // gConnectionsDialog.updateReloadButton().
   { id: "network.proxy.autoconfig_url", type: "string" },
   { id: "network.proxy.type", type: "int" },
   { id: "network.proxy.http", type: "string" },
@@ -80,19 +79,21 @@ window.addEventListener(
         "command",
         makeDisableControllingExtension(PREF_SETTING_TYPE, PROXY_KEY).bind(
           gConnectionsDialog
         )
       );
     gConnectionsDialog.updateProxySettingsUI();
     initializeProxyUI(gConnectionsDialog);
     gConnectionsDialog.registerSyncPrefListeners();
-    document.documentElement.addEventListener("beforeaccept", e =>
-      gConnectionsDialog.beforeAccept(e)
-    );
+    document
+      .getElementById("ConnectionsDialog")
+      .addEventListener("beforeaccept", e =>
+        gConnectionsDialog.beforeAccept(e)
+      );
   },
   { once: true, capture: true }
 );
 
 var gConnectionsDialog = {
   beforeAccept(event) {
     let dnsOverHttpsResolverChoice = document.getElementById(
       "networkDnsOverHttpsResolverChoices"
--- a/browser/components/preferences/connection.xhtml
+++ b/browser/components/preferences/connection.xhtml
@@ -2,25 +2,25 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 
-<dialog id="ConnectionsDialog" type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="connection-window"
         data-l10n-attrs="title, style"
+        persist="lastSelected screenX screenY"
+        onload="gConnectionsDialog.checkForSystemProxy();">
+<dialog id="ConnectionsDialog"
         buttons="accept,cancel,help"
-        persist="lastSelected screenX screenY"
-        role="dialog"
-        onload="gConnectionsDialog.checkForSystemProxy();"
         helpTopic="prefs-connection-settings">
 
   <!-- Used for extension-controlled lockdown message -->
   <linkset>
     <html:link rel="localization" href="browser/preferences/connection.ftl"/>
     <html:link rel="localization" href="browser/preferences/preferences.ftl"/>
     <html:link rel="localization" href="branding/brand.ftl"/>
   </linkset>
@@ -159,8 +159,9 @@
                data-l10n-id="connection-dns-over-https-custom-label"
                control="networkCustomDnsOverHttpsInput"/>
       </hbox>
       <html:input id="networkCustomDnsOverHttpsInput" type="text" style="-moz-box-flex: 1;"
                   preference="network.trr.custom_uri"/>
     </box>
   </groupbox>
 </dialog>
+</window>
--- a/browser/components/preferences/fonts.js
+++ b/browser/components/preferences/fonts.js
@@ -13,20 +13,19 @@ const kFontNameFmtSansSerif = "font.name
 const kFontNameFmtMonospace = "font.name.monospace.%LANG%";
 const kFontNameListFmtSerif = "font.name-list.serif.%LANG%";
 const kFontNameListFmtSansSerif = "font.name-list.sans-serif.%LANG%";
 const kFontNameListFmtMonospace = "font.name-list.monospace.%LANG%";
 const kFontSizeFmtVariable = "font.size.variable.%LANG%";
 const kFontSizeFmtFixed = "font.size.monospace.%LANG%";
 const kFontMinSizeFmt = "font.minimum-size.%LANG%";
 
-document.documentElement.addEventListener(
-  "dialoghelp",
-  window.top.openPrefsHelp
-);
+document
+  .getElementById("FontsDialog")
+  .addEventListener("dialoghelp", window.top.openPrefsHelp);
 window.addEventListener("load", () => gFontsDialog.onLoad());
 
 Preferences.addAll([
   { id: "font.language.group", type: "wstring" },
   { id: "browser.display.use_document_fonts", type: "int" },
   { id: "intl.charset.fallback.override", type: "string" },
 ]);
 
--- a/browser/components/preferences/fonts.xhtml
+++ b/browser/components/preferences/fonts.xhtml
@@ -3,24 +3,24 @@
 <!-- -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -->
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 
-<dialog id="FontsDialog" type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="fonts-window"
         data-l10n-attrs="title"
+        persist="lastSelected screenX screenY">
+<dialog id="FontsDialog"
         buttons="accept,cancel,help"
-        persist="lastSelected screenX screenY"
-        role="dialog"
         helpTopic="prefs-fonts-and-colors">
 
   <linkset>
     <html:link rel="localization" href="browser/preferences/fonts.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/utilityOverlay.js"/>
   <script src="chrome://global/content/preferencesBindings.js"/>
@@ -266,8 +266,9 @@
       </hbox>
     </hbox>
   </groupbox>
 
   <!-- Load the script after the elements for layout issues (bug 1501755). -->
   <script src="chrome://mozapps/content/preferences/fontbuilder.js"/>
   <script src="chrome://browser/content/preferences/fonts.js"/>
 </dialog>
+</window>
--- a/browser/components/preferences/in-content/subdialogs.js
+++ b/browser/components/preferences/in-content/subdialogs.js
@@ -235,20 +235,19 @@ SubDialog.prototype = {
       return;
     }
 
     for (let styleSheetURL of this._injectedStyleSheets) {
       this.injectXMLStylesheet(styleSheetURL);
     }
 
     // Provide the ability for the dialog to know that it is being loaded "in-content".
-    this._frame.contentDocument.documentElement.setAttribute(
-      "subdialog",
-      "true"
-    );
+    for (let dialog of this._frame.contentDocument.querySelectorAll("dialog")) {
+      dialog.setAttribute("subdialog", "true");
+    }
 
     this._frame.contentWindow.addEventListener("dialogclosing", this);
 
     let oldResizeBy = this._frame.contentWindow.resizeBy;
     this._frame.contentWindow.resizeBy = (resizeByWidth, resizeByHeight) => {
       // Only handle resizeByHeight currently.
       let frameHeight = this._frame.clientHeight;
       let boxMinHeight = parseFloat(getComputedStyle(this._box).minHeight, 10);
--- a/browser/components/preferences/in-content/syncChooseWhatToSync.js
+++ b/browser/components/preferences/in-content/syncChooseWhatToSync.js
@@ -27,17 +27,19 @@ let gSyncChooseWhatToSync = {
         options.disconnectFun().then(disconnected => {
           if (disconnected) {
             window.close();
           }
         });
       });
     } else {
       // no "disconnect" - hide the button.
-      document.documentElement.getButton("extra2").hidden = true;
+      document
+        .getElementById("syncChooseOptions")
+        .getButton("extra2").hidden = true;
     }
   },
 
   // make whatever tweaks we need based on preferences.
   _adjustForPrefs() {
     // These 2 engines are unique in that there are prefs that make the
     // entire engine unavailable (which is distinct from "disabled").
     let enginePrefs = [
--- a/browser/components/preferences/in-content/syncChooseWhatToSync.xhtml
+++ b/browser/components/preferences/in-content/syncChooseWhatToSync.xhtml
@@ -2,25 +2,26 @@
 
 <!-- -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -->
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 
-<dialog id="syncChooseOptions"
-        type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        role="dialog"
-        buttons="accept,cancel,extra2"
         onload="gSyncChooseWhatToSync.init();"
         data-l10n-id="sync-choose-what-to-sync-dialog"
-        data-l10n-attrs="title, style, buttonlabelaccept, buttonlabelextra2">
+        data-l10n-attrs="title, style">
+<dialog id="syncChooseOptions"
+        buttons="accept,cancel,extra2"
+        data-l10n-id="sync-choose-what-to-sync-dialog"
+        data-l10n-attrs="buttonlabelaccept, buttonlabelextra2">
 
   <linkset>
     <html:link rel="localization" href="browser/branding/sync-brand.ftl"/>
     <html:link rel="localization" href="browser/preferences/preferences.ftl"/>
   </linkset>
   <script src="chrome://global/content/preferencesBindings.js"/>
   <script src="chrome://browser/content/preferences/in-content/syncChooseWhatToSync.js"/>
 
@@ -54,8 +55,9 @@
                 preference="services.sync.engine.addons"/>
     </html:div>
     <html:div class="sync-engine-prefs">
       <checkbox data-l10n-id="sync-engine-prefs"
                 preference="services.sync.engine.prefs"/>
     </html:div>
   </html:div>
 </dialog>
+</window>
--- a/browser/components/preferences/languages.js
+++ b/browser/components/preferences/languages.js
@@ -2,20 +2,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../../toolkit/content/preferencesBindings.js */
 
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-document.documentElement.addEventListener(
-  "dialoghelp",
-  window.top.openPrefsHelp
-);
+document
+  .getElementById("LanguagesDialog")
+  .addEventListener("dialoghelp", window.top.openPrefsHelp);
 
 Preferences.addAll([
   { id: "intl.accept_languages", type: "wstring" },
   { id: "pref.browser.language.disable_button.up", type: "bool" },
   { id: "pref.browser.language.disable_button.down", type: "bool" },
   { id: "pref.browser.language.disable_button.remove", type: "bool" },
   { id: "privacy.spoof_english", type: "int" },
 ]);
--- a/browser/components/preferences/languages.xhtml
+++ b/browser/components/preferences/languages.xhtml
@@ -2,25 +2,25 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 
-<dialog id="LanguagesDialog" type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="webpage-languages-window"
         data-l10n-attrs="title, style"
+        persist="lastSelected screenX screenY"
+        onload="gLanguagesDialog.onLoad();">
+<dialog id="LanguagesDialog"
         buttons="accept,cancel,help"
-        persist="lastSelected screenX screenY"
-        role="dialog"
-        onload="gLanguagesDialog.onLoad();"
         helpTopic="prefs-languages">
 
   <linkset>
     <html:link rel="localization" href="browser/preferences/languages.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/utilityOverlay.js"/>
   <script src="chrome://global/content/preferencesBindings.js"/>
@@ -59,8 +59,9 @@
                 data-l10n-id="languages-customize-select-language" data-l10n-attrs="placeholder">
         <menupopup id="availableLanguagesPopup"/>
       </menulist>
     </vbox>
     <button id="addButton" class="add-web-language" oncommand="gLanguagesDialog.addLanguage();" disabled="true"
             data-l10n-id="languages-customize-add"/>
   </box>
 </dialog>
+</window>
--- a/browser/components/preferences/sanitize.js
+++ b/browser/components/preferences/sanitize.js
@@ -1,19 +1,18 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../../toolkit/content/preferencesBindings.js */
 
-document.documentElement.addEventListener(
-  "dialoghelp",
-  window.top.openPrefsHelp
-);
+document
+  .getElementById("SanitizeDialog")
+  .addEventListener("dialoghelp", window.top.openPrefsHelp);
 
 Preferences.addAll([
   { id: "privacy.clearOnShutdown.history", type: "bool" },
   { id: "privacy.clearOnShutdown.formdata", type: "bool" },
   { id: "privacy.clearOnShutdown.downloads", type: "bool" },
   { id: "privacy.clearOnShutdown.cookies", type: "bool" },
   { id: "privacy.clearOnShutdown.cache", type: "bool" },
   { id: "privacy.clearOnShutdown.offlineApps", type: "bool" },
--- a/browser/components/preferences/sanitize.xhtml
+++ b/browser/components/preferences/sanitize.xhtml
@@ -3,28 +3,28 @@
 <!-- -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -->
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
-<dialog id="SanitizeDialog" type="child"
+<window type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        buttons="accept,cancel,help"
         persist="lastSelected screenX screenY"
-        role="dialog"
         data-l10n-id="sanitize-prefs"
         data-l10n-attrs="style"
-        helpTopic="prefs-clear-private-data"
         onload="gSanitizeDialog.init();">
+<dialog id="SanitizeDialog"
+        buttons="accept,cancel,help"
+        helpTopic="prefs-clear-private-data">
 
   <linkset>
     <html:link rel="localization" href="browser/sanitize.ftl"/>
     <html:link rel="localization" href="branding/brand.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/utilityOverlay.js"/>
   <script src="chrome://global/content/preferencesBindings.js"/>
@@ -65,8 +65,9 @@
       </vbox>
       <vbox>
         <checkbox data-l10n-id="item-offline-apps"
                   preference="privacy.clearOnShutdown.offlineApps"/>
       </vbox>
     </hbox>
   </groupbox>
 </dialog>
+</window>
--- a/browser/components/preferences/selectBookmark.js
+++ b/browser/components/preferences/selectBookmark.js
@@ -49,17 +49,19 @@ var SelectBookmarkDialog = {
     });
   },
 
   /**
    * Update the disabled state of the OK button as the user changes the
    * selection within the view.
    */
   selectionChanged: function SBD_selectionChanged() {
-    var accept = document.documentElement.getButton("accept");
+    var accept = document
+      .getElementById("selectBookmarkDialog")
+      .getButton("accept");
     var bookmarks = document.getElementById("bookmarks");
     var disableAcceptButton = true;
     if (bookmarks.hasSelection) {
       if (!PlacesUtils.nodeIsSeparator(bookmarks.selectedNode)) {
         disableAcceptButton = false;
       }
     }
     accept.disabled = disableAcceptButton;
@@ -68,17 +70,20 @@ var SelectBookmarkDialog = {
   onItemDblClick: function SBD_onItemDblClick() {
     var bookmarks = document.getElementById("bookmarks");
     var selectedNode = bookmarks.selectedNode;
     if (selectedNode && PlacesUtils.nodeIsURI(selectedNode)) {
       /**
        * The user has double clicked on a tree row that is a link. Take this to
        * mean that they want that link to be their homepage, and close the dialog.
        */
-      document.documentElement.getButton("accept").click();
+      document
+        .getElementById("selectBookmarkDialog")
+        .getButton("accept")
+        .click();
     }
   },
 
   /**
    * User accepts their selection. Set all the selected URLs or the contents
    * of the selected folder as the list of homepages.
    */
   accept: function SBD_accept() {
--- a/browser/components/preferences/selectBookmark.xhtml
+++ b/browser/components/preferences/selectBookmark.xhtml
@@ -4,23 +4,23 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 
 <?xml-stylesheet href="chrome://browser/content/places/places.css"?>
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://browser/skin/places/tree-icons.css"?>
 
-<dialog id="selectBookmarkDialog"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="select-bookmark-window"
         data-l10n-attrs="title, style"
         persist="screenX screenY width height" screenX="24" screenY="24"
         onload="SelectBookmarkDialog.init();">
+<dialog id="selectBookmarkDialog">
 
   <linkset>
     <html:link rel="localization" href="browser/preferences/selectBookmark.ftl"/>
   </linkset>
 
   <script src="chrome://browser/content/preferences/selectBookmark.js"/>
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://browser/content/utilityOverlay.js"/>
@@ -41,8 +41,9 @@
       <treecol id="title" flex="1" primary="true" hideheader="true"/>
     </treecols>
     <treechildren id="bookmarksChildren" flex="1"/>
   </tree>
 
   <separator class="thin"/>
 
 </dialog>
+</window>
--- a/browser/components/preferences/siteDataRemoveSelected.xhtml
+++ b/browser/components/preferences/siteDataRemoveSelected.xhtml
@@ -3,24 +3,26 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/content/preferences/siteDataSettings.css" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/skin/preferences/in-content/siteDataSettings.css" type="text/css"?>
 
-<dialog id="SiteDataRemoveSelectedDialog"
-        windowtype="Browser:SiteDataRemoveSelected"
+<window windowtype="Browser:SiteDataRemoveSelected"
         width="500"
         data-l10n-id="site-data-removing-dialog"
-        data-l10n-attrs="title, buttonlabelaccept"
+        data-l10n-attrs="title"
         onload="gSiteDataRemoveSelected.init();"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml">
+<dialog id="SiteDataRemoveSelectedDialog"
+        data-l10n-id="site-data-removing-dialog"
+        data-l10n-attrs="buttonlabelaccept">
 
   <linkset>
     <html:link rel="localization" href="browser/preferences/siteDataSettings.ftl"/>
   </linkset>
 
   <hbox>
     <vbox>
       <image class="question-icon"/>
@@ -42,8 +44,9 @@
 
   <label data-l10n-id="site-data-removing-table"/>
   <separator class="thin"/>
   <richlistbox id="removalList" class="theme-listbox" flex="1"/>
 
   <!-- Load the script after the elements for layout issues (bug 1501755). -->
   <script src="chrome://browser/content/preferences/siteDataRemoveSelected.js"/>
 </dialog>
+</window>
--- a/browser/components/shell/content/setDesktopBackground.js
+++ b/browser/components/shell/content/setDesktopBackground.js
@@ -26,17 +26,19 @@ var gSetBackground = {
     // Cap ratio to 4 so the dialog width doesn't get ridiculous. Highest
     // regular screens seem to be 32:9 (3.56) according to Wikipedia.
     let screenRatio = Math.min(this._screenWidth / this._screenHeight, 4);
     this._canvas.width = this._canvas.height * screenRatio;
     document.getElementById("preview-unavailable").style.width =
       this._canvas.width + "px";
 
     if (AppConstants.platform == "macosx") {
-      document.documentElement.getButton("accept").hidden = true;
+      document
+        .getElementById("SetDesktopBackgroundDialog")
+        .getButton("accept").hidden = true;
     } else {
       let multiMonitors = false;
       if (AppConstants.platform == "linux") {
         // getMonitors only ever returns the primary monitor on Linux, so just
         // always show the option
         multiMonitors = true;
       } else {
         const gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
--- a/browser/components/shell/content/setDesktopBackground.xul
+++ b/browser/components/shell/content/setDesktopBackground.xul
@@ -11,28 +11,29 @@
 <!DOCTYPE dialog [
 <!ENTITY % setDesktopBackgroundDTD SYSTEM "chrome://browser/locale/setDesktopBackground.dtd">
 %setDesktopBackgroundDTD;
 #ifdef XP_MACOSX
 #include ../../../base/content/browser-doctype.inc
 #endif
 ]>
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         windowtype="Shell:SetDesktopBackground"
+        onload="gSetBackground.load();"
+        title="&setDesktopBackground.title;"
+        style="width: 30em;">
+<dialog id="SetDesktopBackgroundDialog"
 #ifndef XP_MACOSX
         buttons="accept,cancel"
 #else
         buttons="accept"
 #endif
-        buttonlabelaccept="&setDesktopBackground.title;"
-        onload="gSetBackground.load();"
-        title="&setDesktopBackground.title;"
-        style="width: 30em;">
+        buttonlabelaccept="&setDesktopBackground.title;">
 
 #ifdef XP_MACOSX
 #include ../../../base/content/macWindow.inc.xhtml
 #endif
 
     <stringbundle id="backgroundBundle"
                   src="chrome://browser/locale/shellservice.properties"/>
     <script src="chrome://browser/content/utilityOverlay.js"/>
@@ -83,8 +84,9 @@
       <button id="showDesktopPreferences"
               label="&openDesktopPrefs.label;"
               oncommand="gSetBackground.showDesktopPrefs();"
               hidden="true"/>
     </hbox>
 #endif
 
 </dialog>
+</window>
--- a/browser/extensions/formautofill/skin/linux/editDialog.css
+++ b/browser/extensions/formautofill/skin/linux/editDialog.css
@@ -1,8 +1,8 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Linux specific rules */
-:root[subdialog] body {
+dialog[subdialog] body {
   font-size: 0.85rem;
 }
--- a/browser/extensions/formautofill/skin/shared/editAddress.css
+++ b/browser/extensions/formautofill/skin/shared/editAddress.css
@@ -4,17 +4,17 @@
 
 .editAddressForm {
   display: flex;
   flex-wrap: wrap;
   /* Use space-between so --grid-column-row-gap is in between the elements on a row */
   justify-content: space-between;
 }
 
-:root:not([subdialog]) .editAddressForm {
+dialog:not([subdialog]) .editAddressForm {
   margin-inline-start: calc(var(--grid-column-row-gap) / -2);
   margin-inline-end: calc(var(--grid-column-row-gap) / -2);
 }
 
 .editAddressForm .container {
   /* !important is needed to override preferences.css's generic label rule. */
   margin-top: var(--grid-column-row-gap) !important;
   margin-inline-start: calc(var(--grid-column-row-gap) / 2);
@@ -115,11 +115,11 @@
   box-sizing: border-box;
   font-size: 1rem;
   align-items: center;
   text-align: start;
   opacity: .5;
   padding-inline-start: 1em;
 }
 
-:root:not([subdialog]) #country-warning-message {
+dialog:not([subdialog]) #country-warning-message {
   display: none;
 }
--- a/browser/extensions/formautofill/skin/shared/editDialog-shared.css
+++ b/browser/extensions/formautofill/skin/shared/editDialog-shared.css
@@ -4,17 +4,17 @@
 
 :root {
   --in-field-label-size: .8em;
   --grid-column-row-gap: 8px;
   /* Use the animation-easing-function that is defined in xul.css. */
   --animation-easing-function: cubic-bezier(.07,.95,0,1);
 }
 
-:root[subdialog] form {
+dialog[subdialog] form {
   /* Add extra space to ensure invalid input box is displayed properly */
   padding: 2px;
 }
 
 /* The overly specific input attributes are required to override
    padding from common.css */
 form input[type="email"],
 form input[type="tel"],
@@ -80,17 +80,17 @@ form :-moz-any(label, div)[required] .la
 .persist-checkbox label {
   display: flex;
   flex-direction: row;
   align-items: center;
   margin-top: var(--grid-column-row-gap);
   margin-bottom: var(--grid-column-row-gap);
 }
 
-:root[subdialog] form {
+dialog[subdialog] form {
   /* Match the margin-inline-start of the #controls-container buttons
      and provide enough padding at the top of the form so button outlines
      don't get clipped. */
   padding: 4px 4px 0;
 }
 
 #controls-container {
   flex: 0 1 100%;
--- a/browser/themes/linux/preferences/in-content/dialog.css
+++ b/browser/themes/linux/preferences/in-content/dialog.css
@@ -1,10 +1,10 @@
 /* - This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this file,
    - You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 %include ../../../shared/incontentprefs/dialog.inc.css
 
-:root > * {
+dialog > * {
   font-size: 1.05em;
 }
 
--- a/browser/themes/osx/preferences/in-content/dialog.css
+++ b/browser/themes/osx/preferences/in-content/dialog.css
@@ -3,11 +3,11 @@
    - You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 %include ../../../shared/incontentprefs/dialog.inc.css
 
 window {
   font: message-box !important;
 }
 
-:root > * {
+dialog > * {
   font-size: 1.18em;
 }
--- a/browser/themes/windows/preferences/in-content/dialog.css
+++ b/browser/themes/windows/preferences/in-content/dialog.css
@@ -1,9 +1,9 @@
 /* - This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this file,
    - You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 %include ../../../shared/incontentprefs/dialog.inc.css
 
-:root > * {
+dialog > * {
   font-size: 1.12em;
 }
--- a/security/manager/pki/resources/content/certManager.xhtml
+++ b/security/manager/pki/resources/content/certManager.xhtml
@@ -1,26 +1,26 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
-<dialog id="certmanager"
-	windowtype="mozilla:certmanager"
-	xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-  xmlns:html="http://www.w3.org/1999/xhtml"
+<window windowtype="mozilla:certmanager"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="certmgr-title"
         onload="LoadCerts();"
-        buttons="accept"
         style="width: 40em; height: 32em;"
         persist="screenX screenY width height">
+<dialog id="certmanager"
+        buttons="accept">
 
   <linkset>
     <html:link rel="localization" href="security/certificates/certManager.ftl"/>
   </linkset>
 
   <script src="chrome://pippki/content/pippki.js"/>
   <script src="chrome://pippki/content/certManager.js"/>
 
@@ -186,8 +186,9 @@
           </hbox>
         </vbox>
       </tabpanels>
     </tabbox>
 
   </vbox>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/certViewer.xhtml
+++ b/security/manager/pki/resources/content/certViewer.xhtml
@@ -1,25 +1,28 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
+<window
+  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+  xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+  xmlns:html="http://www.w3.org/1999/xhtml"
+  data-l10n-id="certmgr-cert-detail"
+  data-l10n-attrs="title"
+  onload="setWindowName();">
 <dialog id="certDetails"
   data-l10n-id="certmgr-cert-detail"
   data-l10n-attrs="buttonlabelaccept, buttonaccesskeyaccept"
-  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-  xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-  xmlns:html="http://www.w3.org/1999/xhtml"
-  buttons="accept"
-  onload="setWindowName();">
+  buttons="accept">
 
 
 <linkset>
   <html:link rel="localization" href="security/certificates/certManager.ftl"/>
 </linkset>
 
 <script src="chrome://pippki/content/pippki.js"/>
 <script src="chrome://global/content/globalOverlay.js"/>
@@ -158,8 +161,9 @@
           <button id="export_cert" class="normal" data-l10n-id="certmgr-export"
                   oncommand="exportToFile(window, getCurrentCert());"/>
         </hbox>
       </vbox>
     </tabpanels>
   </tabbox>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/changepassword.js
+++ b/security/manager/pki/resources/content/changepassword.js
@@ -9,17 +9,17 @@ var params;
 var token;
 var pw1;
 
 function doPrompt(msg) {
   Services.prompt.alert(window, null, msg);
 }
 
 function onLoad() {
-  document.documentElement.getButton("accept").disabled = true;
+  document.getElementById("set_password").getButton("accept").disabled = true;
   document.addEventListener("dialogaccept", setPassword);
 
   pw1 = document.getElementById("pw1");
   params = window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock);
   token = params.objects.GetElementAt(0).QueryInterface(Ci.nsIPK11Token);
 
   document.getElementById("tokenName").setAttribute("value", token.name);
 
@@ -192,15 +192,18 @@ function checkPasswords() {
   if (oldpwbox) {
     var initpw = oldpwbox.getAttribute("inited");
 
     if (initpw == "empty" && pw1 == "") {
       // The token has already been initialized, therefore this dialog
       // was called with the intention to change the password.
       // The token currently uses an empty password.
       // We will not allow changing the password from empty to empty.
-      document.documentElement.getButton("accept").disabled = true;
+      document
+        .getElementById("set_password")
+        .getButton("accept").disabled = true;
       return;
     }
   }
 
-  document.documentElement.getButton("accept").disabled = pw1 != pw2;
+  document.getElementById("set_password").getButton("accept").disabled =
+    pw1 != pw2;
 }
--- a/security/manager/pki/resources/content/changepassword.xhtml
+++ b/security/manager/pki/resources/content/changepassword.xhtml
@@ -1,22 +1,23 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog SYSTEM "chrome://pippki/locale/pippki.dtd">
+<!DOCTYPE window SYSTEM "chrome://pippki/locale/pippki.dtd">
 
-<dialog id="set_password" title="&setPassword.title;"
+<window title="&setPassword.title;"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
-  buttons="accept,cancel"
   onload="onLoad();">
+<dialog id="set_password"
+  buttons="accept,cancel">
 
 <stringbundle id="pippki_bundle" src="chrome://pippki/locale/pippki.properties"/>
 
 <script src="chrome://global/content/globalOverlay.js"/>
 <script src="chrome://global/content/editMenuOverlay.js"/>
 
 <script src="chrome://pippki/content/changepassword.js"/>
 
@@ -52,8 +53,9 @@
 </vbox>
 
 <vbox style="margin: 6px;">
   <html:label for="pwmeter" style="display: -moz-box;">&setPassword.meter.label;</html:label>
   <html:progress id="pwmeter" value="0" max="100"/>
 </vbox>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/clientauthask.xhtml
+++ b/security/manager/pki/resources/content/clientauthask.xhtml
@@ -1,26 +1,27 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog [
+<!DOCTYPE window [
 <!ENTITY % pippkiDTD SYSTEM "chrome://pippki/locale/pippki.dtd" >
 %pippkiDTD;
 ]>
 
 
-<dialog id="certAuthAsk" title="&clientAuthAsk.title;"
+<window title="&clientAuthAsk.title;"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
-  buttons="accept,cancel"
   onload="onLoad();">
+<dialog id="certAuthAsk"
+  buttons="accept,cancel">
 
 <stringbundleset id="stringbundleset">
   <stringbundle id="pippki_bundle" src="chrome://pippki/locale/pippki.properties"/>
 </stringbundleset>
 
 <script src="chrome://pippki/content/pippki.js"/>
 <script src="chrome://pippki/content/clientauthask.js"/>
 <script src="chrome://global/content/globalOverlay.js"/>
@@ -38,8 +39,9 @@
 <menulist id="nicknames" oncommand="onCertSelected();">
     <menupopup/>
 </menulist>
 <description>&clientAuthAsk.message3;</description>
 <html:textarea readonly="readonly" id="details" style="height: 11em;"/>
 <checkbox id="rememberBox" checked="true"/>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/deletecert.xhtml
+++ b/security/manager/pki/resources/content/deletecert.xhtml
@@ -1,30 +1,31 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
-<dialog id="deleteCertificate"
-  data-l10n-id="certmgr-delete-cert"
+<window data-l10n-id="certmgr-delete-cert"
   data-l10n-attrs="style"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
-  onload="onLoad();"
+  onload="onLoad();">
+<dialog id="deleteCertificate"
   buttons="accept,cancel">
 
   <linkset>
     <html:link rel="localization" href="security/certificates/certManager.ftl"/>
   </linkset>
 
   <script src="pippki.js" />
   <script src="chrome://pippki/content/deletecert.js"/>
 
   <description id="confirm" style="width: 400px;"/>
   <richlistbox id="certlist" class="box-padded" flex="1"
                style="min-height: 8em; height: 8em; min-width: 35em;"/>
   <description id="impact" style="width: 400px;"/>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/device_manager.xhtml
+++ b/security/manager/pki/resources/content/device_manager.xhtml
@@ -2,24 +2,24 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
 <!DOCTYPE dialog>
 
-<dialog id="devicemanager"
-        windowtype="mozilla:devicemanager"
+<window windowtype="mozilla:devicemanager"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="devmgr"
         data-l10n-attrs="style"
         persist="screenX screenY width height"
-        onload="LoadModules();"
+        onload="LoadModules();">
+<dialog id="devicemanager"
         buttons="accept">
 
 <linkset>
   <html:link rel="localization" href="security/certificates/deviceManager.ftl"/>
 </linkset>
 
 <script src="chrome://pippki/content/device_manager.js"/>
 
@@ -62,8 +62,9 @@
             oncommand="doUnload();" disabled="true"/>
     <button id="fipsbutton"
             data-l10n-id="devmgr-button-enable-fips"
             oncommand="toggleFIPS();"/>
   </vbox> <!-- / Buttons for manipulating devices -->
 </hbox>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/downloadcert.xhtml
+++ b/security/manager/pki/resources/content/downloadcert.xhtml
@@ -1,23 +1,23 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog SYSTEM "chrome://pippki/locale/pippki.dtd">
+<!DOCTYPE window SYSTEM "chrome://pippki/locale/pippki.dtd">
 
-<dialog id="download_cert"
-        title="&downloadCert.title;"
+<window title="&downloadCert.title;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         style="width: 46em;"
-        buttons="accept,cancel"
         onload="onLoad();">
+<dialog id="download_cert"
+        buttons="accept,cancel">
 
 <stringbundle id="pippki_bundle" src="chrome://pippki/locale/pippki.properties"/>
 
 <script src="chrome://pippki/content/pippki.js"/>
 <script src="chrome://pippki/content/downloadcert.js"/>
 
 
   <!--  Let 'em know what they're doing -->
@@ -49,8 +49,9 @@
       <button id="viewC-button"
               label="&downloadCert.viewCert.label;"
               oncommand="viewCert();"/>
       <description style="margin: 4px;">&downloadCert.viewCert.text;</description>
     </hbox>
   </vbox>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/editcacert.xhtml
+++ b/security/manager/pki/resources/content/editcacert.xhtml
@@ -1,24 +1,24 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
-<dialog id="editCaCert"
-        data-l10n-id="certmgr-edit-ca-cert"
+<window data-l10n-id="certmgr-edit-ca-cert"
         data-l10n-attrs="style"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        buttons="accept,cancel"
         onload="onLoad();">
+<dialog id="editCaCert"
+        buttons="accept,cancel">
 
   <linkset>
     <html:link rel="localization" href="security/certificates/certManager.ftl"/>
   </linkset>
 
   <script src="chrome://pippki/content/pippki.js"/>
   <script src="chrome://pippki/content/editcacert.js"/>
 
@@ -28,8 +28,9 @@
   <vbox align="start">
     <checkbox data-l10n-id="certmgr-edit-cert-trust-ssl"
               id="trustSSL"/>
     <checkbox data-l10n-id="certmgr-edit-cert-trust-email"
               id="trustEmail"/>
   </vbox>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/exceptionDialog.js
+++ b/security/manager/pki/resources/content/exceptionDialog.js
@@ -13,17 +13,17 @@ var gNeedReset;
 var gSecHistogram;
 
 const { PrivateBrowsingUtils } = ChromeUtils.import(
   "resource://gre/modules/PrivateBrowsingUtils.jsm"
 );
 
 function initExceptionDialog() {
   gNeedReset = false;
-  gDialog = document.documentElement;
+  gDialog = document.getElementById("exceptiondialog");
   gSecHistogram = Services.telemetry.getHistogramById("SECURITY_UI");
   let warningText = document.getElementById("warningText");
   document.l10n.setAttributes(warningText, "add-exception-branded-warning");
   let confirmButton = gDialog.getButton("extra1");
   let l10nUpdatedElements = [confirmButton, warningText];
   confirmButton.disabled = true;
 
   var args = window.arguments;
--- a/security/manager/pki/resources/content/exceptionDialog.xhtml
+++ b/security/manager/pki/resources/content/exceptionDialog.xhtml
@@ -1,26 +1,26 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://pippki/content/exceptionDialog.css" type="text/css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
-<dialog id="exceptiondialog"
-        windowtype="mozilla:exceptiondialog"
+<window windowtype="mozilla:exceptiondialog"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="exception-mgr"
+        onload="initExceptionDialog();">
+<dialog id="exceptiondialog"
         buttonidextra1="exception-mgr-extra-button"
         buttons="cancel,extra1,extra2"
-        onload="initExceptionDialog();"
         defaultButton="extra2">
 
   <linkset>
     <html:link rel="localization" href="branding/brand.ftl"/>
     <html:link rel="localization" href="security/certificates/certManager.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/globalOverlay.js"/>
@@ -80,8 +80,9 @@
   <description id="status3Description"
                class="description"/>
   <description id="status3LongDescription"
                class="longDescription"/>
   <checkbox id="permanent"
             disabled="true"
             data-l10n-id="exception-mgr-permanent"/>
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/load_device.xhtml
+++ b/security/manager/pki/resources/content/load_device.xhtml
@@ -1,21 +1,21 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        xmlns:html="http://www.w3.org/1999/xhtml"
+        data-l10n-id="load-device">
 <dialog id="loaddevice"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        xmlns:html="http://www.w3.org/1999/xhtml"
-        data-l10n-id="load-device"
         buttons="accept,cancel">
 
   <linkset>
     <html:link rel="localization" href="security/certificates/deviceManager.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
@@ -45,8 +45,9 @@
     <html:input id="device_path" />
     <button id="browse" flex="1"
             data-l10n-id="load-device-browse"
             oncommand="onBrowseBtnPress();"/>
   </hbox>
   <label id="helpText" value=""/>
 
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/resetpassword.xhtml
+++ b/security/manager/pki/resources/content/resetpassword.xhtml
@@ -1,23 +1,24 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog SYSTEM "chrome://pippki/locale/pippki.dtd">
+<!DOCTYPE window SYSTEM "chrome://pippki/locale/pippki.dtd">
 
-<dialog id="reset_password" title="&resetPassword.title;"
+<window title="&resetPassword.title;"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+  style="width: 40em;">
+<dialog id="reset_password"
   buttons="accept,cancel"
   buttonlabelaccept="&resetPasswordButtonLabel;"
-  defaultButton="cancel"
-  style="width: 40em;">
+  defaultButton="cancel">
 
   <stringbundle id="pippki_bundle" src="chrome://pippki/locale/pippki.properties"/>
 
   <script src="chrome://pippki/content/pippki.js"/>
   <script src="chrome://pippki/content/resetpassword.js"/>
 
   <hbox flex="1">
     <vbox>
@@ -27,8 +28,9 @@
       <hbox flex="1">
         <vbox flex="1">
           <description>&resetPassword.text;</description>
         </vbox>
       </hbox>
     </vbox>
   </hbox>
 </dialog>
+</window>
--- a/security/manager/pki/resources/content/setp12password.js
+++ b/security/manager/pki/resources/content/setp12password.js
@@ -117,10 +117,11 @@ function onPasswordInput(recalculatePass
 
   if (recalculatePasswordStrength) {
     document.getElementById("pwmeter").value = getPasswordStrength(pw1);
   }
 
   // Disable the accept button if the two passwords don't match, and enable it
   // if the passwords do match.
   let pw2 = document.getElementById("pw2").value;
-  document.documentElement.getButton("accept").disabled = pw1 != pw2;
+  document.getElementById("setp12password").getButton("accept").disabled =
+    pw1 != pw2;
 }
--- a/security/manager/pki/resources/content/setp12password.xhtml
+++ b/security/manager/pki/resources/content/setp12password.xhtml
@@ -1,24 +1,24 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<!DOCTYPE dialog SYSTEM "chrome://pippki/locale/pippki.dtd">
+<!DOCTYPE window SYSTEM "chrome://pippki/locale/pippki.dtd">
 
-<dialog id="setp12password"
-        title="&pkcs12.setpassword.title;"
+<window title="&pkcs12.setpassword.title;"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         style="width: 48em;"
-        buttons="accept,cancel"
         onload="onLoad();">
+<dialog id="setp12password"
+        buttons="accept,cancel">
 
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
 
   <script src="chrome://pippki/content/setp12password.js"/>
 
   <description>&pkcs12.setpassword.message;</description>
   <separator />
@@ -36,8 +36,9 @@
   <description>&pkcs12.setpassword.reminder;</description>
   <separator/>
 
   <vbox style="margin: 6px;">
     <html:label for="pwmeter" style="display: -moz-box;">&setPassword.meter.label;</html:label>
     <html:progress id="pwmeter" value="0" max="100"/>
   </vbox>
 </dialog>
+</window>
--- a/toolkit/components/apppicker/content/appPicker.xul
+++ b/toolkit/components/apppicker/content/appPicker.xul
@@ -2,26 +2,27 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
   <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
   <?xml-stylesheet href="chrome://global/skin/appPicker.css" type="text/css"?>
 
-  <!DOCTYPE dialog SYSTEM "chrome://global/locale/appPicker.dtd" >
+  <!DOCTYPE window SYSTEM "chrome://global/locale/appPicker.dtd" >
 
-  <dialog id="app-picker"
+  <window
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     onload="g_dialog.appPickerLoad();"
+    aria-describedby="content-description suggested-filename"
+    persist="screenX screenY">
+  <dialog id="app-picker"
     buttons="accept,cancel,extra2"
     buttonlabelextra2="&BrowseButton.label;"
-    defaultButton="cancel"
-    aria-describedby="content-description suggested-filename"
-    persist="screenX screenY">
+    defaultButton="cancel">
 
     <script src="chrome://global/content/appPicker.js"/>
 
     <hbox id="file-info" align="center">
       <image id="content-icon" src=""/>
       <vbox flex="1">
         <label id="content-description" crop="center" value=""/>
         <label id="suggested-filename" crop="center" value=""/>
@@ -30,8 +31,9 @@
 
     <label id="sendto-message" value="&SendMsg.label;" control="app-picker-listbox"/>
 
     <richlistbox id="app-picker-listbox"
                  ondblclick="g_dialog.appDoubleClick();"/>
 
     <label id="app-picker-notfound" value="&NoAppFound.label;" hidden="true"/>
   </dialog>
+  </window>
--- a/toolkit/components/printing/content/printPageSetup.xul
+++ b/toolkit/components/printing/content/printPageSetup.xul
@@ -2,24 +2,24 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://global/skin/printPageSetup.css" type="text/css"?>
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   xmlns:html="http://www.w3.org/1999/xhtml"
-  id="printPageSetupDialog"
   onload="onLoad();"
   oncancel="return onCancel();"
   data-l10n-id="print-setup"
   persist="screenX screenY"
   screenX="24" screenY="24">
+<dialog id="printPageSetupDialog">
 
   <linkset>
     <html:link rel="localization" href="toolkit/printing/printDialogs.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
   <script src="chrome://global/content/printPageSetup.js"/>
@@ -204,8 +204,9 @@
               </menupopup>
             </menulist>
           </box>
         </html:fieldset>
       </vbox>
     </tabpanels>
   </tabbox>
 </dialog>
+</window>
--- a/toolkit/components/printing/content/printPreviewProgress.xul
+++ b/toolkit/components/printing/content/printPreviewProgress.xul
@@ -1,24 +1,24 @@
 <?xml version="1.0"?>
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         data-l10n-id="print-preview-window"
         style="width: 36em;"
-        buttons="cancel"
         oncancel="onCancel()"
         onload="onLoad()"
         onunload="onUnload()">
+<dialog buttons="cancel">
 
   <linkset>
     <html:link rel="localization" href="toolkit/printing/printDialogs.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/printPreviewProgress.js"/>
 
   <box flex="1" style="display: grid; grid-template-columns: min-content max-content; grid-template-rows: max-content max-content;">
@@ -26,8 +26,9 @@
     <label id="dialog.titleLabel" data-l10n-id="print-title" style="justify-self: end;"/>
     <label id="dialog.title"/>
 
     <!-- Second row -->
     <label id="dialog.progressSpaces" data-l10n-id="print-preparing" style="justify-self: end;"/>
     <label id="dialog.progressLabel" data-l10n-id="print-progress"/>
   </box>
 </dialog>
+</window>
--- a/toolkit/components/printing/content/printProgress.xul
+++ b/toolkit/components/printing/content/printProgress.xul
@@ -1,23 +1,23 @@
 <?xml version="1.0"?>
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        buttons="cancel"
         data-l10n-id="print-window"
         style="width: 36em;"
         onload="onLoad()"
         onunload="onUnload()">
+<dialog buttons="cancel">
 
   <linkset>
     <html:link rel="localization" href="toolkit/printing/printDialogs.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/printProgress.js"/>
 
   <box style="display: grid; grid-template-columns: auto 1fr auto;" flex="1">
@@ -39,8 +39,9 @@
         <html:progress id="dialog.progress" value="0" max="100" style="width: 100%;"/>
       </vbox>
     </box>
     <hbox pack="end" style="min-width: 2.5em;">
       <label id="dialog.progressText"/>
     </hbox>
   </box>
 </dialog>
+</window>
--- a/toolkit/components/prompts/content/commonDialog.js
+++ b/toolkit/components/prompts/content/commonDialog.js
@@ -13,17 +13,17 @@ function commonDialogOnLoad() {
     .QueryInterface(Ci.nsIWritablePropertyBag2)
     .QueryInterface(Ci.nsIWritablePropertyBag);
   // Convert to a JS object
   args = {};
   for (let prop of propBag.enumerator) {
     args[prop.name] = prop.value;
   }
 
-  let dialog = document.documentElement;
+  let dialog = document.getElementById("commonDialog");
 
   let ui = {
     prompt: window,
     loginContainer: document.getElementById("loginContainer"),
     loginTextbox: document.getElementById("loginTextbox"),
     loginLabel: document.getElementById("loginLabel"),
     password1Container: document.getElementById("password1Container"),
     password1Textbox: document.getElementById("password1Textbox"),
--- a/toolkit/components/prompts/content/commonDialog.xul
+++ b/toolkit/components/prompts/content/commonDialog.xul
@@ -3,24 +3,25 @@
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://global/content/commonDialog.css" type="text/css"?>
 <?xml-stylesheet href="chrome://global/skin/commonDialog.css" type="text/css"?>
 
-<!DOCTYPE dialog SYSTEM "chrome://global/locale/commonDialog.dtd">
+<!DOCTYPE window SYSTEM "chrome://global/locale/commonDialog.dtd">
 
-<dialog id="commonDialog"
+<window id="commonDialogWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         aria-describedby="infoBody"
-        onunload="commonDialogOnUnload();"
+        onunload="commonDialogOnUnload();">
+<dialog id="commonDialog"
         buttonpack="center">
 
   <script src="chrome://global/content/commonDialog.js"/>
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
   <script src="chrome://global/content/customElements.js"/>
   <script>
     document.addEventListener("DOMContentLoaded", function() {
@@ -78,8 +79,9 @@
       <input type="password" id="password1Textbox"/>
     </div>
     <div id="checkboxContainer" class="dialogRow" hidden="hidden">
       <div/> <!-- spacer -->
       <xul:checkbox id="checkbox" oncommand="Dialog.onCheckbox()"/>
     </div>
   </div>
 </dialog>
+</window>
--- a/toolkit/components/prompts/content/selectDialog.xul
+++ b/toolkit/components/prompts/content/selectDialog.xul
@@ -1,21 +1,23 @@
 <?xml version="1.0"?>
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
-<!DOCTYPE dialog SYSTEM "chrome://global/locale/commonDialog.dtd">
+<!DOCTYPE window SYSTEM "chrome://global/locale/commonDialog.dtd">
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
       onload="dialogOnLoad()">
+<dialog>
 
   <script src="chrome://global/content/selectDialog.js" />
   <keyset id="dialogKeys"/>
   <vbox style="width: 24em;margin: 5px;">
     <label id="info.txt"/>
     <vbox>
       <richlistbox id="list" class="theme-listbox" style="height: 8em;"/>
     </vbox>
   </vbox>
 </dialog>
+</window>
--- a/toolkit/content/preferencesBindings.js
+++ b/toolkit/content/preferencesBindings.js
@@ -258,17 +258,18 @@ const Preferences = (window.Preferences 
         return aTarget.dispatchEvent(event);
       } catch (e) {
         Cu.reportError(e);
       }
       return false;
     },
 
     onDialogAccept(event) {
-      if (!this._fireEvent("beforeaccept", document.documentElement)) {
+      let dialog = document.querySelector("dialog");
+      if (!this._fireEvent("beforeaccept", dialog)) {
         event.preventDefault();
         return false;
       }
       this.writePreferences(true);
       return true;
     },
 
     close(event) {
--- a/toolkit/content/resetProfile.xul
+++ b/toolkit/content/resetProfile.xul
@@ -2,33 +2,34 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://global/content/resetProfile.css"?>
 
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        xmlns:html="http://www.w3.org/1999/xhtml"
+        data-l10n-id="refresh-profile-dialog"
+        onload="">
 <dialog id="resetProfileDialog"
-            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-            xmlns:html="http://www.w3.org/1999/xhtml"
-            data-l10n-id="refresh-profile-dialog"
-            buttons="accept,cancel"
-            defaultButton="cancel"
-            buttonidaccept="refresh-profile-dialog-button"
-            onload="">
-	<!-- The empty onload event handler is a hack to get the accept button text applied by Fluent. -->
+        buttons="accept,cancel"
+        defaultButton="cancel"
+        buttonidaccept="refresh-profile-dialog-button">
+  <!-- The empty onload event handler is a hack to get the accept button text applied by Fluent. -->
 
   <linkset>
     <html:link rel="localization" href="branding/brand.ftl"/>
     <html:link rel="localization" href="toolkit/global/resetProfile.ftl"/>
   </linkset>
 
   <script src="chrome://global/content/resetProfile.js"/>
 
   <description data-l10n-id="refresh-profile-description"/>
   <label data-l10n-id="refresh-profile-description-details"/>
 
   <vbox id="migratedItems">
     <label class="migratedLabel" data-l10n-id="refresh-profile-remove"/>
     <label class="migratedLabel" data-l10n-id="refresh-profile-restore"/>
   </vbox>
 </dialog>
+</window>
--- a/toolkit/content/widgets/dialog.js
+++ b/toolkit/content/widgets/dialog.js
@@ -55,17 +55,17 @@
         );
       } else {
         this.addEventListener("focus", this, true);
         this.shadowRoot.addEventListener("focus", this, true);
       }
 
       // listen for when window is closed via native close buttons
       window.addEventListener("close", event => {
-        if (!document.documentElement.cancelDialog()) {
+        if (!this.cancelDialog()) {
           event.preventDefault();
         }
       });
 
       // for things that we need to initialize after onload fires
       window.addEventListener("load", event => this.postLoadInit(event));
     }
 
@@ -124,20 +124,20 @@
         <button dlgtype="cancel" class="dialog-button"/>
         <button dlgtype="help" class="dialog-button" hidden="true"/>
         <button dlgtype="disclosure" class="dialog-button" hidden="true"/>
       </hbox>`;
 
       let key =
         AppConstants.platform == "macosx"
           ? `<key phase="capturing"
-            oncommand="document.documentElement.openHelp(event)"
+            oncommand="document.querySelector('dialog').openHelp(event)"
             key="&openHelpMac.commandkey;" modifiers="accel"/>`
           : `<key phase="capturing"
-            oncommand="document.documentElement.openHelp(event)"
+            oncommand="document.querySelector('dialog').openHelp(event)"
             keycode="&openHelp.commandkey;"/>`;
 
       return `
       <html:link rel="stylesheet" href="chrome://global/content/widgets.css" />
       ${this.hasAttribute("subdialog") ? this.inContentStyle : ""}
       <html:style>
         :host([nobuttonspacer]) .spacer {
           display: none;
@@ -159,16 +159,18 @@
       <keyset>${key}</keyset>`;
     }
 
     connectedCallback() {
       if (this.delayConnectedCallback()) {
         return;
       }
 
+      document.documentElement.setAttribute("role", "dialog");
+
       this.shadowRoot.textContent = "";
       this.shadowRoot.appendChild(
         MozXULElement.parseXULToFragment(this._markup, [
           "chrome://global/locale/globalKeys.dtd",
         ])
       );
       this.initializeAttributeInheritance();
 
@@ -274,24 +276,23 @@
       var yOffset = screen.availHeight / 2 - window.outerHeight / 2;
 
       xOffset = xOffset > 0 ? xOffset : 0;
       yOffset = yOffset > 0 ? yOffset : 0;
       window.moveTo(xOffset, yOffset);
     }
 
     postLoadInit(aEvent) {
-      function focusInit() {
-        const dialog = document.documentElement;
-        const defaultButton = dialog.getButton(dialog.defaultButton);
+      let focusInit = () => {
+        const defaultButton = this.getButton(this.defaultButton);
 
         // give focus to the first focusable element in the dialog
         let focusedElt = document.commandDispatcher.focusedElement;
         if (!focusedElt) {
-          document.commandDispatcher.advanceFocusIntoSubtree(dialog);
+          document.commandDispatcher.advanceFocusIntoSubtree(this);
 
           focusedElt = document.commandDispatcher.focusedElement;
           if (focusedElt) {
             var initialFocusedElt = focusedElt;
             while (
               focusedElt.localName == "tab" ||
               focusedElt.getAttribute("noinitialfocus") == "true"
             ) {
@@ -323,30 +324,30 @@
           }
         }
 
         try {
           if (defaultButton) {
             window.notifyDefaultButtonLoaded(defaultButton);
           }
         } catch (e) {}
-      }
+      };
 
       // Give focus after onload completes, see bug 103197.
       setTimeout(focusInit, 0);
 
       if (this._l10nButtons.length) {
         document.l10n.translateElements(this._l10nButtons).then(() => {
           window.sizeToContent();
         });
       }
     }
 
     openHelp(event) {
-      var helpButton = document.documentElement.getButton("help");
+      var helpButton = this.getButton("help");
       if (helpButton.disabled || helpButton.hidden) {
         return;
       }
       this._fireButtonEvent("help");
       event.stopPropagation();
       event.preventDefault();
     }
 
@@ -373,17 +374,21 @@
         dlgtype = exBtns[i].getAttribute("dlgtype");
         buttons[dlgtype].hidden = true; // hide the anonymous button
         buttons[dlgtype] = exBtns[i];
       }
 
       // add the label and oncommand handler to each button
       for (dlgtype in buttons) {
         var button = buttons[dlgtype];
-        button.addEventListener("command", this._handleButtonCommand, true);
+        button.addEventListener(
+          "command",
+          this._handleButtonCommand.bind(this),
+          true
+        );
 
         // don't override custom labels with pre-defined labels on explicit buttons
         if (!button.hasAttribute("label")) {
           // dialog attributes override the default labels in dialog.properties
           if (this.hasAttribute("buttonlabel" + dlgtype)) {
             button.setAttribute(
               "label",
               this.getAttribute("buttonlabel" + dlgtype)
@@ -496,19 +501,17 @@
           dump(
             "invalid new default button: " + aNewDefault + ", assuming: none\n"
           );
         }
       }
     }
 
     _handleButtonCommand(aEvent) {
-      return document.documentElement._doButtonCommand(
-        aEvent.target.getAttribute("dlgtype")
-      );
+      return this._doButtonCommand(aEvent.target.getAttribute("dlgtype"));
     }
 
     _doButtonCommand(aDlgType) {
       var button = this.getButton(aDlgType);
       if (!button.disabled) {
         var noCancel = this._fireButtonEvent(aDlgType);
         if (noCancel) {
           if (aDlgType == "accept" || aDlgType == "cancel") {
--- a/toolkit/content/xul.css
+++ b/toolkit/content/xul.css
@@ -526,16 +526,17 @@ scrollbox[smoothscroll=true] {
 stringbundle,
 stringbundleset {
   display: none;
 }
 
 /********** dialog **********/
 
 dialog {
+  -moz-box-flex: 1;
   -moz-box-orient: vertical;
 }
 
 /********** wizard **********/
 
 wizard {
   -moz-box-flex: 1;
   -moz-box-orient: vertical;
--- a/toolkit/mozapps/downloads/HelperAppDlg.jsm
+++ b/toolkit/mozapps/downloads/HelperAppDlg.jsm
@@ -501,16 +501,18 @@ nsUnknownContentTypeDialog.prototype = {
 
     var iconString =
       "moz-icon://" +
       iconPath +
       "?size=16&contentType=" +
       this.mLauncher.MIMEInfo.MIMEType;
     this.dialogElement("contentTypeImage").setAttribute("src", iconString);
 
+    let dialog = this.mDialog.document.getElementById("unknownContentType");
+
     // if always-save and is-executable and no-handler
     // then set up simple ui
     var mimeType = this.mLauncher.MIMEInfo.MIMEType;
     var shouldntRememberChoice =
       mimeType == "application/octet-stream" ||
       mimeType == "application/x-msdownload" ||
       this.mLauncher.targetFileIsExecutable;
     if (
@@ -518,26 +520,24 @@ nsUnknownContentTypeDialog.prototype = {
       Services.prefs.getBoolPref("browser.download.forbid_open_with")
     ) {
       // hide featured choice
       this.dialogElement("normalBox").collapsed = true;
       // show basic choice
       this.dialogElement("basicBox").collapsed = false;
       // change button labels and icons; use "save" icon for the accept
       // button since it's the only action possible
-      let acceptButton = this.mDialog.document.documentElement.getButton(
-        "accept"
-      );
+      let acceptButton = dialog.getButton("accept");
       acceptButton.label = this.dialogElement("strings").getString(
         "unknownAccept.label"
       );
       acceptButton.setAttribute("icon", "save");
-      this.mDialog.document.documentElement.getButton(
-        "cancel"
-      ).label = this.dialogElement("strings").getString("unknownCancel.label");
+      dialog.getButton("cancel").label = this.dialogElement(
+        "strings"
+      ).getString("unknownCancel.label");
       // hide other handler
       this.dialogElement("openHandler").collapsed = true;
       // set save as the selected option
       this.dialogElement("mode").selectedItem = this.dialogElement("save");
     } else {
       this.initAppAndSaveToDiskValues();
 
       // Initialize "always ask me" box. This should always be disabled
@@ -584,24 +584,20 @@ nsUnknownContentTypeDialog.prototype = {
     }
 
     this.mDialog.setTimeout(function() {
       this.dialog.postShowCallback();
     }, 0);
 
     this.delayHelper = new EnableDelayHelper({
       disableDialog: () => {
-        this.mDialog.document.documentElement.getButton(
-          "accept"
-        ).disabled = true;
+        dialog.getButton("accept").disabled = true;
       },
       enableDialog: () => {
-        this.mDialog.document.documentElement.getButton(
-          "accept"
-        ).disabled = false;
+        dialog.getButton("accept").disabled = false;
       },
       focusTarget: this.mDialog,
     });
   },
 
   notify(aTimer) {
     if (aTimer == this._showTimer) {
       if (!this.mDialog) {
@@ -888,17 +884,18 @@ nsUnknownContentTypeDialog.prototype = {
           ok =
             this.chosenApp ||
             /\S/.test(this.dialogElement("otherHandler").getAttribute("path"));
           break;
       }
     }
 
     // Enable Ok button if ok to press.
-    this.mDialog.document.documentElement.getButton("accept").disabled = !ok;
+    let dialog = this.mDialog.document.getElementById("unknownContentType");
+    dialog.getButton("accept").disabled = !ok;
   },
 
   // Returns true iff the user-specified helper app has been modified.
   appChanged() {
     return (
       this.helperAppChoice() !=
       this.mLauncher.MIMEInfo.preferredApplicationHandler
     );
@@ -991,19 +988,18 @@ nsUnknownContentTypeDialog.prototype = {
         ]);
         Services.prompt.alert(
           this.mDialog,
           bundle.getString("badApp.title"),
           msg
         );
 
         // Disable the OK button.
-        this.mDialog.document.documentElement.getButton(
-          "accept"
-        ).disabled = true;
+        let dialog = this.mDialog.document.getElementById("unknownContentType");
+        dialog.getButton("accept").disabled = true;
         this.dialogElement("mode").focus();
 
         // Clear chosen application.
         this.chosenApp = null;
 
         // Leave dialog up.
         aEvent.preventDefault();
       }
--- a/toolkit/mozapps/downloads/content/unknownContentType.xul
+++ b/toolkit/mozapps/downloads/content/unknownContentType.xul
@@ -2,37 +2,38 @@
 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="chrome://mozapps/skin/downloads/unknownContentType.css" type="text/css"?>
 
-<!DOCTYPE dialog [
+<!DOCTYPE window [
   <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
   %brandDTD;
   <!ENTITY % uctDTD SYSTEM "chrome://mozapps/locale/downloads/unknownContentType.dtd" >
   %uctDTD;
   <!ENTITY % scDTD SYSTEM "chrome://mozapps/locale/downloads/settingsChange.dtd" >
   %scDTD;
 ]>
 
-<dialog id="unknownContentType"
+<window id="unknownContentTypeWindow"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         onload="dialog.initDialog();" onunload="if (dialog) dialog.onCancel();"
 #ifdef XP_WIN
         style="width: 36em;"
 #else
         style="width: 34em;"
 #endif
         screenX="" screenY=""
         persist="screenX screenY"
         aria-describedby="intro location whichIs type from source unknownPrompt">
+<dialog id="unknownContentType">
 
   <stringbundle id="strings" src="chrome://mozapps/locale/downloads/unknownContentType.properties"/>
 
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
 
   <vbox flex="1" id="container">
     <description id="intro">&intro2.label;</description>
@@ -101,8 +102,9 @@
     <menupopup id="openHandlerPopup" oncommand="dialog.openHandlerCommand();">
       <menuitem id="defaultHandler" default="true" crop="right"/>
       <menuitem id="otherHandler" hidden="true" crop="left"/>
       <menuseparator/>
       <menuitem id="choose" label="&other.label;"/>
     </menupopup>
   </menulist>
 </dialog>
+</window>
--- a/toolkit/mozapps/extensions/content/blocklist.js
+++ b/toolkit/mozapps/extensions/content/blocklist.js
@@ -25,17 +25,19 @@ function init() {
     finish(false);
   });
 
   // NOTE: We use strings from the "updates.properties" bundleset to change the
   // text on the "Cancel" button to "Restart Later". (bug 523784)
   let bundle = Services.strings.createBundle(
     "chrome://mozapps/locale/update/updates.properties"
   );
-  let cancelButton = document.documentElement.getButton("cancel");
+  let cancelButton = document
+    .getElementById("BlocklistDialog")
+    .getButton("cancel");
   cancelButton.setAttribute(
     "label",
     bundle.GetStringFromName("restartLaterButton")
   );
   cancelButton.setAttribute(
     "accesskey",
     bundle.GetStringFromName("restartLaterButton.accesskey")
   );
--- a/toolkit/mozapps/extensions/content/blocklist.xul
+++ b/toolkit/mozapps/extensions/content/blocklist.xul
@@ -2,27 +2,29 @@
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://mozapps/skin/extensions/blocklist.css"?>
 
-<!DOCTYPE dialog [
+<!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
 %brandDTD;
 <!ENTITY % extensionsDTD SYSTEM "chrome://mozapps/locale/extensions/blocklist.dtd">
 %extensionsDTD;
 ]>
 
-<dialog windowtype="Addons:Blocklist" title="&blocklist.title;" align="stretch"
+<window windowtype="Addons:Blocklist" title="&blocklist.title;" align="stretch"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="init();"
-        buttons="accept,cancel" style="&blocklist.style;"
+        style="&blocklist.style;">
+<dialog id="BlocklistDialog"
+        buttons="accept,cancel"
         buttonlabelaccept="&blocklist.accept.label;"
         buttonaccesskeyaccept="&blocklist.accept.accesskey;">
 
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://mozapps/content/extensions/blocklist.js"/>
 
   <hbox align="stretch" flex="1">
     <vbox pack="start">
@@ -37,8 +39,9 @@
       <description id="hardBlockMessage" hidden="true" class="bold">&blocklist.hardblocked;</description>
       <description id="softBlockMessage" hidden="true" class="bold">&blocklist.softblocked;</description>
       <hbox pack="start">
         <label id="moreInfo" value="&blocklist.moreinfo;" is="text-link"/>
       </hbox>
     </vbox>
   </hbox>
 </dialog>
+</window>
--- a/toolkit/mozapps/handling/content/dialog.js
+++ b/toolkit/mozapps/handling/content/dialog.js
@@ -109,17 +109,17 @@ var dialog = {
       this._windowCtxt.QueryInterface(Ci.nsIInterfaceRequestor);
     }
 
     this.isPrivate =
       usePrivateBrowsing ||
       (window.opener && PrivateBrowsingUtils.isWindowPrivate(window.opener));
 
     this._itemChoose = document.getElementById("item-choose");
-    this._okButton = document.documentElement.getButton("extra1");
+    this._okButton = document.getElementById("handling").getButton("extra1");
 
     var description = {
       image: document.getElementById("description-image"),
       text: document.getElementById("description-text"),
     };
     var options = document.getElementById("item-action-text");
     var checkbox = {
       desc: document.getElementById("remember"),
--- a/toolkit/mozapps/handling/content/dialog.xul
+++ b/toolkit/mozapps/handling/content/dialog.xul
@@ -1,25 +1,25 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin/global.css"?>
 <?xml-stylesheet href="chrome://mozapps/content/handling/handler.css"?>
 <?xml-stylesheet href="chrome://mozapps/skin/handling/handling.css"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
-<!DOCTYPE dialog SYSTEM "chrome://mozapps/locale/handling/handling.dtd">
+<!DOCTYPE window SYSTEM "chrome://mozapps/locale/handling/handling.dtd">
 
-<dialog id="handling"
-        onload="dialog.initialize();"
+<window onload="dialog.initialize();"
         style="min-width: &window.emWidth;; min-height: &window.emHeight;;"
         persist="width height screenX screenY"
         aria-describedby="description-text"
-        buttons="cancel,extra1"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog id="handling"
+        buttons="cancel,extra1">
 
   <script src="chrome://mozapps/content/handling/dialog.js" type="application/javascript"/>
 
   <stringbundleset id="strings">
     <stringbundle id="base-strings"
                   src="chrome://mozapps/locale/handling/handling.properties"/>
   </stringbundleset>
 
@@ -50,8 +50,9 @@
     <button dlgtype="extra1" label="&accept;" class="dialog-button"/>
 #else
     <button dlgtype="extra1" label="&accept;" class="dialog-button"/>
     <button dlgtype="cancel" class="dialog-button"/>
 #endif
   </hbox>
 
 </dialog>
+</window>
--- a/toolkit/mozapps/preferences/changemp.js
+++ b/toolkit/mozapps/preferences/changemp.js
@@ -183,17 +183,17 @@ function setPasswordStrength() {
 
   var mymeter = document.getElementById("pwmeter");
   mymeter.value = pwstrength;
 }
 
 function checkPasswords() {
   var pw1 = document.getElementById("pw1").value;
   var pw2 = document.getElementById("pw2").value;
-  var ok = document.documentElement.getButton("accept");
+  var ok = document.getElementById("changemp").getButton("accept");
 
   var oldpwbox = document.getElementById("oldpw");
   if (oldpwbox) {
     var initpw = oldpwbox.getAttribute("inited");
 
     if (initpw == "empty" && pw1 == "") {
       // The token has already been initialized, therefore this dialog
       // was called with the intention to change the password.
--- a/toolkit/mozapps/preferences/changemp.xhtml
+++ b/toolkit/mozapps/preferences/changemp.xhtml
@@ -1,22 +1,22 @@
 <?xml version="1.0"?>
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog id="changemp"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         style="width: 40em;"
         onload="init()"
         data-l10n-id="set-password">
+<dialog id="changemp">
 
   <script src="chrome://mozapps/content/preferences/changemp.js"/>
 
   <linkset>
     <html:link rel="localization" href="branding/brand.ftl"/>
     <html:link rel="localization" href="toolkit/preferences/preferences.ftl"/>
   </linkset>
 
@@ -47,8 +47,9 @@
   </vbox>
 
   <html:label for="pwmeter" style="display: -moz-box;" data-l10n-id="set-password-meter"></html:label>
   <html:progress id="pwmeter" value="0" max="100"/>
 
   <description control="pw2" class="header" data-l10n-id="master-password-warning"></description>
 
 </dialog>
+</window>
--- a/toolkit/mozapps/preferences/removemp.js
+++ b/toolkit/mozapps/preferences/removemp.js
@@ -6,17 +6,17 @@
 
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var gRemovePasswordDialog = {
   _token: null,
   _okButton: null,
   _password: null,
   init() {
-    this._okButton = document.documentElement.getButton("accept");
+    this._okButton = document.getElementById("removemp").getButton("accept");
     document.l10n.setAttributes(this._okButton, "pw-remove-button");
 
     this._password = document.getElementById("password");
 
     var pk11db = Cc["@mozilla.org/security/pk11tokendb;1"].getService(
       Ci.nsIPK11TokenDB
     );
     this._token = pk11db.getInternalKeyToken();
--- a/toolkit/mozapps/preferences/removemp.xhtml
+++ b/toolkit/mozapps/preferences/removemp.xhtml
@@ -1,22 +1,22 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog id="removemp"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         style="width: 35em;"
         onload="gRemovePasswordDialog.init()"
         data-l10n-id="remove-password">
+<dialog id="removemp">
 
   <script src="chrome://mozapps/content/preferences/removemp.js"/>
 
   <linkset>
     <html:link rel="localization" href="toolkit/preferences/preferences.ftl"/>
   </linkset>
 
   <vbox id="warnings">
@@ -35,8 +35,9 @@
                   oninput="gRemovePasswordDialog.validateInput();"
                   aria-describedby="warnings"/>
     </hbox>
   </groupbox>
   
   <separator/>
 
 </dialog>
+</window>
--- a/toolkit/mozapps/update/content/history.js
+++ b/toolkit/mozapps/update/content/history.js
@@ -66,17 +66,17 @@ var gUpdateHistory = {
         document.l10n.setAttributes(statusLabel, "update-status", {
           status: update.statusText,
         });
 
         element.append(topLine, installedOnLabel, statusLabel);
         this._view.appendChild(element);
       }
     }
-    var cancelbutton = document.documentElement.getButton("cancel");
+    var cancelbutton = document.getElementById("history").getButton("cancel");
     cancelbutton.focus();
   },
 
   /**
    * Formats a date into human readable form
    * @param   seconds
    *          A date in seconds since 1970 epoch
    * @returns A human readable date string
--- a/toolkit/mozapps/update/content/history.xhtml
+++ b/toolkit/mozapps/update/content/history.xhtml
@@ -1,34 +1,38 @@
 <?xml version="1.0"?>
 
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
-<!DOCTYPE dialog>
+<!DOCTYPE window>
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://mozapps/skin/update/updates.css"?>
 
-<dialog id="history" windowtype="Update:History"
+<window windowtype="Update:History"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         style="width: 35em;"
+        data-l10n-id="close-button-label"
+        data-l10n-attrs="title"
+        onload="gUpdateHistory.onLoad();">
+<dialog id="history"
         buttons="cancel"
         defaultButton="cancel"
         data-l10n-id="close-button-label"
-        data-l10n-attrs="buttonlabelcancel"
-        onload="gUpdateHistory.onLoad();">
+        data-l10n-attrs="buttonlabelcancel">
 
   <linkset>
     <html:link rel="localization" href="toolkit/updates/history.ftl"/>
   </linkset>
 
   <script src="chrome://mozapps/content/update/history.js"/>
 
   <label data-l10n-id="history-intro"></label>
   <separator class="thin"/>
   <richlistbox id="historyItems" flex="1">
     <label data-l10n-id="no-updates-label"></label>
   </richlistbox>
   <separator class="thin"/>
 </dialog>
+</window>
--- a/toolkit/mozapps/update/content/updateElevation.xul
+++ b/toolkit/mozapps/update/content/updateElevation.xul
@@ -4,36 +4,35 @@
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!-- This is temporary until bug 1521632 is fixed -->
 
 <?xml-stylesheet href="chrome://global/skin/"?>
 <?xml-stylesheet href="chrome://mozapps/skin/update/updates.css"?>
 
-<!DOCTYPE dialog [
+<!DOCTYPE window [
 <!ENTITY % updateDTD SYSTEM "chrome://mozapps/locale/update/updates.dtd">
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
 %updateDTD;
 %brandDTD;
 #if defined(XP_MACOSX) && MOZ_BUILD_APP == browser
 #include ../../../../browser/base/content/browser-doctype.inc
 #endif
 ]>
 
-<dialog id="updates"
-        windowtype="Update:Elevation"
+<window windowtype="Update:Elevation"
         type="child"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
-        buttons="extra2,extra1,accept"
-        role="dialog"
         title="&updateWizard.title;"
         style="width: auto; height: auto"
         onload="gUpdateElevationDialog.onLoad();">
+<dialog id="updates"
+        buttons="extra2,extra1,accept">
 
   <script src="chrome://mozapps/content/update/updateElevation.js"/>
   <script src="chrome://global/content/contentAreaUtils.js"/>
   <script src="chrome://global/content/globalOverlay.js"/>
   <script src="chrome://global/content/editMenuOverlay.js"/>
 
 #if defined(XP_MACOSX) && MOZ_BUILD_APP == browser
 #include ../../../../browser/base/content/macWindow.inc.xhtml
@@ -77,8 +76,9 @@
 	        oncommand="gUpdateElevationDialog.onRestartLater();" />
     <button id="elevateExtra1" dlgtype="extra1" label="" class="dialog-button"
 	        oncommand="gUpdateElevationDialog.onNoThanks();" />
     <spacer flex="1"/>
     <button id="elevateAccept" dlgtype="accept" label="" class="dialog-button"
 	        oncommand="gUpdateElevationDialog.onRestartNow();" default="true"/>
   </hbox>
 </dialog>
+</window>
--- a/toolkit/profile/content/profileDowngrade.xul
+++ b/toolkit/profile/content/profileDowngrade.xul
@@ -1,44 +1,45 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 <?xml-stylesheet href="chrome://mozapps/skin/profile/profileDowngrade.css" type="text/css"?>
 
-<!DOCTYPE dialog [
+<!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
 %brandDTD;
 #ifdef MOZ_SERVICES_SYNC
 <!ENTITY % syncBrandDTD SYSTEM "chrome://browser/locale/syncBrand.dtd">
 %syncBrandDTD;
 #endif
 <!ENTITY % profileDTD SYSTEM "chrome://mozapps/locale/profile/profileDowngrade.dtd">
 %profileDTD;
 ]>
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        title="&window.title;" onload="init()" style="&window.style;"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="&window.title;" onload="init()" style="&window.style;">
+<dialog buttons="accept,extra1" buttonpack="end"
         buttonlabelextra1="&window.create;"
 #ifdef XP_WIN
         buttonlabelaccept="&window.quit-win;"
 #else
         buttonlabelaccept="&window.quit-nonwin;"
 #endif
-        buttons="accept,extra1" buttonpack="end"
         nobuttonspacer="true">
 
   <script src="profileDowngrade.js"/>
   <script src="chrome://global/content/customElements.js"/>
 
   <hbox flex="1" align="start">
     <image id="info" role="presentation"/>
     <vbox flex="1">
       <description id="nosync">&window.nosync;</description>
 #ifdef MOZ_SERVICES_SYNC
       <description id="sync">&window.sync;</description>
 #endif
     </vbox>
   </hbox>
 
 </dialog>
+</window>
--- a/toolkit/profile/content/profileSelection.js
+++ b/toolkit/profile/content/profileSelection.js
@@ -26,17 +26,17 @@ function startup() {
 
     gProfileService = C[ToolkitProfileService].getService(
       I.nsIToolkitProfileService
     );
 
     gProfileManagerBundle = document.getElementById("bundle_profileManager");
     gBrandBundle = document.getElementById("bundle_brand");
 
-    document.documentElement.centerWindowOnScreen();
+    document.getElementById("profileWindow").centerWindowOnScreen();
 
     var profilesElement = document.getElementById("profiles");
 
     for (let profile of gProfileService.profiles.entries(I.nsIToolkitProfile)) {
       var listitem = profilesElement.appendItem(profile.name, "");
 
       var tooltiptext = gProfileManagerBundle.getFormattedString(
         "profileTooltip",
@@ -195,17 +195,17 @@ function onProfilesKey(aEvent) {
     case KeyEvent.DOM_VK_F2:
       RenameProfile();
       break;
   }
 }
 
 function onProfilesDblClick(aEvent) {
   if (aEvent.target.closest("richlistitem")) {
-    document.documentElement.acceptDialog();
+    document.getElementById("profileWindow").acceptDialog();
   }
 }
 
 // invoke the createProfile Wizard
 function CreateProfileWizard() {
   window.openDialog(
     "chrome://mozapps/content/profile/createProfileWizard.xul",
     "",
--- a/toolkit/profile/content/profileSelection.xul
+++ b/toolkit/profile/content/profileSelection.xul
@@ -10,25 +10,25 @@
 
 <!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd">
 %brandDTD;
 <!ENTITY % profileDTD SYSTEM "chrome://mozapps/locale/profile/profileSelection.dtd">
 %profileDTD;
 ]>
 
-<dialog
-  id="profileWindow"
+<window
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
   class="non-resizable"
   title="&windowtitle.label;"
   orient="vertical"
+  style="width: 30em;"
+  onload="startup();">
+<dialog id="profileWindow"
   buttons="accept,cancel"
-  style="width: 30em;"
-  onload="startup();"
   buttonlabelaccept="&start.label;"
   buttonlabelcancel="&exit.label;">
 
   <script src="chrome://global/content/customElements.js"/>
 
   <stringbundle id="bundle_profileManager"
                 src="chrome://mozapps/locale/profile/profileSelection.properties"/>
   <stringbundle id="bundle_brand"
@@ -63,8 +63,9 @@
       <checkbox id="offlineState" label="&offlineState.label;" accesskey="&offlineState.accesskey;"/>
 
       <checkbox id="autoSelectLastProfile" label="&useSelected.label;"
                 accesskey="&useSelected.accesskey;"/>
     </vbox>
 
   </hbox>
 </dialog>
+</window>