From ee4721a1c4ab5344afa9effad79861368033d94b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Wed, 20 Nov 2019 22:51:06 +0000 Subject: [PATCH] Bug 1596148 - Part 1: Allow remote debugging of service workers r=jdescottes Differential Revision: https://phabricator.services.mozilla.com/D53990 --HG-- extra : moz-landing-system : lando --- devtools/client/application/initializer.js | 29 ++++++++++++++-------- devtools/client/definitions.js | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/devtools/client/application/initializer.js b/devtools/client/application/initializer.js index 29e45ac03524..0e0bfe9788a2 100644 --- a/devtools/client/application/initializer.js +++ b/devtools/client/application/initializer.js @@ -28,12 +28,6 @@ const actions = require("./src/actions/index"); const { WorkersListener } = require("devtools/client/shared/workers-listener"); -const { - addDebugServiceWorkersListener, - canDebugServiceWorkers, - removeDebugServiceWorkersListener, -} = require("devtools/shared/service-workers-debug-helper"); - const { services } = require("./src/modules/services"); const App = createFactory(require("./src/components/App")); @@ -59,14 +53,22 @@ window.Application = { services.init(this.toolbox); + this.deviceFront = await this.client.mainRoot.getFront("device"); + this.workersListener = new WorkersListener(this.client.mainRoot); this.workersListener.addListener(this.updateWorkers); this.toolbox.target.on("navigate", this.handleOnNavigate); - addDebugServiceWorkersListener(this.updateCanDebugWorkers); + + if (this.deviceFront) { + this.canDebugWorkersListener = this.deviceFront.on( + "can-debug-sw-updated", + this.updateCanDebugWorkers + ); + } // start up updates for the initial state this.updateDomain(); - this.updateCanDebugWorkers(); + await this.updateCanDebugWorkers(); await this.updateWorkers(); await l10n.init(["devtools/application.ftl"]); @@ -97,15 +99,20 @@ window.Application = { this.actions.updateDomain(this.toolbox.target.url); }, - updateCanDebugWorkers() { - const canDebugWorkers = canDebugServiceWorkers(); + async updateCanDebugWorkers() { + const canDebugWorkers = this.deviceFront + ? (await this.deviceFront.getDescription()).canDebugServiceWorkers + : false; + this.actions.updateCanDebugWorkers(canDebugWorkers); }, destroy() { this.workersListener.removeListener(); + if (this.deviceFront) { + this.deviceFront.off("can-debug-sw-updated", this.updateCanDebugWorkers); + } this.toolbox.target.off("navigate", this.updateDomain); - removeDebugServiceWorkersListener(this.updateCanDebugWorkers); unmountComponentAtNode(this.mount); this.mount = null; diff --git a/devtools/client/definitions.js b/devtools/client/definitions.js index bf4e511880d4..228da7f7b561 100644 --- a/devtools/client/definitions.js +++ b/devtools/client/definitions.js @@ -469,7 +469,7 @@ Tools.application = { hiddenInOptions: true, isTargetSupported: function(target) { - return target.isLocalTab; + return target.hasActor("manifest"); }, build: function(iframeWindow, toolbox) {