Bug 1367424 - add shims for addon sdk to DevToolsShim;r=ochameau
☠☠ backed out by 1330312e91c9 ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 29 May 2017 18:21:21 +0200
changeset 410616 8ecdc6d29e1dc737637d6cc03993aa5ecfb809c2
parent 410615 93a9ea3ab784f2b1aba8a33af5d4e2c2ed731185
child 410617 6f17a72e69cc9ccab071091347f6bb5cf7a57bab
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1367424
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1367424 - add shims for addon sdk to DevToolsShim;r=ochameau Some APIs and methods still used by the addon sdk are not worth exposing or migrating to mozilla-central given that this is only intended for release 56 (after that, legacy extensions will no longer be supported). For those APIs, we create a simple wrapper in DevToolsShim and moved the implementation to framework/devtools MozReview-Commit-ID: 8LiiptqO0NI
devtools/client/framework/devtools.js
devtools/shim/DevToolsShim.jsm
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -11,16 +11,21 @@ const {DevToolsShim} = Cu.import("chrome
 
 // Load gDevToolsBrowser toolbox lazily as they need gDevTools to be fully initialized
 loader.lazyRequireGetter(this, "TargetFactory", "devtools/client/framework/target", true);
 loader.lazyRequireGetter(this, "Toolbox", "devtools/client/framework/toolbox", true);
 loader.lazyRequireGetter(this, "ToolboxHostManager", "devtools/client/framework/toolbox-host-manager", true);
 loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
 loader.lazyImporter(this, "ScratchpadManager", "resource://devtools/client/scratchpad/scratchpad-manager.jsm");
 
+// Dependencies required for addon sdk compatibility layer.
+loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
+loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", true);
+loader.lazyImporter(this, "BrowserToolboxProcess", "resource://devtools/client/framework/ToolboxProcess.jsm");
+
 const {defaultTools: DefaultTools, defaultThemes: DefaultThemes} =
   require("devtools/client/definitions");
 const EventEmitter = require("devtools/shared/event-emitter");
 const {JsonView} = require("devtools/client/jsonview/main");
 const AboutDevTools = require("devtools/client/framework/about-devtools-toolbox");
 const {Task} = require("devtools/shared/task");
 const {getTheme, setTheme, addThemeObserver, removeThemeObserver} =
   require("devtools/client/shared/theme");
@@ -529,16 +534,52 @@ DevTools.prototype = {
    *
    * @return {TabTarget} A target object
    */
   getTargetForTab: function (tab) {
     return TargetFactory.forTab(tab);
   },
 
   /**
+   * Compatibility layer for addon-sdk. Remove when Firefox 57 hits release.
+   * Initialize the debugger server if needed and and create a connection.
+   *
+   * @return {DebuggerTransport} a client-side DebuggerTransport for communicating with
+   *         the created connection.
+   */
+  connectDebuggerServer: function () {
+    if (!DebuggerServer.initialized) {
+      DebuggerServer.init();
+      DebuggerServer.addBrowserActors();
+    }
+
+    return DebuggerServer.connectPipe();
+  },
+
+  /**
+   * Compatibility layer for addon-sdk. Remove when Firefox 57 hits release.
+   *
+   * Create a connection to the debugger server and return a debugger client for this
+   * new connection.
+   */
+  createDebuggerClient: function () {
+    let transport = this.connectDebuggerServer();
+    return new DebuggerClient(transport);
+  },
+
+  /**
+   * Compatibility layer for addon-sdk. Remove when Firefox 57 hits release.
+   *
+   * Create a BrowserToolbox process linked to the provided addon id.
+   */
+  initBrowserToolboxProcessForAddon: function (addonID) {
+    BrowserToolboxProcess.init({ addonID });
+  },
+
+  /**
    * Either the SDK Loader has been destroyed by the add-on contribution
    * workflow, or firefox is shutting down.
 
    * @param {boolean} shuttingDown
    *        True if firefox is currently shutting down. We may prevent doing
    *        some cleanups to speed it up. Otherwise everything need to be
    *        cleaned up in order to be able to load devtools again.
    */
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -191,8 +191,35 @@ this.DevToolsShim = {
       this.gDevTools.registerTheme(theme);
     }
 
     this.listeners = [];
     this.tools = [];
     this.themes = [];
   },
 };
+
+/**
+ * Compatibility layer for addon-sdk. Remove when Firefox 57 hits release.
+ *
+ * The methods below are used by classes and tests from addon-sdk/
+ * If DevTools are not installed when calling one of them, the call will throw.
+ */
+
+let addonSdkMethods = [
+  "closeToolbox",
+  "connectDebuggerServer",
+  "createDebuggerClient",
+  "getTargetForTab",
+  "getToolbox",
+  "initBrowserToolboxProcessForAddon",
+  "showToolbox",
+];
+
+for (let method of addonSdkMethods) {
+  this.DevToolsShim[method] = function () {
+    if (!this.isInstalled()) {
+      throw new Error(`Method ${method} unavailable if DevTools are not installed`);
+    }
+
+    return this.gDevTools[method].apply(this, arguments);
+  };
+}