diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/server/actors/process.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/actors/process.js')
-rw-r--r-- | devtools/server/actors/process.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/devtools/server/actors/process.js b/devtools/server/actors/process.js new file mode 100644 index 0000000000..2ed2da64c0 --- /dev/null +++ b/devtools/server/actors/process.js @@ -0,0 +1,76 @@ +/* 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"; + +loader.lazyGetter(this, "ppmm", () => { + return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService(); +}); + +class ProcessActorList { + constructor() { + this._actors = new Map(); + this._onListChanged = null; + this._mustNotify = false; + this._hasObserver = false; + } + + getList() { + const processes = []; + for (let i = 0; i < ppmm.childCount; i++) { + const mm = ppmm.getChildAt(i); + processes.push({ + // An ID of zero is always used for the parent. It would be nice to fix + // this so that the pid is also used for the parent, see bug 1587443. + id: mm.isInProcess ? 0 : mm.osPid, + parent: mm.isInProcess, + // TODO: exposes process message manager on frameloaders in order to compute this + tabCount: undefined, + }); + } + 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() { + if (this._onListChanged !== null && this._mustNotify) { + if (!this._hasObserver) { + Services.obs.addObserver(this, "ipc:content-created"); + Services.obs.addObserver(this, "ipc:content-shutdown"); + this._hasObserver = true; + } + } else if (this._hasObserver) { + Services.obs.removeObserver(this, "ipc:content-created"); + Services.obs.removeObserver(this, "ipc:content-shutdown"); + this._hasObserver = false; + } + } + + observe() { + if (this._mustNotify) { + this._onListChanged(); + this._mustNotify = false; + } + } +} + +exports.ProcessActorList = ProcessActorList; |