Bug 1450070 - WIP: Add update method to ServiceWorker actor
MozReview-Commit-ID: KAuPEhg3D7g
--- a/devtools/server/actors/worker.js
+++ b/devtools/server/actors/worker.js
@@ -370,16 +370,41 @@ protocol.ActorClassWithSpec(serviceWorke
this._registration.principal);
Services.ppmm.broadcastAsyncMessage("serviceWorkerRegistration:start", {
scope: this._registration.scope
});
return { type: "started" };
},
+ update() {
+ 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
+ // 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);
+
+ Services.ppmm.broadcastAsyncMessage("serviceWorkerRegistration:update", {
+ scope: this._registration.scope
+ });
+ return { type: "updated" };
+ },
+
unregister() {
let { principal, scope } = this._registration;
let unregisterCallback = {
unregisterSucceeded: function() {},
unregisterFailed: function() {
console.error("Failed to unregister the service worker for " + scope);
},
QueryInterface: ChromeUtils.generateQI(
--- a/devtools/server/actors/worker/service-worker-process.js
+++ b/devtools/server/actors/worker/service-worker-process.js
@@ -31,8 +31,36 @@ addMessageListener("serviceWorkerRegistr
// Briefly attaching a debugger to the active service worker will cause
// it to start running.
registration.activeWorker.attachDebugger();
registration.activeWorker.detachDebugger();
return;
}
}
});
+
+function findRegistration(scope) {
+ let array = swm.getAllRegistrations();
+
+ // Find the service worker registration with the desired scope.
+ for (let i = 0; i < array.length; i++) {
+ let registration =
+ array.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
+ if (registration.scope === scope && registration.activeWorker) {
+ return registration;
+ }
+ }
+
+ return null;
+}
+
+addMessageListener("serviceWorkerRegistration:update", message => {
+ let { data } = message;
+ let registration = findRegistration(data.scope);
+
+ if (registration) {
+ let { principal, scope } = registration;
+ // Send update for the registration.
+ swm.propagateSoftUpdate(principal.originAttributes, scope);
+ registration.activeWorker.attachDebugger();
+ registration.activeWorker.detachDebugger();
+ }
+});
--- a/devtools/shared/specs/worker.js
+++ b/devtools/shared/specs/worker.js
@@ -54,16 +54,20 @@ const serviceWorkerRegistrationSpec = ge
start: {
request: {},
response: RetVal("json")
},
unregister: {
request: {},
response: RetVal("json")
},
+ update: {
+ request: {},
+ response: RetVal("json")
+ },
getPushSubscription: {
request: {},
response: {
subscription: RetVal("nullable:pushSubscription")
}
},
},
});