1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const {Cc, Ci, Cu} = require("chrome");
9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
10 Cu.import("resource://gre/modules/Services.jsm");
11 Cu.import("resource:///modules/devtools/gDevTools.jsm");
13 Object.defineProperty(exports, "Toolbox", {
14 get: () => require("devtools/framework/toolbox").Toolbox
16 Object.defineProperty(exports, "TargetFactory", {
17 get: () => require("devtools/framework/target").TargetFactory
20 loader.lazyGetter(this, "osString", () => Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS);
22 let events = require("sdk/system/events");
25 loader.lazyGetter(this, "OptionsPanel", () => require("devtools/framework/toolbox-options").OptionsPanel);
26 loader.lazyGetter(this, "InspectorPanel", () => require("devtools/inspector/inspector-panel").InspectorPanel);
27 loader.lazyGetter(this, "WebConsolePanel", () => require("devtools/webconsole/panel").WebConsolePanel);
28 loader.lazyGetter(this, "DebuggerPanel", () => require("devtools/debugger/panel").DebuggerPanel);
29 loader.lazyGetter(this, "StyleEditorPanel", () => require("devtools/styleeditor/styleeditor-panel").StyleEditorPanel);
30 loader.lazyGetter(this, "ShaderEditorPanel", () => require("devtools/shadereditor/panel").ShaderEditorPanel);
31 loader.lazyGetter(this, "CanvasDebuggerPanel", () => require("devtools/canvasdebugger/panel").CanvasDebuggerPanel);
32 loader.lazyGetter(this, "WebAudioEditorPanel", () => require("devtools/webaudioeditor/panel").WebAudioEditorPanel);
33 loader.lazyGetter(this, "ProfilerPanel", () => require("devtools/profiler/panel"));
34 loader.lazyGetter(this, "NetMonitorPanel", () => require("devtools/netmonitor/panel").NetMonitorPanel);
35 loader.lazyGetter(this, "ScratchpadPanel", () => require("devtools/scratchpad/scratchpad-panel").ScratchpadPanel);
38 const toolboxProps = "chrome://browser/locale/devtools/toolbox.properties";
39 const inspectorProps = "chrome://browser/locale/devtools/inspector.properties";
40 const debuggerProps = "chrome://browser/locale/devtools/debugger.properties";
41 const styleEditorProps = "chrome://browser/locale/devtools/styleeditor.properties";
42 const shaderEditorProps = "chrome://browser/locale/devtools/shadereditor.properties";
43 const canvasDebuggerProps = "chrome://browser/locale/devtools/canvasdebugger.properties";
44 const webAudioEditorProps = "chrome://browser/locale/devtools/webaudioeditor.properties";
46 const webConsoleProps = "chrome://browser/locale/devtools/webconsole.properties";
47 const profilerProps = "chrome://browser/locale/devtools/profiler.properties";
48 const netMonitorProps = "chrome://browser/locale/devtools/netmonitor.properties";
49 const scratchpadProps = "chrome://browser/locale/devtools/scratchpad.properties";
50 loader.lazyGetter(this, "toolboxStrings", () => Services.strings.createBundle(toolboxProps));
51 loader.lazyGetter(this, "webConsoleStrings", () => Services.strings.createBundle(webConsoleProps));
52 loader.lazyGetter(this, "debuggerStrings", () => Services.strings.createBundle(debuggerProps));
53 loader.lazyGetter(this, "styleEditorStrings", () => Services.strings.createBundle(styleEditorProps));
54 loader.lazyGetter(this, "shaderEditorStrings", () => Services.strings.createBundle(shaderEditorProps));
55 loader.lazyGetter(this, "canvasDebuggerStrings", () => Services.strings.createBundle(canvasDebuggerProps));
56 loader.lazyGetter(this, "webAudioEditorStrings", () => Services.strings.createBundle(webAudioEditorProps));
57 loader.lazyGetter(this, "inspectorStrings", () => Services.strings.createBundle(inspectorProps));
58 loader.lazyGetter(this, "profilerStrings",() => Services.strings.createBundle(profilerProps));
59 loader.lazyGetter(this, "netMonitorStrings", () => Services.strings.createBundle(netMonitorProps));
60 loader.lazyGetter(this, "scratchpadStrings", () => Services.strings.createBundle(scratchpadProps));
63 exports.Tools = Tools;
69 url: "chrome://browser/content/devtools/framework/toolbox-options.xul",
70 icon: "chrome://browser/skin/devtools/tool-options.svg",
71 invertIconForLightTheme: true,
72 bgTheme: "theme-body",
73 tooltip: l10n("optionsButton.tooltip", toolboxStrings),
75 isTargetSupported: function(target) {
78 build: function(iframeWindow, toolbox) {
79 let panel = new OptionsPanel(iframeWindow, toolbox);
86 key: l10n("cmd.commandkey", webConsoleStrings),
87 accesskey: l10n("webConsoleCmd.accesskey", webConsoleStrings),
88 modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift",
90 icon: "chrome://browser/skin/devtools/tool-webconsole.svg",
91 invertIconForLightTheme: true,
92 url: "chrome://browser/content/devtools/webconsole.xul",
93 label: l10n("ToolboxTabWebconsole.label", webConsoleStrings),
94 menuLabel: l10n("MenuWebconsole.label", webConsoleStrings),
95 tooltip: l10n("ToolboxWebconsole.tooltip", webConsoleStrings),
97 commands: "devtools/webconsole/console-commands",
99 preventClosingOnKey: true,
100 onkey: function(panel, toolbox) {
101 if (toolbox.splitConsole)
102 return toolbox.focusConsoleInput();
107 isTargetSupported: function(target) {
110 build: function(iframeWindow, toolbox) {
111 let panel = new WebConsolePanel(iframeWindow, toolbox);
118 accesskey: l10n("inspector.accesskey", inspectorStrings),
119 key: l10n("inspector.commandkey", inspectorStrings),
121 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
122 icon: "chrome://browser/skin/devtools/tool-inspector.svg",
123 invertIconForLightTheme: true,
124 url: "chrome://browser/content/devtools/inspector/inspector.xul",
125 label: l10n("inspector.label", inspectorStrings),
126 tooltip: l10n("inspector.tooltip", inspectorStrings),
129 "devtools/resize-commands",
130 "devtools/inspector/inspector-commands",
131 "devtools/eyedropper/commands.js"
134 preventClosingOnKey: true,
135 onkey: function(panel) {
136 panel.toolbox.highlighterUtils.togglePicker();
139 isTargetSupported: function(target) {
140 return !target.isAddon;
143 build: function(iframeWindow, toolbox) {
144 let panel = new InspectorPanel(iframeWindow, toolbox);
151 key: l10n("debuggerMenu.commandkey", debuggerStrings),
152 accesskey: l10n("debuggerMenu.accesskey", debuggerStrings),
153 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
155 icon: "chrome://browser/skin/devtools/tool-debugger.svg",
156 invertIconForLightTheme: true,
157 highlightedicon: "chrome://browser/skin/devtools/tool-debugger-paused.svg",
158 url: "chrome://browser/content/devtools/debugger.xul",
159 label: l10n("ToolboxDebugger.label", debuggerStrings),
160 tooltip: l10n("ToolboxDebugger.tooltip", debuggerStrings),
162 commands: "devtools/debugger/debugger-commands",
164 isTargetSupported: function(target) {
168 build: function(iframeWindow, toolbox) {
169 let panel = new DebuggerPanel(iframeWindow, toolbox);
174 Tools.styleEditor = {
176 key: l10n("open.commandkey", styleEditorStrings),
178 accesskey: l10n("open.accesskey", styleEditorStrings),
180 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
181 invertIconForLightTheme: true,
182 url: "chrome://browser/content/devtools/styleeditor.xul",
183 label: l10n("ToolboxStyleEditor.label", styleEditorStrings),
184 tooltip: l10n("ToolboxStyleEditor.tooltip2", styleEditorStrings),
186 commands: "devtools/styleeditor/styleeditor-commands",
188 isTargetSupported: function(target) {
189 return !target.isAddon;
192 build: function(iframeWindow, toolbox) {
193 let panel = new StyleEditorPanel(iframeWindow, toolbox);
198 Tools.shaderEditor = {
201 visibilityswitch: "devtools.shadereditor.enabled",
202 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
203 invertIconForLightTheme: true,
204 url: "chrome://browser/content/devtools/shadereditor.xul",
205 label: l10n("ToolboxShaderEditor.label", shaderEditorStrings),
206 tooltip: l10n("ToolboxShaderEditor.tooltip", shaderEditorStrings),
208 isTargetSupported: function(target) {
209 return !target.isAddon;
212 build: function(iframeWindow, toolbox) {
213 let panel = new ShaderEditorPanel(iframeWindow, toolbox);
218 Tools.canvasDebugger = {
219 id: "canvasdebugger",
221 visibilityswitch: "devtools.canvasdebugger.enabled",
222 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
223 invertIconForLightTheme: true,
224 url: "chrome://browser/content/devtools/canvasdebugger.xul",
225 label: l10n("ToolboxCanvasDebugger.label", canvasDebuggerStrings),
226 tooltip: l10n("ToolboxCanvasDebugger.tooltip", canvasDebuggerStrings),
227 isTargetSupported: function(target) {
228 return !target.isAddon;
230 build: function (iframeWindow, toolbox) {
231 let panel = new CanvasDebuggerPanel(iframeWindow, toolbox);
236 Tools.webAudioEditor = {
237 id: "webaudioeditor",
239 visibilityswitch: "devtools.webaudioeditor.enabled",
240 icon: "chrome://browser/skin/devtools/tool-webaudio.svg",
241 invertIconForLightTheme: true,
242 url: "chrome://browser/content/devtools/webaudioeditor.xul",
243 label: l10n("ToolboxWebAudioEditor1.label", webAudioEditorStrings),
244 tooltip: l10n("ToolboxWebAudioEditor1.tooltip", webAudioEditorStrings),
245 isTargetSupported: function(target) {
246 return !target.isAddon;
248 build: function(iframeWindow, toolbox) {
249 let panel = new WebAudioEditorPanel(iframeWindow, toolbox);
256 accesskey: l10n("profiler.accesskey", profilerStrings),
257 key: l10n("profiler2.commandkey", profilerStrings),
260 visibilityswitch: "devtools.profiler.enabled",
261 icon: "chrome://browser/skin/devtools/tool-profiler.svg",
262 invertIconForLightTheme: true,
263 url: "chrome://browser/content/devtools/profiler.xul",
264 label: l10n("profiler.label", profilerStrings),
265 tooltip: l10n("profiler.tooltip2", profilerStrings),
267 commands: "devtools/profiler/commands",
269 isTargetSupported: function (target) {
270 return !target.isAddon;
273 build: function (frame, target) {
274 let panel = new ProfilerPanel(frame, target);
281 accesskey: l10n("netmonitor.accesskey", netMonitorStrings),
282 key: l10n("netmonitor.commandkey", netMonitorStrings),
284 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
285 visibilityswitch: "devtools.netmonitor.enabled",
286 icon: "chrome://browser/skin/devtools/tool-network.svg",
287 invertIconForLightTheme: true,
288 url: "chrome://browser/content/devtools/netmonitor.xul",
289 label: l10n("netmonitor.label", netMonitorStrings),
290 tooltip: l10n("netmonitor.tooltip", netMonitorStrings),
293 isTargetSupported: function(target) {
294 let root = target.client.mainRoot;
295 return !target.isAddon && (root.traits.networkMonitor || !target.isApp);
298 build: function(iframeWindow, toolbox) {
299 let panel = new NetMonitorPanel(iframeWindow, toolbox);
307 visibilityswitch: "devtools.scratchpad.enabled",
308 icon: "chrome://browser/skin/devtools/tool-scratchpad.svg",
309 invertIconForLightTheme: true,
310 url: "chrome://browser/content/devtools/scratchpad.xul",
311 label: l10n("scratchpad.label", scratchpadStrings),
312 tooltip: l10n("scratchpad.tooltip", scratchpadStrings),
314 commands: "devtools/scratchpad/scratchpad-commands",
316 isTargetSupported: function(target) {
317 return target.isRemote;
320 build: function(iframeWindow, toolbox) {
321 let panel = new ScratchpadPanel(iframeWindow, toolbox);
333 Tools.canvasDebugger,
334 Tools.webAudioEditor,
340 exports.defaultTools = defaultTools;
342 for (let definition of defaultTools) {
343 gDevTools.registerTool(definition);
346 var unloadObserver = {
347 observe: function(subject, topic, data) {
348 if (subject.wrappedJSObject === require("@loader/unload")) {
349 Services.obs.removeObserver(unloadObserver, "sdk:loader:destroy");
350 for (let definition of gDevTools.getToolDefinitionArray()) {
351 gDevTools.unregisterTool(definition.id);
356 Services.obs.addObserver(unloadObserver, "sdk:loader:destroy", false);
358 events.emit("devtools-loaded", {});
361 * Lookup l10n string from a string bundle.
363 * @param {string} name
365 * @param {StringBundle} bundle
367 * @returns A localized version of the given key.
369 function l10n(name, bundle)
372 return bundle.GetStringFromName(name);
374 Services.console.logStringMessage("Error reading '" + name + "'");
375 throw new Error("l10n error with " + name);