From 882c976a5acaa35659a81dfa24d222189e940f47 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Tue, 6 Jun 2017 14:01:32 +0200 Subject: [PATCH] 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 --HG-- extra : rebase_source : 3e4832bcaffa92d64e9d2490bcc0250bc05573c1 --- devtools/client/framework/devtools.js | 41 +++++++++++++++++++++++++++ devtools/shim/DevToolsShim.jsm | 27 ++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/devtools/client/framework/devtools.js b/devtools/client/framework/devtools.js index 08900d94f5d3..e468d60e26e9 100644 --- a/devtools/client/framework/devtools.js +++ b/devtools/client/framework/devtools.js @@ -16,6 +16,11 @@ loader.lazyRequireGetter(this, "ToolboxHostManager", "devtools/client/framework/ 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"); @@ -533,6 +538,42 @@ DevTools.prototype = { 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. diff --git a/devtools/shim/DevToolsShim.jsm b/devtools/shim/DevToolsShim.jsm index 6f1695d8ce36..d0d2dda3c105 100644 --- a/devtools/shim/DevToolsShim.jsm +++ b/devtools/shim/DevToolsShim.jsm @@ -196,3 +196,30 @@ this.DevToolsShim = { 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.gDevTools, arguments); + }; +}