diff --git a/devtools/server/actors/root.js b/devtools/server/actors/root.js index b6f8c0ee4ce1..1b6c00acc753 100644 --- a/devtools/server/actors/root.js +++ b/devtools/server/actors/root.js @@ -103,6 +103,7 @@ function RootActor(aConnection, aParameters) { this.conn.addActorPool(this._globalActorPool); this._chromeActor = null; + this._processActors = new Map(); } RootActor.prototype = { @@ -230,6 +231,7 @@ RootActor.prototype = { this._globalActorPool = null; this._parameters = null; this._chromeActor = null; + this._processActors.clear(); }, /* The 'listTabs' request and the 'tabListChanged' notification. */ @@ -471,13 +473,24 @@ RootActor.prototype = { return { form: this._chromeActor.form() }; } else { - let mm = ppmm.getChildAt(aRequest.id); + let { id } = aRequest; + let mm = ppmm.getChildAt(id); if (!mm) { return { error: "noProcess", - message: "There is no process with id '" + aRequest.id + "'." }; + message: "There is no process with id '" + id + "'." }; } - return DebuggerServer.connectToContent(this.conn, mm) - .then(form => ({ form })); + let form = this._processActors.get(id); + if (form) { + return { form }; + } + let onDestroy = () => { + this._processActors.delete(id); + }; + return DebuggerServer.connectToContent(this.conn, mm, onDestroy) + .then(form => { + this._processActors.set(id, form); + return { form }; + }); } }, diff --git a/devtools/server/main.js b/devtools/server/main.js index 475995493f23..94ecde6629d3 100644 --- a/devtools/server/main.js +++ b/devtools/server/main.js @@ -715,7 +715,7 @@ var DebuggerServer = { return this._onConnection(transport, prefix, true); }, - connectToContent(connection, mm) { + connectToContent(connection, mm, onDestroy) { let deferred = SyncPromise.defer(); let prefix = connection.allocID("content-process"); @@ -764,6 +764,10 @@ var DebuggerServer = { // Nothing to do } } + + if (onDestroy) { + onDestroy(mm); + } } let onMessageManagerClose = DevToolsUtils.makeInfallible((subject, topic, data) => { diff --git a/devtools/server/tests/mochitest/test_getProcess.html b/devtools/server/tests/mochitest/test_getProcess.html index 3c8ca5727ff9..e10554fb1258 100644 --- a/devtools/server/tests/mochitest/test_getProcess.html +++ b/devtools/server/tests/mochitest/test_getProcess.html @@ -97,12 +97,24 @@ function runTests() { text: "var a = 42; a" }, function (response) { ok(response.result, 42, "console.eval worked"); - cleanup(); + + getProcessAgain(actor, content.id); }); }); }); } + // Assert that calling client.getProcess against the same process id is + // returning the same actor. + function getProcessAgain(firstActor, id) { + client.getProcess(id).then(response => { + let actor = response.form; + is(actor, firstActor, + "Second call to getProcess with the same id returns the same form"); + cleanup(); + }); + } + function cleanup() { client.close().then(function () { DebuggerServer.destroy();