2012-11-30 08:07:59 +00:00
|
|
|
/* 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";
|
|
|
|
|
2013-05-01 16:27:24 +00:00
|
|
|
this.EXPORTED_SYMBOLS = [ "gDevTools", "DevTools", "gDevToolsBrowser" ];
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-05-01 16:27:24 +00:00
|
|
|
Cu.import("resource://gre/modules/devtools/Loader.jsm");
|
2014-04-03 08:19:31 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "promise", "resource://gre/modules/Promise.jsm", "Promise");
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2014-05-20 22:19:41 +00:00
|
|
|
const EventEmitter = devtools.require("devtools/toolkit/event-emitter");
|
2013-02-13 19:36:00 +00:00
|
|
|
const FORBIDDEN_IDS = new Set(["toolbox", ""]);
|
2013-04-30 16:58:04 +00:00
|
|
|
const MAX_ORDINAL = 99;
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-08-03 16:34:05 +00:00
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* DevTools is a class that represents a set of developer tools, it holds a
|
|
|
|
* set of tools and keeps track of open toolboxes in the browser.
|
|
|
|
*/
|
|
|
|
this.DevTools = function DevTools() {
|
2013-01-11 12:16:24 +00:00
|
|
|
this._tools = new Map(); // Map<toolId, tool>
|
|
|
|
this._toolboxes = new Map(); // Map<target, toolbox>
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
// destroy() is an observer's handler so we need to preserve context.
|
|
|
|
this.destroy = this.destroy.bind(this);
|
2013-05-29 17:47:38 +00:00
|
|
|
this._teardown = this._teardown.bind(this);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2014-03-13 21:27:10 +00:00
|
|
|
this._testing = false;
|
|
|
|
|
2012-12-14 07:05:00 +00:00
|
|
|
EventEmitter.decorate(this);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-05-29 17:47:38 +00:00
|
|
|
Services.obs.addObserver(this._teardown, "devtools-unloaded", false);
|
2012-11-30 08:07:59 +00:00
|
|
|
Services.obs.addObserver(this.destroy, "quit-application", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
DevTools.prototype = {
|
2014-03-13 21:27:10 +00:00
|
|
|
/**
|
|
|
|
* When the testing flag is set we take appropriate action to prevent race
|
|
|
|
* conditions in our testing environment. This means setting
|
|
|
|
* dom.send_after_paint_to_content to false to prevent infinite MozAfterPaint
|
|
|
|
* loops and not autohiding the highlighter.
|
|
|
|
*/
|
|
|
|
get testing() {
|
|
|
|
return this._testing;
|
|
|
|
},
|
|
|
|
|
|
|
|
set testing(state) {
|
|
|
|
this._testing = state;
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
// dom.send_after_paint_to_content is set to true (non-default) in
|
|
|
|
// testing/profiles/prefs_general.js so lets set it to the same as it is
|
|
|
|
// in a default browser profile for the duration of the test.
|
|
|
|
Services.prefs.setBoolPref("dom.send_after_paint_to_content", false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Register a new developer tool.
|
|
|
|
*
|
|
|
|
* A definition is a light object that holds different information about a
|
|
|
|
* developer tool. This object is not supposed to have any operational code.
|
|
|
|
* See it as a "manifest".
|
|
|
|
* The only actual code lives in the build() function, which will be used to
|
|
|
|
* start an instance of this tool.
|
|
|
|
*
|
|
|
|
* Each toolDefinition has the following properties:
|
|
|
|
* - id: Unique identifier for this tool (string|required)
|
2013-05-04 06:31:07 +00:00
|
|
|
* - visibilityswitch: Property name to allow us to hide this tool from the
|
|
|
|
* DevTools Toolbox.
|
2013-11-18 20:12:02 +00:00
|
|
|
* A falsy value indicates that it cannot be hidden.
|
2012-11-30 08:07:59 +00:00
|
|
|
* - icon: URL pointing to a graphic which will be used as the src for an
|
|
|
|
* 16x16 img tag (string|required)
|
2014-02-10 13:50:13 +00:00
|
|
|
* - invertIconForLightTheme: The icon can automatically have an inversion
|
|
|
|
* filter applied (default is false). All builtin tools are true, but
|
|
|
|
* addons may omit this to prevent unwanted changes to the `icon`
|
|
|
|
* image. See browser/themes/shared/devtools/filters.svg#invert for
|
|
|
|
* the filter being applied to the images (boolean|optional)
|
2012-11-30 08:07:59 +00:00
|
|
|
* - url: URL pointing to a XUL/XHTML document containing the user interface
|
|
|
|
* (string|required)
|
|
|
|
* - label: Localized name for the tool to be displayed to the user
|
|
|
|
* (string|required)
|
|
|
|
* - 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) {
|
|
|
|
let toolId = toolDefinition.id;
|
|
|
|
|
|
|
|
if (!toolId || FORBIDDEN_IDS.has(toolId)) {
|
|
|
|
throw new Error("Invalid definition.id");
|
|
|
|
}
|
|
|
|
|
2013-11-18 20:12:02 +00:00
|
|
|
// Make sure that additional tools will always be able to be hidden.
|
|
|
|
// When being called from main.js, defaultTools has not yet been exported.
|
|
|
|
// But, we can assume that in this case, it is a default tool.
|
|
|
|
if (devtools.defaultTools && devtools.defaultTools.indexOf(toolDefinition) == -1) {
|
|
|
|
toolDefinition.visibilityswitch = "devtools." + toolId + ".enabled";
|
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
this._tools.set(toolId, toolDefinition);
|
|
|
|
|
|
|
|
this.emit("tool-registered", toolId);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all tools that match the given |toolId|
|
|
|
|
* Needed so that add-ons can remove themselves when they are deactivated
|
|
|
|
*
|
2013-04-19 13:44:38 +00:00
|
|
|
* @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.
|
2013-01-11 12:16:24 +00:00
|
|
|
* @param {boolean} isQuitApplication
|
|
|
|
* true to indicate that the call is due to app quit, so we should not
|
|
|
|
* cause a cascade of costly events
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
2013-04-19 13:44:38 +00:00
|
|
|
unregisterTool: function DT_unregisterTool(tool, isQuitApplication) {
|
|
|
|
let toolId = null;
|
|
|
|
if (typeof tool == "string") {
|
|
|
|
toolId = tool;
|
|
|
|
tool = this._tools.get(tool);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
toolId = tool.id;
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
this._tools.delete(toolId);
|
|
|
|
|
2013-01-11 12:16:24 +00:00
|
|
|
if (!isQuitApplication) {
|
2013-04-19 13:44:38 +00:00
|
|
|
this.emit("tool-unregistered", tool);
|
2013-01-11 12:16:24 +00:00
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-04-30 16:58:04 +00:00
|
|
|
/**
|
|
|
|
* Sorting function used for sorting tools based on their ordinals.
|
|
|
|
*/
|
|
|
|
ordinalSort: function DT_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;
|
|
|
|
},
|
|
|
|
|
2013-04-15 12:34:48 +00:00
|
|
|
getDefaultTools: function DT_getDefaultTools() {
|
2013-04-30 16:58:04 +00:00
|
|
|
return devtools.defaultTools.sort(this.ordinalSort);
|
2013-04-15 12:34:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getAdditionalTools: function DT_getAdditionalTools() {
|
|
|
|
let tools = [];
|
|
|
|
for (let [key, value] of this._tools) {
|
2013-04-11 20:59:08 +00:00
|
|
|
if (devtools.defaultTools.indexOf(value) == -1) {
|
2013-04-15 12:34:48 +00:00
|
|
|
tools.push(value);
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 16:58:04 +00:00
|
|
|
return tools.sort(this.ordinalSort);
|
2013-04-15 12:34:48 +00:00
|
|
|
},
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
let tool = this._tools.get(toolId);
|
|
|
|
if (!tool) {
|
|
|
|
return null;
|
2013-11-18 20:12:02 +00:00
|
|
|
} else if (!tool.visibilityswitch) {
|
2013-09-23 20:36:44 +00:00
|
|
|
return tool;
|
|
|
|
}
|
|
|
|
|
|
|
|
let enabled;
|
|
|
|
try {
|
|
|
|
enabled = Services.prefs.getBoolPref(tool.visibilityswitch);
|
|
|
|
} catch (e) {
|
|
|
|
enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return enabled ? tool : null;
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2013-01-11 12:16:31 +00:00
|
|
|
getToolDefinitionMap: function DT_getToolDefinitionMap() {
|
2012-11-30 08:07:59 +00:00
|
|
|
let tools = new Map();
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
for (let [id, definition] of this._tools) {
|
|
|
|
if (this.getToolDefinition(id)) {
|
|
|
|
tools.set(id, definition);
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-23 20:36:44 +00:00
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
return tools;
|
|
|
|
},
|
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
let definitions = [];
|
2013-09-23 20:36:44 +00:00
|
|
|
|
|
|
|
for (let [id, definition] of this._tools) {
|
|
|
|
if (this.getToolDefinition(id)) {
|
|
|
|
definitions.push(definition);
|
|
|
|
}
|
2013-01-11 12:16:31 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 16:58:04 +00:00
|
|
|
return definitions.sort(this.ordinalSort);
|
2013-01-11 12:16:31 +00:00
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
2012-12-13 13:03:55 +00:00
|
|
|
* Show a Toolbox for a target (either by creating a new one, or if a toolbox
|
|
|
|
* already exists for the target, by bring to the front the existing one)
|
|
|
|
* If |toolId| is specified then the displayed toolbox will have the
|
|
|
|
* specified tool selected.
|
|
|
|
* If |hostType| is specified then the toolbox will be displayed using the
|
|
|
|
* specified HostType.
|
2012-11-30 08:07:59 +00:00
|
|
|
*
|
|
|
|
* @param {Target} target
|
|
|
|
* The target the toolbox will debug
|
2012-12-13 13:03:55 +00:00
|
|
|
* @param {string} toolId
|
|
|
|
* The id of the tool to show
|
2012-11-30 08:07:59 +00:00
|
|
|
* @param {Toolbox.HostType} hostType
|
2012-12-13 13:03:55 +00:00
|
|
|
* The type of host (bottom, window, side)
|
2013-11-16 02:47:00 +00:00
|
|
|
* @param {object} hostOptions
|
|
|
|
* Options for host specifically
|
2012-11-30 08:07:59 +00:00
|
|
|
*
|
|
|
|
* @return {Toolbox} toolbox
|
|
|
|
* The toolbox that was opened
|
|
|
|
*/
|
2013-11-16 02:47:00 +00:00
|
|
|
showToolbox: function(target, toolId, hostType, hostOptions) {
|
2013-07-11 07:12:20 +00:00
|
|
|
let deferred = promise.defer();
|
2012-12-13 13:03:55 +00:00
|
|
|
|
|
|
|
let toolbox = this._toolboxes.get(target);
|
|
|
|
if (toolbox) {
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-07-11 07:12:20 +00:00
|
|
|
let hostPromise = (hostType != null && toolbox.hostType != hostType) ?
|
2012-12-13 13:03:55 +00:00
|
|
|
toolbox.switchHost(hostType) :
|
2013-07-11 07:12:20 +00:00
|
|
|
promise.resolve(null);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
if (toolId != null && toolbox.currentToolId != toolId) {
|
2013-07-11 07:12:20 +00:00
|
|
|
hostPromise = hostPromise.then(function() {
|
2012-12-13 13:03:55 +00:00
|
|
|
return toolbox.selectTool(toolId);
|
|
|
|
});
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-07-11 07:12:20 +00:00
|
|
|
return hostPromise.then(function() {
|
2013-01-09 09:32:35 +00:00
|
|
|
toolbox.raise();
|
2012-12-13 13:03:55 +00:00
|
|
|
return toolbox;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// No toolbox for target, create one
|
2013-11-16 02:47:00 +00:00
|
|
|
toolbox = new devtools.Toolbox(target, toolId, hostType, hostOptions);
|
2012-12-13 13:03:55 +00:00
|
|
|
|
|
|
|
this._toolboxes.set(target, toolbox);
|
|
|
|
|
2014-06-14 10:49:00 +00:00
|
|
|
toolbox.once("destroyed", () => {
|
2012-12-13 13:03:55 +00:00
|
|
|
this._toolboxes.delete(target);
|
|
|
|
this.emit("toolbox-destroyed", target);
|
2014-06-14 10:49:00 +00:00
|
|
|
});
|
2012-12-13 13:03:55 +00:00
|
|
|
|
|
|
|
// If we were asked for a specific tool then we need to wait for the
|
|
|
|
// tool to be ready, otherwise we can just wait for toolbox open
|
|
|
|
if (toolId != null) {
|
2014-06-14 10:49:00 +00:00
|
|
|
toolbox.once(toolId + "-ready", (event, panel) => {
|
2012-12-13 13:03:55 +00:00
|
|
|
this.emit("toolbox-ready", toolbox);
|
|
|
|
deferred.resolve(toolbox);
|
2014-06-14 10:49:00 +00:00
|
|
|
});
|
2012-12-13 13:03:55 +00:00
|
|
|
toolbox.open();
|
|
|
|
}
|
|
|
|
else {
|
2014-06-14 10:49:00 +00:00
|
|
|
toolbox.open().then(() => {
|
2012-12-13 13:03:55 +00:00
|
|
|
deferred.resolve(toolbox);
|
|
|
|
this.emit("toolbox-ready", toolbox);
|
2014-06-14 10:49:00 +00:00
|
|
|
});
|
2012-12-13 13:03:55 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
return deferred.promise;
|
|
|
|
},
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
/**
|
|
|
|
* Return the toolbox for a given target.
|
|
|
|
*
|
|
|
|
* @param {object} target
|
|
|
|
* Target value e.g. the target that owns this toolbox
|
|
|
|
*
|
|
|
|
* @return {Toolbox} toolbox
|
|
|
|
* The toobox that is debugging the given target
|
|
|
|
*/
|
|
|
|
getToolbox: function DT_getToolbox(target) {
|
|
|
|
return this._toolboxes.get(target);
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the toolbox for a given target
|
2014-04-11 21:47:22 +00:00
|
|
|
*
|
|
|
|
* @return promise
|
|
|
|
* This promise will resolve to false if no toolbox was found
|
|
|
|
* associated to the target. true, if the toolbox was successfuly
|
|
|
|
* closed.
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
|
|
|
closeToolbox: function DT_closeToolbox(target) {
|
|
|
|
let toolbox = this._toolboxes.get(target);
|
|
|
|
if (toolbox == null) {
|
2014-04-11 21:47:22 +00:00
|
|
|
return promise.resolve(false);
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
2014-04-11 21:47:22 +00:00
|
|
|
return toolbox.destroy().then(() => true);
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-04-11 20:59:08 +00:00
|
|
|
/**
|
|
|
|
* Called to tear down a tools provider.
|
|
|
|
*/
|
|
|
|
_teardown: function DT_teardown() {
|
|
|
|
for (let [target, toolbox] of this._toolboxes) {
|
|
|
|
toolbox.destroy();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
2012-12-13 13:03:55 +00:00
|
|
|
* All browser windows have been closed, tidy up remaining objects.
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
2012-12-13 13:03:55 +00:00
|
|
|
destroy: function() {
|
|
|
|
Services.obs.removeObserver(this.destroy, "quit-application");
|
2013-05-29 17:47:38 +00:00
|
|
|
Services.obs.removeObserver(this._teardown, "devtools-unloaded");
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-05-04 06:31:07 +00:00
|
|
|
for (let [key, tool] of this.getToolDefinitionMap()) {
|
2013-01-11 12:16:24 +00:00
|
|
|
this.unregisterTool(key, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleaning down the toolboxes: i.e.
|
|
|
|
// for (let [target, toolbox] of this._toolboxes) toolbox.destroy();
|
|
|
|
// Is taken care of by the gDevToolsBrowser.forgetBrowserWindow
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
2013-10-04 19:44:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterator that yields each of the toolboxes.
|
|
|
|
*/
|
|
|
|
'@@iterator': function*() {
|
|
|
|
for (let toolbox of this._toolboxes) {
|
|
|
|
yield toolbox;
|
|
|
|
}
|
|
|
|
}
|
2012-12-13 13:03:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gDevTools is a singleton that controls the Firefox Developer Tools.
|
|
|
|
*
|
|
|
|
* It is an instance of a DevTools class that holds a set of tools. It has the
|
|
|
|
* same lifetime as the browser.
|
|
|
|
*/
|
|
|
|
let gDevTools = new DevTools();
|
|
|
|
this.gDevTools = gDevTools;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gDevToolsBrowser exposes functions to connect the gDevTools instance with a
|
|
|
|
* Firefox instance.
|
|
|
|
*/
|
|
|
|
let gDevToolsBrowser = {
|
|
|
|
/**
|
|
|
|
* A record of the windows whose menus we altered, so we can undo the changes
|
|
|
|
* as the window is closed
|
|
|
|
*/
|
|
|
|
_trackedBrowserWindows: new Set(),
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-09 09:32:35 +00:00
|
|
|
* This function is for the benefit of Tools:DevToolbox in
|
2012-11-30 08:07:59 +00:00
|
|
|
* browser/base/content/browser-sets.inc and should not be used outside
|
|
|
|
* of there
|
|
|
|
*/
|
2013-01-09 09:32:35 +00:00
|
|
|
toggleToolboxCommand: function(gBrowser) {
|
2013-04-11 20:59:08 +00:00
|
|
|
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
|
2012-12-13 13:03:55 +00:00
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-01-09 09:32:35 +00:00
|
|
|
toolbox ? toolbox.destroy() : gDevTools.showToolbox(target);
|
|
|
|
},
|
|
|
|
|
2013-04-11 20:59:08 +00:00
|
|
|
toggleBrowserToolboxCommand: function(gBrowser) {
|
|
|
|
let target = devtools.TargetFactory.forWindow(gBrowser.ownerDocument.defaultView);
|
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
|
|
|
|
|
|
|
toolbox ? toolbox.destroy()
|
|
|
|
: gDevTools.showToolbox(target, "inspector", Toolbox.HostType.WINDOW);
|
|
|
|
},
|
|
|
|
|
2013-09-19 07:10:42 +00:00
|
|
|
/**
|
|
|
|
* This function ensures the right commands are enabled in a window,
|
|
|
|
* depending on their relevant prefs. It gets run when a window is registered,
|
|
|
|
* or when any of the devtools prefs change.
|
|
|
|
*/
|
|
|
|
updateCommandAvailability: function(win) {
|
|
|
|
let doc = win.document;
|
|
|
|
|
|
|
|
function toggleCmd(id, isEnabled) {
|
|
|
|
let cmd = doc.getElementById(id);
|
|
|
|
if (isEnabled) {
|
|
|
|
cmd.removeAttribute("disabled");
|
|
|
|
cmd.removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
cmd.setAttribute("disabled", "true");
|
|
|
|
cmd.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Enable developer toolbar?
|
|
|
|
let devToolbarEnabled = Services.prefs.getBoolPref("devtools.toolbar.enabled");
|
|
|
|
toggleCmd("Tools:DevToolbar", devToolbarEnabled);
|
|
|
|
let focusEl = doc.getElementById("Tools:DevToolbarFocus");
|
|
|
|
if (devToolbarEnabled) {
|
|
|
|
focusEl.removeAttribute("disabled");
|
|
|
|
} else {
|
|
|
|
focusEl.setAttribute("disabled", "true");
|
|
|
|
}
|
|
|
|
if (devToolbarEnabled && Services.prefs.getBoolPref("devtools.toolbar.visible")) {
|
|
|
|
win.DeveloperToolbar.show(false);
|
|
|
|
}
|
|
|
|
|
2014-06-23 09:36:11 +00:00
|
|
|
// Enable WebIDE?
|
|
|
|
let webIDEEnabled = Services.prefs.getBoolPref("devtools.webide.enabled");
|
|
|
|
toggleCmd("Tools:WebIDE", webIDEEnabled);
|
|
|
|
|
2013-09-19 07:10:42 +00:00
|
|
|
// Enable App Manager?
|
|
|
|
let appMgrEnabled = Services.prefs.getBoolPref("devtools.appmanager.enabled");
|
2014-06-23 09:36:11 +00:00
|
|
|
toggleCmd("Tools:DevAppMgr", !webIDEEnabled && appMgrEnabled);
|
2013-09-19 07:10:42 +00:00
|
|
|
|
2013-12-02 08:28:01 +00:00
|
|
|
// Enable Browser Toolbox?
|
2013-09-19 07:10:42 +00:00
|
|
|
let chromeEnabled = Services.prefs.getBoolPref("devtools.chrome.enabled");
|
|
|
|
let devtoolsRemoteEnabled = Services.prefs.getBoolPref("devtools.debugger.remote-enabled");
|
|
|
|
let remoteEnabled = chromeEnabled && devtoolsRemoteEnabled &&
|
|
|
|
Services.prefs.getBoolPref("devtools.debugger.chrome-enabled");
|
2013-12-02 08:28:01 +00:00
|
|
|
toggleCmd("Tools:BrowserToolbox", remoteEnabled);
|
2013-09-19 07:10:42 +00:00
|
|
|
|
|
|
|
// Enable Error Console?
|
|
|
|
let consoleEnabled = Services.prefs.getBoolPref("devtools.errorconsole.enabled");
|
|
|
|
toggleCmd("Tools:ErrorConsole", consoleEnabled);
|
|
|
|
|
|
|
|
// Enable DevTools connection screen, if the preference allows this.
|
|
|
|
toggleCmd("Tools:DevToolsConnect", devtoolsRemoteEnabled);
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function(subject, topic, prefName) {
|
|
|
|
if (prefName.endsWith("enabled")) {
|
|
|
|
for (let win of this._trackedBrowserWindows) {
|
|
|
|
this.updateCommandAvailability(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_prefObserverRegistered: false,
|
|
|
|
|
|
|
|
ensurePrefObserver: function() {
|
|
|
|
if (!this._prefObserverRegistered) {
|
|
|
|
this._prefObserverRegistered = true;
|
|
|
|
Services.prefs.addObserver("devtools.", this, false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2013-01-09 09:32:35 +00:00
|
|
|
/**
|
|
|
|
* This function is for the benefit of Tools:{toolId} commands,
|
|
|
|
* triggered from the WebDeveloper menu and keyboard shortcuts.
|
|
|
|
*
|
|
|
|
* selectToolCommand's behavior:
|
|
|
|
* - if the toolbox is closed,
|
|
|
|
* we open the toolbox and select the tool
|
|
|
|
* - if the toolbox is open, and the targetted tool is not selected,
|
|
|
|
* we select it
|
|
|
|
* - if the toolbox is open, and the targetted tool is selected,
|
|
|
|
* and the host is NOT a window, we close the toolbox
|
|
|
|
* - if the toolbox is open, and the targetted tool is selected,
|
|
|
|
* and the host is a window, we raise the toolbox window
|
|
|
|
*/
|
|
|
|
selectToolCommand: function(gBrowser, toolId) {
|
2013-04-11 20:59:08 +00:00
|
|
|
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
|
2013-01-09 09:32:35 +00:00
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
2013-09-23 20:36:44 +00:00
|
|
|
let toolDefinition = gDevTools.getToolDefinition(toolId);
|
2013-01-09 09:32:35 +00:00
|
|
|
|
2014-02-07 13:56:00 +00:00
|
|
|
if (toolbox &&
|
|
|
|
(toolbox.currentToolId == toolId ||
|
|
|
|
(toolId == "webconsole" && toolbox.splitConsole)))
|
|
|
|
{
|
2013-08-02 18:28:37 +00:00
|
|
|
toolbox.fireCustomKey(toolId);
|
|
|
|
|
|
|
|
if (toolDefinition.preventClosingOnKey || toolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
|
2013-01-09 09:32:35 +00:00
|
|
|
toolbox.raise();
|
|
|
|
} else {
|
|
|
|
toolbox.destroy();
|
|
|
|
}
|
2014-06-12 16:03:00 +00:00
|
|
|
gDevTools.emit("select-tool-command", toolId);
|
2013-01-09 09:32:35 +00:00
|
|
|
} else {
|
2013-08-02 18:28:37 +00:00
|
|
|
gDevTools.showToolbox(target, toolId).then(() => {
|
|
|
|
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
|
|
|
|
let toolbox = gDevTools.getToolbox(target);
|
|
|
|
|
|
|
|
toolbox.fireCustomKey(toolId);
|
2014-06-12 16:03:00 +00:00
|
|
|
gDevTools.emit("select-tool-command", toolId);
|
2013-08-02 18:28:37 +00:00
|
|
|
});
|
2013-01-09 09:32:35 +00:00
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-12-13 13:03:55 +00:00
|
|
|
* Open a tab to allow connects to a remote browser
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
2012-12-13 13:03:55 +00:00
|
|
|
openConnectScreen: function(gBrowser) {
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab("chrome://browser/content/devtools/connect.xhtml");
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-09-05 05:37:00 +00:00
|
|
|
/**
|
|
|
|
* Open the App Manager
|
|
|
|
*/
|
|
|
|
openAppManager: function(gBrowser) {
|
2014-06-23 09:36:11 +00:00
|
|
|
gBrowser.selectedTab = gBrowser.addTab("about:app-manager");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open WebIDE
|
|
|
|
*/
|
|
|
|
openWebIDE: function() {
|
|
|
|
let win = Services.wm.getMostRecentWindow("devtools:webide");
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
2014-05-12 06:53:00 +00:00
|
|
|
} else {
|
2014-06-23 09:36:11 +00:00
|
|
|
let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher);
|
|
|
|
ww.openWindow(null, "chrome://webide/content/", "webide", "chrome,centerscreen,resizable", null);
|
2014-05-12 06:53:00 +00:00
|
|
|
}
|
2013-09-05 05:37:00 +00:00
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Add this DevTools's presence to a browser window's document
|
|
|
|
*
|
2012-12-13 13:03:55 +00:00
|
|
|
* @param {XULDocument} doc
|
|
|
|
* The document to which menuitems and handlers are to be added
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
|
|
|
registerBrowserWindow: function DT_registerBrowserWindow(win) {
|
2013-09-19 07:10:42 +00:00
|
|
|
this.updateCommandAvailability(win);
|
|
|
|
this.ensurePrefObserver();
|
2012-12-13 13:03:55 +00:00
|
|
|
gDevToolsBrowser._trackedBrowserWindows.add(win);
|
|
|
|
gDevToolsBrowser._addAllToolsToMenu(win.document);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-08-03 16:34:05 +00:00
|
|
|
if (this._isFirebugInstalled()) {
|
|
|
|
let broadcaster = win.document.getElementById("devtoolsMenuBroadcaster_DevToolbox");
|
|
|
|
broadcaster.removeAttribute("key");
|
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
let tabContainer = win.document.getElementById("tabbrowser-tabs")
|
2012-12-13 13:03:55 +00:00
|
|
|
tabContainer.addEventListener("TabSelect",
|
|
|
|
gDevToolsBrowser._updateMenuCheckbox, false);
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-01-22 18:10:21 +00:00
|
|
|
/**
|
|
|
|
* Add a <key> to <keyset id="devtoolsKeyset">.
|
|
|
|
* Appending a <key> element is not always enough. The <keyset> needs
|
|
|
|
* to be detached and reattached to make sure the <key> is taken into
|
|
|
|
* account (see bug 832984).
|
|
|
|
*
|
|
|
|
* @param {XULDocument} doc
|
|
|
|
* The document to which keys are to be added
|
|
|
|
* @param {XULElement} or {DocumentFragment} keys
|
|
|
|
* Keys to add
|
|
|
|
*/
|
|
|
|
attachKeybindingsToBrowser: function DT_attachKeybindingsToBrowser(doc, keys) {
|
|
|
|
let devtoolsKeyset = doc.getElementById("devtoolsKeyset");
|
2013-08-03 16:34:05 +00:00
|
|
|
|
2013-01-22 18:10:21 +00:00
|
|
|
if (!devtoolsKeyset) {
|
|
|
|
devtoolsKeyset = doc.createElement("keyset");
|
|
|
|
devtoolsKeyset.setAttribute("id", "devtoolsKeyset");
|
|
|
|
}
|
|
|
|
devtoolsKeyset.appendChild(keys);
|
|
|
|
let mainKeyset = doc.getElementById("mainKeyset");
|
|
|
|
mainKeyset.parentNode.insertBefore(devtoolsKeyset, mainKeyset);
|
|
|
|
},
|
|
|
|
|
2014-05-21 01:27:25 +00:00
|
|
|
/**
|
|
|
|
* Hook the JS debugger tool to the "Debug Script" button of the slow script
|
|
|
|
* dialog.
|
|
|
|
*/
|
|
|
|
setSlowScriptDebugHandler: function DT_setSlowScriptDebugHandler() {
|
|
|
|
let debugService = Cc["@mozilla.org/dom/slow-script-debug;1"]
|
|
|
|
.getService(Ci.nsISlowScriptDebug);
|
|
|
|
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
|
|
|
|
|
|
|
|
debugService.activationHandler = function(aWindow) {
|
|
|
|
let chromeWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
|
|
let target = devtools.TargetFactory.forTab(chromeWindow.gBrowser.selectedTab);
|
|
|
|
|
|
|
|
let setupFinished = false;
|
|
|
|
gDevTools.showToolbox(target, "jsdebugger").then(toolbox => {
|
|
|
|
let threadClient = toolbox.getCurrentPanel().panelWin.gThreadClient;
|
|
|
|
|
|
|
|
// Break in place, which means resuming the debuggee thread and pausing
|
|
|
|
// right before the next step happens.
|
|
|
|
switch (threadClient.state) {
|
|
|
|
case "paused":
|
|
|
|
// When the debugger is already paused.
|
|
|
|
threadClient.breakOnNext();
|
|
|
|
setupFinished = true;
|
|
|
|
break;
|
|
|
|
case "attached":
|
|
|
|
// When the debugger is already open.
|
|
|
|
threadClient.interrupt(() => {
|
|
|
|
threadClient.breakOnNext();
|
|
|
|
setupFinished = true;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "resuming":
|
|
|
|
// The debugger is newly opened.
|
|
|
|
threadClient.addOneTimeListener("resumed", () => {
|
|
|
|
threadClient.interrupt(() => {
|
|
|
|
threadClient.breakOnNext();
|
|
|
|
setupFinished = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw Error("invalid thread client state in slow script debug handler: " +
|
|
|
|
threadClient.state);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't return from the interrupt handler until the debugger is brought
|
|
|
|
// up; no reason to continue executing the slow script.
|
|
|
|
let utils = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
utils.enterModalState();
|
|
|
|
while (!setupFinished) {
|
|
|
|
tm.currentThread.processNextEvent(true);
|
|
|
|
}
|
|
|
|
utils.leaveModalState();
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unset the slow script debug handler.
|
|
|
|
*/
|
|
|
|
unsetSlowScriptDebugHandler: function DT_unsetSlowScriptDebugHandler() {
|
|
|
|
let debugService = Cc["@mozilla.org/dom/slow-script-debug;1"]
|
|
|
|
.getService(Ci.nsISlowScriptDebug);
|
|
|
|
debugService.activationHandler = undefined;
|
|
|
|
},
|
2013-08-03 16:34:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Detect the presence of a Firebug.
|
|
|
|
*
|
|
|
|
* @return promise
|
|
|
|
*/
|
|
|
|
_isFirebugInstalled: function DT_isFirebugInstalled() {
|
|
|
|
let bootstrappedAddons = Services.prefs.getCharPref("extensions.bootstrappedAddons");
|
|
|
|
return bootstrappedAddons.indexOf("firebug@software.joehewitt.com") != -1;
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
2013-05-04 06:31:07 +00:00
|
|
|
* Add the menuitem for a tool to all open browser windows.
|
2012-11-30 08:07:59 +00:00
|
|
|
*
|
|
|
|
* @param {object} toolDefinition
|
|
|
|
* properties of the tool to add
|
|
|
|
*/
|
|
|
|
_addToolToWindows: function DT_addToolToWindows(toolDefinition) {
|
2013-05-04 06:31:07 +00:00
|
|
|
// No menu item or global shortcut is required for options panel.
|
2013-10-09 18:47:00 +00:00
|
|
|
if (!toolDefinition.inMenu) {
|
2013-05-04 06:31:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip if the tool is disabled.
|
|
|
|
try {
|
2013-11-18 20:12:02 +00:00
|
|
|
if (toolDefinition.visibilityswitch &&
|
|
|
|
!Services.prefs.getBoolPref(toolDefinition.visibilityswitch)) {
|
2013-05-04 06:31:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} catch(e) {}
|
2013-04-19 13:44:38 +00:00
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
// We need to insert the new tool in the right place, which means knowing
|
|
|
|
// the tool that comes before the tool that we're trying to add
|
|
|
|
let allDefs = gDevTools.getToolDefinitionArray();
|
|
|
|
let prevDef;
|
|
|
|
for (let def of allDefs) {
|
2013-10-09 18:47:00 +00:00
|
|
|
if (!def.inMenu) {
|
2013-05-29 17:47:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-01-11 12:16:31 +00:00
|
|
|
if (def === toolDefinition) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevDef = def;
|
|
|
|
}
|
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
for (let win of gDevToolsBrowser._trackedBrowserWindows) {
|
2013-01-11 12:16:31 +00:00
|
|
|
let doc = win.document;
|
|
|
|
let elements = gDevToolsBrowser._createToolMenuElements(toolDefinition, doc);
|
|
|
|
|
|
|
|
doc.getElementById("mainCommandSet").appendChild(elements.cmd);
|
|
|
|
|
|
|
|
if (elements.key) {
|
2013-02-10 16:40:37 +00:00
|
|
|
this.attachKeybindingsToBrowser(doc, elements.key);
|
2013-01-11 12:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc.getElementById("mainBroadcasterSet").appendChild(elements.bc);
|
|
|
|
|
|
|
|
let amp = doc.getElementById("appmenu_webDeveloper_popup");
|
|
|
|
if (amp) {
|
2013-05-24 10:26:17 +00:00
|
|
|
let ref;
|
|
|
|
|
|
|
|
if (prevDef != null) {
|
|
|
|
let menuitem = doc.getElementById("appmenuitem_" + prevDef.id);
|
|
|
|
ref = menuitem && menuitem.nextSibling ? menuitem.nextSibling : null;
|
|
|
|
} else {
|
|
|
|
ref = doc.getElementById("appmenu_devtools_separator");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref) {
|
|
|
|
amp.insertBefore(elements.appmenuitem, ref);
|
|
|
|
}
|
2013-01-11 12:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let mp = doc.getElementById("menuWebDeveloperPopup");
|
2013-05-24 10:26:17 +00:00
|
|
|
if (mp) {
|
|
|
|
let ref;
|
|
|
|
|
|
|
|
if (prevDef != null) {
|
|
|
|
let menuitem = doc.getElementById("menuitem_" + prevDef.id);
|
|
|
|
ref = menuitem && menuitem.nextSibling ? menuitem.nextSibling : null;
|
|
|
|
} else {
|
|
|
|
ref = doc.getElementById("menu_devtools_separator");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref) {
|
|
|
|
mp.insertBefore(elements.menuitem, ref);
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
2014-05-21 01:27:25 +00:00
|
|
|
|
|
|
|
if (toolDefinition.id === "jsdebugger") {
|
|
|
|
gDevToolsBrowser.setSlowScriptDebugHandler();
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add all tools to the developer tools menu of a window.
|
|
|
|
*
|
|
|
|
* @param {XULDocument} doc
|
|
|
|
* The document to which the tool items are to be added.
|
|
|
|
*/
|
|
|
|
_addAllToolsToMenu: function DT_addAllToolsToMenu(doc) {
|
|
|
|
let fragCommands = doc.createDocumentFragment();
|
|
|
|
let fragKeys = doc.createDocumentFragment();
|
|
|
|
let fragBroadcasters = doc.createDocumentFragment();
|
|
|
|
let fragAppMenuItems = doc.createDocumentFragment();
|
|
|
|
let fragMenuItems = doc.createDocumentFragment();
|
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
for (let toolDefinition of gDevTools.getToolDefinitionArray()) {
|
2013-10-09 18:47:00 +00:00
|
|
|
if (!toolDefinition.inMenu) {
|
2013-05-04 06:31:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
let elements = gDevToolsBrowser._createToolMenuElements(toolDefinition, doc);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
if (!elements) {
|
2012-11-30 08:07:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
fragCommands.appendChild(elements.cmd);
|
|
|
|
if (elements.key) {
|
|
|
|
fragKeys.appendChild(elements.key);
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
2013-01-11 12:16:31 +00:00
|
|
|
fragBroadcasters.appendChild(elements.bc);
|
|
|
|
fragAppMenuItems.appendChild(elements.appmenuitem);
|
|
|
|
fragMenuItems.appendChild(elements.menuitem);
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let mcs = doc.getElementById("mainCommandSet");
|
|
|
|
mcs.appendChild(fragCommands);
|
|
|
|
|
2013-01-22 18:10:21 +00:00
|
|
|
this.attachKeybindingsToBrowser(doc, fragKeys);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
let mbs = doc.getElementById("mainBroadcasterSet");
|
|
|
|
mbs.appendChild(fragBroadcasters);
|
|
|
|
|
|
|
|
let amp = doc.getElementById("appmenu_webDeveloper_popup");
|
|
|
|
if (amp) {
|
|
|
|
let amps = doc.getElementById("appmenu_devtools_separator");
|
|
|
|
amp.insertBefore(fragAppMenuItems, amps);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mp = doc.getElementById("menuWebDeveloperPopup");
|
|
|
|
let mps = doc.getElementById("menu_devtools_separator");
|
|
|
|
mp.insertBefore(fragMenuItems, mps);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a menu entry for a tool definition
|
|
|
|
*
|
|
|
|
* @param {string} toolDefinition
|
|
|
|
* Tool definition of the tool to add a menu entry.
|
|
|
|
* @param {XULDocument} doc
|
|
|
|
* The document to which the tool menu item is to be added.
|
|
|
|
*/
|
2013-01-11 12:16:31 +00:00
|
|
|
_createToolMenuElements: function DT_createToolMenuElements(toolDefinition, doc) {
|
2012-11-30 08:07:59 +00:00
|
|
|
let id = toolDefinition.id;
|
|
|
|
|
|
|
|
// Prevent multiple entries for the same tool.
|
|
|
|
if (doc.getElementById("Tools:" + id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let cmd = doc.createElement("command");
|
|
|
|
cmd.id = "Tools:" + id;
|
|
|
|
cmd.setAttribute("oncommand",
|
2013-01-09 09:32:35 +00:00
|
|
|
'gDevToolsBrowser.selectToolCommand(gBrowser, "' + id + '");');
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
let key = null;
|
|
|
|
if (toolDefinition.key) {
|
|
|
|
key = doc.createElement("key");
|
|
|
|
key.id = "key_" + id;
|
|
|
|
|
|
|
|
if (toolDefinition.key.startsWith("VK_")) {
|
|
|
|
key.setAttribute("keycode", toolDefinition.key);
|
|
|
|
} else {
|
|
|
|
key.setAttribute("key", toolDefinition.key);
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:32:35 +00:00
|
|
|
key.setAttribute("command", cmd.id);
|
2012-11-30 08:07:59 +00:00
|
|
|
key.setAttribute("modifiers", toolDefinition.modifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
let bc = doc.createElement("broadcaster");
|
|
|
|
bc.id = "devtoolsMenuBroadcaster_" + id;
|
2013-05-10 22:27:16 +00:00
|
|
|
bc.setAttribute("label", toolDefinition.menuLabel || toolDefinition.label);
|
2013-01-09 09:32:35 +00:00
|
|
|
bc.setAttribute("command", cmd.id);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
if (key) {
|
|
|
|
bc.setAttribute("key", "key_" + id);
|
|
|
|
}
|
|
|
|
|
|
|
|
let appmenuitem = doc.createElement("menuitem");
|
|
|
|
appmenuitem.id = "appmenuitem_" + id;
|
|
|
|
appmenuitem.setAttribute("observes", "devtoolsMenuBroadcaster_" + id);
|
|
|
|
|
|
|
|
let menuitem = doc.createElement("menuitem");
|
|
|
|
menuitem.id = "menuitem_" + id;
|
|
|
|
menuitem.setAttribute("observes", "devtoolsMenuBroadcaster_" + id);
|
|
|
|
|
|
|
|
if (toolDefinition.accesskey) {
|
|
|
|
menuitem.setAttribute("accesskey", toolDefinition.accesskey);
|
|
|
|
}
|
|
|
|
|
2013-01-11 12:16:31 +00:00
|
|
|
return {
|
|
|
|
cmd: cmd,
|
|
|
|
key: key,
|
|
|
|
bc: bc,
|
|
|
|
appmenuitem: appmenuitem,
|
|
|
|
menuitem: menuitem
|
|
|
|
};
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-12-17 19:01:31 +00:00
|
|
|
* Update the "Toggle Tools" checkbox in the developer tools menu. This is
|
2012-11-30 08:07:59 +00:00
|
|
|
* called when a toolbox is created or destroyed.
|
|
|
|
*/
|
|
|
|
_updateMenuCheckbox: function DT_updateMenuCheckbox() {
|
2012-12-13 13:03:55 +00:00
|
|
|
for (let win of gDevToolsBrowser._trackedBrowserWindows) {
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
let hasToolbox = false;
|
2013-04-11 20:59:08 +00:00
|
|
|
if (devtools.TargetFactory.isKnownTab(win.gBrowser.selectedTab)) {
|
|
|
|
let target = devtools.TargetFactory.forTab(win.gBrowser.selectedTab);
|
2012-12-13 13:03:55 +00:00
|
|
|
if (gDevTools._toolboxes.has(target)) {
|
2012-11-30 08:07:59 +00:00
|
|
|
hasToolbox = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let broadcaster = win.document.getElementById("devtoolsMenuBroadcaster_DevToolbox");
|
|
|
|
if (hasToolbox) {
|
|
|
|
broadcaster.setAttribute("checked", "true");
|
|
|
|
} else {
|
|
|
|
broadcaster.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-05-14 22:25:28 +00:00
|
|
|
/**
|
|
|
|
* Connects to the SPS profiler when the developer tools are open.
|
|
|
|
*/
|
|
|
|
_connectToProfiler: function DT_connectToProfiler() {
|
2014-04-03 08:19:31 +00:00
|
|
|
let ProfilerController = devtools.require("devtools/profiler/controller");
|
|
|
|
|
2013-05-14 22:25:28 +00:00
|
|
|
for (let win of gDevToolsBrowser._trackedBrowserWindows) {
|
|
|
|
if (devtools.TargetFactory.isKnownTab(win.gBrowser.selectedTab)) {
|
|
|
|
let target = devtools.TargetFactory.forTab(win.gBrowser.selectedTab);
|
|
|
|
if (gDevTools._toolboxes.has(target)) {
|
|
|
|
target.makeRemote().then(() => {
|
|
|
|
let profiler = new ProfilerController(target);
|
|
|
|
profiler.connect();
|
|
|
|
}).then(null, Cu.reportError);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
2013-05-04 06:31:07 +00:00
|
|
|
* Remove the menuitem for a tool to all open browser windows.
|
2012-11-30 08:07:59 +00:00
|
|
|
*
|
2013-05-04 06:31:07 +00:00
|
|
|
* @param {string} toolId
|
2012-11-30 08:07:59 +00:00
|
|
|
* id of the tool to remove
|
|
|
|
*/
|
2013-05-04 06:31:07 +00:00
|
|
|
_removeToolFromWindows: function DT_removeToolFromWindows(toolId) {
|
2012-12-13 13:03:55 +00:00
|
|
|
for (let win of gDevToolsBrowser._trackedBrowserWindows) {
|
|
|
|
gDevToolsBrowser._removeToolFromMenu(toolId, win.document);
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
2014-05-21 01:27:25 +00:00
|
|
|
|
|
|
|
if (toolId === "jsdebugger") {
|
|
|
|
gDevToolsBrowser.unsetSlowScriptDebugHandler();
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a tool's menuitem from a window
|
|
|
|
*
|
|
|
|
* @param {string} toolId
|
|
|
|
* Id of the tool to add a menu entry for
|
|
|
|
* @param {XULDocument} doc
|
|
|
|
* The document to which the tool menu item is to be removed from
|
|
|
|
*/
|
|
|
|
_removeToolFromMenu: function DT_removeToolFromMenu(toolId, doc) {
|
|
|
|
let command = doc.getElementById("Tools:" + toolId);
|
2013-01-05 00:21:27 +00:00
|
|
|
if (command) {
|
|
|
|
command.parentNode.removeChild(command);
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
let key = doc.getElementById("key_" + toolId);
|
|
|
|
if (key) {
|
|
|
|
key.parentNode.removeChild(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
let bc = doc.getElementById("devtoolsMenuBroadcaster_" + toolId);
|
2013-01-05 00:21:27 +00:00
|
|
|
if (bc) {
|
|
|
|
bc.parentNode.removeChild(bc);
|
|
|
|
}
|
|
|
|
|
|
|
|
let appmenuitem = doc.getElementById("appmenuitem_" + toolId);
|
|
|
|
if (appmenuitem) {
|
|
|
|
appmenuitem.parentNode.removeChild(appmenuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
let menuitem = doc.getElementById("menuitem_" + toolId);
|
|
|
|
if (menuitem) {
|
|
|
|
menuitem.parentNode.removeChild(menuitem);
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on browser unload to remove menu entries, toolboxes and event
|
|
|
|
* listeners from the closed browser window.
|
|
|
|
*
|
|
|
|
* @param {XULWindow} win
|
|
|
|
* The window containing the menu entry
|
|
|
|
*/
|
|
|
|
forgetBrowserWindow: function DT_forgetBrowserWindow(win) {
|
2012-12-13 13:03:55 +00:00
|
|
|
gDevToolsBrowser._trackedBrowserWindows.delete(win);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
// Destroy toolboxes for closed window
|
2012-12-13 13:03:55 +00:00
|
|
|
for (let [target, toolbox] of gDevTools._toolboxes) {
|
2013-03-25 03:39:00 +00:00
|
|
|
if (toolbox.frame && toolbox.frame.ownerDocument.defaultView == win) {
|
2012-11-30 08:07:59 +00:00
|
|
|
toolbox.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabContainer = win.document.getElementById("tabbrowser-tabs")
|
|
|
|
tabContainer.removeEventListener("TabSelect",
|
2012-12-13 13:03:55 +00:00
|
|
|
gDevToolsBrowser._updateMenuCheckbox, false);
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All browser windows have been closed, tidy up remaining objects.
|
|
|
|
*/
|
|
|
|
destroy: function() {
|
2013-05-14 22:25:28 +00:00
|
|
|
gDevTools.off("toolbox-ready", gDevToolsBrowser._connectToProfiler);
|
2013-09-19 07:10:42 +00:00
|
|
|
Services.prefs.removeObserver("devtools.", gDevToolsBrowser);
|
2012-12-13 13:03:55 +00:00
|
|
|
Services.obs.removeObserver(gDevToolsBrowser.destroy, "quit-application");
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
2012-12-13 13:03:55 +00:00
|
|
|
}
|
2013-08-03 16:34:05 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
this.gDevToolsBrowser = gDevToolsBrowser;
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
gDevTools.on("tool-registered", function(ev, toolId) {
|
|
|
|
let toolDefinition = gDevTools._tools.get(toolId);
|
|
|
|
gDevToolsBrowser._addToolToWindows(toolDefinition);
|
|
|
|
});
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
gDevTools.on("tool-unregistered", function(ev, toolId) {
|
2013-05-04 06:31:07 +00:00
|
|
|
if (typeof toolId != "string") {
|
2013-04-19 13:44:38 +00:00
|
|
|
toolId = toolId.id;
|
|
|
|
}
|
2013-05-04 06:31:07 +00:00
|
|
|
gDevToolsBrowser._removeToolFromWindows(toolId);
|
2012-12-13 13:03:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gDevTools.on("toolbox-ready", gDevToolsBrowser._updateMenuCheckbox);
|
2013-05-14 22:25:28 +00:00
|
|
|
gDevTools.on("toolbox-ready", gDevToolsBrowser._connectToProfiler);
|
2012-12-13 13:03:55 +00:00
|
|
|
gDevTools.on("toolbox-destroyed", gDevToolsBrowser._updateMenuCheckbox);
|
|
|
|
|
|
|
|
Services.obs.addObserver(gDevToolsBrowser.destroy, "quit-application", false);
|
2013-04-11 20:59:08 +00:00
|
|
|
|
2013-05-01 16:27:24 +00:00
|
|
|
// Load the browser devtools main module as the loader's main module.
|
2013-05-29 17:48:06 +00:00
|
|
|
devtools.main("main");
|