Bug 940045 - Part 4: Support multiple requestURL in one process. r=vingtetun

This commit is contained in:
Shih-Chiang Chien 2013-11-26 14:22:23 +08:00
parent 5997ad7b8c
commit 5b16cf3343

View File

@ -1265,11 +1265,10 @@ window.addEventListener('ContentStart', function update_onContentStart() {
(function recordingStatusTracker() {
// Recording status is tracked per process with following data structure:
// {<processId>: {count: <N>,
// requestURL: <requestURL>,
// isApp: <isApp>,
// audioCount: <N>,
// videoCount: <N>}}
// {<processId>: {<requestURL>: {isApp: <isApp>,
// count: <N>,
// audioCount: <N>,
// videoCount: <N>}}
let gRecordingActiveProcesses = {};
let recordingHandler = function(aSubject, aTopic, aData) {
@ -1277,58 +1276,88 @@ window.addEventListener('ContentStart', function update_onContentStart() {
let processId = (props.hasKey('childID')) ? props.get('childID')
: 'main';
if (processId && !gRecordingActiveProcesses.hasOwnProperty(processId)) {
gRecordingActiveProcesses[processId] = {count: 0,
requestURL: props.get('requestURL'),
isApp: props.get('isApp'),
audioCount: 0,
videoCount: 0 };
gRecordingActiveProcesses[processId] = {};
}
let currentActive = gRecordingActiveProcesses[processId];
let wasActive = (currentActive['count'] > 0);
let wasAudioActive = (currentActive['audioCount'] > 0);
let wasVideoActive = (currentActive['videoCount'] > 0);
let commandHandler = function (requestURL, command) {
let currentProcess = gRecordingActiveProcesses[processId];
let currentActive = currentProcess[requestURL];
let wasActive = (currentActive['count'] > 0);
let wasAudioActive = (currentActive['audioCount'] > 0);
let wasVideoActive = (currentActive['videoCount'] > 0);
switch (command.type) {
case 'starting':
currentActive['count']++;
currentActive['audioCount'] += (command.isAudio) ? 1 : 0;
currentActive['videoCount'] += (command.isVideo) ? 1 : 0;
break;
case 'shutdown':
currentActive['count']--;
currentActive['audioCount'] -= (command.isAudio) ? 1 : 0;
currentActive['videoCount'] -= (command.isVideo) ? 1 : 0;
break;
case 'content-shutdown':
currentActive['count'] = 0;
currentActive['audioCount'] = 0;
currentActive['videoCount'] = 0;
break;
}
if (currentActive['count'] > 0) {
currentProcess[requestURL] = currentActive;
} else {
delete currentProcess[requestURL];
}
// 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: isActive,
requestURL: requestURL,
isApp: currentActive['isApp'],
isAudio: isAudioActive,
isVideo: isVideoActive
});
}
};
switch (aData) {
case 'starting':
currentActive['count']++;
currentActive['audioCount'] += (props.get('isAudio')) ? 1 : 0;
currentActive['videoCount'] += (props.get('isVideo')) ? 1 : 0;
break;
case 'shutdown':
currentActive['count']--;
currentActive['audioCount'] -= (props.get('isAudio')) ? 1 : 0;
currentActive['videoCount'] -= (props.get('isVideo')) ? 1 : 0;
// create page record if it is not existed yet.
let requestURL = props.get('requestURL');
if (requestURL &&
!gRecordingActiveProcesses[processId].hasOwnProperty(requestURL)) {
gRecordingActiveProcesses[processId][requestURL] = {isApp: props.get('isApp'),
count: 0,
audioCount: 0,
videoCount: 0};
}
commandHandler(requestURL, { type: aData,
isAudio: props.get('isAudio'),
isVideo: props.get('isVideo')});
break;
case 'content-shutdown':
currentActive['count'] = 0;
currentActive['audioCount'] = 0;
currentActive['videoCount'] = 0;
// iterate through all the existing active processes
Object.keys(gRecordingActiveProcesses[processId]).foreach(function(requestURL) {
commandHandler(requestURL, { type: aData,
isAudio: true,
isVideo: true});
});
break;
}
if (currentActive['count'] > 0) {
gRecordingActiveProcesses[processId] = currentActive;
} else {
// clean up process record if no page record in it.
if (Object.keys(gRecordingActiveProcesses[processId]).length == 0) {
delete gRecordingActiveProcesses[processId];
}
// 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: isActive,
requestURL: currentActive['requestURL'],
isApp: currentActive['isApp'],
isAudio: isAudioActive,
isVideo: isVideoActive
});
}
};
Services.obs.addObserver(recordingHandler, 'recording-device-events', false);
Services.obs.addObserver(recordingHandler, 'recording-device-ipc-events', false);