commit d5e3e7cab7cee84970878a7f131a9bd73f721b45 parent 4d376753552c7e2c7d1ee63a9a258c633420afe0 Author: agoloman <agoloman@mozilla.com> Date: Sat, 29 Nov 2025 15:45:29 +0200 Revert "Bug 1369833 - Part 5: Remove showAlertNotification r=nalexander,nrishel,geckoview-reviewers,win-reviewers,gstoll" for causing bc failures @browser_device_connected.js. This reverts commit 446248523d95999f658d8571493e3be0abfe5597. Revert "Bug 1369833 - Part 4: Use initWithObject instead of showAlertNotification in browser/ r=firefox-desktop-core-reviewers ,Gijs" This reverts commit 9ee3a6db7fb64d4afdb092275ae5646611ab48fd. Revert "Bug 1369833 - Part 3: Remove unused showAlertNotification in dom/notification/test r=asuth" This reverts commit 153cd95271ed3f17e6a870ed93565ab5aa582178. Revert "Bug 1369833 - Part 2: Use initWithObject instead of showAlertNotification for WebExtensions r=extension-reviewers,willdurand" This reverts commit e36669b3f824da899ed6a3e580935797a9635021. Revert "Bug 1369833 - Part 1: Add a way to init with an object r=nalexander,tschuster" This reverts commit 5e7addaf7736fda3c69e983078e530904104833d. Diffstat:
22 files changed, 274 insertions(+), 176 deletions(-)
diff --git a/browser/components/AccountsGlue.sys.mjs b/browser/components/AccountsGlue.sys.mjs @@ -37,12 +37,6 @@ 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. @@ -133,12 +127,14 @@ export const AccountsGlue = { } this._openPreferences("sync"); }; - let alert = new AlertNotification({ + lazy.AlertsService.showAlertNotification( + null, title, - text: body, - textClickable: true, - }); - lazy.AlertsService.showAlert(alert, clickCallback); + body, + true, + null, + clickCallback + ); }, _openURLInNewWindow(url) { @@ -255,13 +251,14 @@ export const AccountsGlue = { if (AppConstants.platform == "win") { imageURL = "chrome://branding/content/icon64.png"; } - let alert = new AlertNotification({ + lazy.AlertsService.showAlertNotification( imageURL, title, - text: body, - textClickable: true, - }); - lazy.AlertsService.showAlert(alert, clickCallback); + body, + true, + null, + clickCallback + ); } catch (ex) { console.error("Error displaying tab(s) received by Sync: ", ex); } @@ -346,14 +343,15 @@ export const AccountsGlue = { ]); try { - let alert = new AlertNotification({ + lazy.AlertsService.showAlertNotification( imageURL, title, - text: body, - textClickable: true, - name: "closed-tab-notification", - }); - lazy.AlertsService.showAlert(alert, clickCallback); + body, + true, + null, + clickCallback, + "closed-tab-notification" + ); } catch (ex) { console.error("Error notifying user of closed tab(s) ", ex); } @@ -382,13 +380,14 @@ export const AccountsGlue = { }; try { - let alert = new AlertNotification({ + lazy.AlertsService.showAlertNotification( imageURL, title, body, - textClickable: true, - }); - lazy.AlertsService.showAlert(alert, clickCallback); + true, + null, + clickCallback + ); } catch (ex) { console.error("Error notifying of a verify login event: ", ex); } @@ -418,12 +417,14 @@ export const AccountsGlue = { }; try { - let alert = new AlertNotification({ + lazy.AlertsService.showAlertNotification( + null, title, - text: body, - textClickable: true, - }); - lazy.AlertsService.showAlert(alert, clickCallback); + body, + true, + null, + clickCallback + ); } catch (ex) { console.error("Error notifying of a new Sync device: ", ex); } @@ -441,13 +442,14 @@ export const AccountsGlue = { } this._openPreferences("sync"); }; - - let alert = new AlertNotification({ + lazy.AlertsService.showAlertNotification( + null, title, - text: body, - textClickable: true, - }); - lazy.AlertsService.showAlert(alert, clickCallback); + body, + true, + null, + clickCallback + ); }, _updateFxaBadges(win) { diff --git a/browser/components/screenshots/ScreenshotsUtils.sys.mjs b/browser/components/screenshots/ScreenshotsUtils.sys.mjs @@ -52,12 +52,6 @@ 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. @@ -990,9 +984,7 @@ export var ScreenshotsUtils = { }, showAlertMessage(title, message) { - lazy.AlertsService.showAlert( - new AlertNotification({ title, text: message }) - ); + lazy.AlertsService.showAlertNotification(null, title, message); }, /** diff --git a/browser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs b/browser/extensions/newtab/lib/Widgets/TimerFeed.sys.mjs @@ -22,12 +22,6 @@ 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 @@ -55,12 +49,14 @@ export class TimerFeed { Ci.nsIAlertsService ); - alertsService.showAlert( - new AlertNotification({ - imageURL: "chrome://branding/content/icon64.png", - title, - text: body, - }) + // TODO: Add more readable args as defined in toolkit/components/alerts/nsIAlertsService.idl + alertsService.showAlertNotification( + "chrome://branding/content/icon64.png", + title, + body, + false, + "", + null ); } catch (err) { console.error("Failed to show system notification", err); diff --git a/dom/notification/test/chrome/test_notification_system_principal.xhtml b/dom/notification/test/chrome/test_notification_system_principal.xhtml @@ -30,6 +30,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=874090 SimpleTest.finish(); }, + showAlertNotification() { + this.showAlert(); + }, + QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]), createInstance(aIID) { diff --git a/dom/notification/test/mochitest/MockAlertsService.js b/dom/notification/test/mochitest/MockAlertsService.js @@ -51,6 +51,25 @@ function mockServicesChromeScript() { } }, + showAlertNotification( + imageUrl, + title, + text, + textClickable, + cookie, + alertListener, + name + ) { + this.showAlert( + { + name, + cookie, + title, + }, + alertListener + ); + }, + closeAlert(name) { let alertNotification = activeNotifications[name]; if (alertNotification) { diff --git a/dom/notification/test/mochitest/test_notification_tag.html b/dom/notification/test/mochitest/test_notification_tag.html @@ -84,6 +84,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=782211 } }, + showAlertNotification( + imageUrl, + title, + text, + textClickable, + cookie, + alertListener, + name + ) { + this.showAlert({ name }); + }, + QueryInterface(aIID) { if (aIID.equals(Ci.nsISupports) || aIID.equals(Ci.nsIAlertsService)) { return this; diff --git a/toolkit/components/alerts/AlertNotification.cpp b/toolkit/components/alerts/AlertNotification.cpp @@ -22,6 +22,11 @@ namespace mozilla { NS_IMPL_ISUPPORTS(AlertNotification, nsIAlertNotification) +AlertNotification::AlertNotification() + : mTextClickable(false), mInPrivateBrowsing(false) {} + +AlertNotification::~AlertNotification() = default; + NS_IMETHODIMP AlertNotification::Init(const nsAString& aName, const nsAString& aImageURL, const nsAString& aTitle, const nsAString& aText, @@ -52,36 +57,6 @@ AlertNotification::Init(const nsAString& aName, const nsAString& aImageURL, return InitId(); } -NS_IMETHODIMP -AlertNotification::InitWithObject(nsIAlertNotification* aAlertNotification) { - MOZ_TRY(aAlertNotification->GetName(mName)); - MOZ_TRY(aAlertNotification->GetImageURL(mImageURL)); - MOZ_TRY(aAlertNotification->GetTitle(mTitle)); - MOZ_TRY(aAlertNotification->GetText(mText)); - MOZ_TRY(aAlertNotification->GetTextClickable(&mTextClickable)); - MOZ_TRY(aAlertNotification->GetCookie(mCookie)); - MOZ_TRY(aAlertNotification->GetDir(mDir)); - MOZ_TRY(aAlertNotification->GetLang(mLang)); - MOZ_TRY(aAlertNotification->GetData(mData)); - MOZ_TRY(aAlertNotification->GetPrincipal(getter_AddRefs(mPrincipal))); - MOZ_TRY(aAlertNotification->GetInPrivateBrowsing(&mInPrivateBrowsing)); - MOZ_TRY(aAlertNotification->GetRequireInteraction(&mRequireInteraction)); - MOZ_TRY(aAlertNotification->GetSilent(&mSilent)); - if (NS_FAILED(aAlertNotification->GetVibrate(mVibrate))) { - mVibrate.Clear(); - }; - nsTArray<RefPtr<nsIAlertAction>> actions; - if (NS_SUCCEEDED(aAlertNotification->GetActions(actions))) { - for (auto& action : actions) { - if (RefPtr<nsIAlertAction> copied = - AlertAction::Copy(*action).unwrapOr(nullptr)) { - mActions.AppendElement(copied); - } - } - }; - return InitId(); -} - nsresult AlertNotification::InitId() { nsAutoString id; @@ -489,15 +464,6 @@ NS_IMPL_ISUPPORTS(AlertAction, nsIAlertAction) AlertAction::AlertAction(const nsAString& aAction, const nsAString& aTitle) : mAction(aAction), mTitle(aTitle) {} -Result<already_AddRefed<AlertAction>, nsresult> AlertAction::Copy( - nsIAlertAction& aAction) { - nsAutoString action; - nsAutoString title; - MOZ_TRY(aAction.GetAction(action)); - MOZ_TRY(aAction.GetTitle(title)); - return do_AddRef(new AlertAction(action, title)); -} - NS_IMETHODIMP AlertAction::GetAction(nsAString& aAction) { aAction = mAction; diff --git a/toolkit/components/alerts/AlertNotification.h b/toolkit/components/alerts/AlertNotification.h @@ -57,9 +57,10 @@ class AlertNotification : public nsIAlertNotification { public: NS_DECL_ISUPPORTS NS_DECL_NSIALERTNOTIFICATION + AlertNotification(); protected: - virtual ~AlertNotification() = default; + virtual ~AlertNotification(); private: nsresult InitId(); @@ -69,15 +70,15 @@ class AlertNotification : public nsIAlertNotification { nsString mImageURL; nsString mTitle; nsString mText; - bool mTextClickable = false; + bool mTextClickable; nsString mCookie; nsString mDir; nsString mLang; - bool mRequireInteraction = false; + bool mRequireInteraction; nsString mData; nsCOMPtr<nsIPrincipal> mPrincipal; - bool mInPrivateBrowsing = false; - bool mSilent = false; + bool mInPrivateBrowsing; + bool mSilent; nsTArray<uint32_t> mVibrate; nsTArray<RefPtr<nsIAlertAction>> mActions; nsString mOpaqueRelaunchData; @@ -88,8 +89,6 @@ class AlertAction : public nsIAlertAction { NS_DECL_NSIALERTACTION AlertAction(const nsAString& aAction, const nsAString& aTitle); - static Result<already_AddRefed<AlertAction>, nsresult> Copy( - nsIAlertAction& aAction); protected: virtual ~AlertAction() = default; diff --git a/toolkit/components/alerts/nsAlertsService.cpp b/toolkit/components/alerts/nsAlertsService.cpp @@ -82,6 +82,26 @@ 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 @@ -106,12 +106,6 @@ interface nsIAlertNotification : nsISupports [optional] in Array<uint32_t> aVibrate); /** - * Initializes an alert notification with another instance. - * Can be useful in JS as it can provide a dictionary object. - */ - void initWithObject(in nsIAlertNotification aAlertNotification); - - /** * The unique ID of the notification, based on the profile path and the caller * given name. * @@ -272,11 +266,12 @@ 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 aAlert The alert notification to show. - * @param aAlertListener Used for callbacks. May be omitted if the caller + * @param aAlertListener Used for callbacks. May be null 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. @@ -296,8 +291,19 @@ interface nsIAlertsService : nsISupports * In that case, if an alert listener is passed in it will receive the * "alertfinished" notification immediately. */ - void showAlert(in nsIAlertNotification aAlert, - [optional] in nsIObserver aAlertListener); + 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); /** * Close alerts created by the service. diff --git a/toolkit/components/alerts/nsXULAlerts.cpp b/toolkit/components/alerts/nsXULAlerts.cpp @@ -90,6 +90,27 @@ 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,11 +20,6 @@ <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 */ @@ -77,10 +72,8 @@ async function runTest() { if (notifier) { try { - notifier.showAlert(new AlertNotification({ - title: "Notification test", - body: "This notification has no observer" - })); + notifier.showAlertNotification(null, "Notification test", + "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,11 +10,6 @@ <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 */ @@ -57,16 +52,9 @@ function promiseCreateXULAlert(alertService, listener, name) { }); chromeScript.sendAsyncMessage("waitForXULAlert"); - - let alert = new AlertNotification({ - title: "title", - text: "body", - textClickable: true, - cookie: cookie++, - name, - requireInteraction: true - }); - alertService.showAlert(alert, listener); + alertService.showAlertNotification(null, "title", "body", + true, cookie++, listener, name, null, null, null, + null, false, true); }); } diff --git a/toolkit/components/alerts/test/chrome/test_multiple_alerts.html b/toolkit/components/alerts/test/chrome/test_multiple_alerts.html @@ -10,11 +10,6 @@ <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 */ @@ -65,7 +60,7 @@ function promiseAlertPosition(alertService) { }); chromeScript.sendAsyncMessage("waitForPosition"); - alertService.showAlert(new AlertNotification({ title: "title", text: "body" })); + alertService.showAlertNotification(null, "title", "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,11 +15,6 @@ 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); @@ -55,14 +50,10 @@ function notify(alertName, principal) { resolve(source); } } - let alert = new AlertNotification({ - title: "Notification test", - body: "Surprise! I'm here to test notifications!", - cookie: alertName, - name: alertName, - principal - }); - notifier.showAlert(alert, observe); + notifier.showAlertNotification(null, "Notification test", + "Surprise! I'm here to test notifications!", + false, alertName, observe, alertName, + null, null, null, principal); if (SpecialPowers.Services.appinfo.OS == "Darwin") { notifier.closeAlert(alertName); } diff --git a/toolkit/components/extensions/parent/ext-notifications.js b/toolkit/components/extensions/parent/ext-notifications.js @@ -10,12 +10,6 @@ ChromeUtils.defineESModuleGetters(ToolkitModules, { EventEmitter: "resource://gre/modules/EventEmitter.sys.mjs", }); -const AlertNotification = Components.Constructor( - "@mozilla.org/alert-notification;1", - "nsIAlertNotification", - "initWithObject" -); - var { ignoreEvent } = ExtensionCommon; // Manages a notification popup (notifications API) created by the extension. @@ -37,19 +31,23 @@ function Notification(context, notificationsMap, id, options) { let svc = Cc["@mozilla.org/alerts-service;1"].getService( Ci.nsIAlertsService ); - // Principal is not set because doing so reveals buttons to control - // notification preferences, which are currently not implemented for - // notifications triggered via this extension API (bug 1589693). - let alert = new AlertNotification({ + svc.showAlertNotification( imageURL, - title: options.title, - text: options.message, - textClickable: true, - cookie: this.id, - name: this.id, - inPrivateBrowsing: context.incognito, - }); - svc.showAlert(alert, this); + options.title, + options.message, + true, // textClickable + this.id, + this, + this.id, + undefined, + undefined, + undefined, + // Principal is not set because doing so reveals buttons to control + // notification preferences, which are currently not implemented for + // notifications triggered via this extension API (bug 1589693). + undefined, + context.incognito + ); } catch (e) { // This will fail if alerts aren't available on the system. diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_notifications_incognito.js b/toolkit/components/extensions/test/xpcshell/test_ext_notifications_incognito.js @@ -12,6 +12,23 @@ const mockAlertsService = { listener.observe(null, "alertfinished", alert.cookie); }, + showAlertNotification( + imageUrl, + title, + text, + textClickable, + cookie, + alertListener, + name, + dir, + lang, + data, + principal, + privateBrowsing + ) { + this.showAlert({ cookie, title, text, privateBrowsing }, alertListener); + }, + closeAlert() { // This mock immediately close the alert on show, so this is empty. }, @@ -74,7 +91,7 @@ add_task(async function test_notification_privateBrowsing_flag() { Assert.equal(notification.cookie, "notifid", "notification id"); Assert.equal(notification.title, "titl", "notification title"); Assert.equal(notification.text, "msg", "notification text"); - Assert.equal(notification.inPrivateBrowsing, privateBrowsing, "pbm flag"); + Assert.equal(notification.privateBrowsing, privateBrowsing, "pbm flag"); } await checkPrivateBrowsingFlag(false); diff --git a/toolkit/system/gnome/nsSystemAlertsService.cpp b/toolkit/system/gnome/nsSystemAlertsService.cpp @@ -22,6 +22,26 @@ 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,6 +836,7 @@ 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,6 +35,18 @@ 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,6 +162,27 @@ 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,6 +360,31 @@ 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; }