--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -1,18 +1,16 @@
/* 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";
const {Cu} = require("chrome");
const Services = require("Services");
-const promise = require("promise");
-const defer = require("devtools/shared/defer");
// Load gDevToolsBrowser toolbox lazily as they need gDevTools to be fully initialized
loader.lazyRequireGetter(this, "Toolbox", "devtools/client/framework/toolbox", true);
loader.lazyRequireGetter(this, "ToolboxHostManager", "devtools/client/framework/toolbox-host-manager", true);
loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
const {defaultTools: DefaultTools, defaultThemes: DefaultThemes} =
require("devtools/client/definitions");
@@ -41,17 +39,17 @@ function DevTools() {
AboutDevTools.register();
EventEmitter.decorate(this);
// This is important step in initialization codepath where we are going to
// start registering all default tools and themes: create menuitems, keys, emit
// related events.
this.registerDefaults();
-};
+}
DevTools.prototype = {
// The windowtype of the main window, used in various tools. This may be set
// to something different by other gecko apps.
chromeWindowType: "navigator:browser",
registerDefaults() {
// Ensure registering items in the sorted order (getDefault* functions
@@ -95,17 +93,17 @@ DevTools.prototype = {
* (string|required)
* - hideInOptions: Boolean indicating whether or not this tool should be
shown in toolbox options or not. Defaults to false.
* (boolean)
* - build: Function that takes an iframe, which has been populated with the
* markup from |url|, and also the toolbox containing the panel.
* And returns an instance of ToolPanel (function|required)
*/
- registerTool: function DT_registerTool(toolDefinition) {
+ registerTool(toolDefinition) {
let toolId = toolDefinition.id;
if (!toolId || FORBIDDEN_IDS.has(toolId)) {
throw new Error("Invalid definition.id");
}
// Make sure that additional tools will always be able to be hidden.
// When being called from main.js, defaultTools has not yet been exported.
@@ -125,52 +123,51 @@ DevTools.prototype = {
*
* @param {string|object} tool
* Definition or the id of the tool to unregister. Passing the
* tool id should be avoided as it is a temporary measure.
* @param {boolean} isQuitApplication
* true to indicate that the call is due to app quit, so we should not
* cause a cascade of costly events
*/
- unregisterTool: function DT_unregisterTool(tool, isQuitApplication) {
+ unregisterTool(tool, isQuitApplication) {
let toolId = null;
if (typeof tool == "string") {
toolId = tool;
tool = this._tools.get(tool);
- }
- else {
+ } else {
let {Deprecated} = Cu.import("resource://gre/modules/Deprecated.jsm", {});
- Deprecated.warning("Deprecation WARNING: gDevTools.unregisterTool(tool) is deprecated. " +
- "You should unregister a tool using its toolId: " +
- "gDevTools.unregisterTool(toolId).");
+ Deprecated.warning("Deprecation WARNING: gDevTools.unregisterTool(tool) is " +
+ "deprecated. You should unregister a tool using its toolId: " +
+ "gDevTools.unregisterTool(toolId).");
toolId = tool.id;
}
this._tools.delete(toolId);
if (!isQuitApplication) {
this.emit("tool-unregistered", toolId);
}
},
/**
* Sorting function used for sorting tools based on their ordinals.
*/
- ordinalSort: function DT_ordinalSort(d1, d2) {
+ ordinalSort(d1, d2) {
let o1 = (typeof d1.ordinal == "number") ? d1.ordinal : MAX_ORDINAL;
let o2 = (typeof d2.ordinal == "number") ? d2.ordinal : MAX_ORDINAL;
return o1 - o2;
},
- getDefaultTools: function DT_getDefaultTools() {
+ getDefaultTools() {
return DefaultTools.sort(this.ordinalSort);
},
- getAdditionalTools: function DT_getAdditionalTools() {
+ getAdditionalTools() {
let tools = [];
- for (let [key, value] of this._tools) {
+ for (let [, value] of this._tools) {
if (DefaultTools.indexOf(value) == -1) {
tools.push(value);
}
}
return tools.sort(this.ordinalSort);
},
getDefaultThemes() {
@@ -181,17 +178,17 @@ DevTools.prototype = {
* Get a tool definition if it exists and is enabled.
*
* @param {string} toolId
* The id of the tool to show
*
* @return {ToolDefinition|null} tool
* The ToolDefinition for the id or null.
*/
- getToolDefinition: function DT_getToolDefinition(toolId) {
+ getToolDefinition(toolId) {
let tool = this._tools.get(toolId);
if (!tool) {
return null;
} else if (!tool.visibilityswitch) {
return tool;
}
let enabled = Services.prefs.getBoolPref(tool.visibilityswitch, true);
@@ -201,17 +198,17 @@ DevTools.prototype = {
/**
* Allow ToolBoxes to get at the list of tools that they should populate
* themselves with.
*
* @return {Map} tools
* A map of the the tool definitions registered in this instance
*/
- getToolDefinitionMap: function DT_getToolDefinitionMap() {
+ getToolDefinitionMap() {
let tools = new Map();
for (let [id, definition] of this._tools) {
if (this.getToolDefinition(id)) {
tools.set(id, definition);
}
}
@@ -221,17 +218,17 @@ DevTools.prototype = {
/**
* Tools have an inherent ordering that can't be represented in a Map so
* getToolDefinitionArray provides an alternative representation of the
* definitions sorted by ordinal value.
*
* @return {Array} tools
* A sorted array of the tool definitions registered in this instance
*/
- getToolDefinitionArray: function DT_getToolDefinitionArray() {
+ getToolDefinitionArray() {
let definitions = [];
for (let [id, definition] of this._tools) {
if (this.getToolDefinition(id)) {
definitions.push(definition);
}
}
@@ -255,17 +252,17 @@ DevTools.prototype = {
* the theme (array|required)
* - onApply: Function that is executed by the framework when the theme
* is applied. The function takes the current iframe window
* and the previous theme id as arguments (function)
* - onUnapply: Function that is executed by the framework when the theme
* is unapplied. The function takes the current iframe window
* and the new theme id as arguments (function)
*/
- registerTheme: function DT_registerTheme(themeDefinition) {
+ registerTheme(themeDefinition) {
let themeId = themeDefinition.id;
if (!themeId) {
throw new Error("Invalid theme id");
}
if (this._themes.get(themeId)) {
throw new Error("Theme with the same id is already registered");
@@ -278,23 +275,22 @@ DevTools.prototype = {
/**
* Removes an existing theme from the list of registered themes.
* Needed so that add-ons can remove themselves when they are deactivated
*
* @param {string|object} theme
* Definition or the id of the theme to unregister.
*/
- unregisterTheme: function DT_unregisterTheme(theme) {
+ unregisterTheme(theme) {
let themeId = null;
if (typeof theme == "string") {
themeId = theme;
theme = this._themes.get(theme);
- }
- else {
+ } else {
themeId = theme.id;
}
let currTheme = Services.prefs.getCharPref("devtools.theme");
// Note that we can't check if `theme` is an item
// of `DefaultThemes` as we end up reloading definitions
// module and end up with different theme objects
@@ -318,31 +314,31 @@ DevTools.prototype = {
* Get a theme definition if it exists.
*
* @param {string} themeId
* The id of the theme
*
* @return {ThemeDefinition|null} theme
* The ThemeDefinition for the id or null.
*/
- getThemeDefinition: function DT_getThemeDefinition(themeId) {
+ getThemeDefinition(themeId) {
let theme = this._themes.get(themeId);
if (!theme) {
return null;
}
return theme;
},
/**
* Get map of registered themes.
*
* @return {Map} themes
* A map of the the theme definitions registered in this instance
*/
- getThemeDefinitionMap: function DT_getThemeDefinitionMap() {
+ getThemeDefinitionMap() {
let themes = new Map();
for (let [id, definition] of this._themes) {
if (this.getThemeDefinition(id)) {
themes.set(id, definition);
}
}
@@ -350,17 +346,17 @@ DevTools.prototype = {
},
/**
* Get registered themes definitions sorted by ordinal value.
*
* @return {Array} themes
* A sorted array of the theme definitions registered in this instance
*/
- getThemeDefinitionArray: function DT_getThemeDefinitionArray() {
+ getThemeDefinitionArray() {
let definitions = [];
for (let [id, definition] of this._themes) {
if (this.getThemeDefinition(id)) {
definitions.push(definition);
}
}
@@ -385,17 +381,16 @@ DevTools.prototype = {
* Options for host specifically
*
* @return {Toolbox} toolbox
* The toolbox that was opened
*/
showToolbox: Task.async(function* (target, toolId, hostType, hostOptions) {
let toolbox = this._toolboxes.get(target);
if (toolbox) {
-
if (hostType != null && toolbox.hostType != hostType) {
yield toolbox.switchHost(hostType);
}
if (toolId != null && toolbox.currentToolId != toolId) {
yield toolbox.selectTool(toolId);
}
@@ -444,17 +439,17 @@ DevTools.prototype = {
* Return the toolbox for a given target.
*
* @param {object} target
* Target value e.g. the target that owns this toolbox
*
* @return {Toolbox} toolbox
* The toolbox that is debugging the given target
*/
- getToolbox: function DT_getToolbox(target) {
+ getToolbox(target) {
return this._toolboxes.get(target);
},
/**
* Close the toolbox for a given target
*
* @return promise
* This promise will resolve to false if no toolbox was found
@@ -477,42 +472,42 @@ DevTools.prototype = {
* Either the SDK Loader has been destroyed by the add-on contribution
* workflow, or firefox is shutting down.
* @param {boolean} shuttingDown
* True if firefox is currently shutting down. We may prevent doing
* some cleanups to speed it up. Otherwise everything need to be
* cleaned up in order to be able to load devtools again.
*/
- destroy: function ({ shuttingDown }) {
+ destroy({ shuttingDown }) {
// Do not cleanup everything during firefox shutdown, but only when
// devtools are reloaded via the add-on contribution workflow.
if (!shuttingDown) {
- for (let [target, toolbox] of this._toolboxes) {
+ for (let [, toolbox] of this._toolboxes) {
toolbox.destroy();
}
AboutDevTools.unregister();
}
- for (let [key, tool] of this.getToolDefinitionMap()) {
+ for (let [key, ] of this.getToolDefinitionMap()) {
this.unregisterTool(key, true);
}
JsonView.destroy();
gDevTools.unregisterDefaults();
// Cleaning down the toolboxes: i.e.
// for (let [target, toolbox] of this._toolboxes) toolbox.destroy();
// Is taken care of by the gDevToolsBrowser.forgetBrowserWindow
},
/**
* Iterator that yields each of the toolboxes.
*/
- *[Symbol.iterator ]() {
+ * [Symbol.iterator ]() {
for (let toolbox of this._toolboxes) {
yield toolbox;
}
}
};
const gDevTools = exports.gDevTools = new DevTools();