diff options
author | pastarmovj@google.com <pastarmovj@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-13 14:07:05 +0000 |
---|---|---|
committer | pastarmovj@google.com <pastarmovj@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-13 14:07:05 +0000 |
commit | e3d733fd25129e9c20f8047fd3c2bbed065d1b19 (patch) | |
tree | 42659e0a0ea8be0619103800501015c7f9f12ba7 /content | |
parent | 25c4c3a42d5ff285878fc2ec3c3bc5cd07cc83ed (diff) | |
download | chromium_src-e3d733fd25129e9c20f8047fd3c2bbed065d1b19.zip chromium_src-e3d733fd25129e9c20f8047fd3c2bbed065d1b19.tar.gz chromium_src-e3d733fd25129e9c20f8047fd3c2bbed065d1b19.tar.bz2 |
Make sure that all OpenDevice requests are scrutinized against the audio and video policies.
BUG=159404
TEST=unit_tests,browser_tests,Manually by setting the policy and observing flapper obey it.
Review URL: https://codereview.chromium.org/11446042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172877 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
6 files changed, 48 insertions, 48 deletions
diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index 02575b3..062423a 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -64,16 +64,9 @@ static bool Requested(const StreamOptions& options, // TODO(xians): Merge DeviceRequest with MediaStreamRequest. class MediaStreamManager::DeviceRequest { public: - enum RequestType { - DEVICE_ACCESS = 0, - GENERATE_STREAM, - ENUMERATE_DEVICES, - OPEN_DEVICE - }; - DeviceRequest() : requester(NULL), - type(GENERATE_STREAM), + type(MEDIA_GENERATE_STREAM), render_process_id(-1), render_view_id(-1), state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { @@ -81,7 +74,7 @@ class MediaStreamManager::DeviceRequest { DeviceRequest(MediaStreamRequester* requester, const StreamOptions& request_options, - RequestType request_type, + MediaStreamRequestType request_type, int render_process_id, int render_view_id, const GURL& request_security_origin) @@ -129,7 +122,7 @@ class MediaStreamManager::DeviceRequest { MediaStreamRequester* requester; // Can be NULL. StreamOptions options; - RequestType type; + MediaStreamRequestType type; int render_process_id; int render_view_id; GURL security_origin; @@ -202,7 +195,7 @@ std::string MediaStreamManager::MakeMediaAccessRequest( // Create a new request based on options. DeviceRequest* request = new DeviceRequest(NULL, options, - DeviceRequest::DEVICE_ACCESS, + MEDIA_DEVICE_ACCESS, render_process_id, render_view_id, security_origin); @@ -229,7 +222,7 @@ std::string MediaStreamManager::GenerateStream( // Create a new request based on options. DeviceRequest* request = new DeviceRequest(requester, options, - DeviceRequest::GENERATE_STREAM, + MEDIA_GENERATE_STREAM, render_process_id, render_view_id, security_origin); @@ -266,7 +259,7 @@ std::string MediaStreamManager::GenerateStreamForDevice( // Create a new request based on options. DeviceRequest* request = new DeviceRequest(requester, options, - DeviceRequest::GENERATE_STREAM, + MEDIA_GENERATE_STREAM, target_render_process_id, target_render_view_id, security_origin); @@ -334,7 +327,7 @@ void MediaStreamManager::StopGeneratedStream(const std::string& label) { // Find the request and close all open devices for the request. DeviceRequests::iterator it = requests_.find(label); if (it != requests_.end()) { - if (it->second->type == DeviceRequest::ENUMERATE_DEVICES) { + if (it->second->type == MEDIA_ENUMERATE_DEVICES) { StopEnumerateDevices(label); return; } @@ -346,7 +339,7 @@ void MediaStreamManager::StopGeneratedStream(const std::string& label) { device_it != request->devices.end(); ++device_it) { GetDeviceManager(device_it->stream_type)->Close(device_it->session_id); } - if (request->type == DeviceRequest::GENERATE_STREAM && + if (request->type == MEDIA_GENERATE_STREAM && RequestDone(*request)) { // Notify observers that this device is being closed. for (int i = MEDIA_NO_SERVICE + 1; i != NUM_MEDIA_TYPES; ++i) { @@ -400,7 +393,7 @@ std::string MediaStreamManager::EnumerateDevices( DeviceRequest* request = new DeviceRequest(requester, options, - DeviceRequest::ENUMERATE_DEVICES, + MEDIA_ENUMERATE_DEVICES, render_process_id, render_view_id, security_origin); @@ -428,7 +421,7 @@ void MediaStreamManager::StopEnumerateDevices(const std::string& label) { DeviceRequests::iterator it = requests_.find(label); if (it != requests_.end()) { - DCHECK_EQ(it->second->type, DeviceRequest::ENUMERATE_DEVICES); + DCHECK_EQ(it->second->type, MEDIA_ENUMERATE_DEVICES); // Delete the DeviceRequest. scoped_ptr<DeviceRequest> request(it->second); requests_.erase(it); @@ -459,7 +452,7 @@ std::string MediaStreamManager::OpenDevice( DeviceRequest* request = new DeviceRequest(requester, options, - DeviceRequest::OPEN_DEVICE, + MEDIA_OPEN_DEVICE, render_process_id, render_view_id, security_origin); @@ -467,6 +460,8 @@ std::string MediaStreamManager::OpenDevice( const std::string& label = AddRequest(request); StartEnumeration(request); + PostRequestToUI(label); + return label; } @@ -587,7 +582,8 @@ void MediaStreamManager::PostRequestToUI(const std::string& label) { request->render_process_id, request->render_view_id, request->options, - request->security_origin); + request->security_origin, + request->type); } void MediaStreamManager::HandleRequest(const std::string& label) { @@ -692,10 +688,10 @@ void MediaStreamManager::Opened(MediaStreamType stream_type, } switch (request->type) { - case DeviceRequest::OPEN_DEVICE: + case MEDIA_OPEN_DEVICE: request->requester->DeviceOpened(label, devices->front()); break; - case DeviceRequest::GENERATE_STREAM: { + case MEDIA_GENERATE_STREAM: { // Partition the array of devices into audio vs video. StreamDeviceInfoArray audio_devices, video_devices; for (StreamDeviceInfoArray::const_iterator device_it = devices->begin(); @@ -755,7 +751,7 @@ void MediaStreamManager::DevicesEnumerated( if (it->second->state(stream_type) == MEDIA_REQUEST_STATE_REQUESTED && Requested(it->second->options, stream_type)) { - if (it->second->type != DeviceRequest::ENUMERATE_DEVICES) + if (it->second->type != MEDIA_ENUMERATE_DEVICES) it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); label_list.push_back(it->first); } @@ -764,26 +760,10 @@ void MediaStreamManager::DevicesEnumerated( it != label_list.end(); ++it) { DeviceRequest* request = requests_[*it]; switch (request->type) { - case DeviceRequest::ENUMERATE_DEVICES: + case MEDIA_ENUMERATE_DEVICES: if (need_update_clients && request->requester) request->requester->DevicesEnumerated(*it, devices); break; - case DeviceRequest::OPEN_DEVICE: - DCHECK(!request->requested_device_id.empty()); - for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); - device_it != devices.end(); ++device_it) { - if (request->requested_device_id == device_it->device_id) { - StreamDeviceInfo device = *device_it; - device.in_use = false; - device.session_id = - GetDeviceManager(device_it->stream_type)->Open(device); - request->SetState(device_it->stream_type, - MEDIA_REQUEST_STATE_OPENING); - request->devices.push_back(device); - break; - } - } - break; default: if (request->state(request->options.audio_type) == MEDIA_REQUEST_STATE_REQUESTED || @@ -868,7 +848,7 @@ void MediaStreamManager::DevicesAccepted(const std::string& label, return; } - if (request_it->second->type == DeviceRequest::DEVICE_ACCESS) { + if (request_it->second->type == MEDIA_DEVICE_ACCESS) { scoped_ptr<DeviceRequest> request(request_it->second); if (!request->callback.is_null()) { // Map the devices to MediaStreamDevices. @@ -939,7 +919,7 @@ void MediaStreamManager::SettingsError(const std::string& label) { if (request->requester) request->requester->StreamGenerationFailed(label); - if (request->type == DeviceRequest::DEVICE_ACCESS && + if (request->type == MEDIA_DEVICE_ACCESS && !request->callback.is_null()) { request->callback.Run(label, MediaStreamDevices()); } diff --git a/content/browser/renderer_host/media/media_stream_ui_controller.cc b/content/browser/renderer_host/media/media_stream_ui_controller.cc index 0190936..03ffaff 100644 --- a/content/browser/renderer_host/media/media_stream_ui_controller.cc +++ b/content/browser/renderer_host/media/media_stream_ui_controller.cc @@ -71,9 +71,10 @@ class MediaStreamRequestForUI : public MediaStreamRequest { MediaStreamRequestForUI(int render_pid, int render_vid, const GURL& origin, - const StreamOptions& options) - : MediaStreamRequest(render_pid, render_vid, origin, options.audio_type, - options.video_type), + const StreamOptions& options, + MediaStreamRequestType request_type) + : MediaStreamRequest(render_pid, render_vid, origin, request_type, + options.audio_type, options.video_type), posted_task(false) { DCHECK(IsAudioMediaType(options.audio_type) || IsVideoMediaType(options.video_type)); @@ -124,14 +125,14 @@ void MediaStreamUIController::MakeUIRequest( int render_process_id, int render_view_id, const StreamOptions& request_options, - const GURL& security_origin) { + const GURL& security_origin, MediaStreamRequestType request_type) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // Create a new request. if (!requests_.insert( std::make_pair(label, new MediaStreamRequestForUI( render_process_id, render_view_id, security_origin, - request_options))).second) { + request_options, request_type))).second) { NOTREACHED(); } diff --git a/content/browser/renderer_host/media/media_stream_ui_controller.h b/content/browser/renderer_host/media/media_stream_ui_controller.h index 26777a5..1d0cf00 100644 --- a/content/browser/renderer_host/media/media_stream_ui_controller.h +++ b/content/browser/renderer_host/media/media_stream_ui_controller.h @@ -44,7 +44,8 @@ class CONTENT_EXPORT MediaStreamUIController { int render_process_id, int render_view_id, const StreamOptions& stream_components, - const GURL& security_origin); + const GURL& security_origin, + MediaStreamRequestType request_type); // Called to cancel a pending UI request of capture device access when the // user has no action for the media stream InfoBar. diff --git a/content/browser/renderer_host/media/media_stream_ui_controller_unittest.cc b/content/browser/renderer_host/media/media_stream_ui_controller_unittest.cc index 2bbfb70..9f728db 100644 --- a/content/browser/renderer_host/media/media_stream_ui_controller_unittest.cc +++ b/content/browser/renderer_host/media/media_stream_ui_controller_unittest.cc @@ -62,7 +62,8 @@ class MediaStreamDeviceUIControllerTest dummy_render_process_id, dummy_render_view_id, components, - security_origin); + security_origin, + MEDIA_GENERATE_STREAM); } scoped_ptr<MessageLoop> message_loop_; diff --git a/content/public/common/media_stream_request.cc b/content/public/common/media_stream_request.cc index 622b18af..3113ddb 100644 --- a/content/public/common/media_stream_request.cc +++ b/content/public/common/media_stream_request.cc @@ -31,11 +31,13 @@ MediaStreamRequest::MediaStreamRequest( int render_process_id, int render_view_id, const GURL& security_origin, + MediaStreamRequestType request_type, MediaStreamDeviceType audio_type, MediaStreamDeviceType video_type) : render_process_id(render_process_id), render_view_id(render_view_id), security_origin(security_origin), + request_type(request_type), audio_type(audio_type), video_type(video_type) { } diff --git a/content/public/common/media_stream_request.h b/content/public/common/media_stream_request.h index 90210c4..497a163 100644 --- a/content/public/common/media_stream_request.h +++ b/content/public/common/media_stream_request.h @@ -30,6 +30,14 @@ enum MediaStreamDeviceType { NUM_MEDIA_TYPES }; +// Types of media stream requests that can be made to the media controller. +enum MediaStreamRequestType { + MEDIA_DEVICE_ACCESS = 0, + MEDIA_GENERATE_STREAM, + MEDIA_ENUMERATE_DEVICES, + MEDIA_OPEN_DEVICE +}; + // Convenience predicates to determine whether the given type represents some // audio or some video device. CONTENT_EXPORT bool IsAudioMediaType(MediaStreamDeviceType type); @@ -66,6 +74,7 @@ struct CONTENT_EXPORT MediaStreamRequest { int render_process_id, int render_view_id, const GURL& security_origin, + MediaStreamRequestType request_type, MediaStreamDeviceType audio_type, MediaStreamDeviceType video_type); @@ -80,6 +89,12 @@ struct CONTENT_EXPORT MediaStreamRequest { // The WebKit security origin for the current request (e.g. "html5rocks.com"). GURL security_origin; + // Stores the type of request that was made to the media controller. Right now + // this is only used to destinguish between WebRTC and Pepper requests, as the + // latter should not be subject to user approval but only to policy check. + // Pepper requests are signified by the |MEDIA_OPEN_DEVICE| value. + MediaStreamRequestType request_type; + // Flag to indicate if the request contains audio. MediaStreamDeviceType audio_type; |