Bug 926289 - Part 4, Separate recording status for each process. r=vingtetun,jesup.

This commit is contained in:
Shih-Chiang Chien 2013-10-25 20:04:57 -04:00
parent bc5f77ba8d
commit 7f01ae5f4d

View File

@ -1259,49 +1259,69 @@ window.addEventListener('ContentStart', function update_onContentStart() {
})();
(function recordingStatusTracker() {
let gRecordingActiveCount = 0;
// Recording status is tracked per process with following data structure:
// {<processId>: {count: <N>,
// requestURL: <requestURL>,
// isApp: <isApp>,
// audioCount: <N>,
// videoCount: <N>}}
let gRecordingActiveProcesses = {};
let recordingHandler = function(aSubject, aTopic, aData) {
let oldCount = gRecordingActiveCount;
let processId = (!aSubject) ? 'main'
: aSubject.QueryInterface(Ci.nsIPropertyBag2).get('childID');
let props = aSubject.QueryInterface(Ci.nsIPropertyBag2);
let processId = (props.hasKey('childID')) ? props.get('childID')
: 'main';
if (processId && !gRecordingActiveProcesses.hasOwnProperty(processId)) {
gRecordingActiveProcesses[processId] = 0;
gRecordingActiveProcesses[processId] = {count: 0,
requestURL: props.get('requestURL'),
isApp: props.get('isApp'),
audioCount: 0,
videoCount: 0 };
}
let currentActive = gRecordingActiveProcesses[processId];
let wasActive = (currentActive['count'] > 0);
let wasAudioActive = (currentActive['audioCount'] > 0);
let wasVideoActive = (currentActive['videoCount'] > 0);
switch (aData) {
case 'starting':
gRecordingActiveCount++;
currentActive++;
currentActive['count']++;
currentActive['audioCount'] += (props.get('isAudio')) ? 1 : 0;
currentActive['videoCount'] += (props.get('isVideo')) ? 1 : 0;
break;
case 'shutdown':
// Bug 928206 will make shutdown be sent even if no starting.
if (currentActive > 0) {
gRecordingActiveCount--;
currentActive--;
}
currentActive['count']--;
currentActive['audioCount'] -= (props.get('isAudio')) ? 1 : 0;
currentActive['videoCount'] -= (props.get('isVideo')) ? 1 : 0;
break;
case 'content-shutdown':
gRecordingActiveCount -= currentActive;
currentActive = 0;
currentActive['count'] = 0;
currentActive['audioCount'] = 0;
currentActive['videoCount'] = 0;
break;
}
if (currentActive > 0) {
if (currentActive['count'] > 0) {
gRecordingActiveProcesses[processId] = currentActive;
} else {
delete gRecordingActiveProcesses[processId];
}
// We need to track changes from N <-> 0
if ((oldCount === 0 && gRecordingActiveCount > 0) ||
(gRecordingActiveCount === 0 && oldCount > 0)) {
// We need to track changes if any active state is changed.
let isActive = (currentActive['count'] > 0);
let isAudioActive = (currentActive['audioCount'] > 0);
let isVideoActive = (currentActive['videoCount'] > 0);
if ((isActive != wasActive) ||
(isAudioActive != wasAudioActive) ||
(isVideoActive != wasVideoActive)) {
shell.sendChromeEvent({
type: 'recording-status',
active: (gRecordingActiveCount > 0)
active: isActive,
requestURL: currentActive['requestURL'],
isApp: currentActive['isApp'],
isAudio: isAudioActive,
isVideo: isVideoActive
});
}
};
@ -1310,9 +1330,8 @@ window.addEventListener('ContentStart', function update_onContentStart() {
Services.obs.addObserver(function(aSubject, aTopic, aData) {
// send additional recording events if content process is being killed
let props = aSubject.QueryInterface(Ci.nsIPropertyBag2);
let childId = aSubject.get('childID');
if (gRecordingActiveProcesses.hasOwnProperty(childId) >= 0) {
let processId = aSubject.QueryInterface(Ci.nsIPropertyBag2).get('childID');
if (gRecordingActiveProcesses.hasOwnProperty(processId)) {
Services.obs.notifyObservers(aSubject, 'recording-device-ipc-events', 'content-shutdown');
}
}, 'ipc:content-shutdown', false);