2015-12-03 17:42:34 +03:00
|
|
|
/* 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";
|
|
|
|
|
2019-10-10 00:17:44 +03:00
|
|
|
const { Cc } = require("chrome");
|
|
|
|
const Services = require("Services");
|
2015-12-03 17:42:34 +03:00
|
|
|
|
|
|
|
loader.lazyGetter(this, "ppmm", () => {
|
2018-03-01 22:19:56 +03:00
|
|
|
return Cc["@mozilla.org/parentprocessmessagemanager;1"].getService();
|
2015-12-03 17:42:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
function ProcessActorList() {
|
|
|
|
this._actors = new Map();
|
|
|
|
this._onListChanged = null;
|
|
|
|
this._mustNotify = false;
|
2019-10-10 00:17:44 +03:00
|
|
|
this._hasObserver = false;
|
2015-12-03 17:42:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ProcessActorList.prototype = {
|
2018-03-12 21:24:38 +03:00
|
|
|
getList: function() {
|
2018-06-01 13:36:09 +03:00
|
|
|
const processes = [];
|
2015-12-03 17:42:34 +03:00
|
|
|
for (let i = 0; i < ppmm.childCount; i++) {
|
2019-10-09 23:52:47 +03:00
|
|
|
const mm = ppmm.getChildAt(i);
|
2015-12-03 17:42:34 +03:00
|
|
|
processes.push({
|
2019-10-09 23:52:47 +03:00
|
|
|
// 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,
|
2017-01-16 20:51:00 +03:00
|
|
|
// TODO: exposes process message manager on frameloaders in order to compute this
|
|
|
|
tabCount: undefined,
|
2015-12-03 17:42:34 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
2018-03-12 21:24:38 +03:00
|
|
|
_checkListening: function() {
|
2015-12-03 17:42:34 +03:00
|
|
|
if (this._onListChanged !== null && this._mustNotify) {
|
2019-10-10 00:17:44 +03:00
|
|
|
if (!this._hasObserver) {
|
|
|
|
Services.obs.addObserver(this, "ipc:content-created");
|
|
|
|
Services.obs.addObserver(this, "ipc:content-shutdown");
|
|
|
|
this._hasObserver = true;
|
2015-12-03 17:42:34 +03:00
|
|
|
}
|
2019-10-10 00:17:44 +03:00
|
|
|
} else if (this._hasObserver) {
|
|
|
|
Services.obs.removeObserver(this, "ipc:content-created");
|
|
|
|
Services.obs.removeObserver(this, "ipc:content-shutdown");
|
|
|
|
this._hasObserver = false;
|
2015-12-03 17:42:34 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-10 00:17:44 +03:00
|
|
|
observe() {
|
2015-12-03 17:42:34 +03:00
|
|
|
if (this._mustNotify) {
|
|
|
|
this._onListChanged();
|
|
|
|
this._mustNotify = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.ProcessActorList = ProcessActorList;
|