--- a/devtools/client/responsive.html/manager.js
+++ b/devtools/client/responsive.html/manager.js
@@ -8,32 +8,27 @@ const { Ci } = require("chrome");
const promise = require("promise");
const Services = require("Services");
const EventEmitter = require("devtools/shared/old-event-emitter");
const TOOL_URL = "chrome://devtools/content/responsive.html/index.xhtml";
loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/debugger-client", true);
loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
-loader.lazyRequireGetter(this, "TargetFactory", "devtools/client/framework/target", true);
-loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
-loader.lazyRequireGetter(this, "throttlingProfiles",
- "devtools/client/shared/network-throttling-profiles");
-loader.lazyRequireGetter(this, "swapToInnerBrowser",
- "devtools/client/responsive.html/browser/swap", true);
-loader.lazyRequireGetter(this, "startup",
- "devtools/client/responsive.html/utils/window", true);
-loader.lazyRequireGetter(this, "message",
- "devtools/client/responsive.html/utils/message");
-loader.lazyRequireGetter(this, "getStr",
- "devtools/client/responsive.html/utils/l10n", true);
-loader.lazyRequireGetter(this, "EmulationFront",
- "devtools/shared/fronts/emulation", true);
+loader.lazyRequireGetter(this, "throttlingProfiles", "devtools/client/shared/network-throttling-profiles");
+loader.lazyRequireGetter(this, "swapToInnerBrowser", "devtools/client/responsive.html/browser/swap", true);
+loader.lazyRequireGetter(this, "startup", "devtools/client/responsive.html/utils/window", true);
+loader.lazyRequireGetter(this, "message", "devtools/client/responsive.html/utils/message");
+loader.lazyRequireGetter(this, "showNotification", "devtools/client/responsive.html/utils/notification", true);
+loader.lazyRequireGetter(this, "l10n", "devtools/client/responsive.html/utils/l10n");
+loader.lazyRequireGetter(this, "EmulationFront", "devtools/shared/fronts/emulation", true);
+loader.lazyRequireGetter(this, "PriorityLevels", "devtools/client/shared/components/NotificationBox", true);
const RELOAD_CONDITION_PREF_PREFIX = "devtools.responsive.reloadConditions.";
+const RELOAD_NOTIFICATION_PREF = "devtools.responsive.reloadNotification.enabled";
function debug(msg) {
// console.log(`RDM manager: ${msg}`);
}
/**
* ResponsiveUIManager is the external API for the browser UI, etc. to use when
* opening and closing the responsive UI.
@@ -219,52 +214,30 @@ const ResponsiveUIManager = exports.Resp
await startup(window);
let menu = window.document.getElementById("menu_responsiveUI");
if (menu) {
menu.setAttribute("checked", this.isActiveForTab(tab));
}
},
- showRemoteOnlyNotification(window, tab, options) {
- this.showErrorNotification(window, tab, options, getStr("responsive.remoteOnly"));
- },
-
- showNoContainerTabsNotification(window, tab, options) {
- this.showErrorNotification(window, tab, options,
- getStr("responsive.noContainerTabs"));
+ showRemoteOnlyNotification(window, tab, { command } = {}) {
+ showNotification(window, tab, {
+ command,
+ msg: l10n.getStr("responsive.remoteOnly"),
+ priority: PriorityLevels.PRIORITY_CRITICAL_MEDIUM,
+ });
},
- showErrorNotification(window, tab, { command } = {}, msg) {
- // Default to using the browser's per-tab notification box
- let nbox = window.gBrowser.getNotificationBox(tab.linkedBrowser);
-
- // If opening was initiated by GCLI command bar or 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 (command) {
- let target = TargetFactory.forTab(tab);
- let toolbox = gDevTools.getToolbox(target);
- if (toolbox) {
- nbox = toolbox.notificationBox;
- }
- }
-
- let value = "devtools-responsive-error";
- if (nbox.getNotificationWithValue(value)) {
- // Notification already displayed
- return;
- }
-
- nbox.appendNotification(
- msg,
- value,
- null,
- nbox.PRIORITY_CRITICAL_MEDIUM,
- []);
+ showNoContainerTabsNotification(window, tab, { command } = {}) {
+ showNotification(window, tab, {
+ command,
+ msg: l10n.getStr("responsive.noContainerTabs"),
+ priority: PriorityLevels.PRIORITY_CRITICAL_MEDIUM,
+ });
},
};
// GCLI commands in ./commands.js listen for events from this object to know
// when the UI for a tab has opened or closed.
EventEmitter.decorate(ResponsiveUIManager);
/**
@@ -450,17 +423,31 @@ ResponsiveUI.prototype = {
DebuggerServer.init();
DebuggerServer.registerAllActors();
this.client = new DebuggerClient(DebuggerServer.connectPipe());
await this.client.connect();
let { tab } = await this.client.getTab();
this.emulationFront = EmulationFront(this.client, tab);
},
+ /**
+ * Show one-time notification about reloads for emulation.
+ */
+ showReloadNotification() {
+ if (Services.prefs.getBoolPref(RELOAD_NOTIFICATION_PREF, false)) {
+ showNotification(this.browserWindow, this.tab, {
+ msg: l10n.getFormatStr("responsive.reloadNotification.description",
+ l10n.getStr("responsive.reloadConditions.label")),
+ });
+ Services.prefs.setBoolPref(RELOAD_NOTIFICATION_PREF, false);
+ }
+ },
+
reloadOnChange(id) {
+ this.showReloadNotification();
let pref = RELOAD_CONDITION_PREF_PREFIX + id;
return Services.prefs.getBoolPref(pref, false);
},
handleEvent(event) {
let { browserWindow, tab } = this;
switch (event.type) {
new file mode 100644
--- /dev/null
+++ b/devtools/client/responsive.html/utils/notification.js
@@ -0,0 +1,53 @@
+/* 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:
+ * - `command`: Whether initiated via GCLI command bar or toolbox button
+ * - `msg`: String to show in the notification
+ * - `priority`: Priority level for the notification, which affects the icon and
+ * overall appearance.
+ */
+function showNotification(window, tab, { command, msg, priority } = {}) {
+ // Default to using the browser's per-tab notification box
+ let nbox = window.gBrowser.getNotificationBox(tab.linkedBrowser);
+
+ // If opening was initiated by GCLI command bar or 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 (command) {
+ let target = TargetFactory.forTab(tab);
+ let toolbox = gDevTools.getToolbox(target);
+ if (toolbox) {
+ nbox = toolbox.notificationBox;
+ }
+ }
+
+ let 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;