michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const {Cc, Ci, Cu} = require("chrome"); michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource:///modules/devtools/gDevTools.jsm"); michael@0: michael@0: Object.defineProperty(exports, "Toolbox", { michael@0: get: () => require("devtools/framework/toolbox").Toolbox michael@0: }); michael@0: Object.defineProperty(exports, "TargetFactory", { michael@0: get: () => require("devtools/framework/target").TargetFactory michael@0: }); michael@0: michael@0: loader.lazyGetter(this, "osString", () => Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS); michael@0: michael@0: let events = require("sdk/system/events"); michael@0: michael@0: // Panels michael@0: loader.lazyGetter(this, "OptionsPanel", () => require("devtools/framework/toolbox-options").OptionsPanel); michael@0: loader.lazyGetter(this, "InspectorPanel", () => require("devtools/inspector/inspector-panel").InspectorPanel); michael@0: loader.lazyGetter(this, "WebConsolePanel", () => require("devtools/webconsole/panel").WebConsolePanel); michael@0: loader.lazyGetter(this, "DebuggerPanel", () => require("devtools/debugger/panel").DebuggerPanel); michael@0: loader.lazyGetter(this, "StyleEditorPanel", () => require("devtools/styleeditor/styleeditor-panel").StyleEditorPanel); michael@0: loader.lazyGetter(this, "ShaderEditorPanel", () => require("devtools/shadereditor/panel").ShaderEditorPanel); michael@0: loader.lazyGetter(this, "CanvasDebuggerPanel", () => require("devtools/canvasdebugger/panel").CanvasDebuggerPanel); michael@0: loader.lazyGetter(this, "WebAudioEditorPanel", () => require("devtools/webaudioeditor/panel").WebAudioEditorPanel); michael@0: loader.lazyGetter(this, "ProfilerPanel", () => require("devtools/profiler/panel")); michael@0: loader.lazyGetter(this, "NetMonitorPanel", () => require("devtools/netmonitor/panel").NetMonitorPanel); michael@0: loader.lazyGetter(this, "ScratchpadPanel", () => require("devtools/scratchpad/scratchpad-panel").ScratchpadPanel); michael@0: michael@0: // Strings michael@0: const toolboxProps = "chrome://browser/locale/devtools/toolbox.properties"; michael@0: const inspectorProps = "chrome://browser/locale/devtools/inspector.properties"; michael@0: const debuggerProps = "chrome://browser/locale/devtools/debugger.properties"; michael@0: const styleEditorProps = "chrome://browser/locale/devtools/styleeditor.properties"; michael@0: const shaderEditorProps = "chrome://browser/locale/devtools/shadereditor.properties"; michael@0: const canvasDebuggerProps = "chrome://browser/locale/devtools/canvasdebugger.properties"; michael@0: const webAudioEditorProps = "chrome://browser/locale/devtools/webaudioeditor.properties"; michael@0: michael@0: const webConsoleProps = "chrome://browser/locale/devtools/webconsole.properties"; michael@0: const profilerProps = "chrome://browser/locale/devtools/profiler.properties"; michael@0: const netMonitorProps = "chrome://browser/locale/devtools/netmonitor.properties"; michael@0: const scratchpadProps = "chrome://browser/locale/devtools/scratchpad.properties"; michael@0: loader.lazyGetter(this, "toolboxStrings", () => Services.strings.createBundle(toolboxProps)); michael@0: loader.lazyGetter(this, "webConsoleStrings", () => Services.strings.createBundle(webConsoleProps)); michael@0: loader.lazyGetter(this, "debuggerStrings", () => Services.strings.createBundle(debuggerProps)); michael@0: loader.lazyGetter(this, "styleEditorStrings", () => Services.strings.createBundle(styleEditorProps)); michael@0: loader.lazyGetter(this, "shaderEditorStrings", () => Services.strings.createBundle(shaderEditorProps)); michael@0: loader.lazyGetter(this, "canvasDebuggerStrings", () => Services.strings.createBundle(canvasDebuggerProps)); michael@0: loader.lazyGetter(this, "webAudioEditorStrings", () => Services.strings.createBundle(webAudioEditorProps)); michael@0: loader.lazyGetter(this, "inspectorStrings", () => Services.strings.createBundle(inspectorProps)); michael@0: loader.lazyGetter(this, "profilerStrings",() => Services.strings.createBundle(profilerProps)); michael@0: loader.lazyGetter(this, "netMonitorStrings", () => Services.strings.createBundle(netMonitorProps)); michael@0: loader.lazyGetter(this, "scratchpadStrings", () => Services.strings.createBundle(scratchpadProps)); michael@0: michael@0: let Tools = {}; michael@0: exports.Tools = Tools; michael@0: michael@0: // Definitions michael@0: Tools.options = { michael@0: id: "options", michael@0: ordinal: 0, michael@0: url: "chrome://browser/content/devtools/framework/toolbox-options.xul", michael@0: icon: "chrome://browser/skin/devtools/tool-options.svg", michael@0: invertIconForLightTheme: true, michael@0: bgTheme: "theme-body", michael@0: tooltip: l10n("optionsButton.tooltip", toolboxStrings), michael@0: inMenu: false, michael@0: isTargetSupported: function(target) { michael@0: return true; michael@0: }, michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new OptionsPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: } michael@0: michael@0: Tools.webConsole = { michael@0: id: "webconsole", michael@0: key: l10n("cmd.commandkey", webConsoleStrings), michael@0: accesskey: l10n("webConsoleCmd.accesskey", webConsoleStrings), michael@0: modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift", michael@0: ordinal: 1, michael@0: icon: "chrome://browser/skin/devtools/tool-webconsole.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/webconsole.xul", michael@0: label: l10n("ToolboxTabWebconsole.label", webConsoleStrings), michael@0: menuLabel: l10n("MenuWebconsole.label", webConsoleStrings), michael@0: tooltip: l10n("ToolboxWebconsole.tooltip", webConsoleStrings), michael@0: inMenu: true, michael@0: commands: "devtools/webconsole/console-commands", michael@0: michael@0: preventClosingOnKey: true, michael@0: onkey: function(panel, toolbox) { michael@0: if (toolbox.splitConsole) michael@0: return toolbox.focusConsoleInput(); michael@0: michael@0: panel.focusInput(); michael@0: }, michael@0: michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon; michael@0: }, michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new WebConsolePanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.inspector = { michael@0: id: "inspector", michael@0: accesskey: l10n("inspector.accesskey", inspectorStrings), michael@0: key: l10n("inspector.commandkey", inspectorStrings), michael@0: ordinal: 2, michael@0: modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift", michael@0: icon: "chrome://browser/skin/devtools/tool-inspector.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/inspector/inspector.xul", michael@0: label: l10n("inspector.label", inspectorStrings), michael@0: tooltip: l10n("inspector.tooltip", inspectorStrings), michael@0: inMenu: true, michael@0: commands: [ michael@0: "devtools/resize-commands", michael@0: "devtools/inspector/inspector-commands", michael@0: "devtools/eyedropper/commands.js" michael@0: ], michael@0: michael@0: preventClosingOnKey: true, michael@0: onkey: function(panel) { michael@0: panel.toolbox.highlighterUtils.togglePicker(); michael@0: }, michael@0: michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon; michael@0: }, michael@0: michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new InspectorPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.jsdebugger = { michael@0: id: "jsdebugger", michael@0: key: l10n("debuggerMenu.commandkey", debuggerStrings), michael@0: accesskey: l10n("debuggerMenu.accesskey", debuggerStrings), michael@0: modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift", michael@0: ordinal: 3, michael@0: icon: "chrome://browser/skin/devtools/tool-debugger.svg", michael@0: invertIconForLightTheme: true, michael@0: highlightedicon: "chrome://browser/skin/devtools/tool-debugger-paused.svg", michael@0: url: "chrome://browser/content/devtools/debugger.xul", michael@0: label: l10n("ToolboxDebugger.label", debuggerStrings), michael@0: tooltip: l10n("ToolboxDebugger.tooltip", debuggerStrings), michael@0: inMenu: true, michael@0: commands: "devtools/debugger/debugger-commands", michael@0: michael@0: isTargetSupported: function(target) { michael@0: return true; michael@0: }, michael@0: michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new DebuggerPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.styleEditor = { michael@0: id: "styleeditor", michael@0: key: l10n("open.commandkey", styleEditorStrings), michael@0: ordinal: 4, michael@0: accesskey: l10n("open.accesskey", styleEditorStrings), michael@0: modifiers: "shift", michael@0: icon: "chrome://browser/skin/devtools/tool-styleeditor.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/styleeditor.xul", michael@0: label: l10n("ToolboxStyleEditor.label", styleEditorStrings), michael@0: tooltip: l10n("ToolboxStyleEditor.tooltip2", styleEditorStrings), michael@0: inMenu: true, michael@0: commands: "devtools/styleeditor/styleeditor-commands", michael@0: michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon; michael@0: }, michael@0: michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new StyleEditorPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.shaderEditor = { michael@0: id: "shadereditor", michael@0: ordinal: 5, michael@0: visibilityswitch: "devtools.shadereditor.enabled", michael@0: icon: "chrome://browser/skin/devtools/tool-styleeditor.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/shadereditor.xul", michael@0: label: l10n("ToolboxShaderEditor.label", shaderEditorStrings), michael@0: tooltip: l10n("ToolboxShaderEditor.tooltip", shaderEditorStrings), michael@0: michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon; michael@0: }, michael@0: michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new ShaderEditorPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.canvasDebugger = { michael@0: id: "canvasdebugger", michael@0: ordinal: 6, michael@0: visibilityswitch: "devtools.canvasdebugger.enabled", michael@0: icon: "chrome://browser/skin/devtools/tool-styleeditor.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/canvasdebugger.xul", michael@0: label: l10n("ToolboxCanvasDebugger.label", canvasDebuggerStrings), michael@0: tooltip: l10n("ToolboxCanvasDebugger.tooltip", canvasDebuggerStrings), michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon; michael@0: }, michael@0: build: function (iframeWindow, toolbox) { michael@0: let panel = new CanvasDebuggerPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.webAudioEditor = { michael@0: id: "webaudioeditor", michael@0: ordinal: 10, michael@0: visibilityswitch: "devtools.webaudioeditor.enabled", michael@0: icon: "chrome://browser/skin/devtools/tool-styleeditor.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/webaudioeditor.xul", michael@0: label: l10n("ToolboxWebAudioEditor.label", webAudioEditorStrings), michael@0: tooltip: l10n("ToolboxWebAudioEditor.tooltip", webAudioEditorStrings), michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon; michael@0: }, michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new WebAudioEditorPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.jsprofiler = { michael@0: id: "jsprofiler", michael@0: accesskey: l10n("profiler.accesskey", profilerStrings), michael@0: key: l10n("profiler2.commandkey", profilerStrings), michael@0: ordinal: 7, michael@0: modifiers: "shift", michael@0: visibilityswitch: "devtools.profiler.enabled", michael@0: icon: "chrome://browser/skin/devtools/tool-profiler.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/profiler.xul", michael@0: label: l10n("profiler.label", profilerStrings), michael@0: tooltip: l10n("profiler.tooltip2", profilerStrings), michael@0: inMenu: true, michael@0: commands: "devtools/profiler/commands", michael@0: michael@0: isTargetSupported: function (target) { michael@0: return !target.isAddon; michael@0: }, michael@0: michael@0: build: function (frame, target) { michael@0: let panel = new ProfilerPanel(frame, target); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.netMonitor = { michael@0: id: "netmonitor", michael@0: accesskey: l10n("netmonitor.accesskey", netMonitorStrings), michael@0: key: l10n("netmonitor.commandkey", netMonitorStrings), michael@0: ordinal: 8, michael@0: modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift", michael@0: visibilityswitch: "devtools.netmonitor.enabled", michael@0: icon: "chrome://browser/skin/devtools/tool-network.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/netmonitor.xul", michael@0: label: l10n("netmonitor.label", netMonitorStrings), michael@0: tooltip: l10n("netmonitor.tooltip", netMonitorStrings), michael@0: inMenu: true, michael@0: michael@0: isTargetSupported: function(target) { michael@0: let root = target.client.mainRoot; michael@0: return !target.isAddon && (root.traits.networkMonitor || !target.isApp); michael@0: }, michael@0: michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new NetMonitorPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: Tools.scratchpad = { michael@0: id: "scratchpad", michael@0: ordinal: 9, michael@0: visibilityswitch: "devtools.scratchpad.enabled", michael@0: icon: "chrome://browser/skin/devtools/tool-scratchpad.svg", michael@0: invertIconForLightTheme: true, michael@0: url: "chrome://browser/content/devtools/scratchpad.xul", michael@0: label: l10n("scratchpad.label", scratchpadStrings), michael@0: tooltip: l10n("scratchpad.tooltip", scratchpadStrings), michael@0: inMenu: false, michael@0: commands: "devtools/scratchpad/scratchpad-commands", michael@0: michael@0: isTargetSupported: function(target) { michael@0: return !target.isAddon && target.isRemote; michael@0: }, michael@0: michael@0: build: function(iframeWindow, toolbox) { michael@0: let panel = new ScratchpadPanel(iframeWindow, toolbox); michael@0: return panel.open(); michael@0: } michael@0: }; michael@0: michael@0: let defaultTools = [ michael@0: Tools.options, michael@0: Tools.webConsole, michael@0: Tools.inspector, michael@0: Tools.jsdebugger, michael@0: Tools.styleEditor, michael@0: Tools.shaderEditor, michael@0: Tools.canvasDebugger, michael@0: Tools.webAudioEditor, michael@0: Tools.jsprofiler, michael@0: Tools.netMonitor, michael@0: Tools.scratchpad michael@0: ]; michael@0: michael@0: exports.defaultTools = defaultTools; michael@0: michael@0: for (let definition of defaultTools) { michael@0: gDevTools.registerTool(definition); michael@0: } michael@0: michael@0: var unloadObserver = { michael@0: observe: function(subject, topic, data) { michael@0: if (subject.wrappedJSObject === require("@loader/unload")) { michael@0: Services.obs.removeObserver(unloadObserver, "sdk:loader:destroy"); michael@0: for (let definition of gDevTools.getToolDefinitionArray()) { michael@0: gDevTools.unregisterTool(definition.id); michael@0: } michael@0: } michael@0: } michael@0: }; michael@0: Services.obs.addObserver(unloadObserver, "sdk:loader:destroy", false); michael@0: michael@0: events.emit("devtools-loaded", {}); michael@0: michael@0: /** michael@0: * Lookup l10n string from a string bundle. michael@0: * michael@0: * @param {string} name michael@0: * The key to lookup. michael@0: * @param {StringBundle} bundle michael@0: * The key to lookup. michael@0: * @returns A localized version of the given key. michael@0: */ michael@0: function l10n(name, bundle) michael@0: { michael@0: try { michael@0: return bundle.GetStringFromName(name); michael@0: } catch (ex) { michael@0: Services.console.logStringMessage("Error reading '" + name + "'"); michael@0: throw new Error("l10n error with " + name); michael@0: } michael@0: }