2012-11-30 00:07:59 -08: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-11 13:59:08 -07:00
|
|
|
const {Cc, Ci, Cu} = require("chrome");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-04-11 13:59:08 -07:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource:///modules/devtools/gDevTools.jsm");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Object.defineProperty(exports, "Toolbox", {
|
|
|
|
get: () => require("devtools/framework/toolbox").Toolbox
|
|
|
|
});
|
|
|
|
Object.defineProperty(exports, "TargetFactory", {
|
|
|
|
get: () => require("devtools/framework/target").TargetFactory
|
|
|
|
});
|
2012-12-13 14:17:00 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
loader.lazyGetter(this, "osString", () => Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS);
|
2013-04-28 14:42:23 -07:00
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
let events = require("sdk/system/events");
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
// Panels
|
2013-08-28 06:20:18 -07:00
|
|
|
loader.lazyGetter(this, "OptionsPanel", () => require("devtools/framework/toolbox-options").OptionsPanel);
|
|
|
|
loader.lazyGetter(this, "InspectorPanel", () => require("devtools/inspector/inspector-panel").InspectorPanel);
|
|
|
|
loader.lazyGetter(this, "WebConsolePanel", () => require("devtools/webconsole/panel").WebConsolePanel);
|
|
|
|
loader.lazyGetter(this, "DebuggerPanel", () => require("devtools/debugger/debugger-panel").DebuggerPanel);
|
2013-04-11 13:59:08 -07:00
|
|
|
loader.lazyImporter(this, "StyleEditorPanel", "resource:///modules/devtools/StyleEditorPanel.jsm");
|
2013-10-25 00:18:41 -07:00
|
|
|
loader.lazyGetter(this, "ShaderEditorPanel", () => require("devtools/shadereditor/panel").ShaderEditorPanel);
|
2013-08-28 06:20:18 -07:00
|
|
|
loader.lazyGetter(this, "ProfilerPanel", () => require("devtools/profiler/panel"));
|
2013-08-25 02:57:52 -07:00
|
|
|
loader.lazyGetter(this, "NetMonitorPanel", () => require("devtools/netmonitor/netmonitor-panel").NetMonitorPanel);
|
2013-10-04 12:44:09 -07:00
|
|
|
loader.lazyGetter(this, "ScratchpadPanel", () => require("devtools/scratchpad/scratchpad-panel").ScratchpadPanel);
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
// Strings
|
2013-05-03 23:31:07 -07:00
|
|
|
const toolboxProps = "chrome://browser/locale/devtools/toolbox.properties";
|
2013-04-11 13:59:08 -07:00
|
|
|
const inspectorProps = "chrome://browser/locale/devtools/inspector.properties";
|
|
|
|
const debuggerProps = "chrome://browser/locale/devtools/debugger.properties";
|
|
|
|
const styleEditorProps = "chrome://browser/locale/devtools/styleeditor.properties";
|
2013-10-25 00:18:41 -07:00
|
|
|
const shaderEditorProps = "chrome://browser/locale/devtools/shadereditor.properties";
|
2013-04-11 13:59:08 -07:00
|
|
|
const webConsoleProps = "chrome://browser/locale/devtools/webconsole.properties";
|
|
|
|
const profilerProps = "chrome://browser/locale/devtools/profiler.properties";
|
|
|
|
const netMonitorProps = "chrome://browser/locale/devtools/netmonitor.properties";
|
2013-10-04 12:44:09 -07:00
|
|
|
const scratchpadProps = "chrome://browser/locale/devtools/scratchpad.properties";
|
2013-05-03 23:31:07 -07:00
|
|
|
loader.lazyGetter(this, "toolboxStrings", () => Services.strings.createBundle(toolboxProps));
|
2013-04-11 13:59:08 -07:00
|
|
|
loader.lazyGetter(this, "webConsoleStrings", () => Services.strings.createBundle(webConsoleProps));
|
|
|
|
loader.lazyGetter(this, "debuggerStrings", () => Services.strings.createBundle(debuggerProps));
|
|
|
|
loader.lazyGetter(this, "styleEditorStrings", () => Services.strings.createBundle(styleEditorProps));
|
2013-10-25 00:18:41 -07:00
|
|
|
loader.lazyGetter(this, "shaderEditorStrings", () => Services.strings.createBundle(shaderEditorProps));
|
2013-04-11 13:59:08 -07:00
|
|
|
loader.lazyGetter(this, "inspectorStrings", () => Services.strings.createBundle(inspectorProps));
|
|
|
|
loader.lazyGetter(this, "profilerStrings",() => Services.strings.createBundle(profilerProps));
|
|
|
|
loader.lazyGetter(this, "netMonitorStrings", () => Services.strings.createBundle(netMonitorProps));
|
2013-10-04 12:44:09 -07:00
|
|
|
loader.lazyGetter(this, "scratchpadStrings", () => Services.strings.createBundle(scratchpadProps));
|
2012-12-13 14:17:00 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
let Tools = {};
|
|
|
|
exports.Tools = Tools;
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
// Definitions
|
2013-05-03 23:31:07 -07:00
|
|
|
Tools.options = {
|
|
|
|
id: "options",
|
|
|
|
ordinal: 0,
|
|
|
|
url: "chrome://browser/content/devtools/framework/toolbox-options.xul",
|
|
|
|
icon: "chrome://browser/skin/devtools/tool-options.png",
|
2013-11-13 10:02:05 -08:00
|
|
|
bgTheme: "theme-body",
|
2013-05-03 23:31:07 -07:00
|
|
|
tooltip: l10n("optionsButton.tooltip", toolboxStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: false,
|
2013-05-03 23:31:07 -07:00
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
build: function(iframeWindow, toolbox) {
|
|
|
|
let panel = new OptionsPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.webConsole = {
|
2012-11-30 00:07:59 -08:00
|
|
|
id: "webconsole",
|
2013-08-04 21:11:17 -07:00
|
|
|
key: l10n("cmd.commandkey", webConsoleStrings),
|
2012-11-30 00:07:59 -08:00
|
|
|
accesskey: l10n("webConsoleCmd.accesskey", webConsoleStrings),
|
|
|
|
modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift",
|
2013-05-03 23:31:07 -07:00
|
|
|
ordinal: 1,
|
2012-12-22 19:27:19 -08:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-webconsole.png",
|
2012-11-30 00:07:59 -08:00
|
|
|
url: "chrome://browser/content/devtools/webconsole.xul",
|
2013-05-10 15:27:16 -07:00
|
|
|
label: l10n("ToolboxTabWebconsole.label", webConsoleStrings),
|
|
|
|
menuLabel: l10n("MenuWebconsole.label", webConsoleStrings),
|
2012-12-18 07:11:27 -08:00
|
|
|
tooltip: l10n("ToolboxWebconsole.tooltip", webConsoleStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: true,
|
2012-12-18 07:11:27 -08:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
build: function(iframeWindow, toolbox) {
|
2012-12-13 05:03:55 -08:00
|
|
|
let panel = new WebConsolePanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.inspector = {
|
2012-11-30 00:07:59 -08:00
|
|
|
id: "inspector",
|
|
|
|
accesskey: l10n("inspector.accesskey", inspectorStrings),
|
2013-08-03 11:29:37 -07:00
|
|
|
key: l10n("inspector.commandkey", inspectorStrings),
|
2013-05-03 23:31:07 -07:00
|
|
|
ordinal: 2,
|
2012-11-30 00:07:59 -08:00
|
|
|
modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
|
2012-12-22 19:27:19 -08:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-inspector.png",
|
2012-11-30 00:07:59 -08:00
|
|
|
url: "chrome://browser/content/devtools/inspector/inspector.xul",
|
|
|
|
label: l10n("inspector.label", inspectorStrings),
|
2012-12-18 07:11:27 -08:00
|
|
|
tooltip: l10n("inspector.tooltip", inspectorStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: true,
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-08-02 11:28:37 -07:00
|
|
|
preventClosingOnKey: true,
|
|
|
|
onkey: function(panel) {
|
|
|
|
if (panel.highlighter) {
|
|
|
|
panel.highlighter.toggleLockState();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
isTargetSupported: function(target) {
|
2013-08-12 07:43:18 -07:00
|
|
|
return true;
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
2012-12-13 05:03:55 -08:00
|
|
|
let panel = new InspectorPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-03 23:31:07 -07:00
|
|
|
Tools.jsdebugger = {
|
|
|
|
id: "jsdebugger",
|
2013-06-21 07:33:56 -07:00
|
|
|
key: l10n("debuggerMenu.commandkey", debuggerStrings),
|
2013-05-03 23:31:07 -07:00
|
|
|
accesskey: l10n("debuggerMenu.accesskey", debuggerStrings),
|
|
|
|
modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
|
|
|
|
ordinal: 3,
|
|
|
|
icon: "chrome://browser/skin/devtools/tool-debugger.png",
|
2013-05-25 01:05:34 -07:00
|
|
|
highlightedicon: "chrome://browser/skin/devtools/tool-debugger-paused.png",
|
2013-05-03 23:31:07 -07:00
|
|
|
url: "chrome://browser/content/devtools/debugger.xul",
|
|
|
|
label: l10n("ToolboxDebugger.label", debuggerStrings),
|
|
|
|
tooltip: l10n("ToolboxDebugger.tooltip", debuggerStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: true,
|
2013-05-03 23:31:07 -07:00
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
|
|
|
let panel = new DebuggerPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.styleEditor = {
|
2012-11-30 00:07:59 -08:00
|
|
|
id: "styleeditor",
|
|
|
|
key: l10n("open.commandkey", styleEditorStrings),
|
2013-05-03 23:31:07 -07:00
|
|
|
ordinal: 4,
|
2012-11-30 00:07:59 -08:00
|
|
|
accesskey: l10n("open.accesskey", styleEditorStrings),
|
|
|
|
modifiers: "shift",
|
2012-12-22 19:27:19 -08:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-styleeditor.png",
|
2013-04-30 08:56:00 -07:00
|
|
|
url: "chrome://browser/content/devtools/styleeditor.xul",
|
2013-03-11 23:50:42 -07:00
|
|
|
label: l10n("ToolboxStyleEditor.label", styleEditorStrings),
|
2013-09-17 08:36:40 -07:00
|
|
|
tooltip: l10n("ToolboxStyleEditor.tooltip2", styleEditorStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: true,
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
2013-04-25 09:46:13 -07:00
|
|
|
return true;
|
2012-11-30 00:07:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
2012-12-13 05:03:55 -08:00
|
|
|
let panel = new StyleEditorPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
2012-11-30 00:07:59 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-25 00:18:41 -07:00
|
|
|
Tools.shaderEditor = {
|
|
|
|
id: "shadereditor",
|
|
|
|
ordinal: 5,
|
|
|
|
visibilityswitch: "devtools.shadereditor.enabled",
|
|
|
|
icon: "chrome://browser/skin/devtools/tool-styleeditor.png",
|
|
|
|
url: "chrome://browser/content/devtools/shadereditor.xul",
|
|
|
|
label: l10n("ToolboxShaderEditor.label", shaderEditorStrings),
|
|
|
|
tooltip: l10n("ToolboxShaderEditor.tooltip", shaderEditorStrings),
|
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
|
|
|
let panel = new ShaderEditorPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.jsprofiler = {
|
2012-12-13 14:17:00 -08:00
|
|
|
id: "jsprofiler",
|
2013-02-07 11:09:55 -08:00
|
|
|
accesskey: l10n("profiler.accesskey", profilerStrings),
|
2013-04-01 13:17:24 -07:00
|
|
|
key: l10n("profiler2.commandkey", profilerStrings),
|
2013-10-25 00:18:41 -07:00
|
|
|
ordinal: 6,
|
2013-03-19 11:22:03 -07:00
|
|
|
modifiers: "shift",
|
2013-05-03 23:31:07 -07:00
|
|
|
visibilityswitch: "devtools.profiler.enabled",
|
2013-03-11 23:50:42 -07:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-profiler.png",
|
2013-04-30 08:56:00 -07:00
|
|
|
url: "chrome://browser/content/devtools/profiler.xul",
|
2012-12-13 14:17:00 -08:00
|
|
|
label: l10n("profiler.label", profilerStrings),
|
2013-06-18 17:24:36 -07:00
|
|
|
tooltip: l10n("profiler.tooltip2", profilerStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: true,
|
2012-12-13 14:17:00 -08:00
|
|
|
|
|
|
|
isTargetSupported: function (target) {
|
2013-02-06 12:10:30 -08:00
|
|
|
return true;
|
2012-12-13 14:17:00 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
build: function (frame, target) {
|
|
|
|
let panel = new ProfilerPanel(frame, target);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.netMonitor = {
|
2013-03-11 23:50:42 -07:00
|
|
|
id: "netmonitor",
|
|
|
|
accesskey: l10n("netmonitor.accesskey", netMonitorStrings),
|
|
|
|
key: l10n("netmonitor.commandkey", netMonitorStrings),
|
2013-10-25 00:18:41 -07:00
|
|
|
ordinal: 7,
|
2013-03-11 23:50:42 -07:00
|
|
|
modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
|
2013-05-03 23:31:07 -07:00
|
|
|
visibilityswitch: "devtools.netmonitor.enabled",
|
2013-05-10 23:14:40 -07:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-network.png",
|
2013-03-11 23:50:42 -07:00
|
|
|
url: "chrome://browser/content/devtools/netmonitor.xul",
|
|
|
|
label: l10n("netmonitor.label", netMonitorStrings),
|
|
|
|
tooltip: l10n("netmonitor.tooltip", netMonitorStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: true,
|
2013-03-11 23:50:42 -07:00
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
2013-09-16 22:30:00 -07:00
|
|
|
return !target.isApp;
|
2013-03-11 23:50:42 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
|
|
|
let panel = new NetMonitorPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
};
|
2012-12-13 14:17:00 -08:00
|
|
|
|
2013-10-04 12:44:09 -07:00
|
|
|
Tools.scratchpad = {
|
|
|
|
id: "scratchpad",
|
2013-10-25 00:18:41 -07:00
|
|
|
ordinal: 8,
|
2013-10-04 12:44:09 -07:00
|
|
|
visibilityswitch: "devtools.scratchpad.enabled",
|
|
|
|
icon: "chrome://browser/skin/devtools/tool-scratchpad.png",
|
|
|
|
url: "chrome://browser/content/devtools/scratchpad.xul",
|
|
|
|
label: l10n("scratchpad.label", scratchpadStrings),
|
|
|
|
tooltip: l10n("scratchpad.tooltip", scratchpadStrings),
|
2013-10-09 11:47:00 -07:00
|
|
|
inMenu: false,
|
2013-10-04 12:44:09 -07:00
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return target.isRemote;
|
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
|
|
|
let panel = new ScratchpadPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
let defaultTools = [
|
2013-05-03 23:31:07 -07:00
|
|
|
Tools.options,
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.webConsole,
|
|
|
|
Tools.inspector,
|
2013-10-25 00:18:41 -07:00
|
|
|
Tools.jsdebugger,
|
|
|
|
Tools.styleEditor,
|
|
|
|
Tools.shaderEditor,
|
2013-04-11 13:59:08 -07:00
|
|
|
Tools.jsprofiler,
|
2013-10-04 12:44:09 -07:00
|
|
|
Tools.netMonitor,
|
|
|
|
Tools.scratchpad
|
2012-11-30 00:07:59 -08:00
|
|
|
];
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
exports.defaultTools = defaultTools;
|
|
|
|
|
|
|
|
for (let definition of defaultTools) {
|
|
|
|
gDevTools.registerTool(definition);
|
|
|
|
}
|
|
|
|
|
|
|
|
var unloadObserver = {
|
|
|
|
observe: function(subject, topic, data) {
|
|
|
|
if (subject.wrappedJSObject === require("@loader/unload")) {
|
|
|
|
Services.obs.removeObserver(unloadObserver, "sdk:loader:destroy");
|
2013-05-03 23:31:07 -07:00
|
|
|
for (let definition of gDevTools.getToolDefinitionArray()) {
|
2013-04-11 13:59:08 -07:00
|
|
|
gDevTools.unregisterTool(definition.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Services.obs.addObserver(unloadObserver, "sdk:loader:destroy", false);
|
|
|
|
|
2013-08-03 03:29:48 -07:00
|
|
|
events.emit("devtools-loaded", {});
|
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
/**
|
|
|
|
* Lookup l10n string from a string bundle.
|
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
* The key to lookup.
|
|
|
|
* @param {StringBundle} bundle
|
|
|
|
* The key to lookup.
|
|
|
|
* @returns A localized version of the given key.
|
|
|
|
*/
|
|
|
|
function l10n(name, bundle)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return bundle.GetStringFromName(name);
|
|
|
|
} catch (ex) {
|
|
|
|
Services.console.logStringMessage("Error reading '" + name + "'");
|
|
|
|
throw new Error("l10n error with " + name);
|
|
|
|
}
|
|
|
|
}
|