commit 446248523d95999f658d8571493e3be0abfe5597
parent 9ee3a6db7fb64d4afdb092275ae5646611ab48fd
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date: Sat, 29 Nov 2025 11:01:37 +0000
Bug 1369833 - Part 5: Remove showAlertNotification r=nalexander,nrishel,geckoview-reviewers,win-reviewers,gstoll
Differential Revision: https://phabricator.services.mozilla.com/D273575
Diffstat:
12 files changed, 47 insertions(+), 146 deletions(-)
diff --git a/toolkit/components/alerts/nsAlertsService.cpp b/toolkit/components/alerts/nsAlertsService.cpp
@@ -82,26 +82,6 @@ bool nsAlertsService::ShouldShowAlert() {
return result;
}
-NS_IMETHODIMP nsAlertsService::ShowAlertNotification(
- const nsAString& aImageUrl, const nsAString& aAlertTitle,
- const nsAString& aAlertText, bool aAlertTextClickable,
- const nsAString& aAlertCookie, nsIObserver* aAlertListener,
- const nsAString& aAlertName, const nsAString& aBidi, const nsAString& aLang,
- const nsAString& aData, nsIPrincipal* aPrincipal, bool aInPrivateBrowsing,
- bool aRequireInteraction) {
- nsCOMPtr<nsIAlertNotification> alert =
- do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
- NS_ENSURE_TRUE(alert, NS_ERROR_FAILURE);
- // vibrate is unused
- nsTArray<uint32_t> vibrate;
- nsresult rv = alert->Init(aAlertName, aImageUrl, aAlertTitle, aAlertText,
- aAlertTextClickable, aAlertCookie, aBidi, aLang,
- aData, aPrincipal, aInPrivateBrowsing,
- aRequireInteraction, false, vibrate);
- NS_ENSURE_SUCCESS(rv, rv);
- return ShowAlert(alert, aAlertListener);
-}
-
NS_IMETHODIMP nsAlertsService::ShowAlert(nsIAlertNotification* aAlert,
nsIObserver* aAlertListener) {
NS_ENSURE_ARG(aAlert);
diff --git a/toolkit/components/alerts/nsIAlertsService.idl b/toolkit/components/alerts/nsIAlertsService.idl
@@ -272,12 +272,11 @@ interface nsIAlertNotification : nsISupports
[scriptable, uuid(f7a36392-d98b-4141-a7d7-4e46642684e3)]
interface nsIAlertsService : nsISupports
{
- void showAlert(in nsIAlertNotification aAlert,
- [optional] in nsIObserver aAlertListener);
/**
* Initializes and shows an |nsIAlertNotification| with the given parameters.
*
- * @param aAlertListener Used for callbacks. May be null if the caller
+ * @param aAlert The alert notification to show.
+ * @param aAlertListener Used for callbacks. May be omitted if the caller
* doesn't care about callbacks.
* @see nsIAlertNotification for descriptions of all other parameters.
* @throws NS_ERROR_NOT_AVAILABLE If the notification cannot be displayed.
@@ -297,19 +296,8 @@ interface nsIAlertsService : nsISupports
* In that case, if an alert listener is passed in it will receive the
* "alertfinished" notification immediately.
*/
- void showAlertNotification(in AString aImageURL,
- in AString aTitle,
- in AString aText,
- [optional] in boolean aTextClickable,
- [optional] in AString aCookie,
- [optional] in nsIObserver aAlertListener,
- [optional] in AString aName,
- [optional] in AString aDir,
- [optional] in AString aLang,
- [optional] in AString aData,
- [optional] in nsIPrincipal aPrincipal,
- [optional] in boolean aInPrivateBrowsing,
- [optional] in boolean aRequireInteraction);
+ void showAlert(in nsIAlertNotification aAlert,
+ [optional] in nsIObserver aAlertListener);
/**
* Close alerts created by the service.
diff --git a/toolkit/components/alerts/nsXULAlerts.cpp b/toolkit/components/alerts/nsXULAlerts.cpp
@@ -90,27 +90,6 @@ void nsXULAlerts::PersistentAlertFinished() {
}
NS_IMETHODIMP
-nsXULAlerts::ShowAlertNotification(
- const nsAString& aImageUrl, const nsAString& aAlertTitle,
- const nsAString& aAlertText, bool aAlertTextClickable,
- const nsAString& aAlertCookie, nsIObserver* aAlertListener,
- const nsAString& aAlertName, const nsAString& aBidi, const nsAString& aLang,
- const nsAString& aData, nsIPrincipal* aPrincipal, bool aInPrivateBrowsing,
- bool aRequireInteraction) {
- nsCOMPtr<nsIAlertNotification> alert =
- do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
- NS_ENSURE_TRUE(alert, NS_ERROR_FAILURE);
- // vibrate is unused for now
- nsTArray<uint32_t> vibrate;
- nsresult rv = alert->Init(aAlertName, aImageUrl, aAlertTitle, aAlertText,
- aAlertTextClickable, aAlertCookie, aBidi, aLang,
- aData, aPrincipal, aInPrivateBrowsing,
- aRequireInteraction, false, vibrate);
- NS_ENSURE_SUCCESS(rv, rv);
- return ShowAlert(alert, aAlertListener);
-}
-
-NS_IMETHODIMP
nsXULAlerts::ShowAlert(nsIAlertNotification* aAlert,
nsIObserver* aAlertListener) {
nsAutoString name;
diff --git a/toolkit/components/alerts/test/chrome/test_alerts_noobserve.html b/toolkit/components/alerts/test/chrome/test_alerts_noobserve.html
@@ -20,6 +20,11 @@
<script class="testbody" type="text/javascript">
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
const chromeScript = SpecialPowers.loadChromeScript(_ => {
/* eslint-env mozilla/chrome-script */
@@ -72,8 +77,10 @@ async function runTest() {
if (notifier) {
try {
- notifier.showAlertNotification(null, "Notification test",
- "This notification has no observer");
+ notifier.showAlert(new AlertNotification({
+ title: "Notification test",
+ body: "This notification has no observer"
+ }));
notifier.closeAlert();
ok(true, "showAlertNotification() succeeded");
} catch (ex) {
diff --git a/toolkit/components/alerts/test/chrome/test_alerts_requireinteraction.html b/toolkit/components/alerts/test/chrome/test_alerts_requireinteraction.html
@@ -10,6 +10,11 @@
<script class="testbody" type="text/javascript">
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
const chromeScript = SpecialPowers.loadChromeScript(_ => {
/* eslint-env mozilla/chrome-script */
@@ -52,9 +57,16 @@ function promiseCreateXULAlert(alertService, listener, name) {
});
chromeScript.sendAsyncMessage("waitForXULAlert");
- alertService.showAlertNotification(null, "title", "body",
- true, cookie++, listener, name, null, null, null,
- null, false, true);
+
+ let alert = new AlertNotification({
+ title: "title",
+ text: "body",
+ textClickable: true,
+ cookie: cookie++,
+ name,
+ requireInteraction: true
+ });
+ alertService.showAlert(alert, listener);
});
}
diff --git a/toolkit/components/alerts/test/chrome/test_multiple_alerts.html b/toolkit/components/alerts/test/chrome/test_multiple_alerts.html
@@ -10,6 +10,11 @@
<script class="testbody" type="text/javascript">
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
const chromeScript = SpecialPowers.loadChromeScript(_ => {
/* eslint-env mozilla/chrome-script */
@@ -60,7 +65,7 @@ function promiseAlertPosition(alertService) {
});
chromeScript.sendAsyncMessage("waitForPosition");
- alertService.showAlertNotification(null, "title", "body");
+ alertService.showAlert(new AlertNotification({ title: "title", text: "body" }));
ok(true, "Alert shown.");
});
}
diff --git a/toolkit/components/alerts/test/chrome/test_principal.html b/toolkit/components/alerts/test/chrome/test_principal.html
@@ -15,6 +15,11 @@
const Cc = SpecialPowers.Cc;
const Ci = SpecialPowers.Ci;
const Services = SpecialPowers.Services;
+const AlertNotification = Components.Constructor(
+ "@mozilla.org/alert-notification;1",
+ "nsIAlertNotification",
+ "initWithObject"
+);
const notifier = Cc["@mozilla.org/alerts-service;1"]
.getService(Ci.nsIAlertsService);
@@ -50,10 +55,14 @@ function notify(alertName, principal) {
resolve(source);
}
}
- notifier.showAlertNotification(null, "Notification test",
- "Surprise! I'm here to test notifications!",
- false, alertName, observe, alertName,
- null, null, null, principal);
+ let alert = new AlertNotification({
+ title: "Notification test",
+ body: "Surprise! I'm here to test notifications!",
+ cookie: alertName,
+ name: alertName,
+ principal
+ });
+ notifier.showAlert(alert, observe);
if (SpecialPowers.Services.appinfo.OS == "Darwin") {
notifier.closeAlert(alertName);
}
diff --git a/toolkit/system/gnome/nsSystemAlertsService.cpp b/toolkit/system/gnome/nsSystemAlertsService.cpp
@@ -22,26 +22,6 @@ nsSystemAlertsService::~nsSystemAlertsService() = default;
nsresult nsSystemAlertsService::Init() { return NS_OK; }
-NS_IMETHODIMP nsSystemAlertsService::ShowAlertNotification(
- const nsAString& aImageUrl, const nsAString& aAlertTitle,
- const nsAString& aAlertText, bool aAlertTextClickable,
- const nsAString& aAlertCookie, nsIObserver* aAlertListener,
- const nsAString& aAlertName, const nsAString& aBidi, const nsAString& aLang,
- const nsAString& aData, nsIPrincipal* aPrincipal, bool aInPrivateBrowsing,
- bool aRequireInteraction) {
- nsCOMPtr<nsIAlertNotification> alert =
- do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
- NS_ENSURE_TRUE(alert, NS_ERROR_FAILURE);
- // vibrate is unused for now
- nsTArray<uint32_t> vibrate;
- nsresult rv = alert->Init(aAlertName, aImageUrl, aAlertTitle, aAlertText,
- aAlertTextClickable, aAlertCookie, aBidi, aLang,
- aData, aPrincipal, aInPrivateBrowsing,
- aRequireInteraction, false, vibrate);
- NS_ENSURE_SUCCESS(rv, rv);
- return ShowAlert(alert, aAlertListener);
-}
-
NS_IMETHODIMP nsSystemAlertsService::ShowAlert(nsIAlertNotification* aAlert,
nsIObserver* aAlertListener) {
NS_ENSURE_ARG(aAlert);
diff --git a/tools/@types/generated/lib.gecko.xpcom.d.ts b/tools/@types/generated/lib.gecko.xpcom.d.ts
@@ -836,7 +836,6 @@ interface nsIAlertNotification extends nsISupports {
interface nsIAlertsService extends nsISupports {
showAlert(aAlert: nsIAlertNotification, aAlertListener?: nsIObserver): void;
- showAlertNotification(aImageURL: string, aTitle: string, aText: string, aTextClickable?: boolean, aCookie?: string, aAlertListener?: nsIObserver, aName?: string, aDir?: string, aLang?: string, aData?: string, aPrincipal?: nsIPrincipal, aInPrivateBrowsing?: boolean, aRequireInteraction?: boolean): void;
closeAlert(aName?: string, aContextClosed?: boolean): void;
getHistory(): string[];
teardown(): void;
diff --git a/widget/android/AndroidAlerts.cpp b/widget/android/AndroidAlerts.cpp
@@ -35,18 +35,6 @@ using NotificationMap = nsTHashMap<nsStringHashKey, AndroidNotificationTuple>;
static StaticAutoPtr<NotificationMap> sNotificationMap;
NS_IMETHODIMP
-AndroidAlerts::ShowAlertNotification(
- const nsAString& aImageUrl, const nsAString& aAlertTitle,
- const nsAString& aAlertText, bool aAlertTextClickable,
- const nsAString& aAlertCookie, nsIObserver* aAlertListener,
- const nsAString& aAlertName, const nsAString& aBidi, const nsAString& aLang,
- const nsAString& aData, nsIPrincipal* aPrincipal, bool aInPrivateBrowsing,
- bool aRequireInteraction) {
- MOZ_ASSERT_UNREACHABLE("Should be implemented by nsAlertsService.");
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
AndroidAlerts::ShowAlert(nsIAlertNotification* aAlert,
nsIObserver* aAlertListener) {
// nsAlertsService disables our alerts backend if we ever return failure
diff --git a/widget/cocoa/OSXNotificationCenter.mm b/widget/cocoa/OSXNotificationCenter.mm
@@ -162,27 +162,6 @@ nsresult OSXNotificationCenter::Init() {
}
NS_IMETHODIMP
-OSXNotificationCenter::ShowAlertNotification(
- const nsAString& aImageUrl, const nsAString& aAlertTitle,
- const nsAString& aAlertText, bool aAlertTextClickable,
- const nsAString& aAlertCookie, nsIObserver* aAlertListener,
- const nsAString& aAlertName, const nsAString& aBidi, const nsAString& aLang,
- const nsAString& aData, nsIPrincipal* aPrincipal, bool aInPrivateBrowsing,
- bool aRequireInteraction) {
- nsCOMPtr<nsIAlertNotification> alert =
- do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
- NS_ENSURE_TRUE(alert, NS_ERROR_FAILURE);
- // vibrate is unused for now
- nsTArray<uint32_t> vibrate;
- nsresult rv = alert->Init(aAlertName, aImageUrl, aAlertTitle, aAlertText,
- aAlertTextClickable, aAlertCookie, aBidi, aLang,
- aData, aPrincipal, aInPrivateBrowsing,
- aRequireInteraction, false, vibrate);
- NS_ENSURE_SUCCESS(rv, rv);
- return ShowAlert(alert, aAlertListener);
-}
-
-NS_IMETHODIMP
OSXNotificationCenter::ShowAlert(nsIAlertNotification* aAlert,
nsIObserver* aAlertListener) {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
diff --git a/widget/windows/ToastNotification.cpp b/widget/windows/ToastNotification.cpp
@@ -360,31 +360,6 @@ NS_IMETHODIMP ToastNotification::PbmTeardown() {
}
NS_IMETHODIMP
-ToastNotification::ShowAlertNotification(
- const nsAString& aImageUrl, const nsAString& aAlertTitle,
- const nsAString& aAlertText, bool aAlertTextClickable,
- const nsAString& aAlertCookie, nsIObserver* aAlertListener,
- const nsAString& aAlertName, const nsAString& aBidi, const nsAString& aLang,
- const nsAString& aData, nsIPrincipal* aPrincipal, bool aInPrivateBrowsing,
- bool aRequireInteraction) {
- nsCOMPtr<nsIAlertNotification> alert =
- do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
- if (NS_WARN_IF(!alert)) {
- return NS_ERROR_FAILURE;
- }
- // vibrate is unused for now
- nsTArray<uint32_t> vibrate;
- nsresult rv = alert->Init(aAlertName, aImageUrl, aAlertTitle, aAlertText,
- aAlertTextClickable, aAlertCookie, aBidi, aLang,
- aData, aPrincipal, aInPrivateBrowsing,
- aRequireInteraction, false, vibrate);
- if (NS_WARN_IF(NS_FAILED(rv))) {
- return rv;
- }
- return ShowAlert(alert, aAlertListener);
-}
-
-NS_IMETHODIMP
ToastNotification::SetManualDoNotDisturb(bool aDoNotDisturb) {
return NS_ERROR_NOT_IMPLEMENTED;
}