tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e36669b3f824da899ed6a3e580935797a9635021
parent 5e7addaf7736fda3c69e983078e530904104833d
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date:   Sat, 29 Nov 2025 11:01:36 +0000

Bug 1369833 - Part 2: Use initWithObject instead of showAlertNotification for WebExtensions r=extension-reviewers,willdurand

Differential Revision: https://phabricator.services.mozilla.com/D273193

Diffstat:
Mtoolkit/components/extensions/parent/ext-notifications.js | 34++++++++++++++++++----------------
Mtoolkit/components/extensions/test/xpcshell/test_ext_notifications_incognito.js | 19+------------------
2 files changed, 19 insertions(+), 34 deletions(-)

diff --git a/toolkit/components/extensions/parent/ext-notifications.js b/toolkit/components/extensions/parent/ext-notifications.js @@ -10,6 +10,12 @@ 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. @@ -31,23 +37,19 @@ function Notification(context, notificationsMap, id, options) { let svc = Cc["@mozilla.org/alerts-service;1"].getService( Ci.nsIAlertsService ); - svc.showAlertNotification( + // 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({ imageURL, - 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 - ); + title: options.title, + text: options.message, + textClickable: true, + cookie: this.id, + name: this.id, + inPrivateBrowsing: context.incognito, + }); + svc.showAlert(alert, this); } 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,23 +12,6 @@ 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. }, @@ -91,7 +74,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.privateBrowsing, privateBrowsing, "pbm flag"); + Assert.equal(notification.inPrivateBrowsing, privateBrowsing, "pbm flag"); } await checkPrivateBrowsingFlag(false);