зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
83334cbf7a
Коммит
5502682b68
|
@ -116,7 +116,6 @@ module.exports = {
|
|||
"client/responsive.html/browser/content.js",
|
||||
"client/shared/browser-loader.js",
|
||||
"server/actors/webconsole/content-process-forward.js",
|
||||
"server/actors/worker/service-worker-process.js",
|
||||
"server/startup/content-process.js",
|
||||
"server/startup/frame.js",
|
||||
"shared/base-loader.js",
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
/* eslint-disable no-throw-literal */
|
||||
|
||||
const { Ci } = require("chrome");
|
||||
const ChromeUtils = require("ChromeUtils");
|
||||
const { DevToolsServer } = require("devtools/server/devtools-server");
|
||||
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
|
@ -23,8 +22,6 @@ const {
|
|||
workerDescriptorSpec,
|
||||
} = require("devtools/shared/specs/descriptors/worker");
|
||||
|
||||
loader.lazyRequireGetter(this, "ChromeUtils");
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
"connectToWorker",
|
||||
|
@ -94,11 +91,6 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
|
|||
}
|
||||
|
||||
if (!this._attached) {
|
||||
const isServiceWorker =
|
||||
this._dbg.type == Ci.nsIWorkerDebugger.TYPE_SERVICE;
|
||||
if (isServiceWorker) {
|
||||
this._preventServiceWorkerShutdown();
|
||||
}
|
||||
this._dbg.addListener(this._dbgListener);
|
||||
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() {
|
||||
this.destroy();
|
||||
},
|
||||
|
@ -185,11 +165,6 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
|
|||
return swm.getRegistrationByPrincipal(this._dbg.principal, this._dbg.url);
|
||||
},
|
||||
|
||||
_getServiceWorkerInfo() {
|
||||
const registration = this._getServiceWorkerRegistrationInfo();
|
||||
return registration.getWorkerByID(this._dbg.serviceWorkerID);
|
||||
},
|
||||
|
||||
_detach() {
|
||||
if (this._threadActor !== null) {
|
||||
this._transport.close();
|
||||
|
@ -197,56 +172,9 @@ const WorkerDescriptorActor = protocol.ActorClassWithSpec(
|
|||
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._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();
|
||||
}
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
DevToolsModules(
|
||||
"push-subscription.js",
|
||||
"service-worker-process.js",
|
||||
"service-worker-registration-list.js",
|
||||
"service-worker-registration.js",
|
||||
"service-worker.js",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -32,9 +32,6 @@ XPCOMUtils.defineLazyServiceGetter(
|
|||
"nsIPushService"
|
||||
);
|
||||
|
||||
// Lazily load the service-worker-process.js process script only once.
|
||||
let _serviceWorkerProcessScriptLoaded = false;
|
||||
|
||||
const ServiceWorkerRegistrationActor = protocol.ActorClassWithSpec(
|
||||
serviceWorkerRegistrationSpec,
|
||||
{
|
||||
|
@ -147,48 +144,27 @@ const ServiceWorkerRegistrationActor = protocol.ActorClassWithSpec(
|
|||
},
|
||||
|
||||
start() {
|
||||
if (swm.isParentInterceptEnabled()) {
|
||||
const { activeWorker } = this._registration;
|
||||
|
||||
// TODO: don't return "started" if there's no active worker.
|
||||
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
|
||||
if (!swm.isParentInterceptEnabled()) {
|
||||
throw new Error(
|
||||
"ServiceWorkerRegistrationActor.start can only be used " +
|
||||
"in parent-intercept mode"
|
||||
);
|
||||
_serviceWorkerProcessScriptLoaded = true;
|
||||
}
|
||||
|
||||
// XXX: Send the permissions down to the content process before starting
|
||||
// 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
|
||||
// broadcast channel to talk to it), we just broadcast the permissions to
|
||||
// everyone as well.
|
||||
//
|
||||
// This call should be replaced with a proper implementation when
|
||||
// ServiceWorker debugging is improved to support multiple content processes
|
||||
// correctly.
|
||||
Services.perms.broadcastPermissionsForPrincipalToAllContentProcesses(
|
||||
this._registration.principal
|
||||
);
|
||||
const { activeWorker } = this._registration;
|
||||
|
||||
// TODO: don't return "started" if there's no active worker.
|
||||
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();
|
||||
}
|
||||
|
||||
Services.ppmm.broadcastAsyncMessage("serviceWorkerRegistration:start", {
|
||||
scope: this._registration.scope,
|
||||
});
|
||||
return { type: "started" };
|
||||
},
|
||||
|
||||
|
|
|
@ -21,10 +21,6 @@ const workerDescriptorSpec = generateActorSpec({
|
|||
request: {},
|
||||
response: RetVal("json"),
|
||||
},
|
||||
push: {
|
||||
request: {},
|
||||
response: RetVal("json"),
|
||||
},
|
||||
},
|
||||
|
||||
events: {
|
||||
|
|
Загрузка…
Ссылка в новой задаче