Index: content/browser/renderer_host/media/media_stream_manager.cc |
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc |
index 980ee4b22d5cd9589aec6d4cb85b8d5fdb8bc3aa..e1ce1e07b49360647b80528eb62ac587e975fef2 100644 |
--- a/content/browser/renderer_host/media/media_stream_manager.cc |
+++ b/content/browser/renderer_host/media/media_stream_manager.cc |
@@ -245,11 +245,20 @@ std::string MediaStreamManager::GenerateStreamForDevice( |
const GURL& security_origin) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ int target_render_process_id = -1; |
+ int target_render_view_id = -1; |
+ // We will post the request to the target render view, not the source (i.e. |
+ // source is an extension, and target is the tab we want to capture). |
+ DCHECK(WebContentsCaptureUtil::ExtractTabCaptureTarget( |
no longer working on chromium
2012/12/05 17:38:37
If you put it in DCHECK, the code won't run in rel
|
+ device_id, &target_render_process_id, &target_render_view_id)); |
+ DCHECK_NE(target_render_process_id, -1); |
+ DCHECK_NE(target_render_view_id, -1); |
+ |
// Create a new request based on options. |
DeviceRequest* request = new DeviceRequest(requester, options, |
DeviceRequest::GENERATE_STREAM, |
- render_process_id, |
- render_view_id, |
+ target_render_process_id, |
+ target_render_view_id, |
security_origin); |
const std::string& label = AddRequest(request); |
request->requested_device_id = device_id; |
@@ -282,8 +291,6 @@ std::string MediaStreamManager::GenerateStreamForDevice( |
request->setState(options.video_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
} |
- // TODO(xians): Figure out the way to handle tab capture request. |
- // Can we verify the devices here before sending the request to UI? |
HandleRequest(label); |
return label; |
@@ -585,10 +592,13 @@ void MediaStreamManager::PostRequestToUI(const std::string& label) { |
void MediaStreamManager::HandleRequest(const std::string& label) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
DeviceRequest* request = requests_[label]; |
- if ((IsAudioMediaType(request->options.audio_type) && |
- !audio_enumeration_cache_.valid) || |
- (IsVideoMediaType(request->options.video_type) && |
- !video_enumeration_cache_.valid)) { |
+ // We want to always post request to UI for tab capture to verify the request. |
+ if ((request->options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && |
+ request->options.video_type != MEDIA_TAB_VIDEO_CAPTURE) && |
+ ((IsAudioMediaType(request->options.audio_type) && |
+ !audio_enumeration_cache_.valid) || |
+ (IsVideoMediaType(request->options.video_type) && |
+ !video_enumeration_cache_.valid))) { |
// Enumerate the devices if there is no valid device lists to be used. |
StartEnumeration(request); |
} else { |
@@ -852,6 +862,7 @@ void MediaStreamManager::DevicesAccepted(const std::string& label, |
const StreamDeviceInfoArray& devices) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
DCHECK(!devices.empty()); |
+ |
DeviceRequests::iterator request_it = requests_.find(label); |
if (request_it == requests_.end()) { |
return; |
@@ -883,6 +894,12 @@ void MediaStreamManager::DevicesAccepted(const std::string& label, |
device_it != devices.end(); ++device_it) { |
StreamDeviceInfo device_info = *device_it; // Make a copy. |
+ // TODO(justinlin): Nicer way to do this? |
+ // Re-append the device_id since we lost it when posting request to UI. |
+ if (device_info.stream_type == content::MEDIA_TAB_VIDEO_CAPTURE || |
+ device_info.stream_type == content::MEDIA_TAB_AUDIO_CAPTURE) |
+ device_info.device_id = request->requested_device_id; |
+ |
// Set in_use to false to be able to track if this device has been |
// opened. in_use might be true if the device type can be used in more |
// than one session. |
@@ -987,22 +1004,8 @@ void MediaStreamManager::NotifyDevicesOpened(const DeviceRequest& request) { |
if (opened_devices.empty()) |
return; |
- int target_render_process_id = request.render_process_id; |
- int target_render_view_id = request.render_view_id; |
- |
- // For tab capture requests, we should notify the UI to update the renderer |
- // that is the target of the capture instead of the requester. |
- if (request.options.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || |
- request.options.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
- if (!WebContentsCaptureUtil::ExtractTabCaptureTarget( |
- request.requested_device_id, |
- &target_render_process_id, |
- &target_render_view_id)) |
- return; |
- } |
- |
- NotifyUIDevicesOpened(target_render_process_id, |
- target_render_view_id, |
+ NotifyUIDevicesOpened(request.render_process_id, |
+ request.render_view_id, |
opened_devices); |
} |
@@ -1013,22 +1016,8 @@ void MediaStreamManager::NotifyDevicesClosed(const DeviceRequest& request) { |
if (closed_devices.empty()) |
return; |
- int target_render_process_id = request.render_process_id; |
- int target_render_view_id = request.render_view_id; |
- |
- // For tab capture requests, we should notify the UI to update the renderer |
- // that is the target of the capture instead of the requester. |
- if (request.options.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || |
- request.options.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { |
- if (!WebContentsCaptureUtil::ExtractTabCaptureTarget( |
- request.requested_device_id, |
- &target_render_process_id, |
- &target_render_view_id)) |
- return; |
- } |
- |
- NotifyUIDevicesClosed(target_render_process_id, |
- target_render_view_id, |
+ NotifyUIDevicesClosed(request.render_process_id, |
+ request.render_view_id, |
closed_devices); |
} |