diff options
author | justinlin@chromium.org <justinlin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 08:53:04 +0000 |
---|---|---|
committer | justinlin@chromium.org <justinlin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 08:53:04 +0000 |
commit | b15724d6caeaafefd726fd6e3316621772e4e06d (patch) | |
tree | 10b48f110505833d6c40982172ea1f61803604ab /content | |
parent | 8242f70436a0ff70aa2cf7ee4a8e51c2c9646d03 (diff) | |
download | chromium_src-b15724d6caeaafefd726fd6e3316621772e4e06d.zip chromium_src-b15724d6caeaafefd726fd6e3316621772e4e06d.tar.gz chromium_src-b15724d6caeaafefd726fd6e3316621772e4e06d.tar.bz2 |
Make TabCapture requests use the target render process and render view id's for UI permissions.
BUG= 162097
Review URL: https://chromiumcodereview.appspot.com/11451006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
3 files changed, 33 insertions, 44 deletions
diff --git a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc index 3fe7891..5aab3e5 100644 --- a/content/browser/renderer_host/media/media_stream_dispatcher_host.cc +++ b/content/browser/renderer_host/media/media_stream_dispatcher_host.cc @@ -142,15 +142,15 @@ void MediaStreamDispatcherHost::OnGenerateStream( std::string label; if (components.audio_type == MEDIA_TAB_AUDIO_CAPTURE || components.video_type == MEDIA_TAB_VIDEO_CAPTURE) { - DCHECK(!components.video_device_id.empty()); - - // Append our tab capture device id scheme. + // Append our tab capture device id scheme. It's OK if both device_id's + // are empty since we check their validity in GenerateStreamForDevice. // TODO(justinlin): This is kind of a hack, but the plumbing for audio // streams is too complicated to plumb in by type. Will revisit once it's // refactored. http://crbug.com/163100 const std::string& device_id = WebContentsCaptureUtil::AppendWebContentsDeviceScheme( - components.video_device_id); + components.video_device_id.empty() ? + components.video_device_id : components.audio_device_id); // TODO(justinlin): Cleanup/get rid of GenerateStreamForDevice and merge // with the regular GenerateStream. diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index 864e999..14f7b0e 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -248,30 +248,40 @@ 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). + bool has_valid_device_id = WebContentsCaptureUtil::ExtractTabCaptureTarget( + device_id, &target_render_process_id, &target_render_view_id); + // 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; - // Get user confirmation to use the capture device. - PostRequestToUI(label); - - if (!security_origin.SchemeIs(kExtensionScheme) || + if (!has_valid_device_id || + !security_origin.SchemeIs(kExtensionScheme) || (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && options.audio_type != MEDIA_NO_SERVICE) || (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && options.video_type != MEDIA_NO_SERVICE)) { LOG(ERROR) << "Invalid request or used tab capture outside extension API."; + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind(&MediaStreamManager::CancelRequest, base::Unretained(this), label)); return label; } + // Get user confirmation to use the capture device. + PostRequestToUI(label); + // TODO(miu): We should ask the device manager whether a device with id // |device_id| actually exists. Note that no such MediaStreamProvider API for // this currently exists. Also, we don't have a user-friendly device name for @@ -583,7 +593,6 @@ std::string MediaStreamManager::AddRequest(DeviceRequest* request) { void MediaStreamManager::PostRequestToUI(const std::string& label) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DeviceRequest* request = requests_[label]; // Get user confirmation to use capture devices. ui_controller_->MakeUIRequest(label, @@ -859,6 +868,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. @@ -937,22 +952,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); } @@ -963,22 +964,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); } diff --git a/content/browser/renderer_host/media/web_contents_capture_util.cc b/content/browser/renderer_host/media/web_contents_capture_util.cc index 505364a..46b7376 100644 --- a/content/browser/renderer_host/media/web_contents_capture_util.cc +++ b/content/browser/renderer_host/media/web_contents_capture_util.cc @@ -38,7 +38,9 @@ bool WebContentsCaptureUtil::ExtractTabCaptureTarget( const std::string& device_id_param, int* render_process_id, int* render_view_id) { - DCHECK(IsWebContentsDeviceId(device_id_param)); + if (!IsWebContentsDeviceId(device_id_param)) + return false; + const std::string device_id = device_id_param.substr( arraysize(kVirtualDeviceScheme) - 1); |