commit e67f734a6f9e3783d259733069c7301765e9075f
parent aa721d24cfcbcb870249c636e1ff2284c6a6d4f9
Author: Henry Wilkes <henry@torproject.org>
Date: Mon, 28 Jul 2025 14:56:19 +0100
BB 44040: Modify prompt service for Base Browser.
Diffstat:
5 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/netwerk/base/nsIPrompt.idl b/netwerk/base/nsIPrompt.idl
@@ -67,6 +67,8 @@ interface nsIPrompt : nsISupports
const unsigned long BUTTON_POS_1_IS_SECONDARY = 1 << 29;
+ const unsigned long BUTTON_DEFAULT_IS_DESTRUCTIVE = 1 << 30;
+
const unsigned long STD_OK_CANCEL_BUTTONS = (BUTTON_TITLE_OK * BUTTON_POS_0) +
(BUTTON_TITLE_CANCEL * BUTTON_POS_1);
const unsigned long STD_YES_NO_BUTTONS = (BUTTON_TITLE_YES * BUTTON_POS_0) +
diff --git a/toolkit/components/prompts/content/commonDialog.js b/toolkit/components/prompts/content/commonDialog.js
@@ -39,7 +39,7 @@ function commonDialogOnLoad() {
["promptUserAndPass", "promptPassword"].includes(args.promptType) ||
args.headerIconCSSValue;
let root = document.documentElement;
- if (needIconifiedHeader) {
+ if (needIconifiedHeader && !args.noIcon) {
root.setAttribute("neediconheader", "true");
}
let title = { raw: args.title };
@@ -107,6 +107,10 @@ function commonDialogOnLoad() {
dialog.setAttribute("extra1-is-secondary", true);
}
+ if (args.isDefaultDestructive) {
+ dialog.setAttribute("default-is-destructive", true);
+ }
+
Dialog = new CommonDialog(args, ui);
window.addEventListener("dialogclosing", function (aEvent) {
if (aEvent.detail?.abort) {
diff --git a/toolkit/components/prompts/src/Prompter.sys.mjs b/toolkit/components/prompts/src/Prompter.sys.mjs
@@ -1524,6 +1524,10 @@ class ModalPrompter {
args.isExtra1Secondary = true;
}
+ if (flags & Ci.nsIPrompt.BUTTON_DEFAULT_IS_DESTRUCTIVE) {
+ args.isDefaultDestructive = true;
+ }
+
if (flags & Ci.nsIPrompt.SHOW_SPINNER) {
args.headerIconCSSValue = "url('chrome://global/skin/icons/loading.svg')";
}
diff --git a/toolkit/components/windowwatcher/nsIPromptService.idl b/toolkit/components/windowwatcher/nsIPromptService.idl
@@ -287,6 +287,8 @@ interface nsIPromptService : nsISupports
*/
const unsigned long BUTTON_POS_1_IS_SECONDARY = 1 << 29;
+ const unsigned long BUTTON_DEFAULT_IS_DESTRUCTIVE = 1 << 30;
+
/**
* Selects the standard set of OK/Cancel buttons.
*/
diff --git a/toolkit/content/widgets/dialog.js b/toolkit/content/widgets/dialog.js
@@ -21,7 +21,8 @@
static get observedAttributes() {
return super.observedAttributes.concat(
"subdialog",
- "extra1-is-secondary"
+ "extra1-is-secondary",
+ "default-is-destructive"
);
}
@@ -40,6 +41,12 @@
if (name === "extra1-is-secondary" && AppConstants.XP_UNIX) {
this.getButton("cancel").after(this.getButton("extra1"));
}
+ if (name === "default-is-destructive") {
+ this.#setButtonIsDestructive(
+ this.getButton(this.defaultButton),
+ this.hasAttribute("default-is-destructive")
+ );
+ }
super.attributeChangedCallback(name, oldValue, newValue);
}
@@ -491,12 +498,17 @@
var oldDefaultButton = this.getButton(this.defaultButton);
if (oldDefaultButton) {
oldDefaultButton.removeAttribute("default");
+ this.#setButtonIsDestructive(oldDefaultButton, false);
}
var newDefaultButton = this.getButton(aNewDefault);
if (newDefaultButton) {
this.setAttribute("defaultButton", aNewDefault);
newDefaultButton.setAttribute("default", "true");
+ this.#setButtonIsDestructive(
+ newDefaultButton,
+ this.hasAttribute("default-is-destructive")
+ );
} else {
this.setAttribute("defaultButton", "none");
if (aNewDefault != "none") {
@@ -507,6 +519,16 @@
}
}
+ /**
+ * Mark or un-mark a button as a destructive action.
+ *
+ * @param {?Element} button - The button to mark.
+ * @param {boolean} isDestructive - Whether the button is destructive.
+ */
+ #setButtonIsDestructive(button, isDestructive) {
+ button?.classList.toggle("danger-button", isDestructive);
+ }
+
_handleButtonCommand(aEvent) {
return this._doButtonCommand(aEvent.target.getAttribute("dlgtype"));
}