2012-11-30 12:07:59 +04: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-04-30 20:58:04 +04:00
|
|
|
const MAX_ORDINAL = 99;
|
2013-09-15 10:26:18 +04:00
|
|
|
const ZOOM_PREF = "devtools.toolbox.zoomValue";
|
2014-07-29 00:54:41 +04:00
|
|
|
const SPLITCONSOLE_ENABLED_PREF = "devtools.toolbox.splitconsoleEnabled";
|
2014-07-31 21:33:23 +04:00
|
|
|
const SPLITCONSOLE_HEIGHT_PREF = "devtools.toolbox.splitconsoleHeight";
|
2013-09-15 10:26:18 +04:00
|
|
|
const MIN_ZOOM = 0.5;
|
|
|
|
const MAX_ZOOM = 2;
|
2015-03-13 14:52:45 +03:00
|
|
|
const OS_HISTOGRAM = "DEVTOOLS_OS_ENUMERATED_PER_USER";
|
|
|
|
const OS_IS_64_BITS = "DEVTOOLS_OS_IS_64_BITS_PER_USER";
|
|
|
|
const SCREENSIZE_HISTOGRAM = "DEVTOOLS_SCREEN_RESOLUTION_ENUMERATED_PER_USER";
|
2013-09-15 10:26:18 +04:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var {Cc, Ci, Cu} = require("chrome");
|
|
|
|
var promise = require("promise");
|
2015-09-21 20:04:18 +03:00
|
|
|
var EventEmitter = require("devtools/shared/event-emitter");
|
|
|
|
var Telemetry = require("devtools/client/shared/telemetry");
|
|
|
|
var HUDService = require("devtools/client/webconsole/hudservice");
|
|
|
|
var sourceUtils = require("devtools/client/shared/source-utils");
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2015-09-21 20:04:18 +03:00
|
|
|
Cu.import("resource:///modules/devtools/client/framework/gDevTools.jsm");
|
|
|
|
Cu.import("resource:///modules/devtools/client/scratchpad/scratchpad-manager.jsm");
|
|
|
|
Cu.import("resource:///modules/devtools/client/shared/DOMHelpers.jsm");
|
2014-02-05 23:50:25 +04:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyImporter(this, "CommandUtils",
|
2015-09-21 20:04:18 +03:00
|
|
|
"resource:///modules/devtools/client/shared/DeveloperToolbar.jsm");
|
2013-09-24 00:36:44 +04:00
|
|
|
loader.lazyGetter(this, "toolboxStrings", () => {
|
2015-06-11 12:11:35 +03:00
|
|
|
const properties = "chrome://browser/locale/devtools/toolbox.properties";
|
|
|
|
const bundle = Services.strings.createBundle(properties);
|
2013-09-24 00:36:44 +04:00
|
|
|
return (name, ...args) => {
|
2012-12-18 19:11:27 +04:00
|
|
|
try {
|
2013-09-24 00:36:44 +04:00
|
|
|
if (!args.length) {
|
|
|
|
return bundle.GetStringFromName(name);
|
2013-02-26 16:40:19 +04:00
|
|
|
}
|
2013-09-24 00:36:44 +04:00
|
|
|
return bundle.formatStringFromName(name, args, args.length);
|
2012-12-18 19:11:27 +04:00
|
|
|
} catch (ex) {
|
2013-09-24 00:36:44 +04:00
|
|
|
Services.console.logStringMessage("Error reading '" + name + "'");
|
2014-01-01 07:28:42 +04:00
|
|
|
return null;
|
2012-12-18 19:11:27 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyRequireGetter(this, "getHighlighterUtils",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/client/framework/toolbox-highlighter-utils", true);
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyRequireGetter(this, "Hosts",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/client/framework/toolbox-hosts", true);
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyRequireGetter(this, "Selection",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/client/framework/selection", true);
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyRequireGetter(this, "InspectorFront",
|
|
|
|
"devtools/server/actors/inspector", true);
|
|
|
|
loader.lazyRequireGetter(this, "DevToolsUtils",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/shared/DevToolsUtils");
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyRequireGetter(this, "showDoorhanger",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/client/shared/doorhanger", true);
|
2015-08-13 04:42:54 +03:00
|
|
|
loader.lazyRequireGetter(this, "createPerformanceFront",
|
|
|
|
"devtools/server/actors/performance", true);
|
2015-06-19 23:56:59 +03:00
|
|
|
loader.lazyRequireGetter(this, "system",
|
2015-10-07 23:18:14 +03:00
|
|
|
"devtools/shared/system");
|
2015-06-11 12:11:35 +03:00
|
|
|
loader.lazyGetter(this, "osString", () => {
|
|
|
|
return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
|
|
|
|
});
|
2015-06-17 15:34:45 +03:00
|
|
|
loader.lazyGetter(this, "registerHarOverlay", () => {
|
2015-09-21 20:04:18 +03:00
|
|
|
return require("devtools/client/netmonitor/har/toolbox-overlay").register;
|
2015-06-17 15:34:45 +03:00
|
|
|
});
|
2015-03-13 14:52:45 +03:00
|
|
|
|
2014-08-27 14:19:30 +04:00
|
|
|
// White-list buttons that can be toggled to prevent adding prefs for
|
|
|
|
// addons that have manually inserted toolbarbuttons into DOM.
|
|
|
|
// (By default, supported target is only local tab)
|
2015-05-06 20:34:28 +03:00
|
|
|
const ToolboxButtons = exports.ToolboxButtons = [
|
2014-08-27 14:19:30 +04:00
|
|
|
{ id: "command-button-pick",
|
2014-11-12 06:57:00 +03:00
|
|
|
isTargetSupported: target =>
|
|
|
|
target.getTrait("highlightable")
|
|
|
|
},
|
2014-08-27 14:19:30 +04:00
|
|
|
{ id: "command-button-frames",
|
2015-06-11 12:11:35 +03:00
|
|
|
isTargetSupported: target => {
|
|
|
|
return target.activeTab && target.activeTab.traits.frames;
|
|
|
|
}
|
2014-08-27 14:19:30 +04:00
|
|
|
},
|
2014-09-09 13:55:00 +04:00
|
|
|
{ id: "command-button-splitconsole",
|
|
|
|
isTargetSupported: target => !target.isAddon },
|
2014-08-27 14:19:30 +04:00
|
|
|
{ id: "command-button-responsive" },
|
|
|
|
{ id: "command-button-paintflashing" },
|
2015-05-06 20:34:28 +03:00
|
|
|
{ id: "command-button-tilt",
|
2015-09-21 20:04:18 +03:00
|
|
|
commands: "devtools/client/tilt/tilt-commands" },
|
2014-08-27 14:19:30 +04:00
|
|
|
{ id: "command-button-scratchpad" },
|
|
|
|
{ id: "command-button-eyedropper" },
|
2015-04-01 20:28:57 +03:00
|
|
|
{ id: "command-button-screenshot" },
|
2015-09-28 16:14:00 +03:00
|
|
|
{ id: "command-button-rulers" },
|
|
|
|
{ id: "command-button-measure" }
|
2014-08-27 14:19:30 +04:00
|
|
|
];
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* A "Toolbox" is the component that holds all the tools for one specific
|
|
|
|
* target. Visually, it's a document that includes the tools tabs and all
|
|
|
|
* the iframes where the tool panels will be living in.
|
|
|
|
*
|
|
|
|
* @param {object} target
|
|
|
|
* The object the toolbox is debugging.
|
|
|
|
* @param {string} selectedTool
|
|
|
|
* Tool to select initially
|
2012-12-13 17:03:55 +04:00
|
|
|
* @param {Toolbox.HostType} hostType
|
|
|
|
* Type of host that will host the toolbox (e.g. sidebar, window)
|
2013-11-16 06:47:00 +04:00
|
|
|
* @param {object} hostOptions
|
|
|
|
* Options for host specifically
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2013-11-16 06:47:00 +04:00
|
|
|
function Toolbox(target, selectedTool, hostType, hostOptions) {
|
2012-11-30 12:07:59 +04:00
|
|
|
this._target = target;
|
|
|
|
this._toolPanels = new Map();
|
2013-05-24 14:26:17 +04:00
|
|
|
this._telemetry = new Telemetry();
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2015-05-04 13:58:25 +03:00
|
|
|
this._initInspector = null;
|
|
|
|
this._inspector = null;
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
this._toolRegistered = this._toolRegistered.bind(this);
|
|
|
|
this._toolUnregistered = this._toolUnregistered.bind(this);
|
2013-09-24 00:36:44 +04:00
|
|
|
this._refreshHostTitle = this._refreshHostTitle.bind(this);
|
2014-08-27 14:19:30 +04:00
|
|
|
this.selectFrame = this.selectFrame.bind(this);
|
|
|
|
this._updateFrames = this._updateFrames.bind(this);
|
2014-07-17 13:39:56 +04:00
|
|
|
this._splitConsoleOnKeypress = this._splitConsoleOnKeypress.bind(this);
|
2012-11-30 12:07:59 +04:00
|
|
|
this.destroy = this.destroy.bind(this);
|
2014-06-13 18:27:10 +04:00
|
|
|
this.highlighterUtils = getHighlighterUtils(this);
|
2014-03-14 01:36:48 +04:00
|
|
|
this._highlighterReady = this._highlighterReady.bind(this);
|
|
|
|
this._highlighterHidden = this._highlighterHidden.bind(this);
|
2014-07-17 13:39:56 +04:00
|
|
|
this._prefChanged = this._prefChanged.bind(this);
|
2014-07-31 21:33:23 +04:00
|
|
|
this._saveSplitConsoleHeight = this._saveSplitConsoleHeight.bind(this);
|
2014-08-15 16:50:43 +04:00
|
|
|
this._onFocus = this._onFocus.bind(this);
|
2014-10-23 04:18:31 +04:00
|
|
|
this._showDevEditionPromo = this._showDevEditionPromo.bind(this);
|
2015-04-16 21:15:28 +03:00
|
|
|
this._updateTextboxMenuItems = this._updateTextboxMenuItems.bind(this);
|
2015-06-08 16:49:38 +03:00
|
|
|
this._onBottomHostMinimized = this._onBottomHostMinimized.bind(this);
|
|
|
|
this._onBottomHostMaximized = this._onBottomHostMaximized.bind(this);
|
|
|
|
this._onToolSelectWhileMinimized = this._onToolSelectWhileMinimized.bind(this);
|
2015-08-13 04:42:54 +03:00
|
|
|
this._onPerformanceFrontEvent = this._onPerformanceFrontEvent.bind(this);
|
2015-06-08 16:49:38 +03:00
|
|
|
this._onBottomHostWillChange = this._onBottomHostWillChange.bind(this);
|
2015-06-11 12:11:35 +03:00
|
|
|
this._toggleMinimizeMode = this._toggleMinimizeMode.bind(this);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-03-07 11:30:03 +04:00
|
|
|
this._target.on("close", this.destroy);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
if (!hostType) {
|
|
|
|
hostType = Services.prefs.getCharPref(this._prefs.LAST_HOST);
|
|
|
|
}
|
|
|
|
if (!selectedTool) {
|
|
|
|
selectedTool = Services.prefs.getCharPref(this._prefs.LAST_TOOL);
|
|
|
|
}
|
|
|
|
this._defaultToolId = selectedTool;
|
|
|
|
|
2014-11-10 13:14:31 +03:00
|
|
|
this._hostOptions = hostOptions;
|
2013-11-16 06:47:00 +04:00
|
|
|
this._host = this._createHost(hostType, hostOptions);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2012-12-14 11:05:00 +04:00
|
|
|
EventEmitter.decorate(this);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-02-26 16:40:19 +04:00
|
|
|
this._target.on("navigate", this._refreshHostTitle);
|
2014-08-27 14:19:30 +04:00
|
|
|
this._target.on("frame-update", this._updateFrames);
|
|
|
|
|
2013-02-26 16:40:19 +04:00
|
|
|
this.on("host-changed", this._refreshHostTitle);
|
|
|
|
this.on("select", this._refreshHostTitle);
|
|
|
|
|
2014-10-23 04:18:31 +04:00
|
|
|
this.on("ready", this._showDevEditionPromo);
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
gDevTools.on("tool-registered", this._toolRegistered);
|
|
|
|
gDevTools.on("tool-unregistered", this._toolUnregistered);
|
|
|
|
}
|
2013-04-12 00:59:08 +04:00
|
|
|
exports.Toolbox = Toolbox;
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The toolbox can be 'hosted' either embedded in a browser window
|
|
|
|
* or in a separate window.
|
|
|
|
*/
|
|
|
|
Toolbox.HostType = {
|
|
|
|
BOTTOM: "bottom",
|
|
|
|
SIDE: "side",
|
2013-11-16 06:47:00 +04:00
|
|
|
WINDOW: "window",
|
|
|
|
CUSTOM: "custom"
|
2013-09-24 00:36:44 +04:00
|
|
|
};
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
Toolbox.prototype = {
|
2015-09-21 20:02:37 +03:00
|
|
|
_URL: "chrome://devtools/content/framework/toolbox.xul",
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
_prefs: {
|
|
|
|
LAST_HOST: "devtools.toolbox.host",
|
|
|
|
LAST_TOOL: "devtools.toolbox.selectedTool",
|
2015-06-10 00:59:27 +03:00
|
|
|
SIDE_ENABLED: "devtools.toolbox.sideEnabled",
|
|
|
|
PREVIOUS_HOST: "devtools.toolbox.previousHost"
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
currentToolId: null,
|
2015-09-01 19:36:18 +03:00
|
|
|
lastUsedToolId: null,
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a *copy* of the _toolPanels collection.
|
|
|
|
*
|
|
|
|
* @return {Map} panels
|
|
|
|
* All the running panels in the toolbox
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
getToolPanels: function() {
|
|
|
|
return new Map(this._toolPanels);
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2012-12-13 17:03:55 +04:00
|
|
|
/**
|
|
|
|
* Access the panel for a given tool
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
getPanel: function(id) {
|
|
|
|
return this._toolPanels.get(id);
|
2012-12-13 17:03:55 +04:00
|
|
|
},
|
|
|
|
|
2014-12-08 18:19:00 +03:00
|
|
|
/**
|
|
|
|
* Get the panel instance for a given tool once it is ready.
|
|
|
|
* If the tool is already opened, the promise will resolve immediately,
|
|
|
|
* otherwise it will wait until the tool has been opened before resolving.
|
|
|
|
*
|
|
|
|
* Note that this does not open the tool, use selectTool if you'd
|
|
|
|
* like to select the tool right away.
|
|
|
|
*
|
|
|
|
* @param {String} id
|
|
|
|
* The id of the panel, for example "jsdebugger".
|
|
|
|
* @returns Promise
|
|
|
|
* A promise that resolves once the panel is ready.
|
|
|
|
*/
|
|
|
|
getPanelWhenReady: function(id) {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
let panel = this.getPanel(id);
|
|
|
|
if (panel) {
|
|
|
|
deferred.resolve(panel);
|
|
|
|
} else {
|
|
|
|
this.on(id + "-ready", (e, panel) => {
|
|
|
|
deferred.resolve(panel);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2012-12-13 17:03:55 +04:00
|
|
|
/**
|
|
|
|
* This is a shortcut for getPanel(currentToolId) because it is much more
|
|
|
|
* likely that we're going to want to get the panel that we've just made
|
|
|
|
* visible
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
getCurrentPanel: function() {
|
|
|
|
return this._toolPanels.get(this.currentToolId);
|
2012-12-13 17:03:55 +04:00
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Get/alter the target of a Toolbox so we're debugging something different.
|
|
|
|
* See Target.jsm for more details.
|
|
|
|
* TODO: Do we allow |toolbox.target = null;| ?
|
|
|
|
*/
|
|
|
|
get target() {
|
|
|
|
return this._target;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get/alter the host of a Toolbox, i.e. is it in browser or in a separate
|
|
|
|
* tab. See HostType for more details.
|
|
|
|
*/
|
|
|
|
get hostType() {
|
|
|
|
return this._host.type;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the iframe containing the toolbox UI.
|
|
|
|
*/
|
|
|
|
get frame() {
|
|
|
|
return this._host.frame;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut to the document containing the toolbox UI
|
|
|
|
*/
|
|
|
|
get doc() {
|
|
|
|
return this.frame.contentDocument;
|
|
|
|
},
|
|
|
|
|
2013-09-15 10:26:18 +04:00
|
|
|
/**
|
|
|
|
* Get current zoom level of toolbox
|
|
|
|
*/
|
|
|
|
get zoomValue() {
|
|
|
|
return parseFloat(Services.prefs.getCharPref(ZOOM_PREF));
|
|
|
|
},
|
|
|
|
|
2014-01-09 15:36:01 +04:00
|
|
|
/**
|
|
|
|
* Get the toolbox highlighter front. Note that it may not always have been
|
|
|
|
* initialized first. Use `initInspector()` if needed.
|
2014-06-13 18:27:10 +04:00
|
|
|
* Consider using highlighterUtils instead, it exposes the highlighter API in
|
|
|
|
* a useful way for the toolbox panels
|
2014-01-09 15:36:01 +04:00
|
|
|
*/
|
|
|
|
get highlighter() {
|
2014-06-13 18:27:10 +04:00
|
|
|
return this._highlighter;
|
2014-01-09 15:36:01 +04:00
|
|
|
},
|
|
|
|
|
2015-06-06 23:44:05 +03:00
|
|
|
/**
|
|
|
|
* Get the toolbox's performance front. Note that it may not always have been
|
|
|
|
* initialized first. Use `initPerformance()` if needed.
|
|
|
|
*/
|
|
|
|
get performance() {
|
|
|
|
return this._performance;
|
|
|
|
},
|
|
|
|
|
2014-01-09 15:36:01 +04:00
|
|
|
/**
|
|
|
|
* Get the toolbox's inspector front. Note that it may not always have been
|
|
|
|
* initialized first. Use `initInspector()` if needed.
|
|
|
|
*/
|
|
|
|
get inspector() {
|
|
|
|
return this._inspector;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the toolbox's walker front. Note that it may not always have been
|
|
|
|
* initialized first. Use `initInspector()` if needed.
|
|
|
|
*/
|
|
|
|
get walker() {
|
|
|
|
return this._walker;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the toolbox's node selection. Note that it may not always have been
|
|
|
|
* initialized first. Use `initInspector()` if needed.
|
|
|
|
*/
|
|
|
|
get selection() {
|
|
|
|
return this._selection;
|
|
|
|
},
|
|
|
|
|
2013-12-06 19:46:51 +04:00
|
|
|
/**
|
|
|
|
* Get the toggled state of the split console
|
|
|
|
*/
|
|
|
|
get splitConsole() {
|
|
|
|
return this._splitConsole;
|
|
|
|
},
|
2015-10-07 23:09:55 +03:00
|
|
|
/**
|
|
|
|
* Get the focused state of the split console
|
|
|
|
*/
|
|
|
|
isSplitConsoleFocused: function() {
|
|
|
|
if (!this._splitConsole) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let focusedWin = Services.focus.focusedWindow;
|
|
|
|
return focusedWin && focusedWin ===
|
|
|
|
this.doc.querySelector("#toolbox-panel-iframe-webconsole").contentWindow;
|
|
|
|
},
|
2013-12-06 19:46:51 +04:00
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Open the toolbox
|
|
|
|
*/
|
2015-06-08 17:03:49 +03:00
|
|
|
open: function() {
|
2015-04-14 18:58:58 +03:00
|
|
|
return Task.spawn(function*() {
|
|
|
|
let iframe = yield this._host.create();
|
|
|
|
let domReady = promise.defer();
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
// Load the toolbox-level actor fronts and utilities now
|
|
|
|
yield this._target.makeRemote();
|
|
|
|
iframe.setAttribute("src", this._URL);
|
|
|
|
iframe.setAttribute("aria-label", toolboxStrings("toolbox.label"));
|
|
|
|
let domHelper = new DOMHelpers(iframe.contentWindow);
|
|
|
|
domHelper.onceDOMReady(() => domReady.resolve());
|
2013-09-24 00:36:44 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
yield domReady.promise;
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
this.isReady = true;
|
|
|
|
let framesPromise = this._listFrames();
|
2014-08-27 14:19:30 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
this.closeButton = this.doc.getElementById("toolbox-close");
|
|
|
|
this.closeButton.addEventListener("command", this.destroy, true);
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
gDevTools.on("pref-changed", this._prefChanged);
|
2014-07-17 13:39:56 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
let framesMenu = this.doc.getElementById("command-button-frames");
|
|
|
|
framesMenu.addEventListener("command", this.selectFrame, true);
|
2014-08-27 14:19:30 +04:00
|
|
|
|
2015-04-16 21:15:28 +03:00
|
|
|
this.textboxContextMenuPopup =
|
|
|
|
this.doc.getElementById("toolbox-textbox-context-popup");
|
|
|
|
this.textboxContextMenuPopup.addEventListener("popupshowing",
|
|
|
|
this._updateTextboxMenuItems, true);
|
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
this._buildDockButtons();
|
|
|
|
this._buildOptions();
|
|
|
|
this._buildTabs();
|
|
|
|
this._applyCacheSettings();
|
|
|
|
this._applyServiceWorkersTestingSettings();
|
|
|
|
this._addKeysToWindow();
|
|
|
|
this._addReloadKeys();
|
|
|
|
this._addHostListeners();
|
2015-06-17 15:34:45 +03:00
|
|
|
this._registerOverlays();
|
2015-04-14 18:58:58 +03:00
|
|
|
if (this._hostOptions && this._hostOptions.zoom === false) {
|
|
|
|
this._disableZoomKeys();
|
|
|
|
} else {
|
|
|
|
this._addZoomKeys();
|
|
|
|
this._loadInitialZoom();
|
|
|
|
}
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
this.webconsolePanel = this.doc.querySelector("#toolbox-panel-webconsole");
|
|
|
|
this.webconsolePanel.height = Services.prefs.getIntPref(SPLITCONSOLE_HEIGHT_PREF);
|
|
|
|
this.webconsolePanel.addEventListener("resize", this._saveSplitConsoleHeight);
|
2014-07-31 21:33:23 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
let buttonsPromise = this._buildButtons();
|
2014-07-29 00:54:41 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
this._pingTelemetry();
|
2014-03-07 16:14:53 +04:00
|
|
|
|
2015-05-11 12:27:23 +03:00
|
|
|
// The isTargetSupported check needs to happen after the target is
|
|
|
|
// remoted, otherwise we could have done it in the toolbox constructor
|
|
|
|
// (bug 1072764).
|
|
|
|
let toolDef = gDevTools.getToolDefinition(this._defaultToolId);
|
|
|
|
if (!toolDef || !toolDef.isTargetSupported(this._target)) {
|
|
|
|
this._defaultToolId = "webconsole";
|
|
|
|
}
|
|
|
|
|
2015-05-04 13:58:25 +03:00
|
|
|
yield this.selectTool(this._defaultToolId);
|
2014-08-15 16:52:08 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
// Wait until the original tool is selected so that the split
|
|
|
|
// console input will receive focus.
|
|
|
|
let splitConsolePromise = promise.resolve();
|
|
|
|
if (Services.prefs.getBoolPref(SPLITCONSOLE_ENABLED_PREF)) {
|
|
|
|
splitConsolePromise = this.openSplitConsole();
|
|
|
|
}
|
2014-08-15 16:52:08 +04:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
yield promise.all([
|
|
|
|
splitConsolePromise,
|
|
|
|
buttonsPromise,
|
|
|
|
framesPromise
|
|
|
|
]);
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2015-04-17 22:44:52 +03:00
|
|
|
// Lazily connect to the profiler here and don't wait for it to complete,
|
2015-06-06 23:44:05 +03:00
|
|
|
// used to intercept console.profile calls before the performance tools are open.
|
2015-08-11 04:43:19 +03:00
|
|
|
let performanceFrontConnection = this.initPerformance();
|
2013-11-16 06:47:00 +04:00
|
|
|
|
2015-08-11 04:43:19 +03:00
|
|
|
// If in testing environment, wait for performance connection to finish,
|
|
|
|
// so we don't have to explicitly wait for this in tests; ideally, all tests
|
|
|
|
// will handle this on their own, but each have their own tear down function.
|
2015-06-05 01:30:23 +03:00
|
|
|
if (DevToolsUtils.testing) {
|
2015-08-11 04:43:19 +03:00
|
|
|
yield performanceFrontConnection;
|
2015-04-14 18:58:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.emit("ready");
|
|
|
|
}.bind(this)).then(null, console.error.bind(console));
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2015-03-13 14:52:45 +03:00
|
|
|
_pingTelemetry: function() {
|
|
|
|
this._telemetry.toolOpened("toolbox");
|
|
|
|
|
2015-06-19 23:56:59 +03:00
|
|
|
this._telemetry.logOncePerBrowserVersion(OS_HISTOGRAM, system.getOSCPU());
|
|
|
|
this._telemetry.logOncePerBrowserVersion(OS_IS_64_BITS, system.is64Bit ? 1 : 0);
|
|
|
|
this._telemetry.logOncePerBrowserVersion(SCREENSIZE_HISTOGRAM, system.getScreenDimensions());
|
2015-03-13 14:52:45 +03:00
|
|
|
},
|
|
|
|
|
2014-07-17 13:39:56 +04:00
|
|
|
/**
|
|
|
|
* Because our panels are lazy loaded this is a good place to watch for
|
|
|
|
* "pref-changed" events.
|
|
|
|
* @param {String} event
|
|
|
|
* The event type, "pref-changed".
|
|
|
|
* @param {Object} data
|
|
|
|
* {
|
|
|
|
* newValue: The new value
|
|
|
|
* oldValue: The old value
|
|
|
|
* pref: The name of the preference that has changed
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
_prefChanged: function(event, data) {
|
2015-06-08 17:03:49 +03:00
|
|
|
switch (data.pref) {
|
|
|
|
case "devtools.cache.disabled":
|
|
|
|
this._applyCacheSettings();
|
|
|
|
break;
|
|
|
|
case "devtools.serviceWorkers.testing.enabled":
|
|
|
|
this._applyServiceWorkersTestingSettings();
|
|
|
|
break;
|
2014-07-17 13:39:56 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
_buildOptions: function() {
|
2015-09-01 19:36:18 +03:00
|
|
|
let selectOptions = () => {
|
|
|
|
// Flip back to the last used panel if we are already
|
|
|
|
// on the options panel.
|
|
|
|
if (this.currentToolId === "options" &&
|
|
|
|
gDevTools.getToolDefinition(this.lastUsedToolId)) {
|
|
|
|
this.selectTool(this.lastUsedToolId);
|
|
|
|
} else {
|
|
|
|
this.selectTool("options");
|
|
|
|
}
|
|
|
|
};
|
2013-04-15 16:34:48 +04:00
|
|
|
let key = this.doc.getElementById("toolbox-options-key");
|
2015-09-01 19:34:41 +03:00
|
|
|
key.addEventListener("command", selectOptions, true);
|
|
|
|
let key2 = this.doc.getElementById("toolbox-options-key2");
|
|
|
|
key2.addEventListener("command", selectOptions, true);
|
2013-04-15 16:34:48 +04:00
|
|
|
},
|
|
|
|
|
2013-11-12 01:13:28 +04:00
|
|
|
_splitConsoleOnKeypress: function(e) {
|
2014-07-24 09:59:00 +04:00
|
|
|
if (e.keyCode === e.DOM_VK_ESCAPE) {
|
2013-11-12 01:13:28 +04:00
|
|
|
this.toggleSplitConsole();
|
2014-06-19 11:15:14 +04:00
|
|
|
// If the debugger is paused, don't let the ESC key stop any pending
|
|
|
|
// navigation.
|
|
|
|
let jsdebugger = this.getPanel("jsdebugger");
|
|
|
|
if (jsdebugger && jsdebugger.panelWin.gThreadClient.state == "paused") {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2013-11-12 01:13:28 +04:00
|
|
|
}
|
|
|
|
},
|
2015-10-07 23:09:55 +03:00
|
|
|
/**
|
|
|
|
* Add a shortcut key that should work when a split console
|
|
|
|
* has focus to the toolbox.
|
|
|
|
*
|
|
|
|
* @param {element} keyElement
|
|
|
|
* They <key> XUL element describing the shortcut key
|
|
|
|
* @param {string} whichTool
|
|
|
|
* The tool the key belongs to. The corresponding command
|
|
|
|
* will only trigger if this tool is active.
|
|
|
|
*/
|
|
|
|
useKeyWithSplitConsole: function(keyElement, whichTool) {
|
|
|
|
let cloned = keyElement.cloneNode();
|
|
|
|
cloned.setAttribute("oncommand", "void(0)");
|
|
|
|
cloned.removeAttribute("command");
|
|
|
|
cloned.addEventListener("command", (e) => {
|
|
|
|
// Only forward the command if the tool is active
|
|
|
|
if (this.currentToolId === whichTool && this.isSplitConsoleFocused()) {
|
|
|
|
keyElement.doCommand();
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
this.doc.getElementById("toolbox-keyset").appendChild(cloned);
|
|
|
|
},
|
2013-11-12 01:13:28 +04:00
|
|
|
|
2014-05-10 04:41:43 +04:00
|
|
|
_addReloadKeys: function() {
|
|
|
|
[
|
|
|
|
["toolbox-reload-key", false],
|
|
|
|
["toolbox-reload-key2", false],
|
|
|
|
["toolbox-force-reload-key", true],
|
|
|
|
["toolbox-force-reload-key2", true]
|
|
|
|
].forEach(([id, force]) => {
|
2015-06-11 12:11:35 +03:00
|
|
|
this.doc.getElementById(id).addEventListener("command", () => {
|
2014-05-10 04:41:43 +04:00
|
|
|
this.reloadTarget(force);
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-08-15 16:50:43 +04:00
|
|
|
_addHostListeners: function() {
|
2013-07-20 17:36:43 +04:00
|
|
|
let nextKey = this.doc.getElementById("toolbox-next-tool-key");
|
|
|
|
nextKey.addEventListener("command", this.selectNextTool.bind(this), true);
|
2015-06-10 00:59:27 +03:00
|
|
|
|
2013-07-20 17:36:43 +04:00
|
|
|
let prevKey = this.doc.getElementById("toolbox-previous-tool-key");
|
|
|
|
prevKey.addEventListener("command", this.selectPreviousTool.bind(this), true);
|
2013-11-12 01:13:28 +04:00
|
|
|
|
2015-06-11 12:11:35 +03:00
|
|
|
let minimizeKey = this.doc.getElementById("toolbox-minimize-key");
|
|
|
|
minimizeKey.addEventListener("command", this._toggleMinimizeMode, true);
|
|
|
|
|
2015-06-10 00:59:27 +03:00
|
|
|
let toggleKey = this.doc.getElementById("toolbox-toggle-host-key");
|
|
|
|
toggleKey.addEventListener("command", this.switchToPreviousHost.bind(this), true);
|
|
|
|
|
2015-09-29 13:06:25 +03:00
|
|
|
if (Services.prefs.prefHasUserValue("devtools.loader.srcdir")) {
|
|
|
|
let reloadKey = this.doc.getElementById("tools-reload-key");
|
|
|
|
reloadKey.addEventListener("command", this.reload.bind(this), true);
|
|
|
|
}
|
|
|
|
|
2013-11-12 01:13:28 +04:00
|
|
|
// Split console uses keypress instead of command so the event can be
|
|
|
|
// cancelled with stopPropagation on the keypress, and not preventDefault.
|
|
|
|
this.doc.addEventListener("keypress", this._splitConsoleOnKeypress, false);
|
2014-08-15 16:50:43 +04:00
|
|
|
|
|
|
|
this.doc.addEventListener("focus", this._onFocus, true);
|
2013-11-12 01:13:28 +04:00
|
|
|
},
|
|
|
|
|
2015-06-17 15:34:45 +03:00
|
|
|
_registerOverlays: function() {
|
|
|
|
registerHarOverlay(this);
|
|
|
|
},
|
|
|
|
|
2014-07-31 21:33:23 +04:00
|
|
|
_saveSplitConsoleHeight: function() {
|
|
|
|
Services.prefs.setIntPref(SPLITCONSOLE_HEIGHT_PREF,
|
|
|
|
this.webconsolePanel.height);
|
|
|
|
},
|
|
|
|
|
2013-11-12 01:13:28 +04:00
|
|
|
/**
|
|
|
|
* Make sure that the console is showing up properly based on all the
|
|
|
|
* possible conditions.
|
|
|
|
* 1) If the console tab is selected, then regardless of split state
|
|
|
|
* it should take up the full height of the deck, and we should
|
|
|
|
* hide the deck and splitter.
|
|
|
|
* 2) If the console tab is not selected and it is split, then we should
|
|
|
|
* show the splitter, deck, and console.
|
|
|
|
* 3) If the console tab is not selected and it is *not* split,
|
|
|
|
* then we should hide the console and splitter, and show the deck
|
|
|
|
* at full height.
|
|
|
|
*/
|
|
|
|
_refreshConsoleDisplay: function() {
|
|
|
|
let deck = this.doc.getElementById("toolbox-deck");
|
2014-07-31 21:33:23 +04:00
|
|
|
let webconsolePanel = this.webconsolePanel;
|
2013-11-12 01:13:28 +04:00
|
|
|
let splitter = this.doc.getElementById("toolbox-console-splitter");
|
|
|
|
let openedConsolePanel = this.currentToolId === "webconsole";
|
|
|
|
|
|
|
|
if (openedConsolePanel) {
|
|
|
|
deck.setAttribute("collapsed", "true");
|
|
|
|
splitter.setAttribute("hidden", "true");
|
|
|
|
webconsolePanel.removeAttribute("collapsed");
|
|
|
|
} else {
|
|
|
|
deck.removeAttribute("collapsed");
|
2014-07-29 13:50:00 +04:00
|
|
|
if (this.splitConsole) {
|
2013-11-12 01:13:28 +04:00
|
|
|
webconsolePanel.removeAttribute("collapsed");
|
|
|
|
splitter.removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
webconsolePanel.setAttribute("collapsed", "true");
|
|
|
|
splitter.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
}
|
2013-07-20 17:36:43 +04:00
|
|
|
},
|
|
|
|
|
2013-09-15 10:26:18 +04:00
|
|
|
/**
|
|
|
|
* Wire up the listeners for the zoom keys.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_addZoomKeys: function() {
|
2013-09-15 10:26:18 +04:00
|
|
|
let inKey = this.doc.getElementById("toolbox-zoom-in-key");
|
|
|
|
inKey.addEventListener("command", this.zoomIn.bind(this), true);
|
|
|
|
|
|
|
|
let inKey2 = this.doc.getElementById("toolbox-zoom-in-key2");
|
|
|
|
inKey2.addEventListener("command", this.zoomIn.bind(this), true);
|
|
|
|
|
2015-09-01 23:37:54 +03:00
|
|
|
let inKey3 = this.doc.getElementById("toolbox-zoom-in-key3");
|
|
|
|
inKey3.addEventListener("command", this.zoomIn.bind(this), true);
|
|
|
|
|
2013-09-15 10:26:18 +04:00
|
|
|
let outKey = this.doc.getElementById("toolbox-zoom-out-key");
|
|
|
|
outKey.addEventListener("command", this.zoomOut.bind(this), true);
|
|
|
|
|
2015-09-01 23:37:54 +03:00
|
|
|
let outKey2 = this.doc.getElementById("toolbox-zoom-out-key2");
|
|
|
|
outKey2.addEventListener("command", this.zoomOut.bind(this), true);
|
|
|
|
|
2013-09-15 10:26:18 +04:00
|
|
|
let resetKey = this.doc.getElementById("toolbox-zoom-reset-key");
|
|
|
|
resetKey.addEventListener("command", this.zoomReset.bind(this), true);
|
2015-09-01 23:37:54 +03:00
|
|
|
|
|
|
|
let resetKey2 = this.doc.getElementById("toolbox-zoom-reset-key2");
|
|
|
|
resetKey2.addEventListener("command", this.zoomReset.bind(this), true);
|
2013-09-15 10:26:18 +04:00
|
|
|
},
|
|
|
|
|
2014-11-10 13:14:31 +03:00
|
|
|
_disableZoomKeys: function() {
|
|
|
|
let inKey = this.doc.getElementById("toolbox-zoom-in-key");
|
|
|
|
inKey.setAttribute("disabled", "true");
|
|
|
|
|
|
|
|
let inKey2 = this.doc.getElementById("toolbox-zoom-in-key2");
|
|
|
|
inKey2.setAttribute("disabled", "true");
|
|
|
|
|
2015-09-01 23:37:54 +03:00
|
|
|
let inKey3 = this.doc.getElementById("toolbox-zoom-in-key3");
|
|
|
|
inKey3.setAttribute("disabled", "true");
|
|
|
|
|
2014-11-10 13:14:31 +03:00
|
|
|
let outKey = this.doc.getElementById("toolbox-zoom-out-key");
|
|
|
|
outKey.setAttribute("disabled", "true");
|
|
|
|
|
2015-09-01 23:37:54 +03:00
|
|
|
let outKey2 = this.doc.getElementById("toolbox-zoom-out-key2");
|
|
|
|
outKey2.setAttribute("disabled", "true");
|
|
|
|
|
2014-11-10 13:14:31 +03:00
|
|
|
let resetKey = this.doc.getElementById("toolbox-zoom-reset-key");
|
|
|
|
resetKey.setAttribute("disabled", "true");
|
2015-09-01 23:37:54 +03:00
|
|
|
|
|
|
|
let resetKey2 = this.doc.getElementById("toolbox-zoom-reset-key2");
|
|
|
|
resetKey2.setAttribute("disabled", "true");
|
2014-11-10 13:14:31 +03:00
|
|
|
},
|
|
|
|
|
2013-09-15 10:26:18 +04:00
|
|
|
/**
|
|
|
|
* Set zoom on toolbox to whatever the last setting was.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_loadInitialZoom: function() {
|
2013-09-15 10:26:18 +04:00
|
|
|
this.setZoom(this.zoomValue);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase zoom level of toolbox window - make things bigger.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
zoomIn: function() {
|
2013-09-15 10:26:18 +04:00
|
|
|
this.setZoom(this.zoomValue + 0.1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrease zoom level of toolbox window - make things smaller.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
zoomOut: function() {
|
2013-09-15 10:26:18 +04:00
|
|
|
this.setZoom(this.zoomValue - 0.1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset zoom level of the toolbox window.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
zoomReset: function() {
|
2013-09-15 10:26:18 +04:00
|
|
|
this.setZoom(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set zoom level of the toolbox window.
|
|
|
|
*
|
|
|
|
* @param {number} zoomValue
|
|
|
|
* Zoom level e.g. 1.2
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
setZoom: function(zoomValue) {
|
2013-09-15 10:26:18 +04:00
|
|
|
// cap zoom value
|
|
|
|
zoomValue = Math.max(zoomValue, MIN_ZOOM);
|
|
|
|
zoomValue = Math.min(zoomValue, MAX_ZOOM);
|
|
|
|
|
|
|
|
let contViewer = this.frame.docShell.contentViewer;
|
|
|
|
|
2014-07-10 01:27:49 +04:00
|
|
|
contViewer.fullZoom = zoomValue;
|
2013-09-15 10:26:18 +04:00
|
|
|
|
|
|
|
Services.prefs.setCharPref(ZOOM_PREF, zoomValue);
|
|
|
|
},
|
|
|
|
|
2013-01-13 12:52:03 +04:00
|
|
|
/**
|
|
|
|
* Adds the keys and commands to the Toolbox Window in window mode.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_addKeysToWindow: function() {
|
2013-01-13 12:52:03 +04:00
|
|
|
if (this.hostType != Toolbox.HostType.WINDOW) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
let doc = this.doc.defaultView.parent.document;
|
2013-01-13 12:52:03 +04:00
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
for (let [id, toolDefinition] of gDevTools.getToolDefinitionMap()) {
|
|
|
|
// Prevent multiple entries for the same tool.
|
|
|
|
if (!toolDefinition.key || doc.getElementById("key_" + id)) {
|
|
|
|
continue;
|
2013-01-13 12:52:03 +04:00
|
|
|
}
|
2013-08-28 19:26:01 +04:00
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
let toolId = id;
|
2013-08-28 19:26:01 +04:00
|
|
|
let key = doc.createElement("key");
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
key.id = "key_" + toolId;
|
|
|
|
|
|
|
|
if (toolDefinition.key.startsWith("VK_")) {
|
|
|
|
key.setAttribute("keycode", toolDefinition.key);
|
|
|
|
} else {
|
|
|
|
key.setAttribute("key", toolDefinition.key);
|
|
|
|
}
|
|
|
|
|
|
|
|
key.setAttribute("modifiers", toolDefinition.modifiers);
|
2015-06-08 17:03:49 +03:00
|
|
|
// needed. See bug 371900
|
|
|
|
key.setAttribute("oncommand", "void(0);");
|
2013-09-24 00:36:44 +04:00
|
|
|
key.addEventListener("command", () => {
|
|
|
|
this.selectTool(toolId).then(() => this.fireCustomKey(toolId));
|
2013-08-28 19:26:01 +04:00
|
|
|
}, true);
|
|
|
|
doc.getElementById("toolbox-keyset").appendChild(key);
|
|
|
|
}
|
2013-09-15 10:26:18 +04:00
|
|
|
|
2013-08-28 19:26:01 +04:00
|
|
|
// Add key for toggling the browser console from the detached window
|
2013-09-24 00:36:44 +04:00
|
|
|
if (!doc.getElementById("key_browserconsole")) {
|
2013-08-28 19:26:01 +04:00
|
|
|
let key = doc.createElement("key");
|
|
|
|
key.id = "key_browserconsole";
|
|
|
|
|
|
|
|
key.setAttribute("key", toolboxStrings("browserConsoleCmd.commandkey"));
|
|
|
|
key.setAttribute("modifiers", "accel,shift");
|
2015-06-08 17:03:49 +03:00
|
|
|
// needed. See bug 371900
|
|
|
|
key.setAttribute("oncommand", "void(0)");
|
2013-09-24 00:36:44 +04:00
|
|
|
key.addEventListener("command", () => {
|
2013-08-28 19:26:01 +04:00
|
|
|
HUDService.toggleBrowserConsole();
|
|
|
|
}, true);
|
|
|
|
doc.getElementById("toolbox-keyset").appendChild(key);
|
|
|
|
}
|
2013-01-13 12:52:03 +04:00
|
|
|
},
|
|
|
|
|
2013-08-02 22:28:37 +04:00
|
|
|
/**
|
2015-06-08 17:03:49 +03:00
|
|
|
* Handle any custom key events. Returns true if there was a custom key
|
|
|
|
* binding run.
|
|
|
|
* @param {string} toolId Which tool to run the command on (skip if not
|
|
|
|
* current)
|
2013-08-02 22:28:37 +04:00
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
fireCustomKey: function(toolId) {
|
|
|
|
let toolDefinition = gDevTools.getToolDefinition(toolId);
|
2013-08-02 22:28:37 +04:00
|
|
|
|
2014-03-11 14:21:20 +04:00
|
|
|
if (toolDefinition.onkey &&
|
2014-02-07 17:56:00 +04:00
|
|
|
((this.currentToolId === toolId) ||
|
|
|
|
(toolId == "webconsole" && this.splitConsole))) {
|
|
|
|
toolDefinition.onkey(this.getCurrentPanel(), this);
|
2013-08-02 22:28:37 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Build the buttons for changing hosts. Called every time
|
|
|
|
* the host changes.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_buildDockButtons: function() {
|
2012-11-30 12:07:59 +04:00
|
|
|
let dockBox = this.doc.getElementById("toolbox-dock-buttons");
|
|
|
|
|
|
|
|
while (dockBox.firstChild) {
|
|
|
|
dockBox.removeChild(dockBox.firstChild);
|
|
|
|
}
|
|
|
|
|
2012-12-15 05:10:43 +04:00
|
|
|
if (!this._target.isLocalTab) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-08 16:49:38 +03:00
|
|
|
// Bottom-type host can be minimized, add a button for this.
|
|
|
|
if (this.hostType == Toolbox.HostType.BOTTOM) {
|
|
|
|
let minimizeBtn = this.doc.createElement("toolbarbutton");
|
|
|
|
minimizeBtn.id = "toolbox-dock-bottom-minimize";
|
2015-06-11 12:11:35 +03:00
|
|
|
|
|
|
|
minimizeBtn.addEventListener("command", this._toggleMinimizeMode);
|
2015-06-08 16:49:38 +03:00
|
|
|
dockBox.appendChild(minimizeBtn);
|
2015-06-11 12:11:35 +03:00
|
|
|
// Show the button in its maximized state.
|
|
|
|
this._onBottomHostMaximized();
|
2015-06-08 16:49:38 +03:00
|
|
|
|
|
|
|
// Update the label and icon when the state changes.
|
|
|
|
this._host.on("minimized", this._onBottomHostMinimized);
|
|
|
|
this._host.on("maximized", this._onBottomHostMaximized);
|
|
|
|
// Maximize again when a tool gets selected.
|
|
|
|
this.on("before-select", this._onToolSelectWhileMinimized);
|
|
|
|
// Maximize and stop listening before the host type changes.
|
|
|
|
this.once("host-will-change", this._onBottomHostWillChange);
|
|
|
|
}
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
if (this.hostType == Toolbox.HostType.WINDOW) {
|
2014-07-31 21:33:23 +04:00
|
|
|
this.closeButton.setAttribute("hidden", "true");
|
2013-01-21 19:22:47 +04:00
|
|
|
} else {
|
2014-07-31 21:33:23 +04:00
|
|
|
this.closeButton.removeAttribute("hidden");
|
2013-01-21 19:22:47 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
let sideEnabled = Services.prefs.getBoolPref(this._prefs.SIDE_ENABLED);
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
for (let type in Toolbox.HostType) {
|
|
|
|
let position = Toolbox.HostType[type];
|
2012-11-30 12:07:59 +04:00
|
|
|
if (position == this.hostType ||
|
2013-11-16 06:47:00 +04:00
|
|
|
position == Toolbox.HostType.CUSTOM ||
|
2013-09-24 00:36:44 +04:00
|
|
|
(!sideEnabled && position == Toolbox.HostType.SIDE)) {
|
2012-11-30 12:07:59 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let button = this.doc.createElement("toolbarbutton");
|
|
|
|
button.id = "toolbox-dock-" + position;
|
|
|
|
button.className = "toolbox-dock-button";
|
2012-12-18 19:11:27 +04:00
|
|
|
button.setAttribute("tooltiptext", toolboxStrings("toolboxDockButtons." +
|
|
|
|
position + ".tooltip"));
|
2013-09-24 00:36:44 +04:00
|
|
|
button.addEventListener("command", () => {
|
2012-12-13 17:03:55 +04:00
|
|
|
this.switchHost(position);
|
2013-09-24 00:36:44 +04:00
|
|
|
});
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
dockBox.appendChild(button);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-06-11 12:11:35 +03:00
|
|
|
_getMinimizeButtonShortcutTooltip: function() {
|
|
|
|
let key = this.doc.getElementById("toolbox-minimize-key")
|
|
|
|
.getAttribute("key");
|
|
|
|
return "(" + (osString == "Darwin" ? "Cmd+Shift+" : "Ctrl+Shift+") +
|
|
|
|
key.toUpperCase() + ")";
|
|
|
|
},
|
|
|
|
|
2015-06-08 16:49:38 +03:00
|
|
|
_onBottomHostMinimized: function() {
|
|
|
|
let btn = this.doc.querySelector("#toolbox-dock-bottom-minimize");
|
|
|
|
btn.className = "minimized";
|
2015-06-11 12:11:35 +03:00
|
|
|
|
2015-06-08 16:49:38 +03:00
|
|
|
btn.setAttribute("tooltiptext",
|
2015-06-11 12:11:35 +03:00
|
|
|
toolboxStrings("toolboxDockButtons.bottom.maximize") + " " +
|
|
|
|
this._getMinimizeButtonShortcutTooltip());
|
2015-06-08 16:49:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_onBottomHostMaximized: function() {
|
|
|
|
let btn = this.doc.querySelector("#toolbox-dock-bottom-minimize");
|
|
|
|
btn.className = "maximized";
|
2015-06-11 12:11:35 +03:00
|
|
|
|
2015-06-08 16:49:38 +03:00
|
|
|
btn.setAttribute("tooltiptext",
|
2015-06-11 12:11:35 +03:00
|
|
|
toolboxStrings("toolboxDockButtons.bottom.minimize") + " " +
|
|
|
|
this._getMinimizeButtonShortcutTooltip());
|
2015-06-08 16:49:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_onToolSelectWhileMinimized: function() {
|
|
|
|
this._host.maximize();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onBottomHostWillChange: function() {
|
|
|
|
this._host.maximize();
|
|
|
|
|
|
|
|
this._host.off("minimized", this._onBottomHostMinimized);
|
|
|
|
this._host.off("maximized", this._onBottomHostMaximized);
|
|
|
|
this.off("before-select", this._onToolSelectWhileMinimized);
|
|
|
|
},
|
|
|
|
|
2015-06-11 12:11:35 +03:00
|
|
|
_toggleMinimizeMode: function() {
|
|
|
|
if (this.hostType !== Toolbox.HostType.BOTTOM) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the height to which the host should be minimized so the
|
|
|
|
// tabbar is still visible.
|
|
|
|
let toolbarHeight = this.doc.querySelector(".devtools-tabbar")
|
|
|
|
.getBoxQuads({box: "content"})[0]
|
|
|
|
.bounds.height;
|
|
|
|
this._host.toggleMinimizeMode(toolbarHeight);
|
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Add tabs to the toolbox UI for registered tools
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_buildTabs: function() {
|
2013-01-11 16:16:31 +04:00
|
|
|
for (let definition of gDevTools.getToolDefinitionArray()) {
|
2012-11-30 12:07:59 +04:00
|
|
|
this._buildTabForTool(definition);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-01-09 15:36:01 +04:00
|
|
|
* Add buttons to the UI as specified in the devtools.toolbox.toolbarSpec pref
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_buildButtons: function() {
|
2014-04-30 18:48:00 +04:00
|
|
|
if (!this.target.isAddon) {
|
|
|
|
this._buildPickerButton();
|
|
|
|
}
|
2014-01-09 15:36:01 +04:00
|
|
|
|
2015-05-01 23:01:38 +03:00
|
|
|
this.setToolboxButtonsVisibility();
|
|
|
|
|
2015-05-06 20:34:27 +03:00
|
|
|
// Old servers don't have a GCLI Actor, so just return
|
|
|
|
if (!this.target.hasActor("gcli")) {
|
|
|
|
return promise.resolve();
|
|
|
|
}
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
const options = {
|
|
|
|
environment: CommandUtils.createEnvironment(this, '_target')
|
|
|
|
};
|
|
|
|
return CommandUtils.createRequisition(this.target, options).then(requisition => {
|
2014-06-09 18:16:26 +04:00
|
|
|
this._requisition = requisition;
|
2015-04-23 12:24:49 +03:00
|
|
|
|
|
|
|
const spec = CommandUtils.getCommandbarSpec("devtools.toolbox.toolbarSpec");
|
2014-06-09 18:16:26 +04:00
|
|
|
return CommandUtils.createButtons(spec, this.target, this.doc,
|
|
|
|
requisition).then(buttons => {
|
|
|
|
let container = this.doc.getElementById("toolbox-buttons");
|
2014-09-09 13:55:00 +04:00
|
|
|
buttons.forEach(button=> {
|
|
|
|
if (button) {
|
|
|
|
container.appendChild(button);
|
|
|
|
}
|
|
|
|
});
|
2014-06-09 18:16:26 +04:00
|
|
|
this.setToolboxButtonsVisibility();
|
|
|
|
});
|
|
|
|
});
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2014-01-09 15:36:01 +04:00
|
|
|
/**
|
|
|
|
* Adding the element picker button is done here unlike the other buttons
|
|
|
|
* since we want it to work for remote targets too
|
|
|
|
*/
|
|
|
|
_buildPickerButton: function() {
|
|
|
|
this._pickerButton = this.doc.createElement("toolbarbutton");
|
|
|
|
this._pickerButton.id = "command-button-pick";
|
2014-02-10 17:50:13 +04:00
|
|
|
this._pickerButton.className = "command-button command-button-invertable";
|
2014-01-09 15:36:01 +04:00
|
|
|
this._pickerButton.setAttribute("tooltiptext", toolboxStrings("pickButton.tooltip"));
|
2014-08-27 14:19:30 +04:00
|
|
|
this._pickerButton.setAttribute("hidden", "true");
|
2014-01-09 15:36:01 +04:00
|
|
|
|
2014-05-28 18:11:33 +04:00
|
|
|
let container = this.doc.querySelector("#toolbox-picker-container");
|
2014-01-09 15:36:01 +04:00
|
|
|
container.appendChild(this._pickerButton);
|
|
|
|
|
2014-02-01 13:24:44 +04:00
|
|
|
this._togglePicker = this.highlighterUtils.togglePicker.bind(this.highlighterUtils);
|
|
|
|
this._pickerButton.addEventListener("command", this._togglePicker, false);
|
2014-01-09 15:36:01 +04:00
|
|
|
},
|
|
|
|
|
2014-07-17 13:39:56 +04:00
|
|
|
/**
|
|
|
|
* Apply the current cache setting from devtools.cache.disabled to this
|
|
|
|
* toolbox's tab.
|
|
|
|
*/
|
|
|
|
_applyCacheSettings: function() {
|
|
|
|
let pref = "devtools.cache.disabled";
|
|
|
|
let cacheDisabled = Services.prefs.getBoolPref(pref);
|
|
|
|
|
|
|
|
if (this.target.activeTab) {
|
|
|
|
this.target.activeTab.reconfigure({"cacheDisabled": cacheDisabled});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-24 21:15:00 +03:00
|
|
|
/**
|
|
|
|
* Apply the current service workers testing setting from
|
|
|
|
* devtools.serviceWorkers.testing.enabled to this toolbox's tab.
|
|
|
|
*/
|
|
|
|
_applyServiceWorkersTestingSettings: function() {
|
|
|
|
let pref = "devtools.serviceWorkers.testing.enabled";
|
|
|
|
let serviceWorkersTestingEnabled =
|
|
|
|
Services.prefs.getBoolPref(pref) || false;
|
|
|
|
|
|
|
|
if (this.target.activeTab) {
|
|
|
|
this.target.activeTab.reconfigure({
|
|
|
|
"serviceWorkersTestingEnabled": serviceWorkersTestingEnabled
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-06-13 18:27:10 +04:00
|
|
|
/**
|
|
|
|
* Setter for the checked state of the picker button in the toolbar
|
|
|
|
* @param {Boolean} isChecked
|
|
|
|
*/
|
|
|
|
set pickerButtonChecked(isChecked) {
|
|
|
|
if (isChecked) {
|
|
|
|
this._pickerButton.setAttribute("checked", "true");
|
|
|
|
} else {
|
|
|
|
this._pickerButton.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-03-07 02:02:11 +04:00
|
|
|
/**
|
|
|
|
* Return all toolbox buttons (command buttons, plus any others that were
|
|
|
|
* added manually).
|
|
|
|
*/
|
|
|
|
get toolboxButtons() {
|
2014-08-27 14:19:30 +04:00
|
|
|
return ToolboxButtons.map(options => {
|
|
|
|
let button = this.doc.getElementById(options.id);
|
2014-03-07 02:02:11 +04:00
|
|
|
// Some buttons may not exist inside of Browser Toolbox
|
|
|
|
if (!button) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-30 19:23:01 +03:00
|
|
|
|
|
|
|
// Disable tilt in E10S mode. Removing it from the list of toolbox buttons
|
|
|
|
// allows a bunch of tests to pass without modification.
|
|
|
|
if (this.target.isMultiProcess && options.id === "command-button-tilt") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-07 02:02:11 +04:00
|
|
|
return {
|
2014-08-27 14:19:30 +04:00
|
|
|
id: options.id,
|
2014-03-07 02:02:11 +04:00
|
|
|
button: button,
|
|
|
|
label: button.getAttribute("tooltiptext"),
|
2014-08-27 14:19:30 +04:00
|
|
|
visibilityswitch: "devtools." + options.id + ".enabled",
|
2015-06-08 17:03:49 +03:00
|
|
|
isTargetSupported: options.isTargetSupported
|
|
|
|
? options.isTargetSupported
|
|
|
|
: target => target.isLocalTab
|
2014-10-30 19:23:01 +03:00
|
|
|
};
|
2014-03-07 02:02:11 +04:00
|
|
|
}).filter(button=>button);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure the visibility of each toolbox button matches the
|
|
|
|
* preference value. Simply hide buttons that are preffed off.
|
|
|
|
*/
|
|
|
|
setToolboxButtonsVisibility: function() {
|
|
|
|
this.toolboxButtons.forEach(buttonSpec => {
|
2015-06-08 17:03:49 +03:00
|
|
|
let { visibilityswitch, button, isTargetSupported } = buttonSpec;
|
2014-03-07 02:02:11 +04:00
|
|
|
let on = true;
|
|
|
|
try {
|
|
|
|
on = Services.prefs.getBoolPref(visibilityswitch);
|
|
|
|
} catch (ex) { }
|
|
|
|
|
2014-08-27 14:19:30 +04:00
|
|
|
on = on && isTargetSupported(this.target);
|
|
|
|
|
2014-03-07 02:02:11 +04:00
|
|
|
if (button) {
|
|
|
|
if (on) {
|
|
|
|
button.removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
button.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-10-30 19:23:01 +03:00
|
|
|
|
|
|
|
// Tilt is handled separately because it is disabled in E10S mode. Because
|
|
|
|
// we have removed tilt from toolboxButtons we have to deal with it here.
|
|
|
|
let tiltEnabled = !this.target.isMultiProcess &&
|
|
|
|
Services.prefs.getBoolPref("devtools.command-button-tilt.enabled");
|
|
|
|
let tiltButton = this.doc.getElementById("command-button-tilt");
|
2014-11-06 21:56:21 +03:00
|
|
|
// Remote toolboxes don't add the button to the DOM at all
|
|
|
|
if (!tiltButton) {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-30 19:23:01 +03:00
|
|
|
|
|
|
|
if (tiltEnabled) {
|
|
|
|
tiltButton.removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
tiltButton.setAttribute("hidden", "true");
|
|
|
|
}
|
2014-03-07 02:02:11 +04:00
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Build a tab for one tool definition and add to the toolbox
|
|
|
|
*
|
|
|
|
* @param {string} toolDefinition
|
|
|
|
* Tool definition of the tool to build a tab for.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_buildTabForTool: function(toolDefinition) {
|
2012-11-30 12:07:59 +04:00
|
|
|
if (!toolDefinition.isTargetSupported(this._target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabs = this.doc.getElementById("toolbox-tabs");
|
|
|
|
let deck = this.doc.getElementById("toolbox-deck");
|
|
|
|
|
|
|
|
let id = toolDefinition.id;
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
if (toolDefinition.ordinal == undefined || toolDefinition.ordinal < 0) {
|
|
|
|
toolDefinition.ordinal = MAX_ORDINAL;
|
|
|
|
}
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
let radio = this.doc.createElement("radio");
|
2013-05-23 03:24:22 +04:00
|
|
|
// The radio element is not being used in the conventional way, thus
|
|
|
|
// the devtools-tab class replaces the radio XBL binding with its base
|
|
|
|
// binding (the control-item binding).
|
2014-02-10 17:50:13 +04:00
|
|
|
radio.className = "devtools-tab";
|
2012-11-30 12:07:59 +04:00
|
|
|
radio.id = "toolbox-tab-" + id;
|
|
|
|
radio.setAttribute("toolid", id);
|
2013-04-30 20:58:04 +04:00
|
|
|
radio.setAttribute("ordinal", toolDefinition.ordinal);
|
2012-12-18 19:11:27 +04:00
|
|
|
radio.setAttribute("tooltiptext", toolDefinition.tooltip);
|
2014-02-10 17:50:13 +04:00
|
|
|
if (toolDefinition.invertIconForLightTheme) {
|
|
|
|
radio.setAttribute("icon-invertable", "true");
|
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
radio.addEventListener("command", () => {
|
2012-11-30 12:07:59 +04:00
|
|
|
this.selectTool(id);
|
2013-09-24 00:36:44 +04:00
|
|
|
});
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-05-11 05:53:58 +04:00
|
|
|
// spacer lets us center the image and label, while allowing cropping
|
|
|
|
let spacer = this.doc.createElement("spacer");
|
|
|
|
spacer.setAttribute("flex", "1");
|
|
|
|
radio.appendChild(spacer);
|
|
|
|
|
2013-03-14 03:10:15 +04:00
|
|
|
if (toolDefinition.icon) {
|
|
|
|
let image = this.doc.createElement("image");
|
2013-05-25 12:05:34 +04:00
|
|
|
image.className = "default-icon";
|
|
|
|
image.setAttribute("src",
|
|
|
|
toolDefinition.icon || toolDefinition.highlightedicon);
|
|
|
|
radio.appendChild(image);
|
|
|
|
// Adding the highlighted icon image
|
|
|
|
image = this.doc.createElement("image");
|
|
|
|
image.className = "highlighted-icon";
|
|
|
|
image.setAttribute("src",
|
|
|
|
toolDefinition.highlightedicon || toolDefinition.icon);
|
2013-03-14 03:10:15 +04:00
|
|
|
radio.appendChild(image);
|
|
|
|
}
|
|
|
|
|
2014-07-28 22:02:29 +04:00
|
|
|
if (toolDefinition.label && !toolDefinition.iconOnly) {
|
2013-05-04 10:31:07 +04:00
|
|
|
let label = this.doc.createElement("label");
|
2015-06-08 17:03:49 +03:00
|
|
|
label.setAttribute("value", toolDefinition.label);
|
2013-05-04 10:31:07 +04:00
|
|
|
label.setAttribute("crop", "end");
|
|
|
|
label.setAttribute("flex", "1");
|
|
|
|
radio.appendChild(label);
|
|
|
|
radio.setAttribute("flex", "1");
|
|
|
|
}
|
2013-03-14 03:10:15 +04:00
|
|
|
|
2013-11-13 22:02:05 +04:00
|
|
|
if (!toolDefinition.bgTheme) {
|
|
|
|
toolDefinition.bgTheme = "theme-toolbar";
|
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
let vbox = this.doc.createElement("vbox");
|
2013-11-13 22:02:05 +04:00
|
|
|
vbox.className = "toolbox-panel " + toolDefinition.bgTheme;
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-11-12 01:13:28 +04:00
|
|
|
// There is already a container for the webconsole frame.
|
|
|
|
if (!this.doc.getElementById("toolbox-panel-" + id)) {
|
|
|
|
vbox.id = "toolbox-panel-" + id;
|
|
|
|
}
|
2013-04-30 20:58:04 +04:00
|
|
|
|
2014-05-28 18:11:33 +04:00
|
|
|
if (id === "options") {
|
|
|
|
// Options panel is special. It doesn't belong in the same container as
|
|
|
|
// the other tabs.
|
2014-07-08 09:42:00 +04:00
|
|
|
radio.setAttribute("role", "button");
|
2014-05-28 18:11:33 +04:00
|
|
|
let optionTabContainer = this.doc.getElementById("toolbox-option-container");
|
|
|
|
optionTabContainer.appendChild(radio);
|
2013-04-30 20:58:04 +04:00
|
|
|
deck.appendChild(vbox);
|
2013-09-24 00:36:44 +04:00
|
|
|
} else {
|
2014-07-08 09:42:00 +04:00
|
|
|
radio.setAttribute("role", "tab");
|
|
|
|
|
2014-05-28 18:11:33 +04:00
|
|
|
// If there is no tab yet, or the ordinal to be added is the largest one.
|
|
|
|
if (tabs.childNodes.length == 0 ||
|
|
|
|
tabs.lastChild.getAttribute("ordinal") <= toolDefinition.ordinal) {
|
|
|
|
tabs.appendChild(radio);
|
|
|
|
deck.appendChild(vbox);
|
|
|
|
} else {
|
|
|
|
// else, iterate over all the tabs to get the correct location.
|
|
|
|
Array.some(tabs.childNodes, (node, i) => {
|
|
|
|
if (+node.getAttribute("ordinal") > toolDefinition.ordinal) {
|
|
|
|
tabs.insertBefore(radio, node);
|
|
|
|
deck.insertBefore(vbox, deck.childNodes[i]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2013-04-30 20:58:04 +04:00
|
|
|
}
|
2013-01-13 12:52:03 +04:00
|
|
|
|
|
|
|
this._addKeysToWindow();
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2013-05-15 02:25:28 +04:00
|
|
|
/**
|
2013-06-23 07:00:51 +04:00
|
|
|
* Ensure the tool with the given id is loaded.
|
2013-05-15 02:25:28 +04:00
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to load.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
loadTool: function(id) {
|
2014-01-09 15:36:01 +04:00
|
|
|
if (id === "inspector" && !this._inspector) {
|
|
|
|
return this.initInspector().then(() => {
|
|
|
|
return this.loadTool(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:12:20 +04:00
|
|
|
let deferred = promise.defer();
|
2013-05-15 02:25:28 +04:00
|
|
|
let iframe = this.doc.getElementById("toolbox-panel-iframe-" + id);
|
|
|
|
|
|
|
|
if (iframe) {
|
2013-06-23 07:00:51 +04:00
|
|
|
let panel = this._toolPanels.get(id);
|
|
|
|
if (panel) {
|
|
|
|
deferred.resolve(panel);
|
|
|
|
} else {
|
2013-09-24 00:36:44 +04:00
|
|
|
this.once(id + "-ready", panel => {
|
2013-06-23 07:00:51 +04:00
|
|
|
deferred.resolve(panel);
|
|
|
|
});
|
|
|
|
}
|
2013-05-15 02:25:28 +04:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
let definition = gDevTools.getToolDefinition(id);
|
2013-06-23 07:00:51 +04:00
|
|
|
if (!definition) {
|
2015-06-08 17:03:49 +03:00
|
|
|
deferred.reject(new Error("no such tool id " + id));
|
2013-06-23 07:00:51 +04:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
2013-09-24 00:36:44 +04:00
|
|
|
|
2013-05-15 02:25:28 +04:00
|
|
|
iframe = this.doc.createElement("iframe");
|
|
|
|
iframe.className = "toolbox-panel-iframe";
|
|
|
|
iframe.id = "toolbox-panel-iframe-" + id;
|
|
|
|
iframe.setAttribute("flex", 1);
|
|
|
|
iframe.setAttribute("forceOwnRefreshDriver", "");
|
|
|
|
iframe.tooltip = "aHTMLTooltip";
|
2013-11-13 22:02:05 +04:00
|
|
|
iframe.style.visibility = "hidden";
|
2013-05-15 02:25:28 +04:00
|
|
|
|
2014-09-08 15:23:11 +04:00
|
|
|
gDevTools.emit(id + "-init", this, iframe);
|
|
|
|
this.emit(id + "-init", iframe);
|
|
|
|
|
|
|
|
// If no parent yet, append the frame into default location.
|
|
|
|
if (!iframe.parentNode) {
|
|
|
|
let vbox = this.doc.getElementById("toolbox-panel-" + id);
|
|
|
|
vbox.appendChild(iframe);
|
|
|
|
}
|
2013-05-15 02:25:28 +04:00
|
|
|
|
|
|
|
let onLoad = () => {
|
2013-11-13 22:02:05 +04:00
|
|
|
// Prevent flicker while loading by waiting to make visible until now.
|
|
|
|
iframe.style.visibility = "visible";
|
|
|
|
|
2014-09-08 15:23:11 +04:00
|
|
|
// The build method should return a panel instance, so events can
|
|
|
|
// be fired with the panel as an argument. However, in order to keep
|
|
|
|
// backward compatibility with existing extensions do a check
|
|
|
|
// for a promise return value.
|
2013-05-15 02:25:28 +04:00
|
|
|
let built = definition.build(iframe.contentWindow, this);
|
2014-09-08 15:23:11 +04:00
|
|
|
if (!(built instanceof Promise)) {
|
|
|
|
let panel = built;
|
|
|
|
iframe.panel = panel;
|
|
|
|
|
2014-10-07 20:13:51 +04:00
|
|
|
// The panel instance is expected to fire (and listen to) various
|
|
|
|
// framework events, so make sure it's properly decorated with
|
|
|
|
// appropriate API (on, off, once, emit).
|
|
|
|
// In this case we decorate panel instances directly returned by
|
|
|
|
// the tool definition 'build' method.
|
|
|
|
if (typeof panel.emit == "undefined") {
|
|
|
|
EventEmitter.decorate(panel);
|
|
|
|
}
|
|
|
|
|
2014-09-08 15:23:11 +04:00
|
|
|
gDevTools.emit(id + "-build", this, panel);
|
|
|
|
this.emit(id + "-build", panel);
|
|
|
|
|
|
|
|
// The panel can implement an 'open' method for asynchronous
|
|
|
|
// initialization sequence.
|
|
|
|
if (typeof panel.open == "function") {
|
|
|
|
built = panel.open();
|
|
|
|
} else {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
deferred.resolve(panel);
|
|
|
|
built = deferred.promise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait till the panel is fully ready and fire 'ready' events.
|
2013-07-11 11:12:20 +04:00
|
|
|
promise.resolve(built).then((panel) => {
|
2013-05-15 02:25:28 +04:00
|
|
|
this._toolPanels.set(id, panel);
|
2014-09-08 15:23:11 +04:00
|
|
|
|
2014-10-07 20:13:51 +04:00
|
|
|
// Make sure to decorate panel object with event API also in case
|
|
|
|
// where the tool definition 'build' method returns only a promise
|
|
|
|
// and the actual panel instance is available as soon as the
|
|
|
|
// promise is resolved.
|
|
|
|
if (typeof panel.emit == "undefined") {
|
|
|
|
EventEmitter.decorate(panel);
|
|
|
|
}
|
|
|
|
|
2013-05-15 02:25:28 +04:00
|
|
|
gDevTools.emit(id + "-ready", this, panel);
|
2014-09-08 15:23:11 +04:00
|
|
|
this.emit(id + "-ready", panel);
|
|
|
|
|
2013-05-15 02:25:28 +04:00
|
|
|
deferred.resolve(panel);
|
2013-09-03 15:20:27 +04:00
|
|
|
}, console.error);
|
2013-05-15 02:25:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
iframe.setAttribute("src", definition.url);
|
2014-07-07 13:27:10 +04:00
|
|
|
if (definition.panelLabel) {
|
|
|
|
iframe.setAttribute("aria-label", definition.panelLabel);
|
|
|
|
}
|
2013-11-16 06:47:00 +04:00
|
|
|
|
|
|
|
// Depending on the host, iframe.contentWindow is not always
|
|
|
|
// defined at this moment. If it is not defined, we use an
|
|
|
|
// event listener on the iframe DOM node. If it's defined,
|
|
|
|
// we use the chromeEventHandler. We can't use a listener
|
|
|
|
// on the DOM node every time because this won't work
|
|
|
|
// if the (xul chrome) iframe is loaded in a content docshell.
|
|
|
|
if (iframe.contentWindow) {
|
|
|
|
let domHelper = new DOMHelpers(iframe.contentWindow);
|
|
|
|
domHelper.onceDOMReady(onLoad);
|
|
|
|
} else {
|
|
|
|
let callback = () => {
|
|
|
|
iframe.removeEventListener("DOMContentLoaded", callback);
|
|
|
|
onLoad();
|
2015-06-08 17:03:49 +03:00
|
|
|
};
|
2013-11-16 06:47:00 +04:00
|
|
|
iframe.addEventListener("DOMContentLoaded", callback);
|
|
|
|
}
|
|
|
|
|
2013-05-15 02:25:28 +04:00
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Switch to the tool with the given id
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to switch to
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
selectTool: function(id) {
|
2015-06-08 16:49:38 +03:00
|
|
|
this.emit("before-select", id);
|
|
|
|
|
2013-03-14 03:10:15 +04:00
|
|
|
let selected = this.doc.querySelector(".devtools-tab[selected]");
|
|
|
|
if (selected) {
|
|
|
|
selected.removeAttribute("selected");
|
2014-07-08 09:42:00 +04:00
|
|
|
selected.setAttribute("aria-selected", "false");
|
2013-03-14 03:10:15 +04:00
|
|
|
}
|
2013-09-24 00:36:44 +04:00
|
|
|
|
2013-03-14 03:10:15 +04:00
|
|
|
let tab = this.doc.getElementById("toolbox-tab-" + id);
|
|
|
|
tab.setAttribute("selected", "true");
|
2014-07-08 09:42:00 +04:00
|
|
|
tab.setAttribute("aria-selected", "true");
|
2013-03-14 03:10:15 +04:00
|
|
|
|
2014-05-28 18:11:33 +04:00
|
|
|
// If options is selected, the separator between it and the
|
|
|
|
// command buttons should be hidden.
|
|
|
|
let sep = this.doc.getElementById("toolbox-controls-separator");
|
|
|
|
if (id === "options") {
|
|
|
|
sep.setAttribute("invisible", "true");
|
|
|
|
} else {
|
|
|
|
sep.removeAttribute("invisible");
|
|
|
|
}
|
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
if (this.currentToolId == id) {
|
2013-09-15 10:26:18 +04:00
|
|
|
// re-focus tool to get key events again
|
|
|
|
this.focusTool(id);
|
|
|
|
|
2013-03-07 11:30:03 +04:00
|
|
|
// Return the existing panel in order to have a consistent return value.
|
2013-07-11 11:12:20 +04:00
|
|
|
return promise.resolve(this._toolPanels.get(id));
|
2013-01-09 13:32:35 +04:00
|
|
|
}
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
if (!this.isReady) {
|
|
|
|
throw new Error("Can't select tool, wait for toolbox 'ready' event");
|
|
|
|
}
|
2013-09-24 00:36:44 +04:00
|
|
|
|
|
|
|
tab = this.doc.getElementById("toolbox-tab-" + id);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-05-24 14:26:17 +04:00
|
|
|
if (tab) {
|
2013-09-24 00:36:44 +04:00
|
|
|
if (this.currentToolId) {
|
|
|
|
this._telemetry.toolClosed(this.currentToolId);
|
2013-05-24 14:26:17 +04:00
|
|
|
}
|
|
|
|
this._telemetry.toolOpened(id);
|
|
|
|
} else {
|
2012-11-30 12:07:59 +04:00
|
|
|
throw new Error("No tool found");
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabstrip = this.doc.getElementById("toolbox-tabs");
|
|
|
|
|
2013-05-04 10:31:07 +04:00
|
|
|
// select the right tab, making 0th index the default tab if right tab not
|
2014-05-28 18:11:33 +04:00
|
|
|
// found.
|
|
|
|
tabstrip.selectedItem = tab || tabstrip.childNodes[0];
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
// and select the right iframe
|
|
|
|
let deck = this.doc.getElementById("toolbox-deck");
|
2014-05-28 18:11:33 +04:00
|
|
|
let panel = this.doc.getElementById("toolbox-panel-" + id);
|
|
|
|
deck.selectedPanel = panel;
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2015-09-01 19:36:18 +03:00
|
|
|
this.lastUsedToolId = this.currentToolId;
|
2013-09-24 00:36:44 +04:00
|
|
|
this.currentToolId = id;
|
2013-11-12 01:13:28 +04:00
|
|
|
this._refreshConsoleDisplay();
|
2013-04-15 16:34:48 +04:00
|
|
|
if (id != "options") {
|
|
|
|
Services.prefs.setCharPref(this._prefs.LAST_TOOL, id);
|
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-09-24 00:36:44 +04:00
|
|
|
return this.loadTool(id).then(panel => {
|
2013-09-15 10:26:18 +04:00
|
|
|
// focus the tool's frame to start receiving key events
|
|
|
|
this.focusTool(id);
|
|
|
|
|
2013-06-23 07:00:51 +04:00
|
|
|
this.emit("select", id);
|
|
|
|
this.emit(id + "-selected", panel);
|
|
|
|
return panel;
|
|
|
|
});
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2013-09-15 10:26:18 +04:00
|
|
|
/**
|
|
|
|
* Focus a tool's panel by id
|
|
|
|
* @param {string} id
|
|
|
|
* The id of tool to focus
|
|
|
|
*/
|
|
|
|
focusTool: function(id) {
|
|
|
|
let iframe = this.doc.getElementById("toolbox-panel-iframe-" + id);
|
|
|
|
iframe.focus();
|
|
|
|
},
|
|
|
|
|
2014-02-07 17:56:00 +04:00
|
|
|
/**
|
|
|
|
* Focus split console's input line
|
|
|
|
*/
|
|
|
|
focusConsoleInput: function() {
|
2014-08-15 16:52:08 +04:00
|
|
|
let consolePanel = this.getPanel("webconsole");
|
|
|
|
if (consolePanel) {
|
|
|
|
consolePanel.focusInput();
|
2014-03-27 16:50:30 +04:00
|
|
|
}
|
2014-02-07 17:56:00 +04:00
|
|
|
},
|
|
|
|
|
2014-08-15 16:50:43 +04:00
|
|
|
/**
|
|
|
|
* If the console is split and we are focusing an element outside
|
|
|
|
* of the console, then store the newly focused element, so that
|
|
|
|
* it can be restored once the split console closes.
|
|
|
|
*/
|
|
|
|
_onFocus: function({originalTarget}) {
|
|
|
|
// Ignore any non element nodes, or any elements contained
|
|
|
|
// within the webconsole frame.
|
|
|
|
let webconsoleURL = gDevTools.getToolDefinition("webconsole").url;
|
|
|
|
if (originalTarget.nodeType !== 1 ||
|
|
|
|
originalTarget.baseURI === webconsoleURL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._lastFocusedElement = originalTarget;
|
|
|
|
},
|
|
|
|
|
2013-11-12 01:13:28 +04:00
|
|
|
/**
|
2014-07-29 13:50:00 +04:00
|
|
|
* Opens the split console.
|
2014-07-29 00:54:41 +04:00
|
|
|
*
|
|
|
|
* @returns {Promise} a promise that resolves once the tool has been
|
|
|
|
* loaded and focused.
|
2013-11-12 01:13:28 +04:00
|
|
|
*/
|
2014-07-29 13:50:00 +04:00
|
|
|
openSplitConsole: function() {
|
|
|
|
this._splitConsole = true;
|
|
|
|
Services.prefs.setBoolPref(SPLITCONSOLE_ENABLED_PREF, true);
|
|
|
|
this._refreshConsoleDisplay();
|
|
|
|
this.emit("split-console");
|
2014-08-15 16:50:43 +04:00
|
|
|
|
2014-07-29 13:50:00 +04:00
|
|
|
return this.loadTool("webconsole").then(() => {
|
|
|
|
this.focusConsoleInput();
|
|
|
|
});
|
|
|
|
},
|
2014-07-29 00:54:41 +04:00
|
|
|
|
2014-07-29 13:50:00 +04:00
|
|
|
/**
|
|
|
|
* Closes the split console.
|
|
|
|
*
|
|
|
|
* @returns {Promise} a promise that resolves once the tool has been
|
|
|
|
* closed.
|
|
|
|
*/
|
|
|
|
closeSplitConsole: function() {
|
|
|
|
this._splitConsole = false;
|
|
|
|
Services.prefs.setBoolPref(SPLITCONSOLE_ENABLED_PREF, false);
|
|
|
|
this._refreshConsoleDisplay();
|
|
|
|
this.emit("split-console");
|
2014-08-15 16:50:43 +04:00
|
|
|
|
|
|
|
if (this._lastFocusedElement) {
|
|
|
|
this._lastFocusedElement.focus();
|
|
|
|
}
|
2014-07-29 13:50:00 +04:00
|
|
|
return promise.resolve();
|
|
|
|
},
|
2013-11-12 01:13:28 +04:00
|
|
|
|
2014-07-29 13:50:00 +04:00
|
|
|
/**
|
|
|
|
* Toggles the split state of the webconsole. If the webconsole panel
|
|
|
|
* is already selected then this command is ignored.
|
|
|
|
*
|
|
|
|
* @returns {Promise} a promise that resolves once the tool has been
|
|
|
|
* opened or closed.
|
|
|
|
*/
|
|
|
|
toggleSplitConsole: function() {
|
|
|
|
if (this.currentToolId !== "webconsole") {
|
|
|
|
return this.splitConsole ?
|
|
|
|
this.closeSplitConsole() :
|
|
|
|
this.openSplitConsole();
|
2013-11-12 01:13:28 +04:00
|
|
|
}
|
2014-07-29 00:54:41 +04:00
|
|
|
|
2014-07-29 13:50:00 +04:00
|
|
|
return promise.resolve();
|
2013-11-12 01:13:28 +04:00
|
|
|
},
|
|
|
|
|
2014-05-10 04:41:43 +04:00
|
|
|
/**
|
|
|
|
* Tells the target tab to reload.
|
|
|
|
*/
|
|
|
|
reloadTarget: function(force) {
|
|
|
|
this.target.activeTab.reload({ force: force });
|
|
|
|
},
|
|
|
|
|
2013-07-20 17:36:43 +04:00
|
|
|
/**
|
|
|
|
* Loads the tool next to the currently selected tool.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
selectNextTool: function() {
|
2014-05-28 18:11:33 +04:00
|
|
|
let tools = this.doc.querySelectorAll(".devtools-tab");
|
2013-07-20 17:36:43 +04:00
|
|
|
let selected = this.doc.querySelector(".devtools-tab[selected]");
|
2014-05-28 18:11:33 +04:00
|
|
|
let nextIndex = [...tools].indexOf(selected) + 1;
|
|
|
|
let next = tools[nextIndex] || tools[0];
|
2013-07-20 17:36:43 +04:00
|
|
|
let tool = next.getAttribute("toolid");
|
|
|
|
return this.selectTool(tool);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the tool just left to the currently selected tool.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
selectPreviousTool: function() {
|
2014-05-28 18:11:33 +04:00
|
|
|
let tools = this.doc.querySelectorAll(".devtools-tab");
|
2013-07-20 17:36:43 +04:00
|
|
|
let selected = this.doc.querySelector(".devtools-tab[selected]");
|
2014-05-28 18:11:33 +04:00
|
|
|
let prevIndex = [...tools].indexOf(selected) - 1;
|
|
|
|
let prev = tools[prevIndex] || tools[tools.length - 1];
|
|
|
|
let tool = prev.getAttribute("toolid");
|
2013-07-20 17:36:43 +04:00
|
|
|
return this.selectTool(tool);
|
|
|
|
},
|
|
|
|
|
2013-05-25 12:05:34 +04:00
|
|
|
/**
|
|
|
|
* Highlights the tool's tab if it is not the currently selected tool.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to highlight
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
highlightTool: function(id) {
|
2013-05-25 12:05:34 +04:00
|
|
|
let tab = this.doc.getElementById("toolbox-tab-" + id);
|
2013-12-20 20:40:21 +04:00
|
|
|
tab && tab.setAttribute("highlighted", "true");
|
2013-05-25 12:05:34 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* De-highlights the tool's tab.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to unhighlight
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
unhighlightTool: function(id) {
|
2013-05-25 12:05:34 +04:00
|
|
|
let tab = this.doc.getElementById("toolbox-tab-" + id);
|
2013-12-20 20:40:21 +04:00
|
|
|
tab && tab.removeAttribute("highlighted");
|
2013-05-25 12:05:34 +04:00
|
|
|
},
|
|
|
|
|
2013-01-09 13:32:35 +04:00
|
|
|
/**
|
|
|
|
* Raise the toolbox host.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
raise: function() {
|
2013-01-09 13:32:35 +04:00
|
|
|
this._host.raise();
|
|
|
|
},
|
|
|
|
|
2013-02-26 16:40:19 +04:00
|
|
|
/**
|
|
|
|
* Refresh the host's title.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_refreshHostTitle: function() {
|
2013-02-26 16:40:19 +04:00
|
|
|
let toolName;
|
2013-09-24 00:36:44 +04:00
|
|
|
let toolDef = gDevTools.getToolDefinition(this.currentToolId);
|
2013-04-15 16:34:48 +04:00
|
|
|
if (toolDef) {
|
2013-02-26 16:40:19 +04:00
|
|
|
toolName = toolDef.label;
|
|
|
|
} else {
|
|
|
|
// no tool is selected
|
|
|
|
toolName = toolboxStrings("toolbox.defaultTitle");
|
|
|
|
}
|
|
|
|
let title = toolboxStrings("toolbox.titleTemplate",
|
2015-10-06 18:04:36 +03:00
|
|
|
toolName, this.target.name ||
|
|
|
|
this.target.url);
|
2013-02-26 16:40:19 +04:00
|
|
|
this._host.setTitle(title);
|
|
|
|
},
|
|
|
|
|
2015-06-08 17:03:49 +03:00
|
|
|
_listFrames: function(event) {
|
2014-11-12 06:57:00 +03:00
|
|
|
if (!this._target.activeTab || !this._target.activeTab.traits.frames) {
|
2014-08-27 14:19:30 +04:00
|
|
|
// We are not targetting a regular TabActor
|
|
|
|
// it can be either an addon or browser toolbox actor
|
2014-11-03 21:52:00 +03:00
|
|
|
return promise.resolve();
|
2014-08-27 14:19:30 +04:00
|
|
|
}
|
|
|
|
let packet = {
|
|
|
|
to: this._target.form.actor,
|
|
|
|
type: "listFrames"
|
|
|
|
};
|
2014-11-03 21:52:00 +03:00
|
|
|
return this._target.client.request(packet, resp => {
|
2014-08-27 14:19:30 +04:00
|
|
|
this._updateFrames(null, { frames: resp.frames });
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-06-08 17:03:49 +03:00
|
|
|
selectFrame: function(event) {
|
2014-08-27 14:19:30 +04:00
|
|
|
let windowId = event.target.getAttribute("data-window-id");
|
|
|
|
let packet = {
|
|
|
|
to: this._target.form.actor,
|
|
|
|
type: "switchToFrame",
|
|
|
|
windowId: windowId
|
|
|
|
};
|
|
|
|
this._target.client.request(packet);
|
|
|
|
// Wait for frameUpdate event to update the UI
|
|
|
|
},
|
|
|
|
|
2015-06-08 17:03:49 +03:00
|
|
|
_updateFrames: function(event, data) {
|
2014-08-27 14:19:30 +04:00
|
|
|
if (!Services.prefs.getBoolPref("devtools.command-button-frames.enabled")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We may receive this event before the toolbox is ready.
|
|
|
|
if (!this.isReady) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let menu = this.doc.getElementById("command-button-frames");
|
|
|
|
|
|
|
|
if (data.destroyAll) {
|
|
|
|
let menupopup = menu.firstChild;
|
|
|
|
while (menupopup.firstChild) {
|
|
|
|
menupopup.firstChild.remove();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if (data.selected) {
|
|
|
|
let item = menu.querySelector("menuitem[data-window-id=\"" + data.selected + "\"]");
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Toggle the toolbarbutton if we selected a non top-level frame
|
|
|
|
if (item.hasAttribute("data-parent-id")) {
|
|
|
|
menu.setAttribute("checked", "true");
|
|
|
|
} else {
|
|
|
|
menu.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
// Uncheck the previously selected frame
|
2015-06-08 17:03:49 +03:00
|
|
|
let selected = menu.querySelector("menuitem[checked=true]");
|
2014-08-27 14:19:30 +04:00
|
|
|
if (selected) {
|
|
|
|
selected.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
// Check the new one
|
|
|
|
item.setAttribute("checked", "true");
|
|
|
|
} else if (data.frames) {
|
|
|
|
data.frames.forEach(win => {
|
|
|
|
let item = menu.querySelector("menuitem[data-window-id=\"" + win.id + "\"]");
|
|
|
|
if (win.destroy) {
|
|
|
|
if (item) {
|
|
|
|
item.remove();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!item) {
|
|
|
|
item = this.doc.createElement("menuitem");
|
2015-07-03 11:33:00 +03:00
|
|
|
item.setAttribute("type", "radio");
|
2014-08-27 14:19:30 +04:00
|
|
|
item.setAttribute("data-window-id", win.id);
|
|
|
|
if (win.parentID) {
|
|
|
|
item.setAttribute("data-parent-id", win.parentID);
|
|
|
|
}
|
|
|
|
// If we register a root docshell and we don't have any selected,
|
|
|
|
// consider it as the currently targeted one.
|
|
|
|
if (!win.parentID && !menu.querySelector("menuitem[checked=true]")) {
|
|
|
|
item.setAttribute("checked", "true");
|
|
|
|
menu.removeAttribute("checked");
|
|
|
|
}
|
|
|
|
menu.firstChild.appendChild(item);
|
|
|
|
}
|
|
|
|
item.setAttribute("label", win.url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Create a host object based on the given host type.
|
|
|
|
*
|
2013-01-11 21:31:09 +04:00
|
|
|
* Warning: some hosts require that the toolbox target provides a reference to
|
2015-06-08 17:03:49 +03:00
|
|
|
* the attached tab. Not all Targets have a tab property - make sure you
|
|
|
|
* correctly mix and match hosts and targets.
|
2013-01-11 21:31:09 +04:00
|
|
|
*
|
2012-11-30 12:07:59 +04:00
|
|
|
* @param {string} hostType
|
|
|
|
* The host type of the new host object
|
|
|
|
*
|
|
|
|
* @return {Host} host
|
|
|
|
* The created host object
|
|
|
|
*/
|
2013-11-16 06:47:00 +04:00
|
|
|
_createHost: function(hostType, options) {
|
2012-11-30 12:07:59 +04:00
|
|
|
if (!Hosts[hostType]) {
|
2013-09-24 00:36:44 +04:00
|
|
|
throw new Error("Unknown hostType: " + hostType);
|
2012-11-30 12:07:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// clean up the toolbox if its window is closed
|
2013-11-16 06:47:00 +04:00
|
|
|
let newHost = new Hosts[hostType](this.target.tab, options);
|
2012-11-30 12:07:59 +04:00
|
|
|
newHost.on("window-closed", this.destroy);
|
|
|
|
return newHost;
|
|
|
|
},
|
|
|
|
|
2015-09-29 13:06:25 +03:00
|
|
|
reload: function () {
|
|
|
|
const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
|
|
|
devtools.reload(true);
|
|
|
|
},
|
|
|
|
|
2015-06-10 00:59:27 +03:00
|
|
|
/**
|
|
|
|
* Switch to the last used host for the toolbox UI.
|
|
|
|
* This is determined by the devtools.toolbox.previousHost pref.
|
|
|
|
*/
|
|
|
|
switchToPreviousHost: function() {
|
|
|
|
let hostType = Services.prefs.getCharPref(this._prefs.PREVIOUS_HOST);
|
|
|
|
|
|
|
|
// Handle the case where the previous host happens to match the current
|
|
|
|
// host. If so, switch to bottom if it's not already used, and side if not.
|
|
|
|
if (hostType === this._host.type) {
|
|
|
|
if (hostType === Toolbox.HostType.BOTTOM) {
|
|
|
|
hostType = Toolbox.HostType.SIDE;
|
|
|
|
} else {
|
|
|
|
hostType = Toolbox.HostType.BOTTOM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.switchHost(hostType);
|
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
2015-05-22 17:06:37 +03:00
|
|
|
* Switch to a new host for the toolbox UI. E.g. bottom, sidebar, window,
|
|
|
|
* and focus the window when done.
|
2012-11-30 12:07:59 +04:00
|
|
|
*
|
|
|
|
* @param {string} hostType
|
|
|
|
* The host type of the new host object
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
switchHost: function(hostType) {
|
|
|
|
if (hostType == this._host.type || !this._target.isLocalTab) {
|
2014-01-01 07:28:42 +04:00
|
|
|
return null;
|
2012-12-15 05:10:43 +04:00
|
|
|
}
|
|
|
|
|
2015-06-08 16:49:38 +03:00
|
|
|
this.emit("host-will-change", hostType);
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
let newHost = this._createHost(hostType);
|
2013-09-24 00:36:44 +04:00
|
|
|
return newHost.create().then(iframe => {
|
2012-11-30 12:07:59 +04:00
|
|
|
// change toolbox document's parent to the new host
|
2012-12-13 17:03:55 +04:00
|
|
|
iframe.QueryInterface(Ci.nsIFrameLoaderOwner);
|
2012-11-30 12:07:59 +04:00
|
|
|
iframe.swapFrameLoaders(this.frame);
|
|
|
|
|
2015-05-22 17:06:37 +03:00
|
|
|
// See bug 1022726, most probably because of swapFrameLoaders we need to
|
|
|
|
// first focus the window here, and then once again further below to make
|
|
|
|
// sure focus actually happens.
|
|
|
|
this.frame.contentWindow.focus();
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
this._host.off("window-closed", this.destroy);
|
2013-11-12 01:13:28 +04:00
|
|
|
this.destroyHost();
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2015-06-10 00:59:27 +03:00
|
|
|
let prevHostType = this._host.type;
|
2012-11-30 12:07:59 +04:00
|
|
|
this._host = newHost;
|
|
|
|
|
2013-11-16 06:47:00 +04:00
|
|
|
if (this.hostType != Toolbox.HostType.CUSTOM) {
|
|
|
|
Services.prefs.setCharPref(this._prefs.LAST_HOST, this._host.type);
|
2015-06-10 00:59:27 +03:00
|
|
|
Services.prefs.setCharPref(this._prefs.PREVIOUS_HOST, prevHostType);
|
2013-11-16 06:47:00 +04:00
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
|
|
|
|
this._buildDockButtons();
|
2013-01-13 12:52:03 +04:00
|
|
|
this._addKeysToWindow();
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2015-05-22 17:06:37 +03:00
|
|
|
// Focus the contentWindow to make sure keyboard shortcuts work straight
|
|
|
|
// away.
|
|
|
|
this.frame.contentWindow.focus();
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
this.emit("host-changed");
|
2013-09-24 00:36:44 +04:00
|
|
|
});
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the tool-registered event.
|
|
|
|
* @param {string} event
|
|
|
|
* Name of the event ("tool-registered")
|
|
|
|
* @param {string} toolId
|
|
|
|
* Id of the tool that was registered
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_toolRegistered: function(event, toolId) {
|
|
|
|
let tool = gDevTools.getToolDefinition(toolId);
|
2012-11-30 12:07:59 +04:00
|
|
|
this._buildTabForTool(tool);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the tool-unregistered event.
|
|
|
|
* @param {string} event
|
|
|
|
* Name of the event ("tool-unregistered")
|
2013-04-19 17:44:38 +04:00
|
|
|
* @param {string|object} toolId
|
|
|
|
* Definition or id of the tool that was unregistered. Passing the
|
|
|
|
* tool id should be avoided as it is a temporary measure.
|
2012-11-30 12:07:59 +04:00
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
_toolUnregistered: function(event, toolId) {
|
2013-04-19 17:44:38 +04:00
|
|
|
if (typeof toolId != "string") {
|
|
|
|
toolId = toolId.id;
|
|
|
|
}
|
|
|
|
|
2013-04-17 12:58:41 +04:00
|
|
|
if (this._toolPanels.has(toolId)) {
|
|
|
|
let instance = this._toolPanels.get(toolId);
|
|
|
|
instance.destroy();
|
|
|
|
this._toolPanels.delete(toolId);
|
|
|
|
}
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
let radio = this.doc.getElementById("toolbox-tab-" + toolId);
|
|
|
|
let panel = this.doc.getElementById("toolbox-panel-" + toolId);
|
|
|
|
|
|
|
|
if (radio) {
|
2013-09-24 00:36:44 +04:00
|
|
|
if (this.currentToolId == toolId) {
|
2013-01-05 04:21:27 +04:00
|
|
|
let nextToolName = null;
|
|
|
|
if (radio.nextSibling) {
|
|
|
|
nextToolName = radio.nextSibling.getAttribute("toolid");
|
|
|
|
}
|
|
|
|
if (radio.previousSibling) {
|
|
|
|
nextToolName = radio.previousSibling.getAttribute("toolid");
|
|
|
|
}
|
|
|
|
if (nextToolName) {
|
|
|
|
this.selectTool(nextToolName);
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
radio.parentNode.removeChild(radio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel) {
|
|
|
|
panel.parentNode.removeChild(panel);
|
|
|
|
}
|
|
|
|
|
2013-01-13 12:52:03 +04:00
|
|
|
if (this.hostType == Toolbox.HostType.WINDOW) {
|
|
|
|
let doc = this.doc.defaultView.parent.document;
|
2013-05-04 10:31:07 +04:00
|
|
|
let key = doc.getElementById("key_" + toolId);
|
2013-01-13 12:52:03 +04:00
|
|
|
if (key) {
|
|
|
|
key.parentNode.removeChild(key);
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
},
|
|
|
|
|
2014-01-09 15:36:01 +04:00
|
|
|
/**
|
|
|
|
* Initialize the inspector/walker/selection/highlighter fronts.
|
|
|
|
* Returns a promise that resolves when the fronts are initialized
|
|
|
|
*/
|
|
|
|
initInspector: function() {
|
2014-03-11 14:21:20 +04:00
|
|
|
if (!this._initInspector) {
|
|
|
|
this._initInspector = Task.spawn(function*() {
|
|
|
|
this._inspector = InspectorFront(this._target.client, this._target.form);
|
2015-01-09 11:27:00 +03:00
|
|
|
this._walker = yield this._inspector.getWalker(
|
|
|
|
{showAllAnonymousContent: Services.prefs.getBoolPref("devtools.inspector.showAllAnonymousContent")}
|
|
|
|
);
|
2014-01-09 15:36:01 +04:00
|
|
|
this._selection = new Selection(this._walker);
|
2014-03-14 01:36:48 +04:00
|
|
|
|
2014-06-13 18:27:10 +04:00
|
|
|
if (this.highlighterUtils.isRemoteHighlightable()) {
|
2014-03-14 01:36:48 +04:00
|
|
|
this.walker.on("highlighter-ready", this._highlighterReady);
|
|
|
|
this.walker.on("highlighter-hide", this._highlighterHidden);
|
|
|
|
|
2015-06-05 01:30:23 +03:00
|
|
|
let autohide = !DevToolsUtils.testing;
|
2014-03-14 01:36:48 +04:00
|
|
|
this._highlighter = yield this._inspector.getHighlighter(autohide);
|
2014-01-09 15:36:01 +04:00
|
|
|
}
|
2014-03-11 14:21:20 +04:00
|
|
|
}.bind(this));
|
2014-01-09 15:36:01 +04:00
|
|
|
}
|
2014-03-11 14:21:20 +04:00
|
|
|
return this._initInspector;
|
2014-01-09 15:36:01 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the inspector/walker/selection fronts
|
|
|
|
* Returns a promise that resolves when the fronts are destroyed
|
|
|
|
*/
|
|
|
|
destroyInspector: function() {
|
2015-08-11 10:51:14 +03:00
|
|
|
if (this._destroyingInspector) {
|
|
|
|
return this._destroyingInspector;
|
2014-03-14 01:36:48 +04:00
|
|
|
}
|
|
|
|
|
2015-08-11 10:51:14 +03:00
|
|
|
return this._destroyingInspector = Task.spawn(function*() {
|
|
|
|
if (!this._inspector) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-05 16:22:37 +04:00
|
|
|
|
2015-08-11 10:51:14 +03:00
|
|
|
// Releasing the walker (if it has been created)
|
|
|
|
// This can fail, but in any case, we want to continue destroying the
|
|
|
|
// inspector/highlighter/selection
|
|
|
|
// FF42+: Inspector actor starts managing Walker actor and auto destroy it.
|
|
|
|
if (this._walker && !this.walker.traits.autoReleased) {
|
|
|
|
try {
|
|
|
|
yield this._walker.release();
|
|
|
|
} catch(e) {}
|
|
|
|
}
|
2014-02-05 23:50:25 +04:00
|
|
|
|
2015-08-11 10:51:14 +03:00
|
|
|
yield this.highlighterUtils.stopPicker();
|
|
|
|
yield this._inspector.destroy();
|
|
|
|
if (this._highlighter) {
|
|
|
|
// Note that if the toolbox is closed, this will work fine, but will fail
|
|
|
|
// in case the browser is closed and will trigger a noSuchActor message.
|
|
|
|
// We ignore the promise that |_hideBoxModel| returns, since we should still
|
|
|
|
// proceed with the rest of destruction if it fails.
|
|
|
|
// FF42+ now does the cleanup from the actor.
|
|
|
|
if (!this.highlighter.traits.autoHideOnDestroy) {
|
|
|
|
this.highlighterUtils.unhighlight();
|
2014-03-14 01:27:10 +04:00
|
|
|
}
|
2015-08-11 10:51:14 +03:00
|
|
|
yield this._highlighter.destroy();
|
|
|
|
}
|
|
|
|
if (this._selection) {
|
|
|
|
this._selection.destroy();
|
|
|
|
}
|
2014-03-14 01:36:48 +04:00
|
|
|
|
2015-08-11 10:51:14 +03:00
|
|
|
if (this.walker) {
|
|
|
|
this.walker.off("highlighter-ready", this._highlighterReady);
|
|
|
|
this.walker.off("highlighter-hide", this._highlighterHidden);
|
|
|
|
}
|
2014-01-09 15:36:01 +04:00
|
|
|
|
2015-08-11 10:51:14 +03:00
|
|
|
this._inspector = null;
|
|
|
|
this._highlighter = null;
|
|
|
|
this._selection = null;
|
|
|
|
this._walker = null;
|
|
|
|
}.bind(this));
|
2014-01-09 15:36:01 +04:00
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Get the toolbox's notification box
|
|
|
|
*
|
|
|
|
* @return The notification box element.
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
getNotificationBox: function() {
|
2012-11-30 12:07:59 +04:00
|
|
|
return this.doc.getElementById("toolbox-notificationbox");
|
|
|
|
},
|
|
|
|
|
2013-11-12 01:13:28 +04:00
|
|
|
/**
|
|
|
|
* Destroy the current host, and remove event listeners from its frame.
|
|
|
|
*
|
|
|
|
* @return {promise} to be resolved when the host is destroyed.
|
|
|
|
*/
|
|
|
|
destroyHost: function() {
|
2014-12-22 16:54:09 +03:00
|
|
|
// The host iframe's contentDocument may already be gone.
|
|
|
|
if (this.doc) {
|
|
|
|
this.doc.removeEventListener("keypress",
|
|
|
|
this._splitConsoleOnKeypress, false);
|
|
|
|
this.doc.removeEventListener("focus", this._onFocus, true);
|
|
|
|
}
|
2013-11-12 01:13:28 +04:00
|
|
|
return this._host.destroy();
|
|
|
|
},
|
|
|
|
|
2012-11-30 12:07:59 +04:00
|
|
|
/**
|
|
|
|
* Remove all UI elements, detach from target and clear up
|
|
|
|
*/
|
2013-09-24 00:36:44 +04:00
|
|
|
destroy: function() {
|
2012-12-13 17:03:55 +04:00
|
|
|
// If several things call destroy then we give them all the same
|
|
|
|
// destruction promise so we're sure to destroy only once
|
|
|
|
if (this._destroyer) {
|
|
|
|
return this._destroyer;
|
2012-11-30 12:07:59 +04:00
|
|
|
}
|
2013-02-26 16:40:19 +04:00
|
|
|
|
2014-10-06 21:40:59 +04:00
|
|
|
this.emit("destroy");
|
|
|
|
|
2013-02-26 16:40:19 +04:00
|
|
|
this._target.off("navigate", this._refreshHostTitle);
|
2014-08-27 14:19:30 +04:00
|
|
|
this._target.off("frame-update", this._updateFrames);
|
2013-02-26 16:40:19 +04:00
|
|
|
this.off("select", this._refreshHostTitle);
|
|
|
|
this.off("host-changed", this._refreshHostTitle);
|
2015-04-14 18:58:58 +03:00
|
|
|
this.off("ready", this._showDevEditionPromo);
|
2012-11-30 12:07:59 +04:00
|
|
|
|
2013-03-07 11:30:03 +04:00
|
|
|
gDevTools.off("tool-registered", this._toolRegistered);
|
|
|
|
gDevTools.off("tool-unregistered", this._toolUnregistered);
|
2012-12-13 17:03:55 +04:00
|
|
|
|
2014-07-17 13:39:56 +04:00
|
|
|
gDevTools.off("pref-changed", this._prefChanged);
|
|
|
|
|
2014-08-15 16:50:43 +04:00
|
|
|
this._lastFocusedElement = null;
|
2015-04-25 00:16:34 +03:00
|
|
|
|
2014-08-26 22:07:00 +04:00
|
|
|
if (this.webconsolePanel) {
|
|
|
|
this._saveSplitConsoleHeight();
|
|
|
|
this.webconsolePanel.removeEventListener("resize",
|
|
|
|
this._saveSplitConsoleHeight);
|
|
|
|
}
|
2014-07-31 21:33:23 +04:00
|
|
|
this.closeButton.removeEventListener("command", this.destroy, true);
|
2015-04-16 21:15:28 +03:00
|
|
|
this.textboxContextMenuPopup.removeEventListener("popupshowing",
|
|
|
|
this._updateTextboxMenuItems, true);
|
2014-07-31 21:33:23 +04:00
|
|
|
|
2013-03-07 11:30:03 +04:00
|
|
|
let outstanding = [];
|
2012-11-30 12:07:59 +04:00
|
|
|
for (let [id, panel] of this._toolPanels) {
|
2013-07-15 02:40:00 +04:00
|
|
|
try {
|
2014-10-06 21:40:59 +04:00
|
|
|
gDevTools.emit(id + "-destroy", this, panel);
|
|
|
|
this.emit(id + "-destroy", panel);
|
|
|
|
|
2013-07-15 02:40:00 +04:00
|
|
|
outstanding.push(panel.destroy());
|
2013-09-24 00:36:44 +04:00
|
|
|
} catch (e) {
|
2013-07-15 02:40:00 +04:00
|
|
|
// We don't want to stop here if any panel fail to close.
|
Make the debugger frontend cope with an already connected target (bug 933212); r=jryans,fitzgen
* Made the DebuggerClient, which is actually the RootActor front, not consider one of the attached child fronts as "active". Since a single DebuggerClient (or RootFront) is kept around for the App Manager's lifetime, it makes sense to move the notion of "active" tab to the toolbox's target. As each toolbox gets destroyed, the fronts should be detaching from their actors (if they are stateful) so that the app is no longer in a debugging state. Debugging a new app (or reconnecting to a previous one) will create new fronts anyway.
* Slightly refactored the TabClient, ThreadClient, SourceClient and TracerClient towards a protocol.js-based architecture, by adding parent-child references and lifecycle management. Now a tab-scoped thread actor for instance has the tab as its parent, while a global-scoped thread actor (chrome debugger) has the DebuggerCLient (RootFront) as its parent. This lets parents reference their children, so that caching in the target object can work. It also allowed me to move some methods from the DebuggerClient to the actual front that should be responsible, like reconfigureTab, reconfigureThread and attachThread. These methods now use DebuggerClient.requester, too.
* Added some error handling in the debugger client requester around "before" and "after" callbacks, which exposed some errors in tests that are now fixed.
* Fixed the state handling in the thread actor so that merely detaching from a thread doesn't put it in the exited state. This is the part that what was necessary for Firebug's use case.
* Properly loading tracer and webgl actors now on b2g.
2014-01-14 19:39:40 +04:00
|
|
|
console.error("Panel " + id + ":", e);
|
2013-07-15 02:40:00 +04:00
|
|
|
}
|
2012-11-30 12:07:59 +04:00
|
|
|
}
|
|
|
|
|
2015-03-24 21:15:00 +03:00
|
|
|
// Now that we are closing the toolbox we can re-enable the cache settings
|
|
|
|
// and disable the service workers testing settings for the current tab.
|
2015-05-18 21:15:35 +03:00
|
|
|
// FF41+ automatically cleans up state in actor on disconnect.
|
|
|
|
if (this.target.activeTab && !this.target.activeTab.traits.noTabReconfigureOnClose) {
|
2015-03-24 21:15:00 +03:00
|
|
|
this.target.activeTab.reconfigure({
|
|
|
|
"cacheDisabled": false,
|
|
|
|
"serviceWorkersTestingEnabled": false
|
|
|
|
});
|
2014-07-17 13:39:56 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:36:01 +04:00
|
|
|
// Destroying the walker and inspector fronts
|
2014-08-06 14:16:00 +04:00
|
|
|
outstanding.push(this.destroyInspector().then(() => {
|
|
|
|
// Removing buttons
|
2014-08-13 16:42:29 +04:00
|
|
|
if (this._pickerButton) {
|
|
|
|
this._pickerButton.removeEventListener("command", this._togglePicker, false);
|
|
|
|
this._pickerButton = null;
|
|
|
|
}
|
2014-08-06 14:16:00 +04:00
|
|
|
}));
|
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
// Destroy the profiler connection
|
2015-06-06 23:44:05 +03:00
|
|
|
outstanding.push(this.destroyPerformance());
|
2015-04-14 18:58:58 +03:00
|
|
|
|
2014-09-24 21:59:00 +04:00
|
|
|
// We need to grab a reference to win before this._host is destroyed.
|
|
|
|
let win = this.frame.ownerGlobal;
|
|
|
|
|
2014-09-09 13:55:00 +04:00
|
|
|
if (this._requisition) {
|
2015-04-23 12:24:49 +03:00
|
|
|
CommandUtils.destroyRequisition(this._requisition, this.target);
|
2013-09-03 15:20:27 +04:00
|
|
|
}
|
2014-04-15 14:01:27 +04:00
|
|
|
this._telemetry.toolClosed("toolbox");
|
2013-05-24 14:26:17 +04:00
|
|
|
this._telemetry.destroy();
|
|
|
|
|
2014-12-22 16:54:09 +03:00
|
|
|
// Finish all outstanding tasks (which means finish destroying panels and
|
|
|
|
// then destroying the host, successfully or not) before destroying the
|
2014-09-06 16:57:41 +04:00
|
|
|
// target.
|
2015-02-10 21:37:21 +03:00
|
|
|
this._destroyer = DevToolsUtils.settleAll(outstanding)
|
|
|
|
.catch(console.error)
|
|
|
|
.then(() => this.destroyHost())
|
|
|
|
.catch(console.error)
|
|
|
|
.then(() => {
|
2013-09-14 04:09:52 +04:00
|
|
|
// Targets need to be notified that the toolbox is being torn down.
|
|
|
|
// This is done after other destruction tasks since it may tear down
|
|
|
|
// fronts and the debugger transport which earlier destroy methods may
|
|
|
|
// require to complete.
|
2014-01-01 07:28:42 +04:00
|
|
|
if (!this._target) {
|
|
|
|
return null;
|
2013-09-14 04:09:52 +04:00
|
|
|
}
|
2014-01-01 07:28:42 +04:00
|
|
|
let target = this._target;
|
|
|
|
this._target = null;
|
2014-06-13 18:27:10 +04:00
|
|
|
this.highlighterUtils.release();
|
2014-01-01 07:28:42 +04:00
|
|
|
target.off("close", this.destroy);
|
|
|
|
return target.destroy();
|
2014-09-06 16:57:41 +04:00
|
|
|
}, console.error).then(() => {
|
2012-12-13 17:03:55 +04:00
|
|
|
this.emit("destroyed");
|
2014-08-08 01:35:19 +04:00
|
|
|
|
2013-03-25 07:39:00 +04:00
|
|
|
// Free _host after the call to destroyed in order to let a chance
|
|
|
|
// to destroyed listeners to still query toolbox attributes
|
|
|
|
this._host = null;
|
2013-10-31 05:29:06 +04:00
|
|
|
this._toolPanels.clear();
|
2014-08-08 01:35:19 +04:00
|
|
|
|
|
|
|
// Force GC to prevent long GC pauses when running tests and to free up
|
|
|
|
// memory in general when the toolbox is closed.
|
2015-06-05 01:30:23 +03:00
|
|
|
if (DevToolsUtils.testing) {
|
2014-08-08 01:35:19 +04:00
|
|
|
win.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.garbageCollect();
|
|
|
|
}
|
2013-10-31 05:29:06 +04:00
|
|
|
}).then(null, console.error);
|
2014-08-31 14:15:54 +04:00
|
|
|
|
|
|
|
let leakCheckObserver = ({wrappedJSObject: barrier}) => {
|
|
|
|
// Make the leak detector wait until this toolbox is properly destroyed.
|
|
|
|
barrier.client.addBlocker("DevTools: Wait until toolbox is destroyed",
|
|
|
|
this._destroyer);
|
|
|
|
};
|
|
|
|
|
|
|
|
let topic = "shutdown-leaks-before-check";
|
|
|
|
Services.obs.addObserver(leakCheckObserver, topic, false);
|
|
|
|
this._destroyer.then(() => {
|
|
|
|
Services.obs.removeObserver(leakCheckObserver, topic);
|
|
|
|
});
|
|
|
|
|
|
|
|
return this._destroyer;
|
2014-03-14 01:36:48 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_highlighterReady: function() {
|
|
|
|
this.emit("highlighter-ready");
|
|
|
|
},
|
|
|
|
|
|
|
|
_highlighterHidden: function() {
|
|
|
|
this.emit("highlighter-hide");
|
2014-10-23 04:18:31 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For displaying the promotional Doorhanger on first opening of
|
|
|
|
* the developer tools, promoting the Developer Edition.
|
|
|
|
*/
|
|
|
|
_showDevEditionPromo: function() {
|
|
|
|
// Do not display in browser toolbox
|
|
|
|
if (this.target.chrome) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let window = this.frame.contentWindow;
|
|
|
|
showDoorhanger({ window, type: "deveditionpromo" });
|
2015-04-14 18:58:58 +03:00
|
|
|
},
|
|
|
|
|
2015-04-16 21:15:28 +03:00
|
|
|
/**
|
|
|
|
* Enable / disable necessary textbox menu items using globalOverlay.js.
|
|
|
|
*/
|
|
|
|
_updateTextboxMenuItems: function() {
|
|
|
|
let window = this.doc.defaultView;
|
2015-06-08 17:03:49 +03:00
|
|
|
["cmd_undo", "cmd_delete", "cmd_cut",
|
|
|
|
"cmd_copy", "cmd_paste", "cmd_selectAll"].forEach(window.goUpdateCommand);
|
2015-04-16 21:15:28 +03:00
|
|
|
},
|
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
/**
|
|
|
|
* Connects to the SPS profiler when the developer tools are open. This is
|
|
|
|
* necessary because of the WebConsole's `profile` and `profileEnd` methods.
|
|
|
|
*/
|
2015-06-06 23:44:05 +03:00
|
|
|
initPerformance: Task.async(function*() {
|
2015-04-14 18:58:58 +03:00
|
|
|
// If target does not have profiler actor (addons), do not
|
|
|
|
// even register the shared performance connection.
|
|
|
|
if (!this.target.hasActor("profiler")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-11 04:43:19 +03:00
|
|
|
if (this._performanceFrontConnection) {
|
|
|
|
return this._performanceFrontConnection.promise;
|
2015-06-06 23:44:05 +03:00
|
|
|
}
|
|
|
|
|
2015-08-11 04:43:19 +03:00
|
|
|
this._performanceFrontConnection = promise.defer();
|
2015-08-13 04:42:54 +03:00
|
|
|
this._performance = createPerformanceFront(this._target);
|
|
|
|
yield this.performance.connect();
|
2015-08-11 04:43:19 +03:00
|
|
|
|
2015-04-14 18:58:58 +03:00
|
|
|
// Emit an event when connected, but don't wait on startup for this.
|
|
|
|
this.emit("profiler-connected");
|
2015-06-06 23:44:05 +03:00
|
|
|
|
2015-08-13 04:42:54 +03:00
|
|
|
this.performance.on("*", this._onPerformanceFrontEvent);
|
2015-08-11 04:43:19 +03:00
|
|
|
this._performanceFrontConnection.resolve(this.performance);
|
|
|
|
return this._performanceFrontConnection.promise;
|
2015-04-14 18:58:58 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
2015-06-15 21:38:39 +03:00
|
|
|
* Disconnects the underlying Performance actor. If the connection
|
2015-04-17 22:44:52 +03:00
|
|
|
* has not finished initializing, as opening a toolbox does not wait,
|
|
|
|
* the performance connection destroy method will wait for it on its own.
|
2015-04-14 18:58:58 +03:00
|
|
|
*/
|
2015-06-06 23:44:05 +03:00
|
|
|
destroyPerformance: Task.async(function*() {
|
|
|
|
if (!this.performance) {
|
2015-04-14 18:58:58 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-11 04:43:19 +03:00
|
|
|
// If still connecting to performance actor, allow the
|
|
|
|
// actor to resolve its connection before attempting to destroy.
|
|
|
|
if (this._performanceFrontConnection) {
|
|
|
|
yield this._performanceFrontConnection.promise;
|
|
|
|
}
|
2015-08-13 04:42:54 +03:00
|
|
|
this.performance.off("*", this._onPerformanceFrontEvent);
|
2015-06-06 23:44:05 +03:00
|
|
|
yield this.performance.destroy();
|
|
|
|
this._performance = null;
|
2015-04-14 18:58:58 +03:00
|
|
|
}),
|
2015-04-25 00:16:34 +03:00
|
|
|
|
2015-08-13 04:42:54 +03:00
|
|
|
/**
|
|
|
|
* Called when any event comes from the PerformanceFront. If the performance tool is already
|
|
|
|
* loaded when the first event comes in, immediately unbind this handler, as this is
|
|
|
|
* only used to queue up observed recordings before the performance tool can handle them,
|
|
|
|
* which will only occur when `console.profile()` recordings are started before the tool loads.
|
|
|
|
*/
|
|
|
|
_onPerformanceFrontEvent: Task.async(function*(eventName, recording) {
|
|
|
|
if (this.getPanel("performance")) {
|
|
|
|
this.performance.off("*", this._onPerformanceFrontEvent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let recordings = this._performanceQueuedRecordings = this._performanceQueuedRecordings || [];
|
|
|
|
|
|
|
|
// Before any console recordings, we'll get a `console-profile-start` event
|
|
|
|
// warning us that a recording will come later (via `recording-started`), so
|
|
|
|
// start to boot up the tool and populate the tool with any other recordings
|
|
|
|
// observed during that time.
|
|
|
|
if (eventName === "console-profile-start" && !this._performanceToolOpenedViaConsole) {
|
|
|
|
this._performanceToolOpenedViaConsole = this.loadTool("performance");
|
|
|
|
let panel = yield this._performanceToolOpenedViaConsole;
|
|
|
|
yield panel.open();
|
|
|
|
|
|
|
|
panel.panelWin.PerformanceController.populateWithRecordings(recordings);
|
|
|
|
this.performance.off("*", this._onPerformanceFrontEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, if it's a recording-started event, we've already started loading
|
|
|
|
// the tool, so just store this recording in our array to be later populated
|
|
|
|
// once the tool loads.
|
|
|
|
if (eventName === "recording-started") {
|
|
|
|
recordings.push(recording);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2015-04-25 00:16:34 +03:00
|
|
|
/**
|
|
|
|
* Returns gViewSourceUtils for viewing source.
|
|
|
|
*/
|
|
|
|
get gViewSourceUtils() {
|
|
|
|
return this.frame.contentWindow.gViewSourceUtils;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens source in style editor. Falls back to plain "view-source:".
|
2015-09-21 20:07:31 +03:00
|
|
|
* @see devtools/client/shared/source-utils.js
|
2015-04-25 00:16:34 +03:00
|
|
|
*/
|
2015-06-08 17:03:49 +03:00
|
|
|
viewSourceInStyleEditor: function(sourceURL, sourceLine) {
|
2015-04-25 00:16:34 +03:00
|
|
|
return sourceUtils.viewSourceInStyleEditor(this, sourceURL, sourceLine);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens source in debugger. Falls back to plain "view-source:".
|
2015-09-21 20:07:31 +03:00
|
|
|
* @see devtools/client/shared/source-utils.js
|
2015-04-25 00:16:34 +03:00
|
|
|
*/
|
2015-06-08 17:03:49 +03:00
|
|
|
viewSourceInDebugger: function(sourceURL, sourceLine) {
|
2015-04-25 00:16:34 +03:00
|
|
|
return sourceUtils.viewSourceInDebugger(this, sourceURL, sourceLine);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens source in scratchpad. Falls back to plain "view-source:".
|
|
|
|
* TODO The `sourceURL` for scratchpad instances are like `Scratchpad/1`.
|
|
|
|
* If instances are scoped one-per-browser-window, then we should be able
|
|
|
|
* to infer the URL from this toolbox, or use the built in scratchpad IN
|
|
|
|
* the toolbox.
|
|
|
|
*
|
2015-09-21 20:07:31 +03:00
|
|
|
* @see devtools/client/shared/source-utils.js
|
2015-04-25 00:16:34 +03:00
|
|
|
*/
|
2015-06-08 17:03:49 +03:00
|
|
|
viewSourceInScratchpad: function(sourceURL, sourceLine) {
|
2015-04-25 00:16:34 +03:00
|
|
|
return sourceUtils.viewSourceInScratchpad(sourceURL, sourceLine);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens source in plain "view-source:".
|
2015-09-21 20:07:31 +03:00
|
|
|
* @see devtools/client/shared/source-utils.js
|
2015-04-25 00:16:34 +03:00
|
|
|
*/
|
2015-06-08 17:03:49 +03:00
|
|
|
viewSource: function(sourceURL, sourceLine) {
|
2015-04-25 00:16:34 +03:00
|
|
|
return sourceUtils.viewSource(this, sourceURL, sourceLine);
|
|
|
|
},
|
2014-02-01 13:24:44 +04:00
|
|
|
};
|