зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1323466 - Split actors/worker.js in two to prevent loading unecessary actor code in parent process. r=jryans
The main goal here is to prevent loading protocol.js in the parent process. MozReview-Commit-ID: 1HzbqNZ81v1 --HG-- extra : rebase_source : 52b815d63002c3584dc1caee2fffef5d3ed10c91
This commit is contained in:
Родитель
05785798fb
Коммит
169218bed0
|
@ -14,7 +14,7 @@ const Services = require("Services");
|
|||
const { assert } = require("devtools/shared/DevToolsUtils");
|
||||
const { TabSources } = require("./utils/TabSources");
|
||||
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker-list", true);
|
||||
|
||||
function ChildProcessActor(aConnection) {
|
||||
this.conn = aConnection;
|
||||
|
|
|
@ -67,5 +67,6 @@ DevToolsModules(
|
|||
'webextension-inspected-window.js',
|
||||
'webextension.js',
|
||||
'webgl.js',
|
||||
'worker-list.js',
|
||||
'worker.js',
|
||||
)
|
||||
|
|
|
@ -27,7 +27,7 @@ var makeDebugger = require("./utils/make-debugger");
|
|||
|
||||
loader.lazyRequireGetter(this, "ThreadActor", "devtools/server/actors/script", true);
|
||||
loader.lazyRequireGetter(this, "unwrapDebuggerObjectGlobal", "devtools/server/actors/script", true);
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker-list", true);
|
||||
loader.lazyImporter(this, "ExtensionContent", "resource://gre/modules/ExtensionContent.jsm");
|
||||
|
||||
// Assumptions on events module:
|
||||
|
|
|
@ -15,8 +15,8 @@ var DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
|||
loader.lazyRequireGetter(this, "RootActor", "devtools/server/actors/root", true);
|
||||
loader.lazyRequireGetter(this, "BrowserAddonActor", "devtools/server/actors/addon", true);
|
||||
loader.lazyRequireGetter(this, "WebExtensionActor", "devtools/server/actors/webextension", true);
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActorList", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker-list", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActorList", "devtools/server/actors/worker-list", true);
|
||||
loader.lazyRequireGetter(this, "ProcessActorList", "devtools/server/actors/process", true);
|
||||
loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
||||
|
||||
|
|
|
@ -0,0 +1,227 @@
|
|||
/* 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, "WorkerActor", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActor", "devtools/server/actors/worker", true);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "wdm",
|
||||
"@mozilla.org/dom/workers/workerdebuggermanager;1",
|
||||
"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;
|
||||
}
|
||||
if ("window" in options) {
|
||||
let window = dbg.window;
|
||||
while (window !== null && window.parent !== window) {
|
||||
window = window.parent;
|
||||
}
|
||||
|
||||
if (window !== options.window) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function WorkerActorList(conn, options) {
|
||||
this._conn = conn;
|
||||
this._options = options;
|
||||
this._actors = new Map();
|
||||
this._onListChanged = null;
|
||||
this._mustNotify = false;
|
||||
this.onRegister = this.onRegister.bind(this);
|
||||
this.onUnregister = this.onUnregister.bind(this);
|
||||
}
|
||||
|
||||
WorkerActorList.prototype = {
|
||||
getList() {
|
||||
// Create a set of debuggers.
|
||||
let dbgs = new Set();
|
||||
let e = wdm.getWorkerDebuggerEnumerator();
|
||||
while (e.hasMoreElements()) {
|
||||
let dbg = e.getNext().QueryInterface(Ci.nsIWorkerDebugger);
|
||||
if (matchWorkerDebugger(dbg, this._options)) {
|
||||
dbgs.add(dbg);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete each actor for which we don't have a debugger.
|
||||
for (let [dbg, ] of this._actors) {
|
||||
if (!dbgs.has(dbg)) {
|
||||
this._actors.delete(dbg);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an actor for each debugger for which we don't have one.
|
||||
for (let dbg of dbgs) {
|
||||
if (!this._actors.has(dbg)) {
|
||||
this._actors.set(dbg, new WorkerActor(this._conn, dbg));
|
||||
}
|
||||
}
|
||||
|
||||
let actors = [];
|
||||
for (let [, actor] of this._actors) {
|
||||
actors.push(actor);
|
||||
}
|
||||
|
||||
if (!this._mustNotify) {
|
||||
if (this._onListChanged !== null) {
|
||||
wdm.addListener(this);
|
||||
}
|
||||
this._mustNotify = true;
|
||||
}
|
||||
|
||||
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 (onListChanged === this._onListChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._mustNotify) {
|
||||
if (this._onListChanged === null && onListChanged !== null) {
|
||||
wdm.addListener(this);
|
||||
}
|
||||
if (this._onListChanged !== null && onListChanged === null) {
|
||||
wdm.removeListener(this);
|
||||
}
|
||||
}
|
||||
this._onListChanged = onListChanged;
|
||||
},
|
||||
|
||||
_notifyListChanged() {
|
||||
this._onListChanged();
|
||||
|
||||
if (this._onListChanged !== null) {
|
||||
wdm.removeListener(this);
|
||||
}
|
||||
this._mustNotify = false;
|
||||
},
|
||||
|
||||
onRegister(dbg) {
|
||||
if (matchWorkerDebugger(dbg, this._options)) {
|
||||
this._notifyListChanged();
|
||||
}
|
||||
},
|
||||
|
||||
onUnregister(dbg) {
|
||||
if (matchWorkerDebugger(dbg, this._options)) {
|
||||
this._notifyListChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.WorkerActorList = WorkerActorList;
|
||||
|
||||
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.
|
||||
let registrations = new Set();
|
||||
let 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 (let [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 (let 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;
|
||||
}
|
||||
|
||||
let actors = [];
|
||||
for (let [, 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;
|
|
@ -9,7 +9,6 @@ const { DebuggerServer } = require("devtools/server/main");
|
|||
const Services = require("Services");
|
||||
const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
const { Arg, method, RetVal } = protocol;
|
||||
const {
|
||||
workerSpec,
|
||||
pushSubscriptionSpec,
|
||||
|
@ -20,12 +19,6 @@ const {
|
|||
loader.lazyRequireGetter(this, "ChromeUtils");
|
||||
loader.lazyRequireGetter(this, "events", "sdk/event/core");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "wdm",
|
||||
"@mozilla.org/dom/workers/workerdebuggermanager;1",
|
||||
"nsIWorkerDebuggerManager"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
this, "swm",
|
||||
"@mozilla.org/serviceworkers/manager;1",
|
||||
|
@ -38,24 +31,6 @@ XPCOMUtils.defineLazyServiceGetter(
|
|||
"nsIPushService"
|
||||
);
|
||||
|
||||
function matchWorkerDebugger(dbg, options) {
|
||||
if ("type" in options && dbg.type !== options.type) {
|
||||
return false;
|
||||
}
|
||||
if ("window" in options) {
|
||||
let window = dbg.window;
|
||||
while (window !== null && window.parent !== window) {
|
||||
window = window.parent;
|
||||
}
|
||||
|
||||
if (window !== options.window) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
let WorkerActor = protocol.ActorClassWithSpec(workerSpec, {
|
||||
initialize(conn, dbg) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
|
@ -212,104 +187,6 @@ let WorkerActor = protocol.ActorClassWithSpec(workerSpec, {
|
|||
|
||||
exports.WorkerActor = WorkerActor;
|
||||
|
||||
function WorkerActorList(conn, options) {
|
||||
this._conn = conn;
|
||||
this._options = options;
|
||||
this._actors = new Map();
|
||||
this._onListChanged = null;
|
||||
this._mustNotify = false;
|
||||
this.onRegister = this.onRegister.bind(this);
|
||||
this.onUnregister = this.onUnregister.bind(this);
|
||||
}
|
||||
|
||||
WorkerActorList.prototype = {
|
||||
getList() {
|
||||
// Create a set of debuggers.
|
||||
let dbgs = new Set();
|
||||
let e = wdm.getWorkerDebuggerEnumerator();
|
||||
while (e.hasMoreElements()) {
|
||||
let dbg = e.getNext().QueryInterface(Ci.nsIWorkerDebugger);
|
||||
if (matchWorkerDebugger(dbg, this._options)) {
|
||||
dbgs.add(dbg);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete each actor for which we don't have a debugger.
|
||||
for (let [dbg, ] of this._actors) {
|
||||
if (!dbgs.has(dbg)) {
|
||||
this._actors.delete(dbg);
|
||||
}
|
||||
}
|
||||
|
||||
// Create an actor for each debugger for which we don't have one.
|
||||
for (let dbg of dbgs) {
|
||||
if (!this._actors.has(dbg)) {
|
||||
this._actors.set(dbg, new WorkerActor(this._conn, dbg));
|
||||
}
|
||||
}
|
||||
|
||||
let actors = [];
|
||||
for (let [, actor] of this._actors) {
|
||||
actors.push(actor);
|
||||
}
|
||||
|
||||
if (!this._mustNotify) {
|
||||
if (this._onListChanged !== null) {
|
||||
wdm.addListener(this);
|
||||
}
|
||||
this._mustNotify = true;
|
||||
}
|
||||
|
||||
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 (onListChanged === this._onListChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._mustNotify) {
|
||||
if (this._onListChanged === null && onListChanged !== null) {
|
||||
wdm.addListener(this);
|
||||
}
|
||||
if (this._onListChanged !== null && onListChanged === null) {
|
||||
wdm.removeListener(this);
|
||||
}
|
||||
}
|
||||
this._onListChanged = onListChanged;
|
||||
},
|
||||
|
||||
_notifyListChanged() {
|
||||
this._onListChanged();
|
||||
|
||||
if (this._onListChanged !== null) {
|
||||
wdm.removeListener(this);
|
||||
}
|
||||
this._mustNotify = false;
|
||||
},
|
||||
|
||||
onRegister(dbg) {
|
||||
if (matchWorkerDebugger(dbg, this._options)) {
|
||||
this._notifyListChanged();
|
||||
}
|
||||
},
|
||||
|
||||
onUnregister(dbg) {
|
||||
if (matchWorkerDebugger(dbg, this._options)) {
|
||||
this._notifyListChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.WorkerActorList = WorkerActorList;
|
||||
|
||||
let PushSubscriptionActor = protocol.ActorClassWithSpec(pushSubscriptionSpec, {
|
||||
initialize(conn, subscription) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
|
@ -513,91 +390,4 @@ protocol.ActorClassWithSpec(serviceWorkerRegistrationSpec, {
|
|||
},
|
||||
});
|
||||
|
||||
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.
|
||||
let registrations = new Set();
|
||||
let 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 (let [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 (let 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;
|
||||
}
|
||||
|
||||
let actors = [];
|
||||
for (let [, 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;
|
||||
exports.ServiceWorkerRegistrationActor = ServiceWorkerRegistrationActor;
|
||||
|
|
Загрузка…
Ссылка в новой задаче