browser/devtools/main.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const {Cc, Ci, Cu} = require("chrome");
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11 Cu.import("resource:///modules/devtools/gDevTools.jsm");
michael@0 12
michael@0 13 Object.defineProperty(exports, "Toolbox", {
michael@0 14 get: () => require("devtools/framework/toolbox").Toolbox
michael@0 15 });
michael@0 16 Object.defineProperty(exports, "TargetFactory", {
michael@0 17 get: () => require("devtools/framework/target").TargetFactory
michael@0 18 });
michael@0 19
michael@0 20 loader.lazyGetter(this, "osString", () => Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS);
michael@0 21
michael@0 22 let events = require("sdk/system/events");
michael@0 23
michael@0 24 // Panels
michael@0 25 loader.lazyGetter(this, "OptionsPanel", () => require("devtools/framework/toolbox-options").OptionsPanel);
michael@0 26 loader.lazyGetter(this, "InspectorPanel", () => require("devtools/inspector/inspector-panel").InspectorPanel);
michael@0 27 loader.lazyGetter(this, "WebConsolePanel", () => require("devtools/webconsole/panel").WebConsolePanel);
michael@0 28 loader.lazyGetter(this, "DebuggerPanel", () => require("devtools/debugger/panel").DebuggerPanel);
michael@0 29 loader.lazyGetter(this, "StyleEditorPanel", () => require("devtools/styleeditor/styleeditor-panel").StyleEditorPanel);
michael@0 30 loader.lazyGetter(this, "ShaderEditorPanel", () => require("devtools/shadereditor/panel").ShaderEditorPanel);
michael@0 31 loader.lazyGetter(this, "CanvasDebuggerPanel", () => require("devtools/canvasdebugger/panel").CanvasDebuggerPanel);
michael@0 32 loader.lazyGetter(this, "WebAudioEditorPanel", () => require("devtools/webaudioeditor/panel").WebAudioEditorPanel);
michael@0 33 loader.lazyGetter(this, "ProfilerPanel", () => require("devtools/profiler/panel"));
michael@0 34 loader.lazyGetter(this, "NetMonitorPanel", () => require("devtools/netmonitor/panel").NetMonitorPanel);
michael@0 35 loader.lazyGetter(this, "ScratchpadPanel", () => require("devtools/scratchpad/scratchpad-panel").ScratchpadPanel);
michael@0 36
michael@0 37 // Strings
michael@0 38 const toolboxProps = "chrome://browser/locale/devtools/toolbox.properties";
michael@0 39 const inspectorProps = "chrome://browser/locale/devtools/inspector.properties";
michael@0 40 const debuggerProps = "chrome://browser/locale/devtools/debugger.properties";
michael@0 41 const styleEditorProps = "chrome://browser/locale/devtools/styleeditor.properties";
michael@0 42 const shaderEditorProps = "chrome://browser/locale/devtools/shadereditor.properties";
michael@0 43 const canvasDebuggerProps = "chrome://browser/locale/devtools/canvasdebugger.properties";
michael@0 44 const webAudioEditorProps = "chrome://browser/locale/devtools/webaudioeditor.properties";
michael@0 45
michael@0 46 const webConsoleProps = "chrome://browser/locale/devtools/webconsole.properties";
michael@0 47 const profilerProps = "chrome://browser/locale/devtools/profiler.properties";
michael@0 48 const netMonitorProps = "chrome://browser/locale/devtools/netmonitor.properties";
michael@0 49 const scratchpadProps = "chrome://browser/locale/devtools/scratchpad.properties";
michael@0 50 loader.lazyGetter(this, "toolboxStrings", () => Services.strings.createBundle(toolboxProps));
michael@0 51 loader.lazyGetter(this, "webConsoleStrings", () => Services.strings.createBundle(webConsoleProps));
michael@0 52 loader.lazyGetter(this, "debuggerStrings", () => Services.strings.createBundle(debuggerProps));
michael@0 53 loader.lazyGetter(this, "styleEditorStrings", () => Services.strings.createBundle(styleEditorProps));
michael@0 54 loader.lazyGetter(this, "shaderEditorStrings", () => Services.strings.createBundle(shaderEditorProps));
michael@0 55 loader.lazyGetter(this, "canvasDebuggerStrings", () => Services.strings.createBundle(canvasDebuggerProps));
michael@0 56 loader.lazyGetter(this, "webAudioEditorStrings", () => Services.strings.createBundle(webAudioEditorProps));
michael@0 57 loader.lazyGetter(this, "inspectorStrings", () => Services.strings.createBundle(inspectorProps));
michael@0 58 loader.lazyGetter(this, "profilerStrings",() => Services.strings.createBundle(profilerProps));
michael@0 59 loader.lazyGetter(this, "netMonitorStrings", () => Services.strings.createBundle(netMonitorProps));
michael@0 60 loader.lazyGetter(this, "scratchpadStrings", () => Services.strings.createBundle(scratchpadProps));
michael@0 61
michael@0 62 let Tools = {};
michael@0 63 exports.Tools = Tools;
michael@0 64
michael@0 65 // Definitions
michael@0 66 Tools.options = {
michael@0 67 id: "options",
michael@0 68 ordinal: 0,
michael@0 69 url: "chrome://browser/content/devtools/framework/toolbox-options.xul",
michael@0 70 icon: "chrome://browser/skin/devtools/tool-options.svg",
michael@0 71 invertIconForLightTheme: true,
michael@0 72 bgTheme: "theme-body",
michael@0 73 tooltip: l10n("optionsButton.tooltip", toolboxStrings),
michael@0 74 inMenu: false,
michael@0 75 isTargetSupported: function(target) {
michael@0 76 return true;
michael@0 77 },
michael@0 78 build: function(iframeWindow, toolbox) {
michael@0 79 let panel = new OptionsPanel(iframeWindow, toolbox);
michael@0 80 return panel.open();
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 Tools.webConsole = {
michael@0 85 id: "webconsole",
michael@0 86 key: l10n("cmd.commandkey", webConsoleStrings),
michael@0 87 accesskey: l10n("webConsoleCmd.accesskey", webConsoleStrings),
michael@0 88 modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift",
michael@0 89 ordinal: 1,
michael@0 90 icon: "chrome://browser/skin/devtools/tool-webconsole.svg",
michael@0 91 invertIconForLightTheme: true,
michael@0 92 url: "chrome://browser/content/devtools/webconsole.xul",
michael@0 93 label: l10n("ToolboxTabWebconsole.label", webConsoleStrings),
michael@0 94 menuLabel: l10n("MenuWebconsole.label", webConsoleStrings),
michael@0 95 tooltip: l10n("ToolboxWebconsole.tooltip", webConsoleStrings),
michael@0 96 inMenu: true,
michael@0 97 commands: "devtools/webconsole/console-commands",
michael@0 98
michael@0 99 preventClosingOnKey: true,
michael@0 100 onkey: function(panel, toolbox) {
michael@0 101 if (toolbox.splitConsole)
michael@0 102 return toolbox.focusConsoleInput();
michael@0 103
michael@0 104 panel.focusInput();
michael@0 105 },
michael@0 106
michael@0 107 isTargetSupported: function(target) {
michael@0 108 return !target.isAddon;
michael@0 109 },
michael@0 110 build: function(iframeWindow, toolbox) {
michael@0 111 let panel = new WebConsolePanel(iframeWindow, toolbox);
michael@0 112 return panel.open();
michael@0 113 }
michael@0 114 };
michael@0 115
michael@0 116 Tools.inspector = {
michael@0 117 id: "inspector",
michael@0 118 accesskey: l10n("inspector.accesskey", inspectorStrings),
michael@0 119 key: l10n("inspector.commandkey", inspectorStrings),
michael@0 120 ordinal: 2,
michael@0 121 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
michael@0 122 icon: "chrome://browser/skin/devtools/tool-inspector.svg",
michael@0 123 invertIconForLightTheme: true,
michael@0 124 url: "chrome://browser/content/devtools/inspector/inspector.xul",
michael@0 125 label: l10n("inspector.label", inspectorStrings),
michael@0 126 tooltip: l10n("inspector.tooltip", inspectorStrings),
michael@0 127 inMenu: true,
michael@0 128 commands: [
michael@0 129 "devtools/resize-commands",
michael@0 130 "devtools/inspector/inspector-commands",
michael@0 131 "devtools/eyedropper/commands.js"
michael@0 132 ],
michael@0 133
michael@0 134 preventClosingOnKey: true,
michael@0 135 onkey: function(panel) {
michael@0 136 panel.toolbox.highlighterUtils.togglePicker();
michael@0 137 },
michael@0 138
michael@0 139 isTargetSupported: function(target) {
michael@0 140 return !target.isAddon;
michael@0 141 },
michael@0 142
michael@0 143 build: function(iframeWindow, toolbox) {
michael@0 144 let panel = new InspectorPanel(iframeWindow, toolbox);
michael@0 145 return panel.open();
michael@0 146 }
michael@0 147 };
michael@0 148
michael@0 149 Tools.jsdebugger = {
michael@0 150 id: "jsdebugger",
michael@0 151 key: l10n("debuggerMenu.commandkey", debuggerStrings),
michael@0 152 accesskey: l10n("debuggerMenu.accesskey", debuggerStrings),
michael@0 153 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
michael@0 154 ordinal: 3,
michael@0 155 icon: "chrome://browser/skin/devtools/tool-debugger.svg",
michael@0 156 invertIconForLightTheme: true,
michael@0 157 highlightedicon: "chrome://browser/skin/devtools/tool-debugger-paused.svg",
michael@0 158 url: "chrome://browser/content/devtools/debugger.xul",
michael@0 159 label: l10n("ToolboxDebugger.label", debuggerStrings),
michael@0 160 tooltip: l10n("ToolboxDebugger.tooltip", debuggerStrings),
michael@0 161 inMenu: true,
michael@0 162 commands: "devtools/debugger/debugger-commands",
michael@0 163
michael@0 164 isTargetSupported: function(target) {
michael@0 165 return true;
michael@0 166 },
michael@0 167
michael@0 168 build: function(iframeWindow, toolbox) {
michael@0 169 let panel = new DebuggerPanel(iframeWindow, toolbox);
michael@0 170 return panel.open();
michael@0 171 }
michael@0 172 };
michael@0 173
michael@0 174 Tools.styleEditor = {
michael@0 175 id: "styleeditor",
michael@0 176 key: l10n("open.commandkey", styleEditorStrings),
michael@0 177 ordinal: 4,
michael@0 178 accesskey: l10n("open.accesskey", styleEditorStrings),
michael@0 179 modifiers: "shift",
michael@0 180 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
michael@0 181 invertIconForLightTheme: true,
michael@0 182 url: "chrome://browser/content/devtools/styleeditor.xul",
michael@0 183 label: l10n("ToolboxStyleEditor.label", styleEditorStrings),
michael@0 184 tooltip: l10n("ToolboxStyleEditor.tooltip2", styleEditorStrings),
michael@0 185 inMenu: true,
michael@0 186 commands: "devtools/styleeditor/styleeditor-commands",
michael@0 187
michael@0 188 isTargetSupported: function(target) {
michael@0 189 return !target.isAddon;
michael@0 190 },
michael@0 191
michael@0 192 build: function(iframeWindow, toolbox) {
michael@0 193 let panel = new StyleEditorPanel(iframeWindow, toolbox);
michael@0 194 return panel.open();
michael@0 195 }
michael@0 196 };
michael@0 197
michael@0 198 Tools.shaderEditor = {
michael@0 199 id: "shadereditor",
michael@0 200 ordinal: 5,
michael@0 201 visibilityswitch: "devtools.shadereditor.enabled",
michael@0 202 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
michael@0 203 invertIconForLightTheme: true,
michael@0 204 url: "chrome://browser/content/devtools/shadereditor.xul",
michael@0 205 label: l10n("ToolboxShaderEditor.label", shaderEditorStrings),
michael@0 206 tooltip: l10n("ToolboxShaderEditor.tooltip", shaderEditorStrings),
michael@0 207
michael@0 208 isTargetSupported: function(target) {
michael@0 209 return !target.isAddon;
michael@0 210 },
michael@0 211
michael@0 212 build: function(iframeWindow, toolbox) {
michael@0 213 let panel = new ShaderEditorPanel(iframeWindow, toolbox);
michael@0 214 return panel.open();
michael@0 215 }
michael@0 216 };
michael@0 217
michael@0 218 Tools.canvasDebugger = {
michael@0 219 id: "canvasdebugger",
michael@0 220 ordinal: 6,
michael@0 221 visibilityswitch: "devtools.canvasdebugger.enabled",
michael@0 222 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
michael@0 223 invertIconForLightTheme: true,
michael@0 224 url: "chrome://browser/content/devtools/canvasdebugger.xul",
michael@0 225 label: l10n("ToolboxCanvasDebugger.label", canvasDebuggerStrings),
michael@0 226 tooltip: l10n("ToolboxCanvasDebugger.tooltip", canvasDebuggerStrings),
michael@0 227 isTargetSupported: function(target) {
michael@0 228 return !target.isAddon;
michael@0 229 },
michael@0 230 build: function (iframeWindow, toolbox) {
michael@0 231 let panel = new CanvasDebuggerPanel(iframeWindow, toolbox);
michael@0 232 return panel.open();
michael@0 233 }
michael@0 234 };
michael@0 235
michael@0 236 Tools.webAudioEditor = {
michael@0 237 id: "webaudioeditor",
michael@0 238 ordinal: 10,
michael@0 239 visibilityswitch: "devtools.webaudioeditor.enabled",
michael@0 240 icon: "chrome://browser/skin/devtools/tool-styleeditor.svg",
michael@0 241 invertIconForLightTheme: true,
michael@0 242 url: "chrome://browser/content/devtools/webaudioeditor.xul",
michael@0 243 label: l10n("ToolboxWebAudioEditor.label", webAudioEditorStrings),
michael@0 244 tooltip: l10n("ToolboxWebAudioEditor.tooltip", webAudioEditorStrings),
michael@0 245 isTargetSupported: function(target) {
michael@0 246 return !target.isAddon;
michael@0 247 },
michael@0 248 build: function(iframeWindow, toolbox) {
michael@0 249 let panel = new WebAudioEditorPanel(iframeWindow, toolbox);
michael@0 250 return panel.open();
michael@0 251 }
michael@0 252 };
michael@0 253
michael@0 254 Tools.jsprofiler = {
michael@0 255 id: "jsprofiler",
michael@0 256 accesskey: l10n("profiler.accesskey", profilerStrings),
michael@0 257 key: l10n("profiler2.commandkey", profilerStrings),
michael@0 258 ordinal: 7,
michael@0 259 modifiers: "shift",
michael@0 260 visibilityswitch: "devtools.profiler.enabled",
michael@0 261 icon: "chrome://browser/skin/devtools/tool-profiler.svg",
michael@0 262 invertIconForLightTheme: true,
michael@0 263 url: "chrome://browser/content/devtools/profiler.xul",
michael@0 264 label: l10n("profiler.label", profilerStrings),
michael@0 265 tooltip: l10n("profiler.tooltip2", profilerStrings),
michael@0 266 inMenu: true,
michael@0 267 commands: "devtools/profiler/commands",
michael@0 268
michael@0 269 isTargetSupported: function (target) {
michael@0 270 return !target.isAddon;
michael@0 271 },
michael@0 272
michael@0 273 build: function (frame, target) {
michael@0 274 let panel = new ProfilerPanel(frame, target);
michael@0 275 return panel.open();
michael@0 276 }
michael@0 277 };
michael@0 278
michael@0 279 Tools.netMonitor = {
michael@0 280 id: "netmonitor",
michael@0 281 accesskey: l10n("netmonitor.accesskey", netMonitorStrings),
michael@0 282 key: l10n("netmonitor.commandkey", netMonitorStrings),
michael@0 283 ordinal: 8,
michael@0 284 modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
michael@0 285 visibilityswitch: "devtools.netmonitor.enabled",
michael@0 286 icon: "chrome://browser/skin/devtools/tool-network.svg",
michael@0 287 invertIconForLightTheme: true,
michael@0 288 url: "chrome://browser/content/devtools/netmonitor.xul",
michael@0 289 label: l10n("netmonitor.label", netMonitorStrings),
michael@0 290 tooltip: l10n("netmonitor.tooltip", netMonitorStrings),
michael@0 291 inMenu: true,
michael@0 292
michael@0 293 isTargetSupported: function(target) {
michael@0 294 let root = target.client.mainRoot;
michael@0 295 return !target.isAddon && (root.traits.networkMonitor || !target.isApp);
michael@0 296 },
michael@0 297
michael@0 298 build: function(iframeWindow, toolbox) {
michael@0 299 let panel = new NetMonitorPanel(iframeWindow, toolbox);
michael@0 300 return panel.open();
michael@0 301 }
michael@0 302 };
michael@0 303
michael@0 304 Tools.scratchpad = {
michael@0 305 id: "scratchpad",
michael@0 306 ordinal: 9,
michael@0 307 visibilityswitch: "devtools.scratchpad.enabled",
michael@0 308 icon: "chrome://browser/skin/devtools/tool-scratchpad.svg",
michael@0 309 invertIconForLightTheme: true,
michael@0 310 url: "chrome://browser/content/devtools/scratchpad.xul",
michael@0 311 label: l10n("scratchpad.label", scratchpadStrings),
michael@0 312 tooltip: l10n("scratchpad.tooltip", scratchpadStrings),
michael@0 313 inMenu: false,
michael@0 314 commands: "devtools/scratchpad/scratchpad-commands",
michael@0 315
michael@0 316 isTargetSupported: function(target) {
michael@0 317 return !target.isAddon && target.isRemote;
michael@0 318 },
michael@0 319
michael@0 320 build: function(iframeWindow, toolbox) {
michael@0 321 let panel = new ScratchpadPanel(iframeWindow, toolbox);
michael@0 322 return panel.open();
michael@0 323 }
michael@0 324 };
michael@0 325
michael@0 326 let defaultTools = [
michael@0 327 Tools.options,
michael@0 328 Tools.webConsole,
michael@0 329 Tools.inspector,
michael@0 330 Tools.jsdebugger,
michael@0 331 Tools.styleEditor,
michael@0 332 Tools.shaderEditor,
michael@0 333 Tools.canvasDebugger,
michael@0 334 Tools.webAudioEditor,
michael@0 335 Tools.jsprofiler,
michael@0 336 Tools.netMonitor,
michael@0 337 Tools.scratchpad
michael@0 338 ];
michael@0 339
michael@0 340 exports.defaultTools = defaultTools;
michael@0 341
michael@0 342 for (let definition of defaultTools) {
michael@0 343 gDevTools.registerTool(definition);
michael@0 344 }
michael@0 345
michael@0 346 var unloadObserver = {
michael@0 347 observe: function(subject, topic, data) {
michael@0 348 if (subject.wrappedJSObject === require("@loader/unload")) {
michael@0 349 Services.obs.removeObserver(unloadObserver, "sdk:loader:destroy");
michael@0 350 for (let definition of gDevTools.getToolDefinitionArray()) {
michael@0 351 gDevTools.unregisterTool(definition.id);
michael@0 352 }
michael@0 353 }
michael@0 354 }
michael@0 355 };
michael@0 356 Services.obs.addObserver(unloadObserver, "sdk:loader:destroy", false);
michael@0 357
michael@0 358 events.emit("devtools-loaded", {});
michael@0 359
michael@0 360 /**
michael@0 361 * Lookup l10n string from a string bundle.
michael@0 362 *
michael@0 363 * @param {string} name
michael@0 364 * The key to lookup.
michael@0 365 * @param {StringBundle} bundle
michael@0 366 * The key to lookup.
michael@0 367 * @returns A localized version of the given key.
michael@0 368 */
michael@0 369 function l10n(name, bundle)
michael@0 370 {
michael@0 371 try {
michael@0 372 return bundle.GetStringFromName(name);
michael@0 373 } catch (ex) {
michael@0 374 Services.console.logStringMessage("Error reading '" + name + "'");
michael@0 375 throw new Error("l10n error with " + name);
michael@0 376 }
michael@0 377 }

mercurial