2012-11-30 08:07:59 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2013-04-30 16:58:04 +00:00
|
|
|
const MAX_ORDINAL = 99;
|
2013-09-15 06:26:18 +00:00
|
|
|
const ZOOM_PREF = "devtools.toolbox.zoomValue";
|
|
|
|
const MIN_ZOOM = 0.5;
|
|
|
|
const MAX_ZOOM = 2;
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
let {Cc, Ci, Cu} = require("chrome");
|
2014-03-17 18:11:00 +00:00
|
|
|
let {Promise: promise} = require("resource://gre/modules/Promise.jsm");
|
2014-02-26 04:22:05 +00:00
|
|
|
let EventEmitter = require("devtools/toolkit/event-emitter");
|
2013-05-24 10:26:17 +00:00
|
|
|
let Telemetry = require("devtools/shared/telemetry");
|
2013-08-28 15:26:01 +00:00
|
|
|
let HUDService = require("devtools/webconsole/hudservice");
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-11-30 08:07:59 +00:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource:///modules/devtools/gDevTools.jsm");
|
2013-08-28 15:26:01 +00:00
|
|
|
Cu.import("resource:///modules/devtools/scratchpad-manager.jsm");
|
2013-11-16 02:47:00 +00:00
|
|
|
Cu.import("resource:///modules/devtools/DOMHelpers.jsm");
|
2014-02-05 19:50:25 +00:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-04-11 20:59:08 +00:00
|
|
|
loader.lazyGetter(this, "Hosts", () => require("devtools/framework/toolbox-hosts").Hosts);
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
loader.lazyImporter(this, "CommandUtils", "resource:///modules/devtools/DeveloperToolbar.jsm");
|
2013-01-04 20:31:38 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
loader.lazyGetter(this, "toolboxStrings", () => {
|
2012-12-18 15:11:27 +00:00
|
|
|
let bundle = Services.strings.createBundle("chrome://browser/locale/devtools/toolbox.properties");
|
2013-09-23 20:36:44 +00:00
|
|
|
return (name, ...args) => {
|
2012-12-18 15:11:27 +00:00
|
|
|
try {
|
2013-09-23 20:36:44 +00:00
|
|
|
if (!args.length) {
|
|
|
|
return bundle.GetStringFromName(name);
|
2013-02-26 12:40:19 +00:00
|
|
|
}
|
2013-09-23 20:36:44 +00:00
|
|
|
return bundle.formatStringFromName(name, args, args.length);
|
2012-12-18 15:11:27 +00:00
|
|
|
} catch (ex) {
|
2013-09-23 20:36:44 +00:00
|
|
|
Services.console.logStringMessage("Error reading '" + name + "'");
|
2014-01-01 03:28:42 +00:00
|
|
|
return null;
|
2012-12-18 15:11:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2014-01-09 11:36:01 +00:00
|
|
|
loader.lazyGetter(this, "Selection", () => require("devtools/framework/selection").Selection);
|
|
|
|
loader.lazyGetter(this, "InspectorFront", () => require("devtools/server/actors/inspector").InspectorFront);
|
|
|
|
|
2012-11-30 08:07:59 +00: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 13:03:55 +00:00
|
|
|
* @param {Toolbox.HostType} hostType
|
|
|
|
* Type of host that will host the toolbox (e.g. sidebar, window)
|
2013-11-16 02:47:00 +00:00
|
|
|
* @param {object} hostOptions
|
|
|
|
* Options for host specifically
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
2013-11-16 02:47:00 +00:00
|
|
|
function Toolbox(target, selectedTool, hostType, hostOptions) {
|
2012-11-30 08:07:59 +00:00
|
|
|
this._target = target;
|
|
|
|
this._toolPanels = new Map();
|
2013-05-24 10:26:17 +00:00
|
|
|
this._telemetry = new Telemetry();
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
this._toolRegistered = this._toolRegistered.bind(this);
|
|
|
|
this._toolUnregistered = this._toolUnregistered.bind(this);
|
2013-09-23 20:36:44 +00:00
|
|
|
this._refreshHostTitle = this._refreshHostTitle.bind(this);
|
2013-11-11 21:13:28 +00:00
|
|
|
this._splitConsoleOnKeypress = this._splitConsoleOnKeypress.bind(this)
|
2012-11-30 08:07:59 +00:00
|
|
|
this.destroy = this.destroy.bind(this);
|
2014-02-01 09:24:44 +00:00
|
|
|
this.highlighterUtils = new ToolboxHighlighterUtils(this);
|
2014-03-13 21:36:48 +00:00
|
|
|
this._highlighterReady = this._highlighterReady.bind(this);
|
|
|
|
this._highlighterHidden = this._highlighterHidden.bind(this);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-03-07 07:30:03 +00:00
|
|
|
this._target.on("close", this.destroy);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
if (!hostType) {
|
|
|
|
hostType = Services.prefs.getCharPref(this._prefs.LAST_HOST);
|
|
|
|
}
|
|
|
|
if (!selectedTool) {
|
|
|
|
selectedTool = Services.prefs.getCharPref(this._prefs.LAST_TOOL);
|
|
|
|
}
|
2013-09-23 20:36:44 +00:00
|
|
|
if (!gDevTools.getToolDefinition(selectedTool)) {
|
2012-11-30 08:07:59 +00:00
|
|
|
selectedTool = "webconsole";
|
|
|
|
}
|
|
|
|
this._defaultToolId = selectedTool;
|
|
|
|
|
2013-11-16 02:47:00 +00:00
|
|
|
this._host = this._createHost(hostType, hostOptions);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2012-12-14 07:05:00 +00:00
|
|
|
EventEmitter.decorate(this);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-02-26 12:40:19 +00:00
|
|
|
this._target.on("navigate", this._refreshHostTitle);
|
|
|
|
this.on("host-changed", this._refreshHostTitle);
|
|
|
|
this.on("select", this._refreshHostTitle);
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
gDevTools.on("tool-registered", this._toolRegistered);
|
|
|
|
gDevTools.on("tool-unregistered", this._toolUnregistered);
|
|
|
|
}
|
2013-04-11 20:59:08 +00:00
|
|
|
exports.Toolbox = Toolbox;
|
2012-11-30 08:07:59 +00: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 02:47:00 +00:00
|
|
|
WINDOW: "window",
|
|
|
|
CUSTOM: "custom"
|
2013-09-23 20:36:44 +00:00
|
|
|
};
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
Toolbox.prototype = {
|
|
|
|
_URL: "chrome://browser/content/devtools/framework/toolbox.xul",
|
|
|
|
|
|
|
|
_prefs: {
|
|
|
|
LAST_HOST: "devtools.toolbox.host",
|
|
|
|
LAST_TOOL: "devtools.toolbox.selectedTool",
|
|
|
|
SIDE_ENABLED: "devtools.toolbox.sideEnabled"
|
|
|
|
},
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
currentToolId: null,
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a *copy* of the _toolPanels collection.
|
|
|
|
*
|
|
|
|
* @return {Map} panels
|
|
|
|
* All the running panels in the toolbox
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
getToolPanels: function() {
|
|
|
|
return new Map(this._toolPanels);
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2012-12-13 13:03:55 +00:00
|
|
|
/**
|
|
|
|
* Access the panel for a given tool
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
getPanel: function(id) {
|
|
|
|
return this._toolPanels.get(id);
|
2012-12-13 13:03:55 +00: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-23 20:36:44 +00:00
|
|
|
getCurrentPanel: function() {
|
|
|
|
return this._toolPanels.get(this.currentToolId);
|
2012-12-13 13:03:55 +00:00
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00: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 06:26:18 +00:00
|
|
|
/**
|
|
|
|
* Get current zoom level of toolbox
|
|
|
|
*/
|
|
|
|
get zoomValue() {
|
|
|
|
return parseFloat(Services.prefs.getCharPref(ZOOM_PREF));
|
|
|
|
},
|
|
|
|
|
2014-01-09 11:36:01 +00:00
|
|
|
/**
|
|
|
|
* Get the toolbox highlighter front. Note that it may not always have been
|
|
|
|
* initialized first. Use `initInspector()` if needed.
|
|
|
|
*/
|
|
|
|
get highlighter() {
|
2014-02-01 09:24:44 +00:00
|
|
|
if (this.highlighterUtils.isRemoteHighlightable) {
|
2014-01-09 11:36:01 +00:00
|
|
|
return this._highlighter;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 15:46:51 +00:00
|
|
|
/**
|
|
|
|
* Get the toggled state of the split console
|
|
|
|
*/
|
|
|
|
get splitConsole() {
|
|
|
|
return this._splitConsole;
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Open the toolbox
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
open: function() {
|
2013-07-11 07:12:20 +00:00
|
|
|
let deferred = promise.defer();
|
2012-12-13 13:03:55 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
return this._host.create().then(iframe => {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
|
2013-05-24 10:26:17 +00:00
|
|
|
let domReady = () => {
|
2012-12-13 13:03:55 +00:00
|
|
|
this.isReady = true;
|
|
|
|
|
|
|
|
let closeButton = this.doc.getElementById("toolbox-close");
|
|
|
|
closeButton.addEventListener("command", this.destroy, true);
|
|
|
|
|
|
|
|
this._buildDockButtons();
|
2013-04-15 12:34:48 +00:00
|
|
|
this._buildOptions();
|
2012-12-13 13:03:55 +00:00
|
|
|
this._buildTabs();
|
2013-01-04 20:31:38 +00:00
|
|
|
this._buildButtons();
|
2013-01-13 08:52:03 +00:00
|
|
|
this._addKeysToWindow();
|
2014-05-10 00:41:43 +00:00
|
|
|
this._addReloadKeys();
|
2013-07-20 13:36:43 +00:00
|
|
|
this._addToolSwitchingKeys();
|
2013-09-15 06:26:18 +00:00
|
|
|
this._addZoomKeys();
|
|
|
|
this._loadInitialZoom();
|
2012-12-13 13:03:55 +00:00
|
|
|
|
2014-03-07 12:14:53 +00:00
|
|
|
this._telemetry.toolOpened("toolbox");
|
|
|
|
|
|
|
|
this.selectTool(this._defaultToolId).then(panel => {
|
|
|
|
this.emit("ready");
|
|
|
|
deferred.resolve();
|
2013-09-23 20:36:44 +00:00
|
|
|
});
|
2013-05-24 10:26:17 +00:00
|
|
|
};
|
2012-12-13 13:03:55 +00:00
|
|
|
|
2014-03-07 12:14:53 +00:00
|
|
|
// Load the toolbox-level actor fronts and utilities now
|
|
|
|
this._target.makeRemote().then(() => {
|
|
|
|
iframe.setAttribute("src", this._URL);
|
|
|
|
let domHelper = new DOMHelpers(iframe.contentWindow);
|
|
|
|
domHelper.onceDOMReady(domReady);
|
|
|
|
});
|
2013-11-16 02:47:00 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
return deferred.promise;
|
|
|
|
});
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
_buildOptions: function() {
|
2013-04-15 12:34:48 +00:00
|
|
|
let key = this.doc.getElementById("toolbox-options-key");
|
2013-09-23 20:36:44 +00:00
|
|
|
key.addEventListener("command", () => {
|
|
|
|
this.selectTool("options");
|
|
|
|
}, true);
|
2013-04-15 12:34:48 +00:00
|
|
|
},
|
|
|
|
|
2013-12-09 16:06:11 +00:00
|
|
|
_isResponsiveModeActive: function() {
|
|
|
|
let responsiveModeActive = false;
|
|
|
|
if (this.target.isLocalTab) {
|
|
|
|
let tab = this.target.tab;
|
|
|
|
let browserWindow = tab.ownerDocument.defaultView;
|
|
|
|
let responsiveUIManager = browserWindow.ResponsiveUI.ResponsiveUIManager;
|
|
|
|
responsiveModeActive = responsiveUIManager.isActiveForTab(tab);
|
|
|
|
}
|
|
|
|
return responsiveModeActive;
|
|
|
|
},
|
|
|
|
|
2013-11-11 21:13:28 +00:00
|
|
|
_splitConsoleOnKeypress: function(e) {
|
2013-12-09 16:06:11 +00:00
|
|
|
let responsiveModeActive = this._isResponsiveModeActive();
|
|
|
|
if (e.keyCode === e.DOM_VK_ESCAPE && !responsiveModeActive) {
|
2013-11-11 21:13:28 +00:00
|
|
|
this.toggleSplitConsole();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-10 00:41:43 +00:00
|
|
|
_addReloadKeys: function() {
|
|
|
|
[
|
|
|
|
["toolbox-reload-key", false],
|
|
|
|
["toolbox-reload-key2", false],
|
|
|
|
["toolbox-force-reload-key", true],
|
|
|
|
["toolbox-force-reload-key2", true]
|
|
|
|
].forEach(([id, force]) => {
|
|
|
|
this.doc.getElementById(id).addEventListener("command", (event) => {
|
|
|
|
this.reloadTarget(force);
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
_addToolSwitchingKeys: function() {
|
2013-07-20 13:36:43 +00:00
|
|
|
let nextKey = this.doc.getElementById("toolbox-next-tool-key");
|
|
|
|
nextKey.addEventListener("command", this.selectNextTool.bind(this), true);
|
|
|
|
let prevKey = this.doc.getElementById("toolbox-previous-tool-key");
|
|
|
|
prevKey.addEventListener("command", this.selectPreviousTool.bind(this), true);
|
2013-11-11 21:13:28 +00: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);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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");
|
|
|
|
let webconsolePanel = this.doc.getElementById("toolbox-panel-webconsole");
|
|
|
|
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");
|
|
|
|
if (this._splitConsole) {
|
|
|
|
webconsolePanel.removeAttribute("collapsed");
|
|
|
|
splitter.removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
webconsolePanel.setAttribute("collapsed", "true");
|
|
|
|
splitter.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
}
|
2013-07-20 13:36:43 +00:00
|
|
|
},
|
|
|
|
|
2013-09-15 06:26:18 +00:00
|
|
|
/**
|
|
|
|
* Wire up the listeners for the zoom keys.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_addZoomKeys: function() {
|
2013-09-15 06:26:18 +00: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);
|
|
|
|
|
|
|
|
let outKey = this.doc.getElementById("toolbox-zoom-out-key");
|
|
|
|
outKey.addEventListener("command", this.zoomOut.bind(this), true);
|
|
|
|
|
|
|
|
let resetKey = this.doc.getElementById("toolbox-zoom-reset-key");
|
|
|
|
resetKey.addEventListener("command", this.zoomReset.bind(this), true);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set zoom on toolbox to whatever the last setting was.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_loadInitialZoom: function() {
|
2013-09-15 06:26:18 +00:00
|
|
|
this.setZoom(this.zoomValue);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increase zoom level of toolbox window - make things bigger.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
zoomIn: function() {
|
2013-09-15 06:26:18 +00:00
|
|
|
this.setZoom(this.zoomValue + 0.1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrease zoom level of toolbox window - make things smaller.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
zoomOut: function() {
|
2013-09-15 06:26:18 +00:00
|
|
|
this.setZoom(this.zoomValue - 0.1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset zoom level of the toolbox window.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
zoomReset: function() {
|
2013-09-15 06:26:18 +00:00
|
|
|
this.setZoom(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set zoom level of the toolbox window.
|
|
|
|
*
|
|
|
|
* @param {number} zoomValue
|
|
|
|
* Zoom level e.g. 1.2
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
setZoom: function(zoomValue) {
|
2013-09-15 06:26:18 +00:00
|
|
|
// cap zoom value
|
|
|
|
zoomValue = Math.max(zoomValue, MIN_ZOOM);
|
|
|
|
zoomValue = Math.min(zoomValue, MAX_ZOOM);
|
|
|
|
|
|
|
|
let contViewer = this.frame.docShell.contentViewer;
|
|
|
|
let docViewer = contViewer.QueryInterface(Ci.nsIMarkupDocumentViewer);
|
|
|
|
|
|
|
|
docViewer.fullZoom = zoomValue;
|
|
|
|
|
|
|
|
Services.prefs.setCharPref(ZOOM_PREF, zoomValue);
|
|
|
|
},
|
|
|
|
|
2013-01-13 08:52:03 +00:00
|
|
|
/**
|
|
|
|
* Adds the keys and commands to the Toolbox Window in window mode.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_addKeysToWindow: function() {
|
2013-01-13 08:52:03 +00:00
|
|
|
if (this.hostType != Toolbox.HostType.WINDOW) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
let doc = this.doc.defaultView.parent.document;
|
2013-01-13 08:52:03 +00:00
|
|
|
|
2013-09-23 20:36:44 +00: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 08:52:03 +00:00
|
|
|
}
|
2013-08-28 15:26:01 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
let toolId = id;
|
2013-08-28 15:26:01 +00:00
|
|
|
let key = doc.createElement("key");
|
|
|
|
|
2013-09-23 20:36:44 +00: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);
|
|
|
|
key.setAttribute("oncommand", "void(0);"); // needed. See bug 371900
|
|
|
|
key.addEventListener("command", () => {
|
|
|
|
this.selectTool(toolId).then(() => this.fireCustomKey(toolId));
|
2013-08-28 15:26:01 +00:00
|
|
|
}, true);
|
|
|
|
doc.getElementById("toolbox-keyset").appendChild(key);
|
|
|
|
}
|
2013-09-15 06:26:18 +00:00
|
|
|
|
2013-08-28 15:26:01 +00:00
|
|
|
// Add key for toggling the browser console from the detached window
|
2013-09-23 20:36:44 +00:00
|
|
|
if (!doc.getElementById("key_browserconsole")) {
|
2013-08-28 15:26:01 +00:00
|
|
|
let key = doc.createElement("key");
|
|
|
|
key.id = "key_browserconsole";
|
|
|
|
|
|
|
|
key.setAttribute("key", toolboxStrings("browserConsoleCmd.commandkey"));
|
|
|
|
key.setAttribute("modifiers", "accel,shift");
|
|
|
|
key.setAttribute("oncommand", "void(0)"); // needed. See bug 371900
|
2013-09-23 20:36:44 +00:00
|
|
|
key.addEventListener("command", () => {
|
2013-08-28 15:26:01 +00:00
|
|
|
HUDService.toggleBrowserConsole();
|
|
|
|
}, true);
|
|
|
|
doc.getElementById("toolbox-keyset").appendChild(key);
|
|
|
|
}
|
2013-01-13 08:52:03 +00:00
|
|
|
},
|
|
|
|
|
2013-08-02 18:28:37 +00: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-09-23 20:36:44 +00:00
|
|
|
fireCustomKey: function(toolId) {
|
|
|
|
let toolDefinition = gDevTools.getToolDefinition(toolId);
|
2013-08-02 18:28:37 +00:00
|
|
|
|
2014-03-11 10:21:20 +00:00
|
|
|
if (toolDefinition.onkey &&
|
2014-02-07 13:56:00 +00:00
|
|
|
((this.currentToolId === toolId) ||
|
|
|
|
(toolId == "webconsole" && this.splitConsole))) {
|
|
|
|
toolDefinition.onkey(this.getCurrentPanel(), this);
|
2013-08-02 18:28:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Build the buttons for changing hosts. Called every time
|
|
|
|
* the host changes.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_buildDockButtons: function() {
|
2012-11-30 08:07:59 +00:00
|
|
|
let dockBox = this.doc.getElementById("toolbox-dock-buttons");
|
|
|
|
|
|
|
|
while (dockBox.firstChild) {
|
|
|
|
dockBox.removeChild(dockBox.firstChild);
|
|
|
|
}
|
|
|
|
|
2012-12-15 01:10:43 +00:00
|
|
|
if (!this._target.isLocalTab) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-21 15:22:47 +00:00
|
|
|
let closeButton = this.doc.getElementById("toolbox-close");
|
2013-09-23 20:36:44 +00:00
|
|
|
if (this.hostType == Toolbox.HostType.WINDOW) {
|
2013-01-21 15:22:47 +00:00
|
|
|
closeButton.setAttribute("hidden", "true");
|
|
|
|
} else {
|
|
|
|
closeButton.removeAttribute("hidden");
|
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
let sideEnabled = Services.prefs.getBoolPref(this._prefs.SIDE_ENABLED);
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
for (let type in Toolbox.HostType) {
|
|
|
|
let position = Toolbox.HostType[type];
|
2012-11-30 08:07:59 +00:00
|
|
|
if (position == this.hostType ||
|
2013-11-16 02:47:00 +00:00
|
|
|
position == Toolbox.HostType.CUSTOM ||
|
2013-09-23 20:36:44 +00:00
|
|
|
(!sideEnabled && position == Toolbox.HostType.SIDE)) {
|
2012-11-30 08:07:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let button = this.doc.createElement("toolbarbutton");
|
|
|
|
button.id = "toolbox-dock-" + position;
|
|
|
|
button.className = "toolbox-dock-button";
|
2012-12-18 15:11:27 +00:00
|
|
|
button.setAttribute("tooltiptext", toolboxStrings("toolboxDockButtons." +
|
|
|
|
position + ".tooltip"));
|
2013-09-23 20:36:44 +00:00
|
|
|
button.addEventListener("command", () => {
|
2012-12-13 13:03:55 +00:00
|
|
|
this.switchHost(position);
|
2013-09-23 20:36:44 +00:00
|
|
|
});
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
dockBox.appendChild(button);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add tabs to the toolbox UI for registered tools
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_buildTabs: function() {
|
2013-01-11 12:16:31 +00:00
|
|
|
for (let definition of gDevTools.getToolDefinitionArray()) {
|
2012-11-30 08:07:59 +00:00
|
|
|
this._buildTabForTool(definition);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-01-09 11:36:01 +00:00
|
|
|
* Add buttons to the UI as specified in the devtools.toolbox.toolbarSpec pref
|
2012-11-30 08:07:59 +00:00
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_buildButtons: function() {
|
2014-04-30 14:48:00 +00:00
|
|
|
if (!this.target.isAddon) {
|
|
|
|
this._buildPickerButton();
|
|
|
|
}
|
2014-01-09 11:36:01 +00:00
|
|
|
|
2013-01-04 20:31:38 +00:00
|
|
|
if (!this.target.isLocalTab) {
|
2012-12-13 13:03:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
let spec = CommandUtils.getCommandbarSpec("devtools.toolbox.toolbarSpec");
|
2013-09-03 11:20:27 +00:00
|
|
|
let environment = CommandUtils.createEnvironment(this, '_target');
|
2014-04-13 06:47:27 +00:00
|
|
|
this._requisition = CommandUtils.createRequisition(environment);
|
2013-09-03 11:20:27 +00:00
|
|
|
let buttons = CommandUtils.createButtons(spec, this._target,
|
|
|
|
this.doc, this._requisition);
|
2012-11-30 08:07:59 +00:00
|
|
|
let container = this.doc.getElementById("toolbox-buttons");
|
2013-05-24 10:26:17 +00:00
|
|
|
buttons.forEach(container.appendChild.bind(container));
|
2014-03-06 22:02:11 +00:00
|
|
|
this.setToolboxButtonsVisibility();
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2014-01-09 11:36:01 +00: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 13:50:13 +00:00
|
|
|
this._pickerButton.className = "command-button command-button-invertable";
|
2014-01-09 11:36:01 +00:00
|
|
|
this._pickerButton.setAttribute("tooltiptext", toolboxStrings("pickButton.tooltip"));
|
|
|
|
|
2014-05-28 14:11:33 +00:00
|
|
|
let container = this.doc.querySelector("#toolbox-picker-container");
|
2014-01-09 11:36:01 +00:00
|
|
|
container.appendChild(this._pickerButton);
|
|
|
|
|
2014-02-01 09:24:44 +00:00
|
|
|
this._togglePicker = this.highlighterUtils.togglePicker.bind(this.highlighterUtils);
|
|
|
|
this._pickerButton.addEventListener("command", this._togglePicker, false);
|
2014-01-09 11:36:01 +00:00
|
|
|
},
|
|
|
|
|
2014-03-06 22:02:11 +00:00
|
|
|
/**
|
|
|
|
* Return all toolbox buttons (command buttons, plus any others that were
|
|
|
|
* added manually).
|
|
|
|
*/
|
|
|
|
get toolboxButtons() {
|
|
|
|
// White-list buttons that can be toggled to prevent adding prefs for
|
|
|
|
// addons that have manually inserted toolbarbuttons into DOM.
|
|
|
|
return [
|
|
|
|
"command-button-pick",
|
|
|
|
"command-button-splitconsole",
|
|
|
|
"command-button-responsive",
|
|
|
|
"command-button-paintflashing",
|
|
|
|
"command-button-tilt",
|
2014-04-24 19:39:00 +00:00
|
|
|
"command-button-scratchpad",
|
2014-05-30 08:47:49 +00:00
|
|
|
"command-button-eyedropper",
|
|
|
|
"command-button-screenshot"
|
2014-03-06 22:02:11 +00:00
|
|
|
].map(id => {
|
|
|
|
let button = this.doc.getElementById(id);
|
|
|
|
// Some buttons may not exist inside of Browser Toolbox
|
|
|
|
if (!button) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
id: id,
|
|
|
|
button: button,
|
|
|
|
label: button.getAttribute("tooltiptext"),
|
|
|
|
visibilityswitch: "devtools." + id + ".enabled"
|
|
|
|
}
|
|
|
|
}).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 => {
|
|
|
|
let {visibilityswitch, id, button}=buttonSpec;
|
|
|
|
let on = true;
|
|
|
|
try {
|
|
|
|
on = Services.prefs.getBoolPref(visibilityswitch);
|
|
|
|
} catch (ex) { }
|
|
|
|
|
|
|
|
if (button) {
|
|
|
|
if (on) {
|
|
|
|
button.removeAttribute("hidden");
|
|
|
|
} else {
|
|
|
|
button.setAttribute("hidden", "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00: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-23 20:36:44 +00:00
|
|
|
_buildTabForTool: function(toolDefinition) {
|
2012-11-30 08:07:59 +00: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-23 20:36:44 +00:00
|
|
|
if (toolDefinition.ordinal == undefined || toolDefinition.ordinal < 0) {
|
|
|
|
toolDefinition.ordinal = MAX_ORDINAL;
|
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
let radio = this.doc.createElement("radio");
|
2013-05-22 23:24:22 +00: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 13:50:13 +00:00
|
|
|
radio.className = "devtools-tab";
|
2012-11-30 08:07:59 +00:00
|
|
|
radio.id = "toolbox-tab-" + id;
|
|
|
|
radio.setAttribute("toolid", id);
|
2013-04-30 16:58:04 +00:00
|
|
|
radio.setAttribute("ordinal", toolDefinition.ordinal);
|
2012-12-18 15:11:27 +00:00
|
|
|
radio.setAttribute("tooltiptext", toolDefinition.tooltip);
|
2014-02-10 13:50:13 +00:00
|
|
|
if (toolDefinition.invertIconForLightTheme) {
|
|
|
|
radio.setAttribute("icon-invertable", "true");
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
radio.addEventListener("command", () => {
|
2012-11-30 08:07:59 +00:00
|
|
|
this.selectTool(id);
|
2013-09-23 20:36:44 +00:00
|
|
|
});
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-05-11 01:53:58 +00: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-13 23:10:15 +00:00
|
|
|
if (toolDefinition.icon) {
|
|
|
|
let image = this.doc.createElement("image");
|
2013-05-25 08:05:34 +00: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-13 23:10:15 +00:00
|
|
|
radio.appendChild(image);
|
|
|
|
}
|
|
|
|
|
2013-05-04 06:31:07 +00:00
|
|
|
if (toolDefinition.label) {
|
|
|
|
let label = this.doc.createElement("label");
|
|
|
|
label.setAttribute("value", toolDefinition.label)
|
|
|
|
label.setAttribute("crop", "end");
|
|
|
|
label.setAttribute("flex", "1");
|
|
|
|
radio.appendChild(label);
|
|
|
|
radio.setAttribute("flex", "1");
|
|
|
|
}
|
2013-03-13 23:10:15 +00:00
|
|
|
|
2013-11-13 18:02:05 +00:00
|
|
|
if (!toolDefinition.bgTheme) {
|
|
|
|
toolDefinition.bgTheme = "theme-toolbar";
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
let vbox = this.doc.createElement("vbox");
|
2013-11-13 18:02:05 +00:00
|
|
|
vbox.className = "toolbox-panel " + toolDefinition.bgTheme;
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-11-11 21:13:28 +00: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 16:58:04 +00:00
|
|
|
|
2014-05-28 14:11:33 +00:00
|
|
|
if (id === "options") {
|
|
|
|
// Options panel is special. It doesn't belong in the same container as
|
|
|
|
// the other tabs.
|
|
|
|
let optionTabContainer = this.doc.getElementById("toolbox-option-container");
|
|
|
|
optionTabContainer.appendChild(radio);
|
2013-04-30 16:58:04 +00:00
|
|
|
deck.appendChild(vbox);
|
2013-09-23 20:36:44 +00:00
|
|
|
} else {
|
2014-05-28 14:11:33 +00: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 16:58:04 +00:00
|
|
|
}
|
2013-01-13 08:52:03 +00:00
|
|
|
|
|
|
|
this._addKeysToWindow();
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-05-14 22:25:28 +00:00
|
|
|
/**
|
2013-06-23 03:00:51 +00:00
|
|
|
* Ensure the tool with the given id is loaded.
|
2013-05-14 22:25:28 +00:00
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to load.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
loadTool: function(id) {
|
2014-01-09 11:36:01 +00:00
|
|
|
if (id === "inspector" && !this._inspector) {
|
|
|
|
return this.initInspector().then(() => {
|
|
|
|
return this.loadTool(id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-11 07:12:20 +00:00
|
|
|
let deferred = promise.defer();
|
2013-05-14 22:25:28 +00:00
|
|
|
let iframe = this.doc.getElementById("toolbox-panel-iframe-" + id);
|
|
|
|
|
|
|
|
if (iframe) {
|
2013-06-23 03:00:51 +00:00
|
|
|
let panel = this._toolPanels.get(id);
|
|
|
|
if (panel) {
|
|
|
|
deferred.resolve(panel);
|
|
|
|
} else {
|
2013-09-23 20:36:44 +00:00
|
|
|
this.once(id + "-ready", panel => {
|
2013-06-23 03:00:51 +00:00
|
|
|
deferred.resolve(panel);
|
|
|
|
});
|
|
|
|
}
|
2013-05-14 22:25:28 +00:00
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
let definition = gDevTools.getToolDefinition(id);
|
2013-06-23 03:00:51 +00:00
|
|
|
if (!definition) {
|
|
|
|
deferred.reject(new Error("no such tool id "+id));
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
2013-09-23 20:36:44 +00:00
|
|
|
|
2013-05-14 22:25:28 +00: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 18:02:05 +00:00
|
|
|
iframe.style.visibility = "hidden";
|
2013-05-14 22:25:28 +00:00
|
|
|
|
|
|
|
let vbox = this.doc.getElementById("toolbox-panel-" + id);
|
|
|
|
vbox.appendChild(iframe);
|
|
|
|
|
|
|
|
let onLoad = () => {
|
2013-11-13 18:02:05 +00:00
|
|
|
// Prevent flicker while loading by waiting to make visible until now.
|
|
|
|
iframe.style.visibility = "visible";
|
|
|
|
|
2013-05-14 22:25:28 +00:00
|
|
|
let built = definition.build(iframe.contentWindow, this);
|
2013-07-11 07:12:20 +00:00
|
|
|
promise.resolve(built).then((panel) => {
|
2013-05-14 22:25:28 +00:00
|
|
|
this._toolPanels.set(id, panel);
|
|
|
|
this.emit(id + "-ready", panel);
|
|
|
|
gDevTools.emit(id + "-ready", this, panel);
|
|
|
|
deferred.resolve(panel);
|
2013-09-03 11:20:27 +00:00
|
|
|
}, console.error);
|
2013-05-14 22:25:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
iframe.setAttribute("src", definition.url);
|
2013-11-16 02:47:00 +00: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();
|
|
|
|
}
|
|
|
|
iframe.addEventListener("DOMContentLoaded", callback);
|
|
|
|
}
|
|
|
|
|
2013-05-14 22:25:28 +00:00
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Switch to the tool with the given id
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to switch to
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
selectTool: function(id) {
|
2013-03-13 23:10:15 +00:00
|
|
|
let selected = this.doc.querySelector(".devtools-tab[selected]");
|
|
|
|
if (selected) {
|
|
|
|
selected.removeAttribute("selected");
|
|
|
|
}
|
2013-09-23 20:36:44 +00:00
|
|
|
|
2013-03-13 23:10:15 +00:00
|
|
|
let tab = this.doc.getElementById("toolbox-tab-" + id);
|
|
|
|
tab.setAttribute("selected", "true");
|
|
|
|
|
2014-05-28 14:11:33 +00: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-23 20:36:44 +00:00
|
|
|
if (this.currentToolId == id) {
|
2013-09-15 06:26:18 +00:00
|
|
|
// re-focus tool to get key events again
|
|
|
|
this.focusTool(id);
|
|
|
|
|
2013-03-07 07:30:03 +00:00
|
|
|
// Return the existing panel in order to have a consistent return value.
|
2013-07-11 07:12:20 +00:00
|
|
|
return promise.resolve(this._toolPanels.get(id));
|
2013-01-09 09:32:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
if (!this.isReady) {
|
|
|
|
throw new Error("Can't select tool, wait for toolbox 'ready' event");
|
|
|
|
}
|
2013-09-23 20:36:44 +00:00
|
|
|
|
|
|
|
tab = this.doc.getElementById("toolbox-tab-" + id);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-05-24 10:26:17 +00:00
|
|
|
if (tab) {
|
2013-09-23 20:36:44 +00:00
|
|
|
if (this.currentToolId) {
|
|
|
|
this._telemetry.toolClosed(this.currentToolId);
|
2013-05-24 10:26:17 +00:00
|
|
|
}
|
|
|
|
this._telemetry.toolOpened(id);
|
|
|
|
} else {
|
2012-11-30 08:07:59 +00:00
|
|
|
throw new Error("No tool found");
|
|
|
|
}
|
|
|
|
|
|
|
|
let tabstrip = this.doc.getElementById("toolbox-tabs");
|
|
|
|
|
2013-05-04 06:31:07 +00:00
|
|
|
// select the right tab, making 0th index the default tab if right tab not
|
2014-05-28 14:11:33 +00:00
|
|
|
// found.
|
|
|
|
tabstrip.selectedItem = tab || tabstrip.childNodes[0];
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
// and select the right iframe
|
|
|
|
let deck = this.doc.getElementById("toolbox-deck");
|
2014-05-28 14:11:33 +00:00
|
|
|
let panel = this.doc.getElementById("toolbox-panel-" + id);
|
|
|
|
deck.selectedPanel = panel;
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
this.currentToolId = id;
|
2013-11-11 21:13:28 +00:00
|
|
|
this._refreshConsoleDisplay();
|
2013-04-15 12:34:48 +00:00
|
|
|
if (id != "options") {
|
|
|
|
Services.prefs.setCharPref(this._prefs.LAST_TOOL, id);
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
return this.loadTool(id).then(panel => {
|
2013-09-15 06:26:18 +00:00
|
|
|
// focus the tool's frame to start receiving key events
|
|
|
|
this.focusTool(id);
|
|
|
|
|
2013-06-23 03:00:51 +00:00
|
|
|
this.emit("select", id);
|
|
|
|
this.emit(id + "-selected", panel);
|
|
|
|
return panel;
|
|
|
|
});
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2013-09-15 06:26:18 +00: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 13:56:00 +00:00
|
|
|
/**
|
|
|
|
* Focus split console's input line
|
|
|
|
*/
|
|
|
|
focusConsoleInput: function() {
|
|
|
|
let hud = this.getPanel("webconsole").hud;
|
2014-03-27 12:50:30 +00:00
|
|
|
if (hud && hud.jsterm) {
|
|
|
|
hud.jsterm.inputNode.focus();
|
|
|
|
}
|
2014-02-07 13:56:00 +00:00
|
|
|
},
|
|
|
|
|
2013-11-11 21:13:28 +00:00
|
|
|
/**
|
|
|
|
* Toggles the split state of the webconsole. If the webconsole panel
|
|
|
|
* is already selected, then this command is ignored.
|
|
|
|
*/
|
|
|
|
toggleSplitConsole: function() {
|
|
|
|
let openedConsolePanel = this.currentToolId === "webconsole";
|
|
|
|
|
|
|
|
// Don't allow changes when console is open, since it could be confusing
|
|
|
|
if (!openedConsolePanel) {
|
|
|
|
this._splitConsole = !this._splitConsole;
|
|
|
|
this._refreshConsoleDisplay();
|
|
|
|
this.emit("split-console");
|
|
|
|
|
|
|
|
if (this._splitConsole) {
|
|
|
|
this.loadTool("webconsole").then(() => {
|
2014-02-07 13:56:00 +00:00
|
|
|
this.focusConsoleInput();
|
2013-11-11 21:13:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-10 00:41:43 +00:00
|
|
|
/**
|
|
|
|
* Tells the target tab to reload.
|
|
|
|
*/
|
|
|
|
reloadTarget: function(force) {
|
|
|
|
this.target.activeTab.reload({ force: force });
|
|
|
|
},
|
|
|
|
|
2013-07-20 13:36:43 +00:00
|
|
|
/**
|
|
|
|
* Loads the tool next to the currently selected tool.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
selectNextTool: function() {
|
2014-05-28 14:11:33 +00:00
|
|
|
let tools = this.doc.querySelectorAll(".devtools-tab");
|
2013-07-20 13:36:43 +00:00
|
|
|
let selected = this.doc.querySelector(".devtools-tab[selected]");
|
2014-05-28 14:11:33 +00:00
|
|
|
let nextIndex = [...tools].indexOf(selected) + 1;
|
|
|
|
let next = tools[nextIndex] || tools[0];
|
2013-07-20 13:36:43 +00:00
|
|
|
let tool = next.getAttribute("toolid");
|
|
|
|
return this.selectTool(tool);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the tool just left to the currently selected tool.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
selectPreviousTool: function() {
|
2014-05-28 14:11:33 +00:00
|
|
|
let tools = this.doc.querySelectorAll(".devtools-tab");
|
2013-07-20 13:36:43 +00:00
|
|
|
let selected = this.doc.querySelector(".devtools-tab[selected]");
|
2014-05-28 14:11:33 +00:00
|
|
|
let prevIndex = [...tools].indexOf(selected) - 1;
|
|
|
|
let prev = tools[prevIndex] || tools[tools.length - 1];
|
|
|
|
let tool = prev.getAttribute("toolid");
|
2013-07-20 13:36:43 +00:00
|
|
|
return this.selectTool(tool);
|
|
|
|
},
|
|
|
|
|
2013-05-25 08:05:34 +00: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-23 20:36:44 +00:00
|
|
|
highlightTool: function(id) {
|
2013-05-25 08:05:34 +00:00
|
|
|
let tab = this.doc.getElementById("toolbox-tab-" + id);
|
2013-12-20 16:40:21 +00:00
|
|
|
tab && tab.setAttribute("highlighted", "true");
|
2013-05-25 08:05:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* De-highlights the tool's tab.
|
|
|
|
*
|
|
|
|
* @param {string} id
|
|
|
|
* The id of the tool to unhighlight
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
unhighlightTool: function(id) {
|
2013-05-25 08:05:34 +00:00
|
|
|
let tab = this.doc.getElementById("toolbox-tab-" + id);
|
2013-12-20 16:40:21 +00:00
|
|
|
tab && tab.removeAttribute("highlighted");
|
2013-05-25 08:05:34 +00:00
|
|
|
},
|
|
|
|
|
2013-01-09 09:32:35 +00:00
|
|
|
/**
|
|
|
|
* Raise the toolbox host.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
raise: function() {
|
2013-01-09 09:32:35 +00:00
|
|
|
this._host.raise();
|
|
|
|
},
|
|
|
|
|
2013-02-26 12:40:19 +00:00
|
|
|
/**
|
|
|
|
* Refresh the host's title.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_refreshHostTitle: function() {
|
2013-02-26 12:40:19 +00:00
|
|
|
let toolName;
|
2013-09-23 20:36:44 +00:00
|
|
|
let toolDef = gDevTools.getToolDefinition(this.currentToolId);
|
2013-04-15 12:34:48 +00:00
|
|
|
if (toolDef) {
|
2013-02-26 12:40:19 +00:00
|
|
|
toolName = toolDef.label;
|
|
|
|
} else {
|
|
|
|
// no tool is selected
|
|
|
|
toolName = toolboxStrings("toolbox.defaultTitle");
|
|
|
|
}
|
|
|
|
let title = toolboxStrings("toolbox.titleTemplate",
|
2014-03-27 17:29:03 +00:00
|
|
|
toolName, this.target.url || this.target.name);
|
2013-02-26 12:40:19 +00:00
|
|
|
this._host.setTitle(title);
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Create a host object based on the given host type.
|
|
|
|
*
|
2013-01-11 17:31:09 +00:00
|
|
|
* Warning: some hosts require that the toolbox target provides a reference to
|
|
|
|
* the attached tab. Not all Targets have a tab property - make sure you correctly
|
|
|
|
* mix and match hosts and targets.
|
|
|
|
*
|
2012-11-30 08:07:59 +00:00
|
|
|
* @param {string} hostType
|
|
|
|
* The host type of the new host object
|
|
|
|
*
|
|
|
|
* @return {Host} host
|
|
|
|
* The created host object
|
|
|
|
*/
|
2013-11-16 02:47:00 +00:00
|
|
|
_createHost: function(hostType, options) {
|
2012-11-30 08:07:59 +00:00
|
|
|
if (!Hosts[hostType]) {
|
2013-09-23 20:36:44 +00:00
|
|
|
throw new Error("Unknown hostType: " + hostType);
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// clean up the toolbox if its window is closed
|
2013-11-16 02:47:00 +00:00
|
|
|
let newHost = new Hosts[hostType](this.target.tab, options);
|
2012-11-30 08:07:59 +00:00
|
|
|
newHost.on("window-closed", this.destroy);
|
|
|
|
return newHost;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Switch to a new host for the toolbox UI. E.g.
|
|
|
|
* bottom, sidebar, separate window.
|
|
|
|
*
|
|
|
|
* @param {string} hostType
|
|
|
|
* The host type of the new host object
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
switchHost: function(hostType) {
|
|
|
|
if (hostType == this._host.type || !this._target.isLocalTab) {
|
2014-01-01 03:28:42 +00:00
|
|
|
return null;
|
2012-12-15 01:10:43 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
let newHost = this._createHost(hostType);
|
2013-09-23 20:36:44 +00:00
|
|
|
return newHost.create().then(iframe => {
|
2012-11-30 08:07:59 +00:00
|
|
|
// change toolbox document's parent to the new host
|
2012-12-13 13:03:55 +00:00
|
|
|
iframe.QueryInterface(Ci.nsIFrameLoaderOwner);
|
2012-11-30 08:07:59 +00:00
|
|
|
iframe.swapFrameLoaders(this.frame);
|
|
|
|
|
|
|
|
this._host.off("window-closed", this.destroy);
|
2013-11-11 21:13:28 +00:00
|
|
|
this.destroyHost();
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
this._host = newHost;
|
|
|
|
|
2013-11-16 02:47:00 +00:00
|
|
|
if (this.hostType != Toolbox.HostType.CUSTOM) {
|
|
|
|
Services.prefs.setCharPref(this._prefs.LAST_HOST, this._host.type);
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
this._buildDockButtons();
|
2013-01-13 08:52:03 +00:00
|
|
|
this._addKeysToWindow();
|
2012-11-30 08:07:59 +00:00
|
|
|
|
|
|
|
this.emit("host-changed");
|
2013-09-23 20:36:44 +00:00
|
|
|
});
|
2012-11-30 08:07:59 +00: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-23 20:36:44 +00:00
|
|
|
_toolRegistered: function(event, toolId) {
|
|
|
|
let tool = gDevTools.getToolDefinition(toolId);
|
2012-11-30 08:07:59 +00:00
|
|
|
this._buildTabForTool(tool);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the tool-unregistered event.
|
|
|
|
* @param {string} event
|
|
|
|
* Name of the event ("tool-unregistered")
|
2013-04-19 13:44:38 +00: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 08:07:59 +00:00
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
_toolUnregistered: function(event, toolId) {
|
2013-04-19 13:44:38 +00:00
|
|
|
if (typeof toolId != "string") {
|
|
|
|
toolId = toolId.id;
|
|
|
|
}
|
|
|
|
|
2013-04-17 08:58:41 +00:00
|
|
|
if (this._toolPanels.has(toolId)) {
|
|
|
|
let instance = this._toolPanels.get(toolId);
|
|
|
|
instance.destroy();
|
|
|
|
this._toolPanels.delete(toolId);
|
|
|
|
}
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
let radio = this.doc.getElementById("toolbox-tab-" + toolId);
|
|
|
|
let panel = this.doc.getElementById("toolbox-panel-" + toolId);
|
|
|
|
|
|
|
|
if (radio) {
|
2013-09-23 20:36:44 +00:00
|
|
|
if (this.currentToolId == toolId) {
|
2013-01-05 00:21:27 +00: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 08:07:59 +00:00
|
|
|
radio.parentNode.removeChild(radio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel) {
|
|
|
|
panel.parentNode.removeChild(panel);
|
|
|
|
}
|
|
|
|
|
2013-01-13 08:52:03 +00:00
|
|
|
if (this.hostType == Toolbox.HostType.WINDOW) {
|
|
|
|
let doc = this.doc.defaultView.parent.document;
|
2013-05-04 06:31:07 +00:00
|
|
|
let key = doc.getElementById("key_" + toolId);
|
2013-01-13 08:52:03 +00:00
|
|
|
if (key) {
|
|
|
|
key.parentNode.removeChild(key);
|
|
|
|
}
|
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
},
|
|
|
|
|
2014-01-09 11:36:01 +00:00
|
|
|
/**
|
|
|
|
* Initialize the inspector/walker/selection/highlighter fronts.
|
|
|
|
* Returns a promise that resolves when the fronts are initialized
|
|
|
|
*/
|
|
|
|
initInspector: function() {
|
2014-03-11 10:21:20 +00:00
|
|
|
if (!this._initInspector) {
|
|
|
|
this._initInspector = Task.spawn(function*() {
|
|
|
|
this._inspector = InspectorFront(this._target.client, this._target.form);
|
|
|
|
this._walker = yield this._inspector.getWalker();
|
2014-01-09 11:36:01 +00:00
|
|
|
this._selection = new Selection(this._walker);
|
2014-03-13 21:36:48 +00:00
|
|
|
|
2014-02-01 09:24:44 +00:00
|
|
|
if (this.highlighterUtils.isRemoteHighlightable) {
|
2014-03-13 21:36:48 +00:00
|
|
|
let autohide = !gDevTools.testing;
|
|
|
|
|
|
|
|
this.walker.on("highlighter-ready", this._highlighterReady);
|
|
|
|
this.walker.on("highlighter-hide", this._highlighterHidden);
|
|
|
|
|
|
|
|
this._highlighter = yield this._inspector.getHighlighter(autohide);
|
2014-01-09 11:36:01 +00:00
|
|
|
}
|
2014-03-11 10:21:20 +00:00
|
|
|
}.bind(this));
|
2014-01-09 11:36:01 +00:00
|
|
|
}
|
2014-03-11 10:21:20 +00:00
|
|
|
return this._initInspector;
|
2014-01-09 11:36:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy the inspector/walker/selection fronts
|
|
|
|
* Returns a promise that resolves when the fronts are destroyed
|
|
|
|
*/
|
|
|
|
destroyInspector: function() {
|
2014-03-13 21:36:48 +00:00
|
|
|
if (this._destroying) {
|
|
|
|
return this._destroying;
|
|
|
|
}
|
|
|
|
|
2014-02-05 19:50:25 +00:00
|
|
|
if (!this._inspector) {
|
|
|
|
return promise.resolve();
|
|
|
|
}
|
2014-02-05 12:22:37 +00:00
|
|
|
|
2014-02-05 19:50:25 +00:00
|
|
|
let outstanding = () => {
|
|
|
|
return Task.spawn(function*() {
|
|
|
|
yield this.highlighterUtils.stopPicker();
|
|
|
|
yield this._inspector.destroy();
|
|
|
|
if (this._highlighter) {
|
|
|
|
yield this._highlighter.destroy();
|
|
|
|
}
|
|
|
|
if (this._selection) {
|
|
|
|
this._selection.destroy();
|
2014-01-09 11:36:01 +00:00
|
|
|
}
|
2014-02-05 19:50:25 +00:00
|
|
|
|
2014-03-13 21:27:10 +00:00
|
|
|
if (this.walker) {
|
|
|
|
this.walker.off("highlighter-ready", this._highlighterReady);
|
|
|
|
this.walker.off("highlighter-hide", this._highlighterHidden);
|
|
|
|
}
|
2014-03-13 21:36:48 +00:00
|
|
|
|
2014-01-09 11:36:01 +00:00
|
|
|
this._inspector = null;
|
|
|
|
this._highlighter = null;
|
2014-02-05 19:50:25 +00:00
|
|
|
this._selection = null;
|
2014-01-09 11:36:01 +00:00
|
|
|
this._walker = null;
|
2014-02-05 19:50:25 +00:00
|
|
|
}.bind(this));
|
|
|
|
};
|
2014-01-09 11:36:01 +00:00
|
|
|
|
2014-02-05 19:50:25 +00: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
|
2014-03-13 21:36:48 +00:00
|
|
|
let walker = (this._destroying = this._walker) ?
|
|
|
|
this._walker.release() :
|
|
|
|
promise.resolve();
|
2014-02-05 19:50:25 +00:00
|
|
|
return walker.then(outstanding, outstanding);
|
2014-01-09 11:36:01 +00:00
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Get the toolbox's notification box
|
|
|
|
*
|
|
|
|
* @return The notification box element.
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
getNotificationBox: function() {
|
2012-11-30 08:07:59 +00:00
|
|
|
return this.doc.getElementById("toolbox-notificationbox");
|
|
|
|
},
|
|
|
|
|
2013-11-11 21:13:28 +00:00
|
|
|
/**
|
|
|
|
* Destroy the current host, and remove event listeners from its frame.
|
|
|
|
*
|
|
|
|
* @return {promise} to be resolved when the host is destroyed.
|
|
|
|
*/
|
|
|
|
destroyHost: function() {
|
|
|
|
this.doc.removeEventListener("keypress",
|
|
|
|
this._splitConsoleOnKeypress, false);
|
|
|
|
return this._host.destroy();
|
|
|
|
},
|
|
|
|
|
2012-11-30 08:07:59 +00:00
|
|
|
/**
|
|
|
|
* Remove all UI elements, detach from target and clear up
|
|
|
|
*/
|
2013-09-23 20:36:44 +00:00
|
|
|
destroy: function() {
|
2012-12-13 13:03:55 +00: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 08:07:59 +00:00
|
|
|
}
|
2013-02-26 12:40:19 +00:00
|
|
|
|
|
|
|
this._target.off("navigate", this._refreshHostTitle);
|
|
|
|
this.off("select", this._refreshHostTitle);
|
|
|
|
this.off("host-changed", this._refreshHostTitle);
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-03-07 07:30:03 +00:00
|
|
|
gDevTools.off("tool-registered", this._toolRegistered);
|
|
|
|
gDevTools.off("tool-unregistered", this._toolUnregistered);
|
2012-12-13 13:03:55 +00:00
|
|
|
|
2013-03-07 07:30:03 +00:00
|
|
|
let outstanding = [];
|
2012-11-30 08:07:59 +00:00
|
|
|
for (let [id, panel] of this._toolPanels) {
|
2013-07-14 22:40:00 +00:00
|
|
|
try {
|
|
|
|
outstanding.push(panel.destroy());
|
2013-09-23 20:36:44 +00:00
|
|
|
} catch (e) {
|
2013-07-14 22:40:00 +00: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 15:39:40 +00:00
|
|
|
console.error("Panel " + id + ":", e);
|
2013-07-14 22:40:00 +00:00
|
|
|
}
|
2012-11-30 08:07:59 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 11:36:01 +00:00
|
|
|
// Destroying the walker and inspector fronts
|
|
|
|
outstanding.push(this.destroyInspector());
|
|
|
|
// Removing buttons
|
2014-02-05 19:50:25 +00:00
|
|
|
outstanding.push(() => {
|
|
|
|
this._pickerButton.removeEventListener("command", this._togglePicker, false);
|
|
|
|
this._pickerButton = null;
|
|
|
|
let container = this.doc.getElementById("toolbox-buttons");
|
|
|
|
while (container.firstChild) {
|
|
|
|
container.removeChild(container.firstChild);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Remove the host UI
|
2013-11-11 21:13:28 +00:00
|
|
|
outstanding.push(this.destroyHost());
|
2012-11-30 08:07:59 +00:00
|
|
|
|
2013-09-03 11:20:27 +00:00
|
|
|
if (this.target.isLocalTab) {
|
|
|
|
this._requisition.destroy();
|
|
|
|
}
|
2014-04-15 10:01:27 +00:00
|
|
|
this._telemetry.toolClosed("toolbox");
|
2013-05-24 10:26:17 +00:00
|
|
|
this._telemetry.destroy();
|
|
|
|
|
2013-09-23 20:36:44 +00:00
|
|
|
return this._destroyer = promise.all(outstanding).then(() => {
|
2013-09-14 00:09:52 +00: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 03:28:42 +00:00
|
|
|
if (!this._target) {
|
|
|
|
return null;
|
2013-09-14 00:09:52 +00:00
|
|
|
}
|
2014-01-01 03:28:42 +00:00
|
|
|
let target = this._target;
|
|
|
|
this._target = null;
|
|
|
|
target.off("close", this.destroy);
|
|
|
|
return target.destroy();
|
2013-09-23 20:36:44 +00:00
|
|
|
}).then(() => {
|
2012-12-13 13:03:55 +00:00
|
|
|
this.emit("destroyed");
|
2013-03-25 03:39:00 +00: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 01:29:06 +00:00
|
|
|
this._toolPanels.clear();
|
|
|
|
}).then(null, console.error);
|
2014-03-13 21:36:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_highlighterReady: function() {
|
|
|
|
this.emit("highlighter-ready");
|
|
|
|
},
|
|
|
|
|
|
|
|
_highlighterHidden: function() {
|
|
|
|
this.emit("highlighter-hide");
|
|
|
|
},
|
2012-11-30 08:07:59 +00:00
|
|
|
};
|
2014-02-01 09:24:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The ToolboxHighlighterUtils is what you should use for anything related to
|
|
|
|
* node highlighting and picking.
|
|
|
|
* It encapsulates the logic to connecting to the HighlighterActor.
|
|
|
|
*/
|
|
|
|
function ToolboxHighlighterUtils(toolbox) {
|
|
|
|
this.toolbox = toolbox;
|
|
|
|
this._onPickerNodeHovered = this._onPickerNodeHovered.bind(this);
|
|
|
|
this._onPickerNodePicked = this._onPickerNodePicked.bind(this);
|
|
|
|
this.stopPicker = this.stopPicker.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolboxHighlighterUtils.prototype = {
|
|
|
|
/**
|
|
|
|
* Indicates whether the highlighter actor exists on the server.
|
|
|
|
*/
|
|
|
|
get isRemoteHighlightable() {
|
|
|
|
return this.toolbox._target.client.traits.highlightable;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start/stop the element picker on the debuggee target.
|
|
|
|
*/
|
|
|
|
togglePicker: function() {
|
|
|
|
if (this._isPicking) {
|
|
|
|
return this.stopPicker();
|
|
|
|
} else {
|
|
|
|
return this.startPicker();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPickerNodeHovered: function(res) {
|
|
|
|
this.toolbox.emit("picker-node-hovered", res.node);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPickerNodePicked: function(res) {
|
|
|
|
this.toolbox.selection.setNodeFront(res.node, "picker-node-picked");
|
|
|
|
this.stopPicker();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start the element picker on the debuggee target.
|
|
|
|
* This will request the inspector actor to start listening for mouse/touch
|
|
|
|
* events on the target to highlight the hovered/picked element.
|
|
|
|
* Depending on the server-side capabilities, this may fire events when nodes
|
|
|
|
* are hovered.
|
2014-02-05 19:50:25 +00:00
|
|
|
* @return A promise that resolves when the picker has started or immediately
|
|
|
|
* if it is already started
|
2014-02-01 09:24:44 +00:00
|
|
|
*/
|
|
|
|
startPicker: function() {
|
2014-02-05 19:50:25 +00:00
|
|
|
if (this._isPicking) {
|
|
|
|
return promise.resolve();
|
|
|
|
}
|
|
|
|
|
2014-02-01 09:24:44 +00:00
|
|
|
let deferred = promise.defer();
|
|
|
|
|
|
|
|
let done = () => {
|
2014-03-13 21:36:48 +00:00
|
|
|
this._isPicking = true;
|
2014-02-01 09:24:44 +00:00
|
|
|
this.toolbox.emit("picker-started");
|
|
|
|
this.toolbox.on("select", this.stopPicker);
|
|
|
|
deferred.resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
promise.all([
|
|
|
|
this.toolbox.initInspector(),
|
|
|
|
this.toolbox.selectTool("inspector")
|
|
|
|
]).then(() => {
|
|
|
|
this.toolbox._pickerButton.setAttribute("checked", "true");
|
|
|
|
|
|
|
|
if (this.isRemoteHighlightable) {
|
|
|
|
this.toolbox.walker.on("picker-node-hovered", this._onPickerNodeHovered);
|
|
|
|
this.toolbox.walker.on("picker-node-picked", this._onPickerNodePicked);
|
2014-03-13 21:36:48 +00:00
|
|
|
|
|
|
|
this.toolbox.highlighter.pick().then(done);
|
2014-02-01 09:24:44 +00:00
|
|
|
} else {
|
2014-03-13 21:36:48 +00:00
|
|
|
return this.toolbox.walker.pick().then(node => {
|
|
|
|
this.toolbox.selection.setNodeFront(node, "picker-node-picked").then(() => {
|
|
|
|
this.stopPicker();
|
|
|
|
done();
|
|
|
|
});
|
2014-02-01 09:24:44 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the element picker
|
2014-02-05 19:50:25 +00:00
|
|
|
* @return A promise that resolves when the picker has stopped or immediately
|
|
|
|
* if it is already stopped
|
2014-02-01 09:24:44 +00:00
|
|
|
*/
|
|
|
|
stopPicker: function() {
|
2014-02-05 19:50:25 +00:00
|
|
|
if (!this._isPicking) {
|
|
|
|
return promise.resolve();
|
|
|
|
}
|
|
|
|
|
2014-02-01 09:24:44 +00:00
|
|
|
let deferred = promise.defer();
|
|
|
|
|
|
|
|
let done = () => {
|
|
|
|
this.toolbox.emit("picker-stopped");
|
|
|
|
this.toolbox.off("select", this.stopPicker);
|
|
|
|
deferred.resolve();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.toolbox.initInspector().then(() => {
|
|
|
|
this._isPicking = false;
|
|
|
|
this.toolbox._pickerButton.removeAttribute("checked");
|
|
|
|
if (this.isRemoteHighlightable) {
|
|
|
|
this.toolbox.highlighter.cancelPick().then(done);
|
|
|
|
this.toolbox.walker.off("picker-node-hovered", this._onPickerNodeHovered);
|
|
|
|
this.toolbox.walker.off("picker-node-picked", this._onPickerNodePicked);
|
|
|
|
} else {
|
|
|
|
this.toolbox.walker.cancelPick().then(done);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the box model highlighter on a node, given its NodeFront (this type
|
|
|
|
* of front is normally returned by the WalkerActor).
|
|
|
|
* @return a promise that resolves to the nodeFront when the node has been
|
|
|
|
* highlit
|
|
|
|
*/
|
|
|
|
highlightNodeFront: function(nodeFront, options={}) {
|
|
|
|
let deferred = promise.defer();
|
|
|
|
|
|
|
|
// If the remote highlighter exists on the target, use it
|
|
|
|
if (this.isRemoteHighlightable) {
|
|
|
|
this.toolbox.initInspector().then(() => {
|
|
|
|
this.toolbox.highlighter.showBoxModel(nodeFront, options).then(() => {
|
|
|
|
this.toolbox.emit("node-highlight", nodeFront);
|
|
|
|
deferred.resolve(nodeFront);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Else, revert to the "older" version of the highlighter in the walker
|
|
|
|
// actor
|
|
|
|
else {
|
|
|
|
this.toolbox.walker.highlight(nodeFront).then(() => {
|
|
|
|
this.toolbox.emit("node-highlight", nodeFront);
|
|
|
|
deferred.resolve(nodeFront);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a convenience method in case you don't have a nodeFront but a
|
|
|
|
* valueGrip. This is often the case with VariablesView properties.
|
|
|
|
* This method will simply translate the grip into a nodeFront and call
|
|
|
|
* highlightNodeFront
|
|
|
|
* @return a promise that resolves to the nodeFront when the node has been
|
|
|
|
* highlit
|
|
|
|
*/
|
|
|
|
highlightDomValueGrip: function(valueGrip, options={}) {
|
|
|
|
return this._translateGripToNodeFront(valueGrip).then(nodeFront => {
|
|
|
|
if (nodeFront) {
|
|
|
|
return this.highlightNodeFront(nodeFront, options);
|
|
|
|
} else {
|
|
|
|
return promise.reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_translateGripToNodeFront: function(grip) {
|
|
|
|
return this.toolbox.initInspector().then(() => {
|
|
|
|
return this.toolbox.walker.getNodeActorFromObjectActor(grip.actor);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the highlighter.
|
|
|
|
* @return a promise that resolves when the highlighter is hidden
|
|
|
|
*/
|
2014-03-13 21:27:10 +00:00
|
|
|
unhighlight: function(forceHide=false) {
|
2014-03-17 18:11:00 +00:00
|
|
|
let unhighlightPromise;
|
|
|
|
forceHide = forceHide || !gDevTools.testing;
|
2014-03-13 21:27:10 +00:00
|
|
|
|
2014-03-17 18:11:00 +00:00
|
|
|
if (forceHide && this.isRemoteHighlightable && this.toolbox.highlighter) {
|
|
|
|
// If the remote highlighter exists on the target, use it
|
|
|
|
unhighlightPromise = this.toolbox.highlighter.hideBoxModel();
|
2014-02-01 09:24:44 +00:00
|
|
|
} else {
|
|
|
|
// If not, no need to unhighlight as the older highlight method uses a
|
|
|
|
// setTimeout to hide itself
|
2014-03-17 18:11:00 +00:00
|
|
|
unhighlightPromise = promise.resolve();
|
2014-02-01 09:24:44 +00:00
|
|
|
}
|
2014-03-17 18:11:00 +00:00
|
|
|
|
|
|
|
return unhighlightPromise.then(() => {
|
|
|
|
this.toolbox.emit("node-unhighlight");
|
|
|
|
});
|
2014-02-01 09:24:44 +00:00
|
|
|
}
|
|
|
|
};
|