|
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/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const {Cc, Ci, Cu} = require("chrome"); |
|
8 |
|
9 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
10 Cu.import("resource://gre/modules/Services.jsm"); |
|
11 Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
|
12 |
|
13 Object.defineProperty(exports, "Toolbox", { |
|
14 get: () => require("devtools/framework/toolbox").Toolbox |
|
15 }); |
|
16 Object.defineProperty(exports, "TargetFactory", { |
|
17 get: () => require("devtools/framework/target").TargetFactory |
|
18 }); |
|
19 |
|
20 loader.lazyGetter(this, "osString", () => Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS); |
|
21 |
|
22 let events = require("sdk/system/events"); |
|
23 |
|
24 // Panels |
|
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); |
|
36 |
|
37 // Strings |
|
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"; |
|
45 |
|
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)); |
|
61 |
|
62 let Tools = {}; |
|
63 exports.Tools = Tools; |
|
64 |
|
65 // Definitions |
|
66 Tools.options = { |
|
67 id: "options", |
|
68 ordinal: 0, |
|
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), |
|
74 inMenu: false, |
|
75 isTargetSupported: function(target) { |
|
76 return true; |
|
77 }, |
|
78 build: function(iframeWindow, toolbox) { |
|
79 let panel = new OptionsPanel(iframeWindow, toolbox); |
|
80 return panel.open(); |
|
81 } |
|
82 } |
|
83 |
|
84 Tools.webConsole = { |
|
85 id: "webconsole", |
|
86 key: l10n("cmd.commandkey", webConsoleStrings), |
|
87 accesskey: l10n("webConsoleCmd.accesskey", webConsoleStrings), |
|
88 modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift", |
|
89 ordinal: 1, |
|
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), |
|
96 inMenu: true, |
|
97 commands: "devtools/webconsole/console-commands", |
|
98 |
|
99 preventClosingOnKey: true, |
|
100 onkey: function(panel, toolbox) { |
|
101 if (toolbox.splitConsole) |
|
102 return toolbox.focusConsoleInput(); |
|
103 |
|
104 panel.focusInput(); |
|
105 }, |
|
106 |
|
107 isTargetSupported: function(target) { |
|
108 return !target.isAddon; |
|
109 }, |
|
110 build: function(iframeWindow, toolbox) { |
|
111 let panel = new WebConsolePanel(iframeWindow, toolbox); |
|
112 return panel.open(); |
|
113 } |
|
114 }; |
|
115 |
|
116 Tools.inspector = { |
|
117 id: "inspector", |
|
118 accesskey: l10n("inspector.accesskey", inspectorStrings), |
|
119 key: l10n("inspector.commandkey", inspectorStrings), |
|
120 ordinal: 2, |
|
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), |
|
127 inMenu: true, |
|
128 commands: [ |
|
129 "devtools/resize-commands", |
|
130 "devtools/inspector/inspector-commands", |
|
131 "devtools/eyedropper/commands.js" |
|
132 ], |
|
133 |
|
134 preventClosingOnKey: true, |
|
135 onkey: function(panel) { |
|
136 panel.toolbox.highlighterUtils.togglePicker(); |
|
137 }, |
|
138 |
|
139 isTargetSupported: function(target) { |
|
140 return !target.isAddon; |
|
141 }, |
|
142 |
|
143 build: function(iframeWindow, toolbox) { |
|
144 let panel = new InspectorPanel(iframeWindow, toolbox); |
|
145 return panel.open(); |
|
146 } |
|
147 }; |
|
148 |
|
149 Tools.jsdebugger = { |
|
150 id: "jsdebugger", |
|
151 key: l10n("debuggerMenu.commandkey", debuggerStrings), |
|
152 accesskey: l10n("debuggerMenu.accesskey", debuggerStrings), |
|
153 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift", |
|
154 ordinal: 3, |
|
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), |
|
161 inMenu: true, |
|
162 commands: "devtools/debugger/debugger-commands", |
|
163 |
|
164 isTargetSupported: function(target) { |
|
165 return true; |
|
166 }, |
|
167 |
|
168 build: function(iframeWindow, toolbox) { |
|
169 let panel = new DebuggerPanel(iframeWindow, toolbox); |
|
170 return panel.open(); |
|
171 } |
|
172 }; |
|
173 |
|
174 Tools.styleEditor = { |
|
175 id: "styleeditor", |
|
176 key: l10n("open.commandkey", styleEditorStrings), |
|
177 ordinal: 4, |
|
178 accesskey: l10n("open.accesskey", styleEditorStrings), |
|
179 modifiers: "shift", |
|
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), |
|
185 inMenu: true, |
|
186 commands: "devtools/styleeditor/styleeditor-commands", |
|
187 |
|
188 isTargetSupported: function(target) { |
|
189 return !target.isAddon; |
|
190 }, |
|
191 |
|
192 build: function(iframeWindow, toolbox) { |
|
193 let panel = new StyleEditorPanel(iframeWindow, toolbox); |
|
194 return panel.open(); |
|
195 } |
|
196 }; |
|
197 |
|
198 Tools.shaderEditor = { |
|
199 id: "shadereditor", |
|
200 ordinal: 5, |
|
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), |
|
207 |
|
208 isTargetSupported: function(target) { |
|
209 return !target.isAddon; |
|
210 }, |
|
211 |
|
212 build: function(iframeWindow, toolbox) { |
|
213 let panel = new ShaderEditorPanel(iframeWindow, toolbox); |
|
214 return panel.open(); |
|
215 } |
|
216 }; |
|
217 |
|
218 Tools.canvasDebugger = { |
|
219 id: "canvasdebugger", |
|
220 ordinal: 6, |
|
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; |
|
229 }, |
|
230 build: function (iframeWindow, toolbox) { |
|
231 let panel = new CanvasDebuggerPanel(iframeWindow, toolbox); |
|
232 return panel.open(); |
|
233 } |
|
234 }; |
|
235 |
|
236 Tools.webAudioEditor = { |
|
237 id: "webaudioeditor", |
|
238 ordinal: 10, |
|
239 visibilityswitch: "devtools.webaudioeditor.enabled", |
|
240 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg", |
|
241 invertIconForLightTheme: true, |
|
242 url: "chrome://browser/content/devtools/webaudioeditor.xul", |
|
243 label: l10n("ToolboxWebAudioEditor.label", webAudioEditorStrings), |
|
244 tooltip: l10n("ToolboxWebAudioEditor.tooltip", webAudioEditorStrings), |
|
245 isTargetSupported: function(target) { |
|
246 return !target.isAddon; |
|
247 }, |
|
248 build: function(iframeWindow, toolbox) { |
|
249 let panel = new WebAudioEditorPanel(iframeWindow, toolbox); |
|
250 return panel.open(); |
|
251 } |
|
252 }; |
|
253 |
|
254 Tools.jsprofiler = { |
|
255 id: "jsprofiler", |
|
256 accesskey: l10n("profiler.accesskey", profilerStrings), |
|
257 key: l10n("profiler2.commandkey", profilerStrings), |
|
258 ordinal: 7, |
|
259 modifiers: "shift", |
|
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), |
|
266 inMenu: true, |
|
267 commands: "devtools/profiler/commands", |
|
268 |
|
269 isTargetSupported: function (target) { |
|
270 return !target.isAddon; |
|
271 }, |
|
272 |
|
273 build: function (frame, target) { |
|
274 let panel = new ProfilerPanel(frame, target); |
|
275 return panel.open(); |
|
276 } |
|
277 }; |
|
278 |
|
279 Tools.netMonitor = { |
|
280 id: "netmonitor", |
|
281 accesskey: l10n("netmonitor.accesskey", netMonitorStrings), |
|
282 key: l10n("netmonitor.commandkey", netMonitorStrings), |
|
283 ordinal: 8, |
|
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), |
|
291 inMenu: true, |
|
292 |
|
293 isTargetSupported: function(target) { |
|
294 let root = target.client.mainRoot; |
|
295 return !target.isAddon && (root.traits.networkMonitor || !target.isApp); |
|
296 }, |
|
297 |
|
298 build: function(iframeWindow, toolbox) { |
|
299 let panel = new NetMonitorPanel(iframeWindow, toolbox); |
|
300 return panel.open(); |
|
301 } |
|
302 }; |
|
303 |
|
304 Tools.scratchpad = { |
|
305 id: "scratchpad", |
|
306 ordinal: 9, |
|
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), |
|
313 inMenu: false, |
|
314 commands: "devtools/scratchpad/scratchpad-commands", |
|
315 |
|
316 isTargetSupported: function(target) { |
|
317 return !target.isAddon && target.isRemote; |
|
318 }, |
|
319 |
|
320 build: function(iframeWindow, toolbox) { |
|
321 let panel = new ScratchpadPanel(iframeWindow, toolbox); |
|
322 return panel.open(); |
|
323 } |
|
324 }; |
|
325 |
|
326 let defaultTools = [ |
|
327 Tools.options, |
|
328 Tools.webConsole, |
|
329 Tools.inspector, |
|
330 Tools.jsdebugger, |
|
331 Tools.styleEditor, |
|
332 Tools.shaderEditor, |
|
333 Tools.canvasDebugger, |
|
334 Tools.webAudioEditor, |
|
335 Tools.jsprofiler, |
|
336 Tools.netMonitor, |
|
337 Tools.scratchpad |
|
338 ]; |
|
339 |
|
340 exports.defaultTools = defaultTools; |
|
341 |
|
342 for (let definition of defaultTools) { |
|
343 gDevTools.registerTool(definition); |
|
344 } |
|
345 |
|
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); |
|
352 } |
|
353 } |
|
354 } |
|
355 }; |
|
356 Services.obs.addObserver(unloadObserver, "sdk:loader:destroy", false); |
|
357 |
|
358 events.emit("devtools-loaded", {}); |
|
359 |
|
360 /** |
|
361 * Lookup l10n string from a string bundle. |
|
362 * |
|
363 * @param {string} name |
|
364 * The key to lookup. |
|
365 * @param {StringBundle} bundle |
|
366 * The key to lookup. |
|
367 * @returns A localized version of the given key. |
|
368 */ |
|
369 function l10n(name, bundle) |
|
370 { |
|
371 try { |
|
372 return bundle.GetStringFromName(name); |
|
373 } catch (ex) { |
|
374 Services.console.logStringMessage("Error reading '" + name + "'"); |
|
375 throw new Error("l10n error with " + name); |
|
376 } |
|
377 } |