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
|
|
|
// Add a couple of globals that we use all over this package.
|
|
|
|
let loaderOptions = require("@loader/options")
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
loaderOptions.globals.loader = {
|
|
|
|
lazyGetter: XPCOMUtils.defineLazyGetter.bind(XPCOMUtils),
|
|
|
|
lazyImporter: XPCOMUtils.defineLazyModuleGetter.bind(XPCOMUtils)
|
|
|
|
};
|
2012-11-30 00:07:59 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
let systemEvents = require("sdk/system/events");
|
2012-11-30 00:07:59 -08:00
|
|
|
|
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
|
|
|
loader.lazyGetter(exports, "Toolbox", () => require("devtools/framework/toolbox").Toolbox);
|
|
|
|
loader.lazyGetter(exports, "TargetFactory", () => require("devtools/framework/target").TargetFactory);
|
2012-11-30 00:07:59 -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);
|
2012-12-13 14:17:00 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
// Panels
|
|
|
|
loader.lazyGetter(this, "InspectorPanel", function() require("devtools/inspector/inspector-panel").InspectorPanel);
|
|
|
|
loader.lazyImporter(this, "WebConsolePanel", "resource:///modules/WebConsolePanel.jsm");
|
|
|
|
loader.lazyImporter(this, "DebuggerPanel", "resource:///modules/devtools/DebuggerPanel.jsm");
|
|
|
|
loader.lazyImporter(this, "StyleEditorPanel", "resource:///modules/devtools/StyleEditorPanel.jsm");
|
|
|
|
loader.lazyImporter(this, "ProfilerPanel", "resource:///modules/devtools/ProfilerPanel.jsm");
|
|
|
|
loader.lazyImporter(this, "NetMonitorPanel", "resource:///modules/devtools/NetMonitorPanel.jsm");
|
2013-03-11 23:50:42 -07:00
|
|
|
|
2012-11-30 00:07:59 -08:00
|
|
|
// Strings
|
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";
|
|
|
|
const webConsoleProps = "chrome://browser/locale/devtools/webconsole.properties";
|
|
|
|
const profilerProps = "chrome://browser/locale/devtools/profiler.properties";
|
|
|
|
const netMonitorProps = "chrome://browser/locale/devtools/netmonitor.properties";
|
|
|
|
loader.lazyGetter(this, "webConsoleStrings", () => Services.strings.createBundle(webConsoleProps));
|
|
|
|
loader.lazyGetter(this, "debuggerStrings", () => Services.strings.createBundle(debuggerProps));
|
|
|
|
loader.lazyGetter(this, "styleEditorStrings", () => Services.strings.createBundle(styleEditorProps));
|
|
|
|
loader.lazyGetter(this, "inspectorStrings", () => Services.strings.createBundle(inspectorProps));
|
|
|
|
loader.lazyGetter(this, "profilerStrings",() => Services.strings.createBundle(profilerProps));
|
|
|
|
loader.lazyGetter(this, "netMonitorStrings", () => Services.strings.createBundle(netMonitorProps));
|
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-04-11 13:59:08 -07:00
|
|
|
Tools.webConsole = {
|
2012-11-30 00:07:59 -08:00
|
|
|
id: "webconsole",
|
|
|
|
key: l10n("cmd.commandkey", webConsoleStrings),
|
|
|
|
accesskey: l10n("webConsoleCmd.accesskey", webConsoleStrings),
|
|
|
|
modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift",
|
|
|
|
ordinal: 0,
|
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",
|
|
|
|
label: l10n("ToolboxWebconsole.label", webConsoleStrings),
|
2012-12-18 07:11:27 -08:00
|
|
|
tooltip: l10n("ToolboxWebconsole.tooltip", webConsoleStrings),
|
|
|
|
|
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.jsdebugger = {
|
2012-11-30 00:07:59 -08:00
|
|
|
id: "jsdebugger",
|
|
|
|
key: l10n("open.commandkey", debuggerStrings),
|
|
|
|
accesskey: l10n("debuggerMenu.accesskey", debuggerStrings),
|
|
|
|
modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
|
2013-02-26 04:40:20 -08:00
|
|
|
ordinal: 2,
|
2012-11-30 00:07:59 -08:00
|
|
|
killswitch: "devtools.debugger.enabled",
|
2012-12-22 19:27:19 -08:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-debugger.png",
|
2013-02-25 09:23:40 -08:00
|
|
|
url: "chrome://browser/content/debugger.xul",
|
2012-11-30 00:07:59 -08:00
|
|
|
label: l10n("ToolboxDebugger.label", debuggerStrings),
|
2012-12-18 07:11:27 -08:00
|
|
|
tooltip: l10n("ToolboxDebugger.tooltip", debuggerStrings),
|
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 DebuggerPanel(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),
|
|
|
|
key: l10n("inspector.commandkey", inspectorStrings),
|
2013-02-26 04:40:20 -08:00
|
|
|
ordinal: 1,
|
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),
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return !target.isRemote;
|
|
|
|
},
|
|
|
|
|
|
|
|
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-04-11 13:59:08 -07:00
|
|
|
Tools.styleEditor = {
|
2012-11-30 00:07:59 -08:00
|
|
|
id: "styleeditor",
|
|
|
|
key: l10n("open.commandkey", styleEditorStrings),
|
|
|
|
ordinal: 3,
|
|
|
|
accesskey: l10n("open.accesskey", styleEditorStrings),
|
|
|
|
modifiers: "shift",
|
2012-12-22 19:27:19 -08:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-styleeditor.png",
|
2013-02-25 09:23:40 -08:00
|
|
|
url: "chrome://browser/content/styleeditor.xul",
|
2013-03-11 23:50:42 -07:00
|
|
|
label: l10n("ToolboxStyleEditor.label", styleEditorStrings),
|
2012-12-18 07:11:27 -08:00
|
|
|
tooltip: l10n("ToolboxStyleEditor.tooltip", styleEditorStrings),
|
2012-11-30 00:07:59 -08:00
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
2013-02-05 09:01:37 -08:00
|
|
|
return !target.isRemote;
|
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-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-02-07 11:09:55 -08:00
|
|
|
ordinal: 4,
|
2013-03-19 11:22:03 -07:00
|
|
|
modifiers: "shift",
|
2012-12-13 14:17:00 -08:00
|
|
|
killswitch: "devtools.profiler.enabled",
|
2013-03-11 23:50:42 -07:00
|
|
|
icon: "chrome://browser/skin/devtools/tool-profiler.png",
|
2012-12-13 14:17:00 -08:00
|
|
|
url: "chrome://browser/content/profiler.xul",
|
|
|
|
label: l10n("profiler.label", profilerStrings),
|
2012-12-18 07:11:27 -08:00
|
|
|
tooltip: l10n("profiler.tooltip", profilerStrings),
|
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),
|
|
|
|
ordinal: 5,
|
|
|
|
modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
|
|
|
|
killswitch: "devtools.netmonitor.enabled",
|
|
|
|
icon: "chrome://browser/skin/devtools/tool-profiler.png",
|
|
|
|
url: "chrome://browser/content/devtools/netmonitor.xul",
|
|
|
|
label: l10n("netmonitor.label", netMonitorStrings),
|
|
|
|
tooltip: l10n("netmonitor.tooltip", netMonitorStrings),
|
|
|
|
|
|
|
|
isTargetSupported: function(target) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
build: function(iframeWindow, toolbox) {
|
|
|
|
let panel = new NetMonitorPanel(iframeWindow, toolbox);
|
|
|
|
return panel.open();
|
|
|
|
}
|
|
|
|
};
|
2012-12-13 14:17:00 -08:00
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
let defaultTools = [
|
|
|
|
Tools.styleEditor,
|
|
|
|
Tools.webConsole,
|
|
|
|
Tools.jsdebugger,
|
|
|
|
Tools.inspector,
|
|
|
|
Tools.netMonitor
|
2012-11-30 00:07:59 -08:00
|
|
|
];
|
|
|
|
|
2012-12-13 14:17:00 -08:00
|
|
|
if (Services.prefs.getBoolPref("devtools.profiler.enabled")) {
|
2013-04-11 13:59:08 -07:00
|
|
|
defaultTools.push(Tools.jsprofiler);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let definition of defaultTools) {
|
|
|
|
gDevTools.registerTool(definition);
|
2012-12-13 14:17:00 -08:00
|
|
|
}
|
|
|
|
|
2013-04-11 13:59:08 -07:00
|
|
|
systemEvents.on("sdk:loader:destroy", function onunload({subject, data: reason}) {
|
|
|
|
if (subject.wrappedJSObject === require("@loader/unload")) {
|
|
|
|
systemEvents.off("sdk:loader:destroy", onunload);
|
|
|
|
for (let definition of defaultTools) {
|
|
|
|
gDevTools.unregisterTool(definition.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|