commit 305692f252362953a599a70efaabaf38d2788dd0 parent e9c5c6ef4e550f002e2c5e8407c572ae7981dcda Author: Kagami Sascha Rosylight <krosylight@proton.me> Date: Sat, 29 Nov 2025 18:32:23 +0000 Bug 1369833 - Part 5: Remove showAlertNotification r=nalexander,nrishel,geckoview-reviewers,win-reviewers,gstoll Differential Revision: https://phabricator.services.mozilla.com/D273575 Diffstat:
14 files changed, 66 insertions(+), 163 deletions(-)
diff --git a/services/fxaccounts/tests/browser/head.js b/services/fxaccounts/tests/browser/head.js @@ -45,21 +45,14 @@ function waitForDocLoadComplete(aBrowser = gBrowser) { function setupMockAlertsService(expectedObj) { const alertsService = { - showAlertNotification: ( - image, - title, - body, - clickable, - cookie, - clickCallback - ) => { + showAlert: (alert, clickCallback) => { // We need to invoke the event handler ourselves. clickCallback(null, "alertshow", null); // check the expectations, if passed in if (expectedObj) { - expectedObj.title && Assert.equal(title, expectedObj.title); - expectedObj.body && Assert.equal(body, expectedObj.body); + expectedObj.title && Assert.equal(alert.title, expectedObj.title); + expectedObj.body && Assert.equal(alert.text, expectedObj.body); } // We are invoking the event handler ourselves directly. 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. @@ -290,26 +289,15 @@ interface nsIAlertsService : nsISupports * "alertsettingscallback" when alert settings should be opened * "alertclickcallback" when the text is clicked * "alertshow" when the alert is shown - * data - the value of the cookie parameter passed to showAlertNotification. + * data - the value of the cookie attribute of the alert parameter. * * @note Depending on current circumstances (if the user's in a fullscreen * application, for instance), the alert might not be displayed at all. * 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.html b/toolkit/components/alerts/test/chrome/test_alerts.html @@ -50,6 +50,11 @@ var observer = { function runTest() { const Cc = SpecialPowers.Cc; const Ci = SpecialPowers.Ci; + const AlertNotification = Components.Constructor( + "@mozilla.org/alert-notification;1", + "nsIAlertNotification", + "initWithObject" + ); if (!("@mozilla.org/alerts-service;1" in Cc)) { todo(false, "Alerts service does not exist in this application"); @@ -70,11 +75,15 @@ function runTest() { try { SimpleTest.waitForExplicitFinish(); - notifier.showAlertNotification(null, "Notification test", - "Surprise! I'm here to test notifications!", - false, "foobarcookie", observer, alertName); + let alert = new AlertNotification({ + title: "Notification test", + text: "Surprise! I'm here to test notifications!", + cookie: "foobarcookie", + name: alertName, + }); + notifier.showAlert(alert, observer); } catch (ex) { - todo(false, "showAlertNotification() failed.", ex); + todo(false, "showAlert() failed.", ex); SimpleTest.finish(); } } 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,12 +77,14 @@ async function runTest() { if (notifier) { try { - notifier.showAlertNotification(null, "Notification test", - "This notification has no observer"); + notifier.showAlert(new AlertNotification({ + title: "Notification test", + text: "This notification has no observer" + })); notifier.closeAlert(); - ok(true, "showAlertNotification() succeeded"); + ok(true, "showAlert() succeeded"); } catch (ex) { - todo(false, "showAlertNotification() failed.", ex); + todo(false, "showAlert() failed.", 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", + text: "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; }