diff --git a/devtools/server/actors/targets/content-process.js b/devtools/server/actors/targets/content-process.js index 6d8c2529ed57..befcd682195b 100644 --- a/devtools/server/actors/targets/content-process.js +++ b/devtools/server/actors/targets/content-process.js @@ -17,10 +17,13 @@ const Services = require("Services"); const { ChromeDebuggerActor } = require("devtools/server/actors/thread"); const { WebConsoleActor } = require("devtools/server/actors/webconsole"); const makeDebugger = require("devtools/server/actors/utils/make-debugger"); -const { ActorPool } = require("devtools/server/actors/common"); const { Pool } = require("devtools/shared/protocol"); const { assert } = require("devtools/shared/DevToolsUtils"); const { TabSources } = require("devtools/server/actors/utils/TabSources"); +const { ActorClassWithSpec, Actor } = require("devtools/shared/protocol"); +const { + contentProcessTargetSpec, +} = require("devtools/shared/specs/targets/content-process"); loader.lazyRequireGetter( this, @@ -41,46 +44,42 @@ loader.lazyRequireGetter( true ); -function ContentProcessTargetActor(connection) { - this.conn = connection; - this._contextPool = new ActorPool(this.conn); - this.conn.addActorPool(this._contextPool); - this.threadActor = null; +const ContentProcessTargetActor = ActorClassWithSpec(contentProcessTargetSpec, { + initialize: function(connection) { + Actor.prototype.initialize.call(this, connection); + this.conn = connection; + this.threadActor = null; - // Use a see-everything debugger - this.makeDebugger = makeDebugger.bind(null, { - findDebuggees: dbg => dbg.findAllGlobals(), - shouldAddNewGlobalAsDebuggee: global => true, - }); + // Use a see-everything debugger + this.makeDebugger = makeDebugger.bind(null, { + findDebuggees: dbg => dbg.findAllGlobals(), + shouldAddNewGlobalAsDebuggee: global => true, + }); - const sandboxPrototype = { - get tabs() { - return Array.from( - Services.ww.getWindowEnumerator(), - win => win.docShell.messageManager - ); - }, - }; + const sandboxPrototype = { + get tabs() { + return Array.from( + Services.ww.getWindowEnumerator(), + win => win.docShell.messageManager + ); + }, + }; - // Scope into which the webconsole executes: - // A sandbox with chrome privileges with a `tabs` getter. - const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance( - Ci.nsIPrincipal - ); - const sandbox = Cu.Sandbox(systemPrincipal, { - sandboxPrototype, - wantGlobalProperties: ["ChromeUtils"], - }); - this._consoleScope = sandbox; + // Scope into which the webconsole executes: + // A sandbox with chrome privileges with a `tabs` getter. + const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance( + Ci.nsIPrincipal + ); + const sandbox = Cu.Sandbox(systemPrincipal, { + sandboxPrototype, + wantGlobalProperties: ["ChromeUtils"], + }); + this._consoleScope = sandbox; - this._workerList = null; - this._workerTargetActorPool = null; - this._onWorkerListChanged = this._onWorkerListChanged.bind(this); -} -exports.ContentProcessTargetActor = ContentProcessTargetActor; - -ContentProcessTargetActor.prototype = { - actorPrefix: "contentProcessTarget", + this._workerList = null; + this._workerTargetActorPool = null; + this._onWorkerListChanged = this._onWorkerListChanged.bind(this); + }, get isRootActor() { return true; @@ -112,22 +111,22 @@ ContentProcessTargetActor.prototype = { form: function() { if (!this._consoleActor) { this._consoleActor = new WebConsoleActor(this.conn, this); - this._contextPool.addActor(this._consoleActor); + this.manage(this._consoleActor); } if (!this.threadActor) { this.threadActor = new ChromeDebuggerActor(this.conn, this); - this._contextPool.addActor(this.threadActor); + this.manage(this.threadActor); } if (!this.memoryActor) { this.memoryActor = new MemoryActor(this.conn, this); - this._contextPool.addActor(this.memoryActor); + this.manage(this.memoryActor); } // Promises actor is being tested by xpcshell test, which uses the content process // target actor. But this actor isn't being used outside of tests yet. if (!this._promisesActor) { this._promisesActor = new PromisesActor(this.conn, this); - this._contextPool.addActor(this._promisesActor); + this.manage(this._promisesActor); } return { @@ -145,7 +144,7 @@ ContentProcessTargetActor.prototype = { }; }, - onListWorkers: function() { + listWorkers: function() { if (!this._workerList) { this._workerList = new WorkerTargetActorList(this.conn, {}); } @@ -156,7 +155,7 @@ ContentProcessTargetActor.prototype = { } // Do not destroy the pool before transfering ownership to the newly created - // pool, so that we do not accidently destroy actors that are still in use. + // pool, so that we do not accidentally destroy actors that are still in use. if (this._workerTargetActorPool) { this._workerTargetActorPool.destroy(); } @@ -166,7 +165,7 @@ ContentProcessTargetActor.prototype = { return { from: this.actorID, - workers: actors.map(actor => actor.form()), + workers: actors, }; }); }, @@ -177,8 +176,7 @@ ContentProcessTargetActor.prototype = { }, destroy: function() { - this.conn.removeActorPool(this._contextPool); - this._contextPool = null; + Actor.prototype.destroy.call(this); // Tell the live lists we aren't watching any more. if (this._workerList) { @@ -193,8 +191,6 @@ ContentProcessTargetActor.prototype = { }, postNest: function() {}, -}; +}); -ContentProcessTargetActor.prototype.requestTypes = { - listWorkers: ContentProcessTargetActor.prototype.onListWorkers, -}; +exports.ContentProcessTargetActor = ContentProcessTargetActor;