mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-22 09:45:41 +00:00
Bug 1510654 - Extract ServiceWorkerRegistrationList from worker-list.js;r=ochameau,ladybenko
Differential Revision: https://phabricator.services.mozilla.com/D15374 --HG-- rename : devtools/server/actors/worker/worker-list.js => devtools/server/actors/worker/service-worker-registration-list.js extra : moz-landing-system : lando
This commit is contained in:
parent
a33221cca2
commit
a701c42419
@ -16,7 +16,8 @@ loader.lazyRequireGetter(this, "RootActor", "devtools/server/actors/root", true)
|
||||
loader.lazyRequireGetter(this, "FrameTargetActorProxy", "devtools/server/actors/targets/frame-proxy", true);
|
||||
loader.lazyRequireGetter(this, "WebExtensionActor", "devtools/server/actors/addon/webextension", true);
|
||||
loader.lazyRequireGetter(this, "WorkerTargetActorList", "devtools/server/actors/worker/worker-list", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActorList", "devtools/server/actors/worker/worker-list", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActorList",
|
||||
"devtools/server/actors/worker/service-worker-registration-list", true);
|
||||
loader.lazyRequireGetter(this, "ProcessActorList", "devtools/server/actors/process", true);
|
||||
loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
||||
loader.lazyImporter(this, "AppConstants", "resource://gre/modules/AppConstants.jsm");
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
DevToolsModules(
|
||||
'service-worker-process.js',
|
||||
'service-worker-registration-list.js',
|
||||
'service-worker.js',
|
||||
'worker-list.js',
|
||||
)
|
||||
|
@ -0,0 +1,104 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { Ci } = require("chrome");
|
||||
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActor", "devtools/server/actors/worker/service-worker", true);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "swm",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager"
|
||||
);
|
||||
|
||||
function ServiceWorkerRegistrationActorList(conn) {
|
||||
this._conn = conn;
|
||||
this._actors = new Map();
|
||||
this._onListChanged = null;
|
||||
this._mustNotify = false;
|
||||
this.onRegister = this.onRegister.bind(this);
|
||||
this.onUnregister = this.onUnregister.bind(this);
|
||||
}
|
||||
|
||||
ServiceWorkerRegistrationActorList.prototype = {
|
||||
getList() {
|
||||
// Create a set of registrations.
|
||||
const registrations = new Set();
|
||||
const array = swm.getAllRegistrations();
|
||||
for (let index = 0; index < array.length; ++index) {
|
||||
registrations.add(
|
||||
array.queryElementAt(index, Ci.nsIServiceWorkerRegistrationInfo));
|
||||
}
|
||||
|
||||
// Delete each actor for which we don't have a registration.
|
||||
for (const [registration ] of this._actors) {
|
||||
if (!registrations.has(registration)) {
|
||||
this._actors.delete(registration);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an actor for each registration for which we don't have one.
|
||||
for (const registration of registrations) {
|
||||
if (!this._actors.has(registration)) {
|
||||
this._actors.set(registration,
|
||||
new ServiceWorkerRegistrationActor(this._conn, registration));
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._mustNotify) {
|
||||
if (this._onListChanged !== null) {
|
||||
swm.addListener(this);
|
||||
}
|
||||
this._mustNotify = true;
|
||||
}
|
||||
|
||||
const actors = [];
|
||||
for (const [, actor] of this._actors) {
|
||||
actors.push(actor);
|
||||
}
|
||||
|
||||
return Promise.resolve(actors);
|
||||
},
|
||||
|
||||
get onListchanged() {
|
||||
return this._onListchanged;
|
||||
},
|
||||
|
||||
set onListChanged(onListChanged) {
|
||||
if (typeof onListChanged !== "function" && onListChanged !== null) {
|
||||
throw new Error("onListChanged must be either a function or null.");
|
||||
}
|
||||
|
||||
if (this._mustNotify) {
|
||||
if (this._onListChanged === null && onListChanged !== null) {
|
||||
swm.addListener(this);
|
||||
}
|
||||
if (this._onListChanged !== null && onListChanged === null) {
|
||||
swm.removeListener(this);
|
||||
}
|
||||
}
|
||||
this._onListChanged = onListChanged;
|
||||
},
|
||||
|
||||
_notifyListChanged() {
|
||||
this._onListChanged();
|
||||
|
||||
if (this._onListChanged !== null) {
|
||||
swm.removeListener(this);
|
||||
}
|
||||
this._mustNotify = false;
|
||||
},
|
||||
|
||||
onRegister(registration) {
|
||||
this._notifyListChanged();
|
||||
},
|
||||
|
||||
onUnregister(registration) {
|
||||
this._notifyListChanged();
|
||||
},
|
||||
};
|
||||
|
||||
exports.ServiceWorkerRegistrationActorList = ServiceWorkerRegistrationActorList;
|
@ -4,10 +4,8 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const { Ci } = require("chrome");
|
||||
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
|
||||
loader.lazyRequireGetter(this, "WorkerTargetActor", "devtools/server/actors/targets/worker", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActor", "devtools/server/actors/worker/service-worker", true);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "wdm",
|
||||
@ -15,12 +13,6 @@ XPCOMUtils.defineLazyServiceGetter(
|
||||
"nsIWorkerDebuggerManager"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "swm",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
"nsIServiceWorkerManager"
|
||||
);
|
||||
|
||||
function matchWorkerDebugger(dbg, options) {
|
||||
if ("type" in options && dbg.type !== options.type) {
|
||||
return false;
|
||||
@ -134,92 +126,3 @@ WorkerTargetActorList.prototype = {
|
||||
};
|
||||
|
||||
exports.WorkerTargetActorList = WorkerTargetActorList;
|
||||
|
||||
function ServiceWorkerRegistrationActorList(conn) {
|
||||
this._conn = conn;
|
||||
this._actors = new Map();
|
||||
this._onListChanged = null;
|
||||
this._mustNotify = false;
|
||||
this.onRegister = this.onRegister.bind(this);
|
||||
this.onUnregister = this.onUnregister.bind(this);
|
||||
}
|
||||
|
||||
ServiceWorkerRegistrationActorList.prototype = {
|
||||
getList() {
|
||||
// Create a set of registrations.
|
||||
const registrations = new Set();
|
||||
const array = swm.getAllRegistrations();
|
||||
for (let index = 0; index < array.length; ++index) {
|
||||
registrations.add(
|
||||
array.queryElementAt(index, Ci.nsIServiceWorkerRegistrationInfo));
|
||||
}
|
||||
|
||||
// Delete each actor for which we don't have a registration.
|
||||
for (const [registration ] of this._actors) {
|
||||
if (!registrations.has(registration)) {
|
||||
this._actors.delete(registration);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an actor for each registration for which we don't have one.
|
||||
for (const registration of registrations) {
|
||||
if (!this._actors.has(registration)) {
|
||||
this._actors.set(registration,
|
||||
new ServiceWorkerRegistrationActor(this._conn, registration));
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._mustNotify) {
|
||||
if (this._onListChanged !== null) {
|
||||
swm.addListener(this);
|
||||
}
|
||||
this._mustNotify = true;
|
||||
}
|
||||
|
||||
const actors = [];
|
||||
for (const [, actor] of this._actors) {
|
||||
actors.push(actor);
|
||||
}
|
||||
|
||||
return Promise.resolve(actors);
|
||||
},
|
||||
|
||||
get onListchanged() {
|
||||
return this._onListchanged;
|
||||
},
|
||||
|
||||
set onListChanged(onListChanged) {
|
||||
if (typeof onListChanged !== "function" && onListChanged !== null) {
|
||||
throw new Error("onListChanged must be either a function or null.");
|
||||
}
|
||||
|
||||
if (this._mustNotify) {
|
||||
if (this._onListChanged === null && onListChanged !== null) {
|
||||
swm.addListener(this);
|
||||
}
|
||||
if (this._onListChanged !== null && onListChanged === null) {
|
||||
swm.removeListener(this);
|
||||
}
|
||||
}
|
||||
this._onListChanged = onListChanged;
|
||||
},
|
||||
|
||||
_notifyListChanged() {
|
||||
this._onListChanged();
|
||||
|
||||
if (this._onListChanged !== null) {
|
||||
swm.removeListener(this);
|
||||
}
|
||||
this._mustNotify = false;
|
||||
},
|
||||
|
||||
onRegister(registration) {
|
||||
this._notifyListChanged();
|
||||
},
|
||||
|
||||
onUnregister(registration) {
|
||||
this._notifyListChanged();
|
||||
},
|
||||
};
|
||||
|
||||
exports.ServiceWorkerRegistrationActorList = ServiceWorkerRegistrationActorList;
|
||||
|
Loading…
Reference in New Issue
Block a user