tor-browser

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

notification.js (1816B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 loader.lazyRequireGetter(
      8  this,
      9  "gDevTools",
     10  "resource://devtools/client/framework/devtools.js",
     11  true
     12 );
     13 
     14 /**
     15 * Displays a notification either at the browser or toolbox level, depending on whether
     16 * a toolbox is currently open for this tab.
     17 *
     18 * @param window
     19 *        The main browser chrome window.
     20 * @param tab
     21 *        The browser tab.
     22 * @param options
     23 *        Other options associated with opening.  Currently includes:
     24 *        - `toolbox`: Whether initiated via toolbox button
     25 *        - `msg`: String to show in the notification
     26 *        - `priority`: Priority level for the notification, which affects the icon and
     27 *                      overall appearance.
     28 */
     29 async function showNotification(
     30  window,
     31  tab,
     32  { toolboxButton, msg, priority } = {}
     33 ) {
     34  // Default to using the browser's per-tab notification box
     35  let nbox = window.gBrowser.getNotificationBox(tab.linkedBrowser);
     36 
     37  // If opening was initiated by a toolbox button, check for an open
     38  // toolbox for the tab.  If one exists, use the toolbox's notification box so that the
     39  // message is placed closer to the action taken by the user.
     40  if (toolboxButton) {
     41    const toolbox = gDevTools.getToolboxForTab(tab);
     42    if (toolbox) {
     43      nbox = toolbox.notificationBox;
     44    }
     45  }
     46 
     47  const value = "devtools-responsive";
     48  if (nbox.getNotificationWithValue(value)) {
     49    // Notification already displayed
     50    return;
     51  }
     52 
     53  if (!priority) {
     54    priority = nbox.PRIORITY_INFO_MEDIUM;
     55  }
     56 
     57  nbox.appendNotification(value, { label: msg, priority });
     58 }
     59 
     60 exports.showNotification = showNotification;