mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1225477 - Support listening for processes creation. r=jryans
This commit is contained in:
parent
98fb41e16b
commit
49a26cab90
@ -40,6 +40,7 @@ DevToolsModules(
|
||||
'performance.js',
|
||||
'preference.js',
|
||||
'pretty-print-worker.js',
|
||||
'process.js',
|
||||
'profiler.js',
|
||||
'promises.js',
|
||||
'root.js',
|
||||
|
83
devtools/server/actors/process.js
Normal file
83
devtools/server/actors/process.js
Normal file
@ -0,0 +1,83 @@
|
||||
/* 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";
|
||||
|
||||
var { Cc, Ci } = require("chrome");
|
||||
|
||||
loader.lazyGetter(this, "ppmm", () => {
|
||||
return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(Ci.nsIMessageBroadcaster);
|
||||
});
|
||||
|
||||
function ProcessActorList() {
|
||||
this._actors = new Map();
|
||||
this._onListChanged = null;
|
||||
this._mustNotify = false;
|
||||
|
||||
this._onMessage = this._onMessage.bind(this);
|
||||
this._processScript = "data:text/javascript,sendAsyncMessage('debug:new-process');";
|
||||
}
|
||||
|
||||
ProcessActorList.prototype = {
|
||||
getList: function () {
|
||||
let processes = [];
|
||||
for (let i = 0; i < ppmm.childCount; i++) {
|
||||
processes.push({
|
||||
id: i, // XXX: may not be a perfect id, but process message manager doesn't expose anything...
|
||||
parent: i == 0, // XXX Weak, but appear to be stable
|
||||
tabCount: undefined, // TODO: exposes process message manager on frameloaders in order to compute this
|
||||
});
|
||||
}
|
||||
this._mustNotify = true;
|
||||
this._checkListening();
|
||||
|
||||
return processes;
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
this._onListChanged = onListChanged;
|
||||
this._checkListening();
|
||||
},
|
||||
|
||||
_checkListening: function () {
|
||||
if (this._onListChanged !== null && this._mustNotify) {
|
||||
this._knownProcesses = [];
|
||||
for (let i = 0; i < ppmm.childCount; i++) {
|
||||
this._knownProcesses.push(ppmm.getChildAt(i));
|
||||
}
|
||||
ppmm.addMessageListener('debug:new-process', this._onMessage);
|
||||
ppmm.loadProcessScript(this._processScript, true);
|
||||
} else {
|
||||
ppmm.removeMessageListener('debug:new-process', this._onMessage);
|
||||
ppmm.removeDelayedProcessScript(this._processScript);
|
||||
}
|
||||
},
|
||||
|
||||
_notifyListChanged: function () {
|
||||
if (this._mustNotify) {
|
||||
this._onListChanged();
|
||||
this._mustNotify = false;
|
||||
}
|
||||
},
|
||||
|
||||
_onMessage: function ({ target }) {
|
||||
if (this._knownProcesses.includes(target)) {
|
||||
return;
|
||||
}
|
||||
this._notifyListChanged();
|
||||
},
|
||||
};
|
||||
|
||||
exports.ProcessActorList = ProcessActorList;
|
@ -96,6 +96,7 @@ function RootActor(aConnection, aParameters) {
|
||||
this._onAddonListChanged = this.onAddonListChanged.bind(this);
|
||||
this._onWorkerListChanged = this.onWorkerListChanged.bind(this);
|
||||
this._onServiceWorkerRegistrationListChanged = this.onServiceWorkerRegistrationListChanged.bind(this);
|
||||
this._onProcessListChanged = this.onProcessListChanged.bind(this);
|
||||
this._extraActors = {};
|
||||
|
||||
this._globalActorPool = new ActorPool(this.conn);
|
||||
@ -419,15 +420,20 @@ RootActor.prototype = {
|
||||
},
|
||||
|
||||
onListProcesses: function () {
|
||||
let processes = [];
|
||||
for (let i = 0; i < ppmm.childCount; i++) {
|
||||
processes.push({
|
||||
id: i, // XXX: may not be a perfect id, but process message manager doesn't expose anything...
|
||||
parent: i == 0, // XXX Weak, but appear to be stable
|
||||
tabCount: undefined, // TODO: exposes process message manager on frameloaders in order to compute this
|
||||
});
|
||||
let { processList } = this._parameters;
|
||||
if (!processList) {
|
||||
return { from: this.actorID, error: "noProcesses",
|
||||
message: "This root actor has no processes." };
|
||||
}
|
||||
return { processes: processes };
|
||||
processList.onListChanged = this._onProcessListChanged;
|
||||
return {
|
||||
processes: processList.getList()
|
||||
};
|
||||
},
|
||||
|
||||
onProcessListChanged: function () {
|
||||
this.conn.send({ from: this.actorID, type: "processListChanged" });
|
||||
this._parameters.processList.onListChanged = null;
|
||||
},
|
||||
|
||||
onGetProcess: function (aRequest) {
|
||||
|
@ -24,6 +24,7 @@ loader.lazyRequireGetter(this, "unwrapDebuggerObjectGlobal", "devtools/server/ac
|
||||
loader.lazyRequireGetter(this, "BrowserAddonActor", "devtools/server/actors/addon", true);
|
||||
loader.lazyRequireGetter(this, "WorkerActorList", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "ServiceWorkerRegistrationActorList", "devtools/server/actors/worker", true);
|
||||
loader.lazyRequireGetter(this, "ProcessActorList", "devtools/server/actors/process", true);
|
||||
loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
||||
|
||||
// Assumptions on events module:
|
||||
@ -132,6 +133,7 @@ function createRootActor(aConnection)
|
||||
addonList: new BrowserAddonList(aConnection),
|
||||
workerList: new WorkerActorList({}),
|
||||
serviceWorkerRegistrationList: new ServiceWorkerRegistrationActorList(),
|
||||
processList: new ProcessActorList(),
|
||||
globalActorFactories: DebuggerServer.globalActorFactories,
|
||||
onShutdown: sendShutdownEvent
|
||||
});
|
||||
|
@ -28,21 +28,15 @@ window.onload = function() {
|
||||
"set": [
|
||||
// Always log packets when running tests.
|
||||
["devtools.debugger.log", true],
|
||||
["dom.mozBrowserFramesEnabled", true]
|
||||
// Enabled mozbrowser frame to support remote=true
|
||||
["dom.mozBrowserFramesEnabled", true],
|
||||
// Allows creating a branch new process when creation the iframe
|
||||
["dom.ipc.processCount", 10],
|
||||
]
|
||||
}, runTests);
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
// Create a remote iframe with a message manager
|
||||
let iframe = document.createElement("iframe");
|
||||
iframe.mozbrowser = true;
|
||||
iframe.setAttribute("remote", "true");
|
||||
iframe.setAttribute("src", "data:text/html,foo");
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
let mm = iframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
|
||||
|
||||
// Instantiate a minimal server
|
||||
if (!DebuggerServer.initialized) {
|
||||
DebuggerServer.init();
|
||||
@ -52,13 +46,41 @@ function runTests() {
|
||||
DebuggerServer.addBrowserActors();
|
||||
}
|
||||
|
||||
function firstClient() {
|
||||
let client, iframe, processCount;
|
||||
|
||||
function connect() {
|
||||
// Fake a first connection to the content process
|
||||
let transport = DebuggerServer.connectPipe();
|
||||
let client = new DebuggerClient(transport);
|
||||
client.connect(() => {
|
||||
client = new DebuggerClient(transport);
|
||||
client.connect(listProcess);
|
||||
}
|
||||
|
||||
function listProcess() {
|
||||
// Call listProcesses in order to start receiving new process notifications
|
||||
client.addListener("processListChanged", function listener() {
|
||||
client.removeListener("processListChanged", listener);
|
||||
ok(true, "Received processListChanged event");
|
||||
getProcess();
|
||||
});
|
||||
client.mainRoot.listProcesses(response => {
|
||||
processCount = response.processes.length;
|
||||
// Create a remote iframe to spawn a new process
|
||||
createRemoteIframe();
|
||||
});
|
||||
}
|
||||
|
||||
function createRemoteIframe() {
|
||||
iframe = document.createElement("iframe");
|
||||
iframe.mozbrowser = true;
|
||||
iframe.setAttribute("remote", "true");
|
||||
iframe.setAttribute("src", "data:text/html,foo");
|
||||
document.body.appendChild(iframe);
|
||||
}
|
||||
|
||||
function getProcess() {
|
||||
client.mainRoot.listProcesses(response => {
|
||||
ok(response.processes.length >= 2, "Got at least the parent process and one child");
|
||||
is(response.processes.length, processCount+1 , "Got one additional process on the second call to listProcesses");
|
||||
|
||||
// Connect to the first content processe available
|
||||
let content = response.processes.filter(p => (!p.parent))[0];
|
||||
@ -75,21 +97,21 @@ function runTests() {
|
||||
text: "var a = 42; a"
|
||||
}, function (response) {
|
||||
ok(response.result, 42, "console.eval worked");
|
||||
|
||||
client.close(cleanup);
|
||||
cleanup();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
DebuggerServer.destroy();
|
||||
iframe.remove();
|
||||
SimpleTest.finish()
|
||||
client.close(function () {
|
||||
DebuggerServer.destroy();
|
||||
iframe.remove();
|
||||
SimpleTest.finish()
|
||||
});
|
||||
}
|
||||
|
||||
firstClient();
|
||||
connect();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user