Bug 1714527 - [devtools] Remove unused serviceworker actor code in DevTools server r=nchevobbe,devtools-backward-compat-reviewers

The actor code for attaching/detaching service worker targets and to push/start workers should no longer be used when parentintercept is disabled because all the UI triggering this is disabled in that case.
Consequently we can remove the server side code supporting this. We still have to be able to list service worker targets when parentintercept is disabled, so there are still some codepaths using isParentInterceptEnabled in the server.

Differential Revision: https://phabricator.services.mozilla.com/D116850
This commit is contained in:
Julian Descottes 2021-06-07 20:13:26 +00:00
parent 83334cbf7a
commit 5502682b68
6 changed files with 17 additions and 160 deletions

View File

@ -116,7 +116,6 @@ module.exports = {
"client/responsive.html/browser/content.js", "client/responsive.html/browser/content.js",
"client/shared/browser-loader.js", "client/shared/browser-loader.js",
"server/actors/webconsole/content-process-forward.js", "server/actors/webconsole/content-process-forward.js",
"server/actors/worker/service-worker-process.js",
"server/startup/content-process.js", "server/startup/content-process.js",
"server/startup/frame.js", "server/startup/frame.js",
"shared/base-loader.js", "shared/base-loader.js",

View File

@ -15,7 +15,6 @@
/* eslint-disable no-throw-literal */ /* eslint-disable no-throw-literal */
const { Ci } = require("chrome"); const { Ci } = require("chrome");
const ChromeUtils = require("ChromeUtils");
const { DevToolsServer } = require("devtools/server/devtools-server"); const { DevToolsServer } = require("devtools/server/devtools-server");
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm"); const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
const protocol = require("devtools/shared/protocol"); const protocol = require("devtools/shared/protocol");
@ -23,8 +22,6 @@ const {
workerDescriptorSpec, workerDescriptorSpec,
} = require("devtools/shared/specs/descriptors/worker"); } = require("devtools/shared/specs/descriptors/worker");
loader.lazyRequireGetter(this, "ChromeUtils");
loader.lazyRequireGetter( loader.lazyRequireGetter(
this, this,
"connectToWorker", "connectToWorker",
@ -94,11 +91,6 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
} }
if (!this._attached) { if (!this._attached) {
const isServiceWorker =
this._dbg.type == Ci.nsIWorkerDebugger.TYPE_SERVICE;
if (isServiceWorker) {
this._preventServiceWorkerShutdown();
}
this._dbg.addListener(this._dbgListener); this._dbg.addListener(this._dbgListener);
this._attached = true; this._attached = true;
} }
@ -161,18 +153,6 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
} }
}, },
push() {
if (this._dbg.type !== Ci.nsIWorkerDebugger.TYPE_SERVICE) {
return { error: "wrongType" };
}
const registration = this._getServiceWorkerRegistrationInfo();
const originAttributes = ChromeUtils.originAttributesToSuffix(
this._dbg.principal.originAttributes
);
swm.sendPushEvent(originAttributes, registration.scope);
return { type: "pushed" };
},
_onWorkerClose() { _onWorkerClose() {
this.destroy(); this.destroy();
}, },
@ -185,11 +165,6 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
return swm.getRegistrationByPrincipal(this._dbg.principal, this._dbg.url); return swm.getRegistrationByPrincipal(this._dbg.principal, this._dbg.url);
}, },
_getServiceWorkerInfo() {
const registration = this._getServiceWorkerRegistrationInfo();
return registration.getWorkerByID(this._dbg.serviceWorkerID);
},
_detach() { _detach() {
if (this._threadActor !== null) { if (this._threadActor !== null) {
this._transport.close(); this._transport.close();
@ -197,56 +172,9 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
this._threadActor = null; this._threadActor = null;
} }
// If the worker is already destroyed, nsIWorkerDebugger.type throws
// (_dbg.closed appears to be false when it throws)
let type;
try {
type = this._dbg.type;
} catch (e) {
// nothing
}
const isServiceWorker = type == Ci.nsIWorkerDebugger.TYPE_SERVICE;
if (isServiceWorker) {
this._allowServiceWorkerShutdown();
}
this._dbg.removeListener(this._dbgListener); this._dbg.removeListener(this._dbgListener);
this._attached = false; this._attached = false;
}, },
/**
* Automatically disable the internal sw timeout that shut them down by calling
* nsIWorkerInfo.attachDebugger().
* This can be removed when Bug 1496997 lands.
*/
_preventServiceWorkerShutdown() {
if (swm.isParentInterceptEnabled()) {
// In parentIntercept mode, the worker target actor cannot call attachDebugger
// because this API can only be called from the parent process. This will be
// done by the worker target front.
return;
}
const worker = this._getServiceWorkerInfo();
if (worker) {
worker.attachDebugger();
}
},
/**
* Allow the service worker to time out. See _preventServiceWorkerShutdown.
*/
_allowServiceWorkerShutdown() {
if (swm.isParentInterceptEnabled()) {
return;
}
const worker = this._getServiceWorkerInfo();
if (worker) {
worker.detachDebugger();
}
},
} }
); );

