2016-11-02 02:02:43 +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/. */
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import('resource://gre/modules/Services.jsm');
|
2016-11-02 02:02:43 +03:00
|
|
|
|
|
|
|
// Fills up aProcesses until max and then selects randomly from the available
|
|
|
|
// ones.
|
|
|
|
function RandomSelector() {
|
|
|
|
}
|
|
|
|
|
|
|
|
RandomSelector.prototype = {
|
|
|
|
classID: Components.ID("{c616fcfd-9737-41f1-aa74-cee72a38f91b}"),
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIContentProcessProvider]),
|
2016-11-02 02:02:43 +03:00
|
|
|
|
2017-03-30 19:44:20 +03:00
|
|
|
provideProcess(aType, aOpener, aProcesses, aCount, aMaxCount) {
|
|
|
|
if (aCount < aMaxCount) {
|
2016-11-02 02:02:43 +03:00
|
|
|
return Ci.nsIContentProcessProvider.NEW_PROCESS;
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:44:20 +03:00
|
|
|
let startIdx = Math.floor(Math.random() * aMaxCount);
|
2016-11-02 02:02:43 +03:00
|
|
|
let curIdx = startIdx;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (aProcesses[curIdx].opener === aOpener) {
|
|
|
|
return curIdx;
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:44:20 +03:00
|
|
|
curIdx = (curIdx + 1) % aMaxCount;
|
2016-11-02 02:02:43 +03:00
|
|
|
} while (curIdx !== startIdx);
|
|
|
|
|
|
|
|
return Ci.nsIContentProcessProvider.NEW_PROCESS;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-03-07 22:00:28 +03:00
|
|
|
// Fills up aProcesses until max and then selects one from the available
|
|
|
|
// ones that host the least number of tabs.
|
|
|
|
function MinTabSelector() {
|
|
|
|
}
|
|
|
|
|
|
|
|
MinTabSelector.prototype = {
|
|
|
|
classID: Components.ID("{2dc08eaf-6eef-4394-b1df-a3a927c1290b}"),
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIContentProcessProvider]),
|
2017-03-07 22:00:28 +03:00
|
|
|
|
2017-03-30 19:44:20 +03:00
|
|
|
provideProcess(aType, aOpener, aProcesses, aCount, aMaxCount) {
|
|
|
|
if (aCount < aMaxCount) {
|
2017-03-07 22:00:28 +03:00
|
|
|
return Ci.nsIContentProcessProvider.NEW_PROCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
let min = Number.MAX_VALUE;
|
|
|
|
let candidate = Ci.nsIContentProcessProvider.NEW_PROCESS;
|
|
|
|
|
2017-03-30 19:44:20 +03:00
|
|
|
// Note, that at this point aMaxCount is in the valid range and
|
|
|
|
// the reason for not using aCount here is because if we keep
|
|
|
|
// processes alive for testing but want a test to use only single
|
|
|
|
// content process we can just keep relying on dom.ipc.processCount = 1
|
|
|
|
// this way.
|
|
|
|
for (let i = 0; i < aMaxCount; i++) {
|
2017-03-07 22:00:28 +03:00
|
|
|
let process = aProcesses[i];
|
|
|
|
let tabCount = process.tabCount;
|
|
|
|
if (process.opener === aOpener && tabCount < min) {
|
|
|
|
min = tabCount;
|
|
|
|
candidate = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return candidate;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
var components = [RandomSelector, MinTabSelector];
|
2016-11-02 02:02:43 +03:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|