summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsive/utils/notification.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/client/responsive/utils/notification.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--devtools/client/responsive/utils/notification.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/devtools/client/responsive/utils/notification.js b/devtools/client/responsive/utils/notification.js
new file mode 100644
index 0000000000..3045ea9a16
--- /dev/null
+++ b/devtools/client/responsive/utils/notification.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+loader.lazyRequireGetter(
+ this,
+ "TargetFactory",
+ "devtools/client/framework/target",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "gDevTools",
+ "devtools/client/framework/devtools",
+ true
+);
+
+/**
+ * Displays a notification either at the browser or toolbox level, depending on whether
+ * a toolbox is currently open for this tab.
+ *
+ * @param window
+ * The main browser chrome window.
+ * @param tab
+ * The browser tab.
+ * @param options
+ * Other options associated with opening. Currently includes:
+ * - `toolbox`: Whether initiated via toolbox button
+ * - `msg`: String to show in the notification
+ * - `priority`: Priority level for the notification, which affects the icon and
+ * overall appearance.
+ */
+async function showNotification(
+ window,
+ tab,
+ { toolboxButton, msg, priority } = {}
+) {
+ // Default to using the browser's per-tab notification box
+ let nbox = window.gBrowser.getNotificationBox(tab.linkedBrowser);
+
+ // If opening was initiated by a toolbox button, check for an open
+ // toolbox for the tab. If one exists, use the toolbox's notification box so that the
+ // message is placed closer to the action taken by the user.
+ if (toolboxButton) {
+ const target = await TargetFactory.forTab(tab);
+ const toolbox = gDevTools.getToolbox(target);
+ if (toolbox) {
+ nbox = toolbox.notificationBox;
+ }
+ }
+
+ const value = "devtools-responsive";
+ if (nbox.getNotificationWithValue(value)) {
+ // Notification already displayed
+ return;
+ }
+
+ if (!priority) {
+ priority = nbox.PRIORITY_INFO_MEDIUM;
+ }
+
+ nbox.appendNotification(msg, value, null, priority, []);
+}
+
+exports.showNotification = showNotification;