diff --git a/browser/actors/DecoderDoctorParent.jsm b/browser/actors/DecoderDoctorParent.jsm index 6f88e4a89bcd..748623c5ad9f 100644 --- a/browser/actors/DecoderDoctorParent.jsm +++ b/browser/actors/DecoderDoctorParent.jsm @@ -254,10 +254,12 @@ class DecoderDoctorParent extends JSWindowActorParent { } box.appendNotification( - title, notificationId, - "", // This uses the info icon as specified below. - box.PRIORITY_INFO_LOW, + { + label: title, + image: "", // This uses the info icon as specified below. + priority: box.PRIORITY_INFO_LOW, + }, buttons ); } else if (formatsInPref) { diff --git a/browser/actors/EncryptedMediaParent.jsm b/browser/actors/EncryptedMediaParent.jsm index 0fff044ff3c5..1349ca1ad2c8 100644 --- a/browser/actors/EncryptedMediaParent.jsm +++ b/browser/actors/EncryptedMediaParent.jsm @@ -170,10 +170,12 @@ class EncryptedMediaParent extends JSWindowActorParent { let iconURL = "chrome://browser/skin/drm-icon.svg"; notificationBox.appendNotification( - notificationMessage, notificationId, - iconURL, - notificationBox.PRIORITY_INFO_HIGH, + { + label: notificationMessage, + image: iconURL, + priority: notificationBox.PRIORITY_INFO_HIGH, + }, buttons ); } diff --git a/browser/actors/PluginParent.jsm b/browser/actors/PluginParent.jsm index 396d32d174bf..501d8b58b960 100644 --- a/browser/actors/PluginParent.jsm +++ b/browser/actors/PluginParent.jsm @@ -189,10 +189,12 @@ class PluginParent extends JSWindowActorParent { [report.pluginName] ); notification = notificationBox.appendNotification( - messageString, "plugin-crashed", - iconURL, - priority, + { + label: messageString, + image: iconURL, + priority, + }, buttons ); diff --git a/browser/base/content/browser-captivePortal.js b/browser/base/content/browser-captivePortal.js index ea8222875754..42221d1e66ac 100644 --- a/browser/base/content/browser-captivePortal.js +++ b/browser/base/content/browser-captivePortal.js @@ -317,12 +317,13 @@ var CaptivePortalWatcher = { }; gNotificationBox.appendNotification( - message, this.PORTAL_NOTIFICATION_VALUE, - "", - gNotificationBox.PRIORITY_INFO_MEDIUM, - buttons, - closeHandler + { + label: message, + priority: gNotificationBox.PRIORITY_INFO_MEDIUM, + eventCallback: closeHandler, + }, + buttons ); Services.telemetry.recordEvent( diff --git a/browser/base/content/browser-data-submission-info-bar.js b/browser/base/content/browser-data-submission-info-bar.js index e94a0ef546db..c434e937c8fe 100644 --- a/browser/base/content/browser-data-submission-info-bar.js +++ b/browser/base/content/browser-data-submission-info-bar.js @@ -72,19 +72,20 @@ var gDataNotificationInfoBar = { this._log.info("Creating data reporting policy notification."); gNotificationBox.appendNotification( - message, this._DATA_REPORTING_NOTIFICATION, - null, - gNotificationBox.PRIORITY_INFO_HIGH, - buttons, - event => { - if (event == "removed") { - Services.obs.notifyObservers( - null, - "datareporting:notify-data-policy:close" - ); - } - } + { + label: message, + priority: gNotificationBox.PRIORITY_INFO_HIGH, + eventCallback: event => { + if (event == "removed") { + Services.obs.notifyObservers( + null, + "datareporting:notify-data-policy:close" + ); + } + }, + }, + buttons ); // It is important to defer calling onUserNotifyComplete() until we're // actually sure the notification was displayed. If we ever called diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 9aec1c9015be..6df6584a8f9e 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -972,10 +972,11 @@ const gStoragePressureObserver = { messageFragment.appendChild(message); gNotificationBox.appendNotification( - messageFragment, NOTIFICATION_VALUE, - null, - gNotificationBox.PRIORITY_WARNING_HIGH, + { + label: messageFragment, + priority: gNotificationBox.PRIORITY_WARNING_HIGH, + }, buttons ); @@ -1056,10 +1057,12 @@ var gPopupBlockerObserver = { const priority = notificationBox.PRIORITY_INFO_MEDIUM; notificationBox.appendNotification( - message, "popup-blocked", - "chrome://browser/skin/notification-icons/popup.svg", - priority, + { + label: message, + image: "chrome://browser/skin/notification-icons/popup.svg", + priority, + }, buttons ); } @@ -1370,10 +1373,11 @@ var gKeywordURIFixup = { }, ]; let notification = notificationBox.appendNotification( - message, "keyword-uri-fixup", - null, - notificationBox.PRIORITY_INFO_HIGH, + { + label: message, + priority: notificationBox.PRIORITY_INFO_HIGH, + }, buttons ); notification.persistence = 1; @@ -9074,10 +9078,12 @@ const SafeBrowsingNotificationBox = { } let notification = notificationBox.appendNotification( - title, value, - "chrome://global/skin/icons/blocked.svg", - notificationBox.PRIORITY_CRITICAL_HIGH, + { + label: title, + image: "chrome://global/skin/icons/blocked.svg", + priority: notificationBox.PRIORITY_CRITICAL_HIGH, + }, buttons ); // Persist the notification until the user removes so it diff --git a/browser/base/content/tabbrowser.js b/browser/base/content/tabbrowser.js index 47ce5470c1b2..4252c922ba2b 100644 --- a/browser/base/content/tabbrowser.js +++ b/browser/base/content/tabbrowser.js @@ -5528,10 +5528,12 @@ ]; notificationBox.appendNotification( - message, "refresh-blocked", - "chrome://browser/skin/notification-icons/popup.svg", - notificationBox.PRIORITY_INFO_MEDIUM, + { + label: message, + image: "chrome://browser/skin/notification-icons/popup.svg", + priority: notificationBox.PRIORITY_INFO_MEDIUM, + }, buttons ); } diff --git a/browser/base/content/test/notificationbox/browser_notification_stacking.js b/browser/base/content/test/notificationbox/browser_notification_stacking.js index 0d6e43ab0bba..bd8817ea4b9b 100644 --- a/browser/base/content/test/notificationbox/browser_notification_stacking.js +++ b/browser/base/content/test/notificationbox/browser_notification_stacking.js @@ -6,7 +6,7 @@ async function addNotification(box, label, value, priorityName) { let added = BrowserTestUtils.waitForNotificationInNotificationBox(box, value); let priority = gNotificationBox[`PRIORITY_${priorityName}_MEDIUM`]; - let notification = box.appendNotification(label, value, null, priority); + let notification = box.appendNotification(value, { label, priority }); await added; return notification; } diff --git a/browser/base/content/test/notificationbox/browser_tabnotificationbox_switch_tabs.js b/browser/base/content/test/notificationbox/browser_tabnotificationbox_switch_tabs.js index 3a571e395193..f00916c77357 100644 --- a/browser/base/content/test/notificationbox/browser_tabnotificationbox_switch_tabs.js +++ b/browser/base/content/test/notificationbox/browser_tabnotificationbox_switch_tabs.js @@ -34,13 +34,10 @@ function assertNotificationBoxShown(reason, browser) { function createNotification({ browser, label, value, priority }) { let notificationBox = gBrowser.getNotificationBox(browser); - let notification = notificationBox.appendNotification( + let notification = notificationBox.appendNotification(value, { label, - value, - null, - notificationBox[priority], - [] - ); + priority: notificationBox[priority], + }); return notification; } diff --git a/browser/components/BrowserGlue.jsm b/browser/components/BrowserGlue.jsm index 953611c014b1..f82a4f7f4fc0 100644 --- a/browser/components/BrowserGlue.jsm +++ b/browser/components/BrowserGlue.jsm @@ -1565,10 +1565,12 @@ BrowserGlue.prototype = { ]; win.gNotificationBox.appendNotification( - message, "reset-profile-notification", - "chrome://global/skin/icons/help.svg", - win.gNotificationBox.PRIORITY_INFO_LOW, + { + label: message, + image: "chrome://global/skin/icons/question-64.png", + priority: win.gNotificationBox.PRIORITY_INFO_LOW, + }, buttons ); }, @@ -1597,10 +1599,11 @@ BrowserGlue.prototype = { ]; win.gNotificationBox.appendNotification( - message, "unsigned-addons-disabled", - "", - win.gNotificationBox.PRIORITY_WARNING_MEDIUM, + { + label: message, + priority: win.gNotificationBox.PRIORITY_WARNING_MEDIUM, + }, buttons ); }, @@ -3255,7 +3258,6 @@ BrowserGlue.prototype = { var placesBundle = Services.strings.createBundle( "chrome://browser/locale/places/places.properties" ); - var title = placesBundle.GetStringFromName("lockPrompt.title"); var text = placesBundle.formatStringFromName("lockPrompt.text", [ applicationName, ]); @@ -3265,10 +3267,11 @@ BrowserGlue.prototype = { var notifyBox = win.gBrowser.getNotificationBox(); var notification = notifyBox.appendNotification( - text, - title, - null, - notifyBox.PRIORITY_CRITICAL_MEDIUM, + "places-locked", + { + label: text, + priority: win.gNotificationBox.PRIORITY_CRITICAL_MEDIUM, + }, buttons ); notification.persistence = -1; // Until user closes it @@ -4315,10 +4318,11 @@ BrowserGlue.prototype = { // XXXndeakin is this notification still relevant? win.gNotificationBox.appendNotification( - message, "flash-hang", - null, - win.gNotificationBox.PRIORITY_INFO_MEDIUM, + { + label: message, + priority: win.gNotificationBox.PRIORITY_INFO_MEDIUM, + }, buttons ); }, diff --git a/browser/components/aboutlogins/AboutLoginsParent.jsm b/browser/components/aboutlogins/AboutLoginsParent.jsm index db0b55d26abc..267693f4fd33 100644 --- a/browser/components/aboutlogins/AboutLoginsParent.jsm +++ b/browser/components/aboutlogins/AboutLoginsParent.jsm @@ -691,10 +691,12 @@ var AboutLogins = { } notification = notificationBox.appendNotification( - messageFragment, id, - iconURL, - notificationBox[priority], + { + label: messageFragment, + image: iconURL, + priority: notificationBox[priority], + }, buttons ); } diff --git a/browser/components/newtab/lib/InfoBar.jsm b/browser/components/newtab/lib/InfoBar.jsm index c67f64cdee95..dc798edb6675 100644 --- a/browser/components/newtab/lib/InfoBar.jsm +++ b/browser/components/newtab/lib/InfoBar.jsm @@ -53,12 +53,14 @@ class InfoBarNotification { : notificationContainer.PRIORITY_INFO_MEDIUM); this.notification = notificationContainer.appendNotification( - this.formatMessageConfig(doc, content.text), this.message.id, - content.icon || "chrome://branding/content/icon64.png", - priority, - content.buttons.map(b => this.formatButtonConfig(b)), - this.infobarCallback + { + label: this.formatMessageConfig(doc, content.text), + image: content.icon || "chrome://branding/content/icon64.png", + priority, + eventCallback: this.infobarCallback, + }, + content.buttons.map(b => this.formatButtonConfig(b)) ); this.addImpression(); diff --git a/browser/components/protocolhandler/WebProtocolHandlerRegistrar.jsm b/browser/components/protocolhandler/WebProtocolHandlerRegistrar.jsm index 6e71bd91f9cd..6cda756059bf 100644 --- a/browser/components/protocolhandler/WebProtocolHandlerRegistrar.jsm +++ b/browser/components/protocolhandler/WebProtocolHandlerRegistrar.jsm @@ -164,10 +164,12 @@ WebProtocolHandlerRegistrar.prototype = { }; let notificationBox = browser.getTabBrowser().getNotificationBox(browser); notificationBox.appendNotification( - message, notificationValue, - notificationIcon, - notificationBox.PRIORITY_INFO_LOW, + { + label: message, + image: notificationIcon, + priority: notificationBox.PRIORITY_INFO_LOW, + }, [addButton] ); }, diff --git a/browser/components/translation/TranslationParent.jsm b/browser/components/translation/TranslationParent.jsm index a87a4a512725..9cd082ff356c 100644 --- a/browser/components/translation/TranslationParent.jsm +++ b/browser/components/translation/TranslationParent.jsm @@ -302,15 +302,10 @@ class TranslationParent extends JSWindowActorParent { showTranslationInfoBar() { let notificationBox = this.notificationBox; - let notif = notificationBox.appendNotification( - "", - "translation", - null, - notificationBox.PRIORITY_INFO_HIGH, - null, - null, - "translation-notification" - ); + let notif = notificationBox.appendNotification("translation", { + priority: notificationBox.PRIORITY_INFO_HIGH, + notificationIs: "translation-notification", + }); notif.init(this); return notif; } diff --git a/browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js b/browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js index a0d421559e85..2d11a239c0f7 100644 --- a/browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js +++ b/browser/components/urlbar/tests/browser-tips/browser_searchTips_interaction.js @@ -478,15 +478,10 @@ add_task(async function pickingTipDoesNotDisableOtherKinds() { add_task(async function notification() { await BrowserTestUtils.withNewTab("about:blank", async () => { let box = gBrowser.getNotificationBox(); - let note = box.appendNotification( - "Test", - "urlbar-test", - null, - box.PRIORITY_INFO_HIGH, - null, - null, - null - ); + let note = box.appendNotification("urlbar-test", { + label: "Test", + priority: box.PRIORITY_INFO_HIGH, + }); // Give it a big persistence so it doesn't go away on page load. note.persistence = 100; await withDNSRedirect("www.google.com", "/", async url => { diff --git a/browser/extensions/translations/extension/experiment-apis/translateUi/TranslationBrowserChromeUi.js b/browser/extensions/translations/extension/experiment-apis/translateUi/TranslationBrowserChromeUi.js index 9ddec7b42288..6a98841bfaf6 100644 --- a/browser/extensions/translations/extension/experiment-apis/translateUi/TranslationBrowserChromeUi.js +++ b/browser/extensions/translations/extension/experiment-apis/translateUi/TranslationBrowserChromeUi.js @@ -303,13 +303,12 @@ class TranslationBrowserChromeUi { const notificationBox = this.notificationBox; const chromeWin = this.browser.ownerGlobal; const notif = notificationBox.appendNotification( - "", "translation", - null, - notificationBox.PRIORITY_INFO_HIGH, - null, - null, - `translation-notification-${chromeWin.now}`, + { + label: "", + priority: notificationBox.PRIORITY_INFO_HIGH, + is: `translation-notification-${chromeWin.now}`, + } ); notif.init(this.translationBrowserChromeUiNotificationManager); this.translationBrowserChromeUiNotificationManager.infobarDisplayed( diff --git a/browser/locales/en-US/chrome/browser/places/places.properties b/browser/locales/en-US/chrome/browser/places/places.properties index 74f20bb5c9cb..518cffa9d3bc 100644 --- a/browser/locales/en-US/chrome/browser/places/places.properties +++ b/browser/locales/en-US/chrome/browser/places/places.properties @@ -52,7 +52,6 @@ detailsPane.itemsCountLabel=One item;#1 items # LOCALIZATION NOTE (lockPrompt.text) # %S will be replaced with the application name. -lockPrompt.title=Browser Startup Error lockPrompt.text=The bookmarks and history system will not be functional because one of %S’s files is in use by another application. Some security software can cause this problem. # LOCALIZATION NOTE (cmd.deleteSinglePage.accesskey, diff --git a/browser/modules/ContentCrashHandlers.jsm b/browser/modules/ContentCrashHandlers.jsm index eccbe509b38e..ca2d6dd41908 100644 --- a/browser/modules/ContentCrashHandlers.jsm +++ b/browser/modules/ContentCrashHandlers.jsm @@ -433,35 +433,37 @@ var TabCrashHandler = { ); notification = notificationBox.appendNotification( - messageFragment, value, - TABCRASHED_ICON_URI, - notificationBox.PRIORITY_INFO_MEDIUM, - buttons, - eventName => { - if (eventName == "disconnected") { - removeTelemetryFn(); + { + label: messageFragment, + image: TABCRASHED_ICON_URI, + priority: notificationBox.PRIORITY_INFO_MEDIUM, + eventCallback: eventName => { + if (eventName == "disconnected") { + removeTelemetryFn(); - let existingItem = this.notificationsMap.get(childID); - if (existingItem) { - let idx = existingItem.indexOf(notification); - if (idx >= 0) { - existingItem.splice(idx, 1); + let existingItem = this.notificationsMap.get(childID); + if (existingItem) { + let idx = existingItem.indexOf(notification); + if (idx >= 0) { + existingItem.splice(idx, 1); + } + + if (!existingItem.length) { + this.notificationsMap.delete(childID); + } + } + } else if (eventName == "dismissed") { + if (dumpID) { + CrashSubmit.ignore(dumpID); + this.childMap.delete(childID); } - if (!existingItem.length) { - this.notificationsMap.delete(childID); - } + closeAllNotifications(); } - } else if (eventName == "dismissed") { - if (dumpID) { - CrashSubmit.ignore(dumpID); - this.childMap.delete(childID); - } - - closeAllNotifications(); - } - } + }, + }, + buttons ); let existingItem = this.notificationsMap.get(childID); @@ -1154,12 +1156,14 @@ var UnsubmittedCrashHandler = { ); return chromeWin.gNotificationBox.appendNotification( - message, notificationID, - TABCRASHED_ICON_URI, - chromeWin.gNotificationBox.PRIORITY_INFO_HIGH, - buttons, - eventCallback + { + label: message, + image: TABCRASHED_ICON_URI, + priority: chromeWin.gNotificationBox.PRIORITY_INFO_HIGH, + eventCallback, + }, + buttons ); }, diff --git a/browser/modules/ProcessHangMonitor.jsm b/browser/modules/ProcessHangMonitor.jsm index 61d9d7211c7d..4d219c58bf76 100644 --- a/browser/modules/ProcessHangMonitor.jsm +++ b/browser/modules/ProcessHangMonitor.jsm @@ -570,16 +570,18 @@ var ProcessHangMonitor = { win.gNotificationBox .appendNotification( - message, "process-hang", - "chrome://browser/content/aboutRobots-icon.png", - win.gNotificationBox.PRIORITY_INFO_HIGH, - buttons, - event => { - if (event == "dismissed") { - ProcessHangMonitor.waitLonger(win); - } - } + { + label: message, + image: "chrome://browser/content/aboutRobots-icon.png", + priority: win.gNotificationBox.PRIORITY_INFO_HIGH, + eventCallback: event => { + if (event == "dismissed") { + ProcessHangMonitor.waitLonger(win); + } + }, + }, + buttons ) .setAttribute("notification-tag", notificationTag); }, diff --git a/devtools/client/responsive/utils/notification.js b/devtools/client/responsive/utils/notification.js index 421d9aa1e975..9c99358a7217 100644 --- a/devtools/client/responsive/utils/notification.js +++ b/devtools/client/responsive/utils/notification.js @@ -54,7 +54,7 @@ async function showNotification( priority = nbox.PRIORITY_INFO_MEDIUM; } - nbox.appendNotification(msg, value, null, priority, []); + nbox.appendNotification(value, { label: msg, priority }); } exports.showNotification = showNotification; diff --git a/toolkit/components/normandy/lib/Heartbeat.jsm b/toolkit/components/normandy/lib/Heartbeat.jsm index fb9b9a96c418..7e53cbeab5fa 100644 --- a/toolkit/components/normandy/lib/Heartbeat.jsm +++ b/toolkit/components/normandy/lib/Heartbeat.jsm @@ -173,17 +173,19 @@ var Heartbeat = class { this.notificationBox = this.chromeWindow.gNotificationBox; this.notice = this.notificationBox.appendNotification( - this.options.message, "heartbeat-" + this.options.flowId, - "resource://normandy/skin/shared/heartbeat-icon.svg", - this.notificationBox.PRIORITY_SYSTEM, - this.buttons, - eventType => { - if (eventType !== "removed") { - return; - } - this.maybeNotifyHeartbeat("NotificationClosed"); - } + { + label: this.options.message, + image: "resource://normandy/skin/shared/heartbeat-icon.svg", + priority: this.notificationBox.PRIORITY_SYSTEM, + eventCallback: eventType => { + if (eventType !== "removed") { + return; + } + this.maybeNotifyHeartbeat("NotificationClosed"); + }, + }, + this.buttons ); this.notice.classList.add("heartbeat"); this.notice.messageText.classList.add("heartbeat"); diff --git a/toolkit/components/pdfjs/content/PdfjsParent.jsm b/toolkit/components/pdfjs/content/PdfjsParent.jsm index 365057a2723c..2279915cb5b1 100644 --- a/toolkit/components/pdfjs/content/PdfjsParent.jsm +++ b/toolkit/components/pdfjs/content/PdfjsParent.jsm @@ -329,19 +329,20 @@ class PdfjsParent extends JSWindowActorParent { }, ]; notificationBox.appendNotification( - data.message, "pdfjs-fallback", - null, - notificationBox.PRIORITY_INFO_MEDIUM, - buttons, - function eventsCallback(eventType) { - // Currently there is only one event "removed" but if there are any other - // added in the future we still only care about removed at the moment. - if (eventType !== "removed") { - return; - } - sendMessage(false); - } + { + label: data.message, + priority: notificationBox.PRIORITY_INFO_MEDIUM, + eventCallback: eventType => { + // Currently there is only one event "removed" but if there are any other + // added in the future we still only care about removed at the moment. + if (eventType !== "removed") { + return; + } + sendMessage(false); + }, + }, + buttons ); } } diff --git a/toolkit/content/tests/chrome/test_bug457632.xhtml b/toolkit/content/tests/chrome/test_bug457632.xhtml index bd8797b32dbb..7f94eaef09a0 100644 --- a/toolkit/content/tests/chrome/test_bug457632.xhtml +++ b/toolkit/content/tests/chrome/test_bug457632.xhtml @@ -35,10 +35,8 @@ function test() { }); is(gNotificationBox.allNotifications.length, 0, "There should be no initial notifications"); - gNotificationBox.appendNotification("Test notification", - "notification1", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + gNotificationBox.appendNotification("notification1", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); is(gNotificationBox.allNotifications.length, 1, "Notification exists while animating in"); let notification = gNotificationBox.getNotificationWithValue("notification1"); ok(notification, "Notification should exist while animating in"); @@ -62,10 +60,8 @@ function test1() { // Tests that a notification that is animating in gets removed immediately function test2() { - let notification = gNotificationBox.appendNotification("Test notification", - "notification2", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + let notification = gNotificationBox.appendNotification("notification2", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); gNotificationBox.removeNotification(notification); notification = gNotificationBox.getNotificationWithValue("notification2"); ok(!notification, "Test 2 showed notification was still present"); @@ -79,14 +75,10 @@ function test2() { // Tests that a background notification goes away immediately function test3() { - let notification = gNotificationBox.appendNotification("Test notification", - "notification3", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); - let notification2 = gNotificationBox.appendNotification("Test notification", - "notification4", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + let notification = gNotificationBox.appendNotification("notification3", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); + let notification2 = gNotificationBox.appendNotification("notification4", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); is(gNotificationBox.allNotifications.length, 2, "Test 3 should show 2 notifications present"); gNotificationBox.removeNotification(notification); is(gNotificationBox.allNotifications.length, 1, "Test 3 should show 1 notifications present"); @@ -105,14 +97,10 @@ function test3() { // Tests that a foreground notification hiding a background one goes away function test4() { - let notification = gNotificationBox.appendNotification("Test notification", - "notification5", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); - let notification2 = gNotificationBox.appendNotification("Test notification", - "notification6", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + let notification = gNotificationBox.appendNotification("notification5", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); + let notification2 = gNotificationBox.appendNotification("notification6", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); gNotificationBox.removeNotification(notification2); notification2 = gNotificationBox.getNotificationWithValue("notification6"); ok(!notification2, "Test 4 showed notification2 was still present"); @@ -131,14 +119,10 @@ function test4() { // Tests that removeAllNotifications gets rid of everything function test5() { - let notification = gNotificationBox.appendNotification("Test notification", - "notification7", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); - let notification2 = gNotificationBox.appendNotification("Test notification", - "notification8", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + let notification = gNotificationBox.appendNotification("notification7", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); + let notification2 = gNotificationBox.appendNotification("notification8", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); gNotificationBox.removeAllNotifications(); notification = gNotificationBox.getNotificationWithValue("notification7"); notification2 = gNotificationBox.getNotificationWithValue("notification8"); @@ -147,10 +131,8 @@ function test5() { ok(!gNotificationBox.currentNotification, "Test 5 said there was still a current notification"); is(gNotificationBox.allNotifications.length, 0, "Test 5 should show 0 notifications present"); - gNotificationBox.appendNotification("Test notification", - "notification9", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + gNotificationBox.appendNotification("notification9", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); // Wait for the notificaton to finish displaying completeAnimation(test6); @@ -165,10 +147,8 @@ function test6() { ok(!gNotificationBox.currentNotification, "Test 6 shouldn't be any current notification"); is(gNotificationBox.allNotifications.length, 0, "Test 6 allNotifications.length should be 0"); - notification = gNotificationBox.appendNotification("Test notification", - "notification10", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + notification = gNotificationBox.appendNotification("notification10", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); is(notification, gNotificationBox.currentNotification, "Test 6 should have made the current notification"); gNotificationBox.removeNotification(notification); diff --git a/toolkit/content/tests/chrome/test_bug509732.xhtml b/toolkit/content/tests/chrome/test_bug509732.xhtml index 3307d624508c..c886a05fd134 100644 --- a/toolkit/content/tests/chrome/test_bug509732.xhtml +++ b/toolkit/content/tests/chrome/test_bug509732.xhtml @@ -28,10 +28,8 @@ function test() { is(gNotificationBox.allNotifications.length, 0, "There should be no initial notifications"); - gNotificationBox.appendNotification("Test notification", - "notification1", null, - gNotificationBox.PRIORITY_INFO_LOW, - null); + gNotificationBox.appendNotification("notification1", + { label: "Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW }); is(gNotificationBox.allNotifications.length, 1, "Notification exists"); is(gNotificationBox._animating, false, "Notification shouldn't be animating"); diff --git a/toolkit/content/tests/chrome/test_notificationbox.xhtml b/toolkit/content/tests/chrome/test_notificationbox.xhtml index c888e7ccb58d..cf990a2bb973 100644 --- a/toolkit/content/tests/chrome/test_notificationbox.xhtml +++ b/toolkit/content/tests/chrome/test_notificationbox.xhtml @@ -126,8 +126,11 @@ var tests = { test(nb, ntf) { // append a new notification - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + }, testtag_notificationbox_buttons); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification"); return ntf; }, @@ -158,10 +161,12 @@ var tests = { test(nb, ntf) { // append a new notification, but now with an event callback - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, - testtag_notificationbox_buttons, - notification_eventCallback); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + eventCallback: notification_eventCallback, + }, testtag_notificationbox_buttons); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification with callback"); return ntf; }, @@ -185,15 +190,20 @@ var tests = }, { test(nb, ntf) { - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, - testtag_notificationbox_buttons, - notification_eventCallback); - SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification with callback"); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_MEDIUM, + eventCallback: notification_eventCallback, + }, testtag_notificationbox_buttons); + SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification with object"); return ntf; }, result(nb, ntf) { testtag_notificationbox_State(nb, "append with callback", ntf, 1); + testtag_notificationbox_State(nb, "append using object", ntf, 1); + testtag_notification_State(nb, ntf, "append object", "Notification", "note", + "happy.png", nb.PRIORITY_INFO_MEDIUM); return ntf; } }, @@ -214,14 +224,14 @@ var tests = }, { test(nb, ntf) { - ntf = nb.appendNotification( - "Notification", "note", "happy.png", - nb.PRIORITY_WARNING_LOW, - [{ + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_WARNING_LOW, + eventCallback: notification_eventCallback, + }, [{ label: "Button", - }] - ); - + }]); return ntf; }, result(nb, ntf) { @@ -241,8 +251,11 @@ var tests = switch (idx) { case 1: // append a new notification - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + }, testtag_notificationbox_buttons); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification"); // Test persistence @@ -286,8 +299,11 @@ var tests = { test(nb, ntf) { // append another notification - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_MEDIUM, testtag_notificationbox_buttons); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_MEDIUM, + }, testtag_notificationbox_buttons); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification again"); return ntf; }, @@ -311,8 +327,11 @@ var tests = }, { test(nb, ntf) { - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_HIGH, testtag_notificationbox_buttons); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_HIGH, + }, testtag_notificationbox_buttons); return ntf; }, result(nb, ntf) { @@ -325,10 +344,12 @@ var tests = }, { test(nb, ntf) { - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, - testtag_notificationbox_links, - notification_eventCallback); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + eventCallback: notification_eventCallback, + }, testtag_notificationbox_links); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append link notification with callback"); return ntf; }, @@ -350,8 +371,12 @@ var tests = { test(nb, ntf) { // append a new notification - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons_nopopup); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + eventCallback: notification_eventCallback, + }, testtag_notificationbox_supportpage); return ntf; }, result(nb, ntf) { @@ -374,10 +399,12 @@ var tests = }, { test(nb, ntf) { - ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, - testtag_notificationbox_supportpage, - notification_eventCallback); + ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + eventCallback: notification_eventCallback, + }, testtag_notificationbox_supportpage); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append support page notification"); return ntf; }, @@ -400,16 +427,18 @@ var tests = { test(nb, unused) { // add a number of notifications and check that they are added in order - nb.appendNotification("Four", "4", null, nb.PRIORITY_INFO_HIGH, testtag_notificationbox_buttons); - nb.appendNotification("Seven", "7", null, nb.PRIORITY_WARNING_HIGH, testtag_notificationbox_buttons); - nb.appendNotification("Two", "2", null, nb.PRIORITY_INFO_LOW, null); - nb.appendNotification("Eight", "8", null, nb.PRIORITY_CRITICAL_LOW, null); - nb.appendNotification("Five", "5", null, nb.PRIORITY_WARNING_LOW, null); - nb.appendNotification("Six", "6", null, nb.PRIORITY_WARNING_HIGH, null); - nb.appendNotification("One", "1", null, nb.PRIORITY_INFO_LOW, null); - nb.appendNotification("Nine", "9", null, nb.PRIORITY_CRITICAL_MEDIUM, null); - var ntf = nb.appendNotification("Ten", "10", null, nb.PRIORITY_CRITICAL_HIGH, null); - nb.appendNotification("Three", "3", null, nb.PRIORITY_INFO_MEDIUM, null); + nb.appendNotification("4", { label: "Four", priority: nb.PRIORITY_INFO_HIGH }, + testtag_notificationbox_buttons); + nb.appendNotification("7", { label: "Seven", priority: nb.PRIORITY_WARNING_HIGH }, + testtag_notificationbox_buttons); + nb.appendNotification("2", { label: "Two", priority: nb.PRIORITY_INFO_LOW }); + nb.appendNotification("8", { label: "Eight", priority: nb.PRIORITY_CRITICAL_LOW }); + nb.appendNotification("5", { label: "Five", priority: nb.PRIORITY_WARNING_LOW }); + nb.appendNotification("6", { label: "Six", priority: nb.PRIORITY_WARNING_LOW }); + nb.appendNotification("1", { label: "One", priority: nb.PRIORITY_INFO_LOW }); + nb.appendNotification("9", { label: "Nine", priority: nb.PRIORITY_CRITICAL_MEDIUM }); + let ntf = nb.appendNotification("10", { label: "Ten", priority: nb.PRIORITY_CRITICAL_HIGH }); + nb.appendNotification("3", { label: "Three", priority: nb.PRIORITY_INFO_MEDIUM }); return ntf; }, result(nb, ntf) { @@ -445,13 +474,13 @@ var tests = test(nb, ntf) { var exh = false; try { - nb.appendNotification("no", "no", "no", -1, null); + nb.appendNotification("no", { label: "no", priority: 0 }); } catch (ex) { exh = true; } SimpleTest.is(exh, true, "appendNotification priority too low"); exh = false; try { - nb.appendNotification("no", "no", "no", 11, null); + nb.appendNotification("no", { label: "no", priority: 11 }); } catch (ex) { exh = true; } SimpleTest.is(exh, true, "appendNotification priority too high"); @@ -464,8 +493,11 @@ var tests = var appendPriorityTests = [ { test(nb, priority) { - var ntf = nb.appendNotification("Notification", "note", "happy.png", - priority, testtag_notificationbox_buttons); + let ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority, + }, testtag_notificationbox_buttons); SimpleTest.is(ntf && ntf.localName == NOTIFICATION_LOCAL_NAME, true, "append notification " + priority); return [ntf, priority]; }, @@ -481,8 +513,11 @@ var appendPriorityTests = [ }, result(nb, priority) { if (priority == nb.PRIORITY_CRITICAL_HIGH) { - let ntf = nb.appendNotification("Notification", "note", "happy.png", - nb.PRIORITY_INFO_LOW, testtag_notificationbox_buttons); + let ntf = nb.appendNotification("note", { + label: "Notification", + image: "happy.png", + priority: nb.PRIORITY_INFO_LOW, + }, testtag_notificationbox_buttons); setTimeout(checkPopupTest, 50, nb, ntf); } else { diff --git a/toolkit/content/widgets/notificationbox.js b/toolkit/content/widgets/notificationbox.js index b16505ec7e1e..fa7625f9ef02 100644 --- a/toolkit/content/widgets/notificationbox.js +++ b/toolkit/content/widgets/notificationbox.js @@ -79,19 +79,28 @@ * Creates a element and shows it. The calling code can modify * the element synchronously to add features to the notification. * - * @param aLabel - * The main message text, or a DocumentFragment containing elements to - * add as children of the notification's main element. - * @param aValue - * String identifier of the notification. - * @param aImage - * URL of the icon image to display. If not specified, a default icon - * based on the priority will be shown. - * @param aPriority + * aType + * String identifier that can uniquely identify the type of the notification. + * aNotification + * Object that contains any of the following properties, where only the + * priority must be specified: + * priority * One of the PRIORITY_ constants. These determine the appearance of * the notification based on severity (using the "type" attribute), and * only the notification with the highest priority is displayed. - * @param aButtons + * label + * The main message text, or a DocumentFragment containing elements to + * add as children of the notification's main element. + * eventCallback + * This may be called with the "removed", "dismissed" or "disconnected" + * parameter: + * removed - notification has been removed + * dismissed - user dismissed notification + * disconnected - notification removed in any way + * notificationIs + * Defines a Custom Element name to use as the "is" value on creation. + * This allows subclassing the created element. + * aButtons * Array of objects defining action buttons: * { * label: @@ -121,39 +130,24 @@ * Defines a Custom Element name to use as the "is" value on * button creation. * } - * @param aEventCallback - * This may be called with the "removed", "dismissed" or "disconnected" - * parameter: - * removed - notification has been removed - * dismissed - user dismissed notification - * disconnected - notification removed in any way - * @param aNotificationIs - * Defines a Custom Element name to use as the "is" value on creation. - * This allows subclassing the created element. * * @return The element that is shown. */ - appendNotification( - aLabel, - aValue, - aImage, - aPriority, - aButtons, - aEventCallback, - aNotificationIs - ) { + appendNotification(aType, aNotification, aButtons) { if ( - aPriority < this.PRIORITY_SYSTEM || - aPriority > this.PRIORITY_CRITICAL_HIGH + aNotification.priority < this.PRIORITY_SYSTEM || + aNotification.priority > this.PRIORITY_CRITICAL_HIGH ) { - throw new Error("Invalid notification priority " + aPriority); + throw new Error( + "Invalid notification priority " + aNotification.priority + ); } MozXULElement.insertFTLIfNeeded("toolkit/global/notification.ftl"); // Create the Custom Element and connect it to the document immediately. var newitem; - if (!aNotificationIs) { + if (!aNotification.notificationIs) { if (!customElements.get("notification-message")) { // There's some weird timing stuff when this element is created at // script load time, we don't need it until now anyway so be lazy. @@ -164,7 +158,9 @@ } else { newitem = document.createXULElement( "notification", - aNotificationIs ? { is: aNotificationIs } : {} + aNotification.notificationIs + ? { is: aNotification.notificationIs } + : {} ); } @@ -179,30 +175,31 @@ if (newitem.messageText) { // Can't use instanceof in case this was created from a different document: if ( - aLabel && - typeof aLabel == "object" && - aLabel.nodeType && - aLabel.nodeType == aLabel.DOCUMENT_FRAGMENT_NODE + aNotification.label && + typeof aNotification.label == "object" && + aNotification.label.nodeType && + aNotification.label.nodeType == + aNotification.label.DOCUMENT_FRAGMENT_NODE ) { - newitem.messageText.appendChild(aLabel); + newitem.messageText.appendChild(aNotification.label); } else { - newitem.messageText.textContent = aLabel; + newitem.messageText.textContent = aNotification.label; } } - newitem.setAttribute("value", aValue); + newitem.setAttribute("value", aType); - newitem.eventCallback = aEventCallback; + newitem.eventCallback = aNotification.eventCallback; if (aButtons) { newitem.setButtons(aButtons); } - newitem.priority = aPriority; - if (aPriority == this.PRIORITY_SYSTEM) { + newitem.priority = aNotification.priority; + if (aNotification.priority == this.PRIORITY_SYSTEM) { newitem.setAttribute("type", "system"); - } else if (aPriority >= this.PRIORITY_CRITICAL_LOW) { + } else if (aNotification.priority >= this.PRIORITY_CRITICAL_LOW) { newitem.setAttribute("type", "critical"); - } else if (aPriority <= this.PRIORITY_INFO_HIGH) { + } else if (aNotification.priority <= this.PRIORITY_INFO_HIGH) { newitem.setAttribute("type", "info"); } else { newitem.setAttribute("type", "warning");