View File

@ -6,7 +6,6 @@
DevToolsModules( DevToolsModules(
"push-subscription.js", "push-subscription.js",
"service-worker-process.js",
"service-worker-registration-list.js", "service-worker-registration-list.js",
"service-worker-registration.js", "service-worker-registration.js",
"service-worker.js", "service-worker.js",

View File

@ -1,41 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global addMessageListener */
"use strict";
/*
* Process script used to control service workers via a DevTools actor.
* Loaded into content processes by the service worker actors.
*/
const swm = Cc["@mozilla.org/serviceworkers/manager;1"].getService(
Ci.nsIServiceWorkerManager
);
addMessageListener("serviceWorkerRegistration:start", message => {
const { data } = message;
const array = swm.getAllRegistrations();
// Find the service worker registration with the desired scope.
for (let i = 0; i < array.length; i++) {
const registration = array.queryElementAt(
i,
Ci.nsIServiceWorkerRegistrationInfo
);
// XXX: In some rare cases, `registration.activeWorker` can be null for a
// brief moment (e.g. while the service worker is first installing, or if
// there was an unhandled exception during install that will cause the
// registration to be removed). We can't do much about it here, simply
// ignore these cases.
if (registration.scope === data.scope && registration.activeWorker) {
// Briefly attaching a debugger to the active service worker will cause
// it to start running.
registration.activeWorker.attachDebugger();
registration.activeWorker.detachDebugger();
return;
}
}
});

View File

@ -32,9 +32,6 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIPushService" "nsIPushService"
); );
// Lazily load the service-worker-process.js process script only once.
let _serviceWorkerProcessScriptLoaded = false;
const ServiceWorkerRegistrationActor = protocol.ActorClassWithSpec( const ServiceWorkerRegistrationActor = protocol.ActorClassWithSpec(
serviceWorkerRegistrationSpec, serviceWorkerRegistrationSpec,
{ {
@ -147,48 +144,27 @@ const ServiceWorkerRegistrationActor = protocol.ActorClassWithSpec(
}, },
start() { start() {
if (swm.isParentInterceptEnabled()) { if (!swm.isParentInterceptEnabled()) {
const { activeWorker } = this._registration; throw new Error(
"ServiceWorkerRegistrationActor.start can only be used " +
// TODO: don't return "started" if there's no active worker. "in parent-intercept mode"
if (activeWorker) {
// This starts up the Service Worker if it's not already running.
// Note that with parent-intercept (i.e. swm.isParentInterceptEnabled /
// dom.serviceWorkers.parent_intercept=true), the Service Workers exist
// in content processes but are managed from the parent process. This is
// why we call `attachDebugger` here (in the parent process) instead of
// in a process script.
activeWorker.attachDebugger();
activeWorker.detachDebugger();
}
return { type: "started" };
}
if (!_serviceWorkerProcessScriptLoaded) {
Services.ppmm.loadProcessScript(
"resource://devtools/server/actors/worker/service-worker-process.js",
true
); );
_serviceWorkerProcessScriptLoaded = true;
} }
// XXX: Send the permissions down to the content process before starting const { activeWorker } = this._registration;
// the service worker within the content process. As we don't know what
// content process we're starting the service worker in (as we're using a // TODO: don't return "started" if there's no active worker.
// broadcast channel to talk to it), we just broadcast the permissions to if (activeWorker) {
// everyone as well. // This starts up the Service Worker if it's not already running.
// // Note that with parent-intercept (i.e. swm.isParentInterceptEnabled /
// This call should be replaced with a proper implementation when // dom.serviceWorkers.parent_intercept=true), the Service Workers exist
// ServiceWorker debugging is improved to support multiple content processes // in content processes but are managed from the parent process. This is
// correctly. // why we call `attachDebugger` here (in the parent process) instead of
Services.perms.broadcastPermissionsForPrincipalToAllContentProcesses( // in a process script.
this._registration.principal activeWorker.attachDebugger();
); activeWorker.detachDebugger();
}
Services.ppmm.broadcastAsyncMessage("serviceWorkerRegistration:start", {
scope: this._registration.scope,
});
return { type: "started" }; return { type: "started" };
}, },

View File

@ -21,10 +21,6 @@ const workerDescriptorSpec = generateActorSpec({
request: {}, request: {},
response: RetVal("json"), response: RetVal("json"),
}, },
push: {
request: {},
response: RetVal("json"),
},
}, },
events: { events: {