commit 9ee3a6db7fb64d4afdb092275ae5646611ab48fd
parent 153cd95271ed3f17e6a870ed93565ab5aa582178
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date: Sat, 29 Nov 2025 11:01:37 +0000
Bug 1369833 - Part 4: Use initWithObject instead of showAlertNotification in browser/ r=firefox-desktop-core-reviewers ,Gijs
Differential Revision: https://phabricator.services.mozilla.com/D273574
Diffstat:
3 files changed, 58 insertions(+), 48 deletions(-)
diff --git a/browser/components/AccountsGlue.sys.mjs b/browser/components/AccountsGlue.sys.mjs
@@ -37,6 +37,12 @@ ChromeUtils.defineLazyGetter(
() => new Localization(["browser/accounts.ftl", "branding/brand.ftl"], true)
);
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
+
/**
* Manages Mozilla Account and Sync related functionality
* needed at startup. It mainly handles various account-related events and notifications.
@@ -127,14 +133,12 @@ export const AccountsGlue = {
}
this._openPreferences("sync");
};
- lazy.AlertsService.showAlertNotification(
- null,
+ let alert = new AlertNotification({
title,
- body,
- true,
- null,
- clickCallback
- );
+ text: body,
+ textClickable: true,
+ });
+ lazy.AlertsService.showAlert(alert, clickCallback);
},
_openURLInNewWindow(url) {
@@ -251,14 +255,13 @@ export const AccountsGlue = {
if (AppConstants.platform == "win") {
imageURL = "chrome://branding/content/icon64.png";
}
- lazy.AlertsService.showAlertNotification(
+ let alert = new AlertNotification({
imageURL,
title,
- body,
- true,
- null,
- clickCallback
- );
+ text: body,
+ textClickable: true,
+ });
+ lazy.AlertsService.showAlert(alert, clickCallback);
} catch (ex) {
console.error("Error displaying tab(s) received by Sync: ", ex);
}
@@ -343,15 +346,14 @@ export const AccountsGlue = {
]);
try {
- lazy.AlertsService.showAlertNotification(
+ let alert = new AlertNotification({
imageURL,
title,
- body,
- true,
- null,
- clickCallback,
- "closed-tab-notification"
- );
+ text: body,
+ textClickable: true,
+ name: "closed-tab-notification",
+ });
+ lazy.AlertsService.showAlert(alert, clickCallback);
} catch (ex) {
console.error("Error notifying user of closed tab(s) ", ex);
}
@@ -380,14 +382,13 @@ export const AccountsGlue = {
};
try {
- lazy.AlertsService.showAlertNotification(
+ let alert = new AlertNotification({
imageURL,
title,
body,
- true,
- null,
- clickCallback
- );
+ textClickable: true,
+ });
+ lazy.AlertsService.showAlert(alert, clickCallback);
} catch (ex) {
console.error("Error notifying of a verify login event: ", ex);
}
@@ -417,14 +418,12 @@ export const AccountsGlue = {
};
try {
- lazy.AlertsService.showAlertNotification(
- null,
+ let alert = new AlertNotification({
title,
- body,
- true,
- null,
- clickCallback
- );
+ text: body,
+ textClickable: true,
+ });
+ lazy.AlertsService.showAlert(alert, clickCallback);
} catch (ex) {
console.error("Error notifying of a new Sync device: ", ex);
}
@@ -442,14 +441,13 @@ export const AccountsGlue = {
}
this._openPreferences("sync");
};
- lazy.AlertsService.showAlertNotification(
- null,
+
+ let alert = new AlertNotification({
title,
- body,
- true,
- null,
- clickCallback
- );
+ text: body,
+ textClickable: true,
+ });
+ lazy.AlertsService.showAlert(alert, clickCallback);
},
_updateFxaBadges(win) {
diff --git a/browser/components/screenshots/ScreenshotsUtils.sys.mjs b/browser/components/screenshots/ScreenshotsUtils.sys.mjs
@@ -52,6 +52,12 @@ ChromeUtils.defineLazyGetter(lazy, "screenshotsLocalization", () => {
return new Localization(["browser/screenshots.ftl"], true);
});
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
+
// The max dimension for a canvas is 32,767 https://searchfox.org/mozilla-central/rev/f40d29a11f2eb4685256b59934e637012ea6fb78/gfx/cairo/cairo/src/cairo-image-surface.c#62.
// The max number of pixels for a canvas is 472,907,776 pixels (i.e., 22,528 x 20,992) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#maximum_canvas_size
// We have to limit screenshots to these dimensions otherwise it will cause an error.
@@ -984,7 +990,9 @@ export var ScreenshotsUtils = {
},
showAlertMessage(title, message) {
- lazy.AlertsService.showAlertNotification(null, title, message);
+ lazy.AlertsService.showAlert(
+ new AlertNotification({ title, text: message })
+ );
},
/**
diff --git a/browser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs b/browser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs
@@ -22,6 +22,12 @@ const PREF_TIMER_SHOW_NOTIFICATIONS =
"widgets.focusTimer.showSystemNotifications";
const CACHE_KEY = "timer_widget";
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
+
/**
* Class for the Timer widget, which manages the changes to the Timer widget
* and syncs with PersistentCache
@@ -49,14 +55,12 @@ export class TimerFeed {
Ci.nsIAlertsService
);
- // TODO: Add more readable args as defined in toolkit/components/alerts/nsIAlertsService.idl
- alertsService.showAlertNotification(
- "chrome://branding/content/icon64.png",
- title,
- body,
- false,
- "",
- null
+ alertsService.showAlert(
+ new AlertNotification({
+ imageURL: "chrome://branding/content/icon64.png",
+ title,
+ text: body,
+ })
);
} catch (err) {
console.error("Failed to show system notification", err);