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
--- a/devtools/server/actors/child-process.js
+++ b/devtools/server/actors/child-process.js
@@ -9,17 +9,17 @@ const { Cc, Ci, Cu } = require("chrome")
const { ChromeDebuggerActor } = require("devtools/server/actors/script");
const { WebConsoleActor } = require("devtools/server/actors/webconsole");
const makeDebugger = require("devtools/server/actors/utils/make-debugger");
const { ActorPool } = require("devtools/server/main");
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;
this._contextPool = new ActorPool(this.conn);
this.conn.addActorPool(this._contextPool);
this.threadActor = null;
// Use a see-everything debugger
--- a/devtools/server/actors/moz.build
+++ b/devtools/server/actors/moz.build
@@ -62,10 +62,11 @@ DevToolsModules(
'tab.js',
'timeline.js',
'webaudio.js',
'webbrowser.js',
'webconsole.js',
'webextension-inspected-window.js',
'webextension.js',
'webgl.js',
+ 'worker-list.js',
'worker.js',
)
--- a/devtools/server/actors/tab.js
+++ b/devtools/server/actors/tab.js
@@ -22,17 +22,17 @@ var {
var { DebuggerServer } = require("devtools/server/main");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { assert } = DevToolsUtils;
var { TabSources } = require("./utils/TabSources");
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:
// events needs to be dispatched synchronously,
// by calling the listeners in the order or registration.
loader.lazyRequireGetter(this, "events", "sdk/event/core");
loader.lazyRequireGetter(this, "StyleSheetActor", "devtools/server/actors/stylesheets", true);
--- a/devtools/server/actors/webbrowser.js
+++ b/devtools/server/actors/webbrowser.js
@@ -10,18 +10,18 @@ var { Ci } = require("chrome");
var Services = require("Services");
var promise = require("promise");
var { DebuggerServer } = require("devtools/server/main");
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");
/**
* Browser-specific actors.
*/
/**
new file mode 100644
--- /dev/null
+++ b/devtools/server/actors/worker-list.js
@@ -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;
--- a/devtools/server/actors/worker.js
+++ b/devtools/server/actors/worker.js
@@ -4,63 +4,38 @@
"use strict";
const { Ci } = require("chrome");
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,
serviceWorkerRegistrationSpec,
serviceWorkerSpec,
} = require("devtools/shared/specs/worker");
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",
"nsIServiceWorkerManager"
);
XPCOMUtils.defineLazyServiceGetter(
this, "PushService",
"@mozilla.org/push/Service;1",
"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);
this._dbg = dbg;
this._attached = false;
this._threadActor = null;
this._transport = null;
},
@@ -207,114 +182,16 @@ let WorkerActor = protocol.ActorClassWit
this._dbg.removeListener(this);
this._attached = false;
}
});
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);
this._subscription = subscription;
},
form(detail) {
if (detail === "actorid") {
@@ -508,96 +385,9 @@ protocol.ActorClassWithSpec(serviceWorke
this._pushSubscriptionActor = pushSubscriptionActor;
resolve(pushSubscriptionActor);
}
);
});
},
});
-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;