definitions.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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. "use strict";
  5. const Services = require("Services");
  6. const osString = Services.appinfo.OS;
  7. // Panels
  8. loader.lazyGetter(this, "OptionsPanel", () => require("devtools/client/framework/toolbox-options").OptionsPanel);
  9. loader.lazyGetter(this, "InspectorPanel", () => require("devtools/client/inspector/panel").InspectorPanel);
  10. loader.lazyGetter(this, "WebConsolePanel", () => require("devtools/client/webconsole/panel").WebConsolePanel);
  11. loader.lazyGetter(this, "DebuggerPanel", () => require("devtools/client/debugger/panel").DebuggerPanel);
  12. loader.lazyGetter(this, "StyleEditorPanel", () => require("devtools/client/styleeditor/styleeditor-panel").StyleEditorPanel);
  13. loader.lazyGetter(this, "ShaderEditorPanel", () => require("devtools/client/shadereditor/panel").ShaderEditorPanel);
  14. loader.lazyGetter(this, "CanvasDebuggerPanel", () => require("devtools/client/canvasdebugger/panel").CanvasDebuggerPanel);
  15. loader.lazyGetter(this, "WebAudioEditorPanel", () => require("devtools/client/webaudioeditor/panel").WebAudioEditorPanel);
  16. loader.lazyGetter(this, "MemoryPanel", () => require("devtools/client/memory/panel").MemoryPanel);
  17. loader.lazyGetter(this, "PerformancePanel", () => require("devtools/client/performance/panel").PerformancePanel);
  18. loader.lazyGetter(this, "NetMonitorPanel", () => require("devtools/client/netmonitor/panel").NetMonitorPanel);
  19. loader.lazyGetter(this, "StoragePanel", () => require("devtools/client/storage/panel").StoragePanel);
  20. loader.lazyGetter(this, "ScratchpadPanel", () => require("devtools/client/scratchpad/scratchpad-panel").ScratchpadPanel);
  21. loader.lazyGetter(this, "DomPanel", () => require("devtools/client/dom/dom-panel").DomPanel);
  22. const {LocalizationHelper} = require("devtools/shared/l10n");
  23. const L10N = new LocalizationHelper("devtools/client/locales/startup.properties");
  24. var Tools = {};
  25. exports.Tools = Tools;
  26. // Definitions
  27. Tools.options = {
  28. id: "options",
  29. ordinal: 0,
  30. url: "chrome://devtools/content/framework/toolbox-options.xhtml",
  31. icon: "chrome://devtools/skin/images/tool-options.svg",
  32. invertIconForDarkTheme: true,
  33. bgTheme: "theme-body",
  34. label: l10n("options.label"),
  35. iconOnly: true,
  36. panelLabel: l10n("options.panelLabel"),
  37. tooltip: l10n("optionsButton.tooltip"),
  38. inMenu: false,
  39. isTargetSupported: function () {
  40. return true;
  41. },
  42. build: function (iframeWindow, toolbox) {
  43. return new OptionsPanel(iframeWindow, toolbox);
  44. }
  45. };
  46. Tools.inspector = {
  47. id: "inspector",
  48. accesskey: l10n("inspector.accesskey"),
  49. key: l10n("inspector.commandkey"),
  50. ordinal: 1,
  51. modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
  52. icon: "chrome://devtools/skin/images/tool-inspector.svg",
  53. invertIconForDarkTheme: true,
  54. url: "chrome://devtools/content/inspector/inspector.xhtml",
  55. label: l10n("inspector.label"),
  56. panelLabel: l10n("inspector.panelLabel"),
  57. get tooltip() {
  58. return l10n("inspector.tooltip2",
  59. (osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") + this.key);
  60. },
  61. inMenu: true,
  62. commands: [
  63. "devtools/client/responsivedesign/resize-commands",
  64. "devtools/client/inspector/inspector-commands"
  65. ],
  66. preventClosingOnKey: true,
  67. onkey: function (panel, toolbox) {
  68. toolbox.highlighterUtils.togglePicker();
  69. },
  70. isTargetSupported: function (target) {
  71. return target.hasActor("inspector");
  72. },
  73. build: function (iframeWindow, toolbox) {
  74. return new InspectorPanel(iframeWindow, toolbox);
  75. }
  76. };
  77. Tools.webConsole = {
  78. id: "webconsole",
  79. key: l10n("cmd.commandkey"),
  80. accesskey: l10n("webConsoleCmd.accesskey"),
  81. modifiers: Services.appinfo.OS == "Darwin" ? "accel,alt" : "accel,shift",
  82. ordinal: 2,
  83. icon: "chrome://devtools/skin/images/tool-webconsole.svg",
  84. invertIconForDarkTheme: true,
  85. url: "chrome://devtools/content/webconsole/webconsole.xul",
  86. label: l10n("ToolboxTabWebconsole.label"),
  87. menuLabel: l10n("MenuWebconsole.label"),
  88. panelLabel: l10n("ToolboxWebConsole.panelLabel"),
  89. get tooltip() {
  90. return l10n("ToolboxWebconsole.tooltip2",
  91. (osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") + this.key);
  92. },
  93. inMenu: true,
  94. commands: "devtools/client/webconsole/console-commands",
  95. preventClosingOnKey: true,
  96. onkey: function (panel, toolbox) {
  97. if (toolbox.splitConsole) {
  98. return toolbox.focusConsoleInput();
  99. }
  100. panel.focusInput();
  101. return undefined;
  102. },
  103. isTargetSupported: function () {
  104. return true;
  105. },
  106. build: function (iframeWindow, toolbox) {
  107. return new WebConsolePanel(iframeWindow, toolbox);
  108. }
  109. };
  110. Tools.jsdebugger = {
  111. id: "jsdebugger",
  112. key: l10n("debuggerMenu.commandkey"),
  113. accesskey: l10n("debuggerMenu.accesskey"),
  114. modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
  115. ordinal: 3,
  116. icon: "chrome://devtools/skin/images/tool-debugger.svg",
  117. invertIconForDarkTheme: true,
  118. highlightedicon: "chrome://devtools/skin/images/tool-debugger-paused.svg",
  119. url: "chrome://devtools/content/debugger/debugger.xul",
  120. label: l10n("ToolboxDebugger.label"),
  121. panelLabel: l10n("ToolboxDebugger.panelLabel"),
  122. get tooltip() {
  123. return l10n("ToolboxDebugger.tooltip2",
  124. (osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") + this.key);
  125. },
  126. inMenu: true,
  127. commands: "devtools/client/debugger/debugger-commands",
  128. isTargetSupported: function () {
  129. return true;
  130. },
  131. build: function (iframeWindow, toolbox) {
  132. return new DebuggerPanel(iframeWindow, toolbox);
  133. }
  134. };
  135. function switchDebugger() {
  136. if (Services.prefs.getBoolPref("devtools.debugger.new-debugger-frontend")) {
  137. const NewDebuggerPanel = require("devtools/client/debugger/new/panel").DebuggerPanel;
  138. Tools.jsdebugger.url = "chrome://devtools/content/debugger/new/index.html";
  139. Tools.jsdebugger.build = function (iframeWindow, toolbox) {
  140. return new NewDebuggerPanel(iframeWindow, toolbox);
  141. };
  142. } else {
  143. Tools.jsdebugger.url = "chrome://devtools/content/debugger/debugger.xul";
  144. Tools.jsdebugger.build = function (iframeWindow, toolbox) {
  145. return new DebuggerPanel(iframeWindow, toolbox);
  146. };
  147. }
  148. }
  149. switchDebugger();
  150. Services.prefs.addObserver(
  151. "devtools.debugger.new-debugger-frontend",
  152. { observe: switchDebugger },
  153. false
  154. );
  155. Tools.styleEditor = {
  156. id: "styleeditor",
  157. key: l10n("open.commandkey"),
  158. ordinal: 4,
  159. visibilityswitch: "devtools.styleeditor.enabled",
  160. accesskey: l10n("open.accesskey"),
  161. modifiers: "shift",
  162. icon: "chrome://devtools/skin/images/tool-styleeditor.svg",
  163. invertIconForDarkTheme: true,
  164. url: "chrome://devtools/content/styleeditor/styleeditor.xul",
  165. label: l10n("ToolboxStyleEditor.label"),
  166. panelLabel: l10n("ToolboxStyleEditor.panelLabel"),
  167. get tooltip() {
  168. return l10n("ToolboxStyleEditor.tooltip3",
  169. "Shift+" + functionkey(this.key));
  170. },
  171. inMenu: true,
  172. commands: "devtools/client/styleeditor/styleeditor-commands",
  173. isTargetSupported: function (target) {
  174. return target.hasActor("styleEditor") || target.hasActor("styleSheets");
  175. },
  176. build: function (iframeWindow, toolbox) {
  177. return new StyleEditorPanel(iframeWindow, toolbox);
  178. }
  179. };
  180. Tools.shaderEditor = {
  181. id: "shadereditor",
  182. ordinal: 5,
  183. visibilityswitch: "devtools.shadereditor.enabled",
  184. icon: "chrome://devtools/skin/images/tool-shadereditor.svg",
  185. invertIconForDarkTheme: true,
  186. url: "chrome://devtools/content/shadereditor/shadereditor.xul",
  187. label: l10n("ToolboxShaderEditor.label"),
  188. panelLabel: l10n("ToolboxShaderEditor.panelLabel"),
  189. tooltip: l10n("ToolboxShaderEditor.tooltip"),
  190. isTargetSupported: function (target) {
  191. return target.hasActor("webgl") && !target.chrome;
  192. },
  193. build: function (iframeWindow, toolbox) {
  194. return new ShaderEditorPanel(iframeWindow, toolbox);
  195. }
  196. };
  197. Tools.canvasDebugger = {
  198. id: "canvasdebugger",
  199. ordinal: 6,
  200. visibilityswitch: "devtools.canvasdebugger.enabled",
  201. icon: "chrome://devtools/skin/images/tool-canvas.svg",
  202. invertIconForDarkTheme: true,
  203. url: "chrome://devtools/content/canvasdebugger/canvasdebugger.xul",
  204. label: l10n("ToolboxCanvasDebugger.label"),
  205. panelLabel: l10n("ToolboxCanvasDebugger.panelLabel"),
  206. tooltip: l10n("ToolboxCanvasDebugger.tooltip"),
  207. // Hide the Canvas Debugger in the Add-on Debugger and Browser Toolbox
  208. // (bug 1047520).
  209. isTargetSupported: function (target) {
  210. return target.hasActor("canvas") && !target.chrome;
  211. },
  212. build: function (iframeWindow, toolbox) {
  213. return new CanvasDebuggerPanel(iframeWindow, toolbox);
  214. }
  215. };
  216. Tools.performance = {
  217. id: "performance",
  218. ordinal: 7,
  219. icon: "chrome://devtools/skin/images/tool-profiler.svg",
  220. invertIconForDarkTheme: true,
  221. highlightedicon: "chrome://devtools/skin/images/tool-profiler-active.svg",
  222. url: "chrome://devtools/content/performance/performance.xul",
  223. visibilityswitch: "devtools.performance.enabled",
  224. label: l10n("performance.label"),
  225. panelLabel: l10n("performance.panelLabel"),
  226. get tooltip() {
  227. return l10n("performance.tooltip", "Shift+" + functionkey(this.key));
  228. },
  229. accesskey: l10n("performance.accesskey"),
  230. key: l10n("performance.commandkey"),
  231. modifiers: "shift",
  232. inMenu: true,
  233. isTargetSupported: function (target) {
  234. return target.hasActor("profiler");
  235. },
  236. build: function (frame, target) {
  237. return new PerformancePanel(frame, target);
  238. }
  239. };
  240. Tools.memory = {
  241. id: "memory",
  242. ordinal: 8,
  243. icon: "chrome://devtools/skin/images/tool-memory.svg",
  244. invertIconForDarkTheme: true,
  245. highlightedicon: "chrome://devtools/skin/images/tool-memory-active.svg",
  246. url: "chrome://devtools/content/memory/memory.xhtml",
  247. visibilityswitch: "devtools.memory.enabled",
  248. label: l10n("memory.label"),
  249. panelLabel: l10n("memory.panelLabel"),
  250. tooltip: l10n("memory.tooltip"),
  251. isTargetSupported: function (target) {
  252. return target.getTrait("heapSnapshots") && !target.isAddon;
  253. },
  254. build: function (frame, target) {
  255. return new MemoryPanel(frame, target);
  256. }
  257. };
  258. Tools.netMonitor = {
  259. id: "netmonitor",
  260. accesskey: l10n("netmonitor.accesskey"),
  261. key: l10n("netmonitor.commandkey"),
  262. ordinal: 9,
  263. modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
  264. visibilityswitch: "devtools.netmonitor.enabled",
  265. icon: "chrome://devtools/skin/images/tool-network.svg",
  266. invertIconForDarkTheme: true,
  267. url: "chrome://devtools/content/netmonitor/netmonitor.xul",
  268. label: l10n("netmonitor.label"),
  269. panelLabel: l10n("netmonitor.panelLabel"),
  270. get tooltip() {
  271. return l10n("netmonitor.tooltip2",
  272. (osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") + this.key);
  273. },
  274. inMenu: true,
  275. isTargetSupported: function (target) {
  276. return target.getTrait("networkMonitor");
  277. },
  278. build: function (iframeWindow, toolbox) {
  279. return new NetMonitorPanel(iframeWindow, toolbox);
  280. }
  281. };
  282. Tools.storage = {
  283. id: "storage",
  284. key: l10n("storage.commandkey"),
  285. ordinal: 10,
  286. accesskey: l10n("storage.accesskey"),
  287. modifiers: "shift",
  288. visibilityswitch: "devtools.storage.enabled",
  289. icon: "chrome://devtools/skin/images/tool-storage.svg",
  290. invertIconForDarkTheme: true,
  291. url: "chrome://devtools/content/storage/storage.xul",
  292. label: l10n("storage.label"),
  293. menuLabel: l10n("storage.menuLabel"),
  294. panelLabel: l10n("storage.panelLabel"),
  295. get tooltip() {
  296. return l10n("storage.tooltip3", "Shift+" + functionkey(this.key));
  297. },
  298. inMenu: true,
  299. isTargetSupported: function (target) {
  300. return target.isLocalTab ||
  301. (target.hasActor("storage") && target.getTrait("storageInspector"));
  302. },
  303. build: function (iframeWindow, toolbox) {
  304. return new StoragePanel(iframeWindow, toolbox);
  305. }
  306. };
  307. Tools.webAudioEditor = {
  308. id: "webaudioeditor",
  309. ordinal: 11,
  310. visibilityswitch: "devtools.webaudioeditor.enabled",
  311. icon: "chrome://devtools/skin/images/tool-webaudio.svg",
  312. invertIconForDarkTheme: true,
  313. url: "chrome://devtools/content/webaudioeditor/webaudioeditor.xul",
  314. label: l10n("ToolboxWebAudioEditor1.label"),
  315. panelLabel: l10n("ToolboxWebAudioEditor1.panelLabel"),
  316. tooltip: l10n("ToolboxWebAudioEditor1.tooltip"),
  317. isTargetSupported: function (target) {
  318. return !target.chrome && target.hasActor("webaudio");
  319. },
  320. build: function (iframeWindow, toolbox) {
  321. return new WebAudioEditorPanel(iframeWindow, toolbox);
  322. }
  323. };
  324. Tools.scratchpad = {
  325. id: "scratchpad",
  326. ordinal: 12,
  327. visibilityswitch: "devtools.scratchpad.enabled",
  328. icon: "chrome://devtools/skin/images/tool-scratchpad.svg",
  329. invertIconForDarkTheme: true,
  330. url: "chrome://devtools/content/scratchpad/scratchpad.xul",
  331. label: l10n("scratchpad.label"),
  332. panelLabel: l10n("scratchpad.panelLabel"),
  333. tooltip: l10n("scratchpad.tooltip"),
  334. inMenu: false,
  335. commands: "devtools/client/scratchpad/scratchpad-commands",
  336. isTargetSupported: function (target) {
  337. return target.hasActor("console");
  338. },
  339. build: function (iframeWindow, toolbox) {
  340. return new ScratchpadPanel(iframeWindow, toolbox);
  341. }
  342. };
  343. Tools.dom = {
  344. id: "dom",
  345. accesskey: l10n("dom.accesskey"),
  346. key: l10n("dom.commandkey"),
  347. ordinal: 13,
  348. modifiers: osString == "Darwin" ? "accel,alt" : "accel,shift",
  349. visibilityswitch: "devtools.dom.enabled",
  350. icon: "chrome://devtools/skin/images/tool-dom.svg",
  351. invertIconForDarkTheme: true,
  352. url: "chrome://devtools/content/dom/dom.html",
  353. label: l10n("dom.label"),
  354. panelLabel: l10n("dom.panelLabel"),
  355. get tooltip() {
  356. return l10n("dom.tooltip",
  357. (osString == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+") + this.key);
  358. },
  359. inMenu: true,
  360. isTargetSupported: function (target) {
  361. return target.getTrait("webConsoleCommands");
  362. },
  363. build: function (iframeWindow, toolbox) {
  364. return new DomPanel(iframeWindow, toolbox);
  365. }
  366. };
  367. var defaultTools = [
  368. Tools.options,
  369. Tools.webConsole,
  370. Tools.inspector,
  371. Tools.jsdebugger,
  372. Tools.styleEditor,
  373. Tools.shaderEditor,
  374. Tools.canvasDebugger,
  375. Tools.webAudioEditor,
  376. Tools.performance,
  377. Tools.netMonitor,
  378. Tools.storage,
  379. Tools.scratchpad,
  380. Tools.memory,
  381. Tools.dom,
  382. ];
  383. exports.defaultTools = defaultTools;
  384. Tools.darkTheme = {
  385. id: "dark",
  386. label: l10n("options.darkTheme.label2"),
  387. ordinal: 1,
  388. stylesheets: ["chrome://devtools/skin/dark-theme.css"],
  389. classList: ["theme-dark"],
  390. };
  391. Tools.lightTheme = {
  392. id: "light",
  393. label: l10n("options.lightTheme.label2"),
  394. ordinal: 2,
  395. stylesheets: ["chrome://devtools/skin/light-theme.css"],
  396. classList: ["theme-light"],
  397. };
  398. Tools.firebugTheme = {
  399. id: "firebug",
  400. label: l10n("options.firebugTheme.label2"),
  401. ordinal: 3,
  402. stylesheets: ["chrome://devtools/skin/firebug-theme.css"],
  403. classList: ["theme-light", "theme-firebug"],
  404. };
  405. exports.defaultThemes = [
  406. Tools.darkTheme,
  407. Tools.lightTheme,
  408. Tools.firebugTheme,
  409. ];
  410. // White-list buttons that can be toggled to prevent adding prefs for
  411. // addons that have manually inserted toolbarbuttons into DOM.
  412. // (By default, supported target is only local tab)
  413. exports.ToolboxButtons = [
  414. { id: "command-button-frames",
  415. isTargetSupported: target => {
  416. return target.activeTab && target.activeTab.traits.frames;
  417. }
  418. },
  419. { id: "command-button-splitconsole",
  420. isTargetSupported: target => !target.isAddon },
  421. { id: "command-button-responsive" },
  422. { id: "command-button-paintflashing" },
  423. { id: "command-button-scratchpad" },
  424. { id: "command-button-screenshot" },
  425. { id: "command-button-rulers" },
  426. { id: "command-button-measure" },
  427. { id: "command-button-noautohide",
  428. isTargetSupported: target => target.chrome },
  429. ];
  430. /**
  431. * Lookup l10n string from a string bundle.
  432. *
  433. * @param {string} name
  434. * The key to lookup.
  435. * @param {string} arg
  436. * Optional format argument.
  437. * @returns A localized version of the given key.
  438. */
  439. function l10n(name, arg) {
  440. try {
  441. return arg ? L10N.getFormatStr(name, arg) : L10N.getStr(name);
  442. } catch (ex) {
  443. console.log("Error reading '" + name + "'");
  444. throw new Error("l10n error with " + name);
  445. }
  446. }
  447. function functionkey(shortkey) {
  448. return shortkey.split("_")[1];
  449. }