gDevTools.jsm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. /**
  7. * This JSM is here to keep some compatibility with existing add-ons.
  8. * Please now use the modules:
  9. * - devtools/client/framework/devtools for gDevTools
  10. * - devtools/client/framework/devtools-browser for gDevToolsBrowser
  11. */
  12. this.EXPORTED_SYMBOLS = [ "gDevTools", "gDevToolsBrowser" ];
  13. const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
  14. const { loader } = Cu.import("resource://devtools/shared/Loader.jsm", {});
  15. /**
  16. * Do not directly map to the commonjs modules so that callsites of
  17. * gDevTools.jsm do not have to do anything to access to the very last version
  18. * of the module. The `devtools` and `browser` getter are always going to
  19. * retrieve the very last version of the modules.
  20. */
  21. Object.defineProperty(this, "require", {
  22. get() {
  23. let { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
  24. return require;
  25. }
  26. });
  27. Object.defineProperty(this, "devtools", {
  28. get() {
  29. return require("devtools/client/framework/devtools").gDevTools;
  30. }
  31. });
  32. Object.defineProperty(this, "browser", {
  33. get() {
  34. return require("devtools/client/framework/devtools-browser").gDevToolsBrowser;
  35. }
  36. });
  37. /**
  38. * gDevTools is a singleton that controls the Firefox Developer Tools.
  39. *
  40. * It is an instance of a DevTools class that holds a set of tools. It has the
  41. * same lifetime as the browser.
  42. */
  43. let gDevToolsMethods = [
  44. // Used by the reload addon.
  45. // Force reloading dependencies if the loader happens to have reloaded.
  46. "reload",
  47. // Used by: - b2g desktop.js
  48. // - nsContextMenu
  49. // - /devtools code
  50. "showToolbox",
  51. // Used by Addon SDK and /devtools
  52. "closeToolbox",
  53. "getToolbox",
  54. // Used by Addon SDK, main.js and tests:
  55. "registerTool",
  56. "registerTheme",
  57. "unregisterTool",
  58. "unregisterTheme",
  59. // Used by main.js and test
  60. "getToolDefinitionArray",
  61. "getThemeDefinitionArray",
  62. // Used by theme-switching.js
  63. "getThemeDefinition",
  64. "emit",
  65. // Used by /devtools
  66. "on",
  67. "off",
  68. "once",
  69. // Used by tests
  70. "getToolDefinitionMap",
  71. "getThemeDefinitionMap",
  72. "getDefaultTools",
  73. "getAdditionalTools",
  74. "getToolDefinition",
  75. ];
  76. this.gDevTools = {
  77. // Used by tests
  78. get _toolboxes() {
  79. return devtools._toolboxes;
  80. },
  81. get _tools() {
  82. return devtools._tools;
  83. },
  84. *[Symbol.iterator ]() {
  85. for (let toolbox of this._toolboxes) {
  86. yield toolbox;
  87. }
  88. }
  89. };
  90. gDevToolsMethods.forEach(name => {
  91. this.gDevTools[name] = (...args) => {
  92. return devtools[name].apply(devtools, args);
  93. };
  94. });
  95. /**
  96. * gDevToolsBrowser exposes functions to connect the gDevTools instance with a
  97. * Firefox instance.
  98. */
  99. let gDevToolsBrowserMethods = [
  100. // used by browser-sets.inc, command
  101. "toggleToolboxCommand",
  102. // Used by browser.js itself, by setting a oncommand string...
  103. "selectToolCommand",
  104. // Used by browser-sets.inc, command
  105. "openAboutDebugging",
  106. // Used by browser-sets.inc, command
  107. "openConnectScreen",
  108. // Used by browser-sets.inc, command
  109. "openContentProcessToolbox",
  110. // Used by browser.js
  111. "registerBrowserWindow",
  112. // Used by reload addon
  113. "hasToolboxOpened",
  114. // Used by browser.js
  115. "forgetBrowserWindow"
  116. ];
  117. this.gDevToolsBrowser = {
  118. // Used by a test (should be removed)
  119. get _trackedBrowserWindows() {
  120. return browser._trackedBrowserWindows;
  121. }
  122. };
  123. gDevToolsBrowserMethods.forEach(name => {
  124. this.gDevToolsBrowser[name] = (...args) => {
  125. return browser[name].apply(browser, args);
  126. };
  127. });