/* 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/. */
/** * ResponsiveUIManager is the external API for the browser UI, etc. to use when * opening and closing the responsive UI.
*/ class ResponsiveUIManager {
constructor() { this.activeTabs = new Map();
get telemetry() { if (!this._telemetry) { this._telemetry = new Telemetry();
}
returnthis._telemetry;
}
/** * Toggle the responsive UI for a tab. * * @param window * The main browser chrome window. * @param tab * The browser tab. * @param options * Other options associated with toggling. Currently includes: * - `trigger`: String denoting the UI entry point, such as: * - `toolbox`: Toolbox Button * - `menu`: Browser Tools menu item * - `shortcut`: Keyboard shortcut * @return Promise * Resolved when the toggling has completed. If the UI has opened, * it is resolved to the ResponsiveUI instance for this tab. If the * the UI has closed, there is no resolution value.
*/
toggle(window, tab, options = {}) { const completed = this._toggleForTab(window, tab, options);
completed.catch(console.error); return completed;
}
/** * Opens the responsive UI, if not already open. * * @param window * The main browser chrome window. * @param tab * The browser tab. * @param options * Other options associated with opening. Currently includes: * - `trigger`: String denoting the UI entry point, such as: * - `toolbox`: Toolbox Button * - `menu`: Browser Tools menu item * - `shortcut`: Keyboard shortcut * @return Promise * Resolved to the ResponsiveUI instance for this tab when opening is * complete.
*/
async openIfNeeded(window, tab, options = {}) { if (!this.isActiveForTab(tab)) { this.initMenuCheckListenerFor(window);
const ui = new ResponsiveUI(this, window, tab); this.activeTabs.set(tab, ui);
// Explicitly not await on telemetry to avoid delaying RDM opening this.recordTelemetryOpen(window, tab, options);
/** * Record all telemetry probes related to RDM opening.
*/
recordTelemetryOpen(window, tab, options) { // Track whether a toolbox was opened before RDM was opened. const toolbox = gDevTools.getToolboxForTab(tab); const hostType = toolbox ? toolbox.hostType : "none"; const hasToolbox = !!toolbox;
if (hasToolbox) {
Glean.devtoolsResponsive.toolboxOpenedFirst.add(1);
}
// Track opens keyed by the UI entry point used.
let { trigger } = options; if (!trigger) {
trigger = "unknown";
}
Glean.devtoolsResponsive.openTrigger[trigger].add(1);
}
/** * Closes the responsive UI, if not already closed. * * @param window * The main browser chrome window. * @param tab * The browser tab. * @param options * Other options associated with closing. Currently includes: * - `trigger`: String denoting the UI entry point, such as: * - `toolbox`: Toolbox Button * - `menu`: Browser Tools menu item * - `shortcut`: Keyboard shortcut * - `reason`: String detailing the specific cause for closing * @return Promise * Resolved (with no value) when closing is complete.
*/
async closeIfNeeded(window, tab, options = {}) { if (this.isActiveForTab(tab)) { const ui = this.activeTabs.get(tab); const destroyed = await ui.destroy(options); if (!destroyed) { // Already in the process of destroying, abort. return;
}
/** * Returns true if responsive UI is active for a given tab. * * @param tab * The browser tab. * @return boolean
*/
isActiveForTab(tab) { returnthis.activeTabs.has(tab);
}
/** * Returns true if responsive UI is active in any tab in the given window. * * @param window * The main browser chrome window. * @return boolean
*/
isActiveForWindow(window) { return [...this.activeTabs.keys()].some(t => t.ownerGlobal === window);
}
/** * Return the responsive UI controller for a tab. * * @param tab * The browser tab. * @return ResponsiveUI * The UI instance for this tab.
*/
getResponsiveUIForTab(tab) { returnthis.activeTabs.get(tab);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.