diff options
-rw-r--r-- | chrome/browser/media/media_stream_devices_controller.cc | 57 | ||||
-rw-r--r-- | chrome/browser/media/media_stream_devices_controller.h | 10 | ||||
-rw-r--r-- | content/browser/renderer_host/media/media_stream_manager.cc | 28 | ||||
-rw-r--r-- | content/browser/renderer_host/media/video_capture_manager.cc | 29 | ||||
-rw-r--r-- | content/common/media/media_stream_options.cc | 1 | ||||
-rw-r--r-- | content/common/media/media_stream_options.h | 1 | ||||
-rw-r--r-- | content/public/common/content_switches.cc | 4 | ||||
-rw-r--r-- | content/public/common/content_switches.h | 1 | ||||
-rw-r--r-- | content/public/common/media_stream_request.cc | 3 | ||||
-rw-r--r-- | content/public/common/media_stream_request.h | 3 | ||||
-rw-r--r-- | content/renderer/media/media_stream_impl.cc | 44 |
11 files changed, 117 insertions, 64 deletions
diff --git a/chrome/browser/media/media_stream_devices_controller.cc b/chrome/browser/media/media_stream_devices_controller.cc index 22823c5..f9262ec 100644 --- a/chrome/browser/media/media_stream_devices_controller.cc +++ b/chrome/browser/media/media_stream_devices_controller.cc @@ -4,6 +4,7 @@ #include "chrome/browser/media/media_stream_devices_controller.h" +#include "base/command_line.h" #include "base/values.h" #include "chrome/browser/content_settings/content_settings_provider.h" #include "chrome/browser/content_settings/host_content_settings_map.h" @@ -14,6 +15,7 @@ #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/content_settings.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" @@ -43,15 +45,23 @@ MediaStreamDevicesController::MediaStreamDevicesController( content_settings_(content_settings), request_(request), callback_(callback), - has_audio_(content::IsAudioMediaType(request.audio_type)), - has_video_(content::IsVideoMediaType(request.video_type)) { + microphone_requested_( + request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE), + webcam_requested_( + request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE), + screen_capture_requested_( + request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE) { // Don't call GetDevicePolicy from the initializer list since the // implementation depends on member variables. - if (has_audio_ && GetDevicePolicy(prefs::kAudioCaptureAllowed) == ALWAYS_DENY) - has_audio_ = false; + if (microphone_requested_ && + GetDevicePolicy(prefs::kAudioCaptureAllowed) == ALWAYS_DENY) { + microphone_requested_ = false; + } - if (has_video_ && GetDevicePolicy(prefs::kVideoCaptureAllowed) == ALWAYS_DENY) - has_video_ = false; + if (webcam_requested_ && + GetDevicePolicy(prefs::kVideoCaptureAllowed) == ALWAYS_DENY) { + webcam_requested_ = false; + } } MediaStreamDevicesController::~MediaStreamDevicesController() {} @@ -127,15 +137,15 @@ void MediaStreamDevicesController::Accept(bool update_content_setting) { // Get the default devices for the request. content::MediaStreamDevices devices; - if (has_audio_ || has_video_) { + if (microphone_requested_ || webcam_requested_) { switch (request_.request_type) { case content::MEDIA_OPEN_DEVICE: // For open device request pick the desired device or fall back to the // first available of the given type. MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedDevice( request_.requested_device_id, - has_audio_, - has_video_, + microphone_requested_, + webcam_requested_, &devices); break; case content::MEDIA_DEVICE_ACCESS: @@ -144,8 +154,8 @@ void MediaStreamDevicesController::Accept(bool update_content_setting) { // Get the default devices for the request. MediaCaptureDevicesDispatcher::GetInstance()-> GetDefaultDevicesForProfile(profile_, - has_audio_, - has_video_, + microphone_requested_, + webcam_requested_, &devices); break; } @@ -154,6 +164,14 @@ void MediaStreamDevicesController::Accept(bool update_content_setting) { SetPermission(true); } + if (screen_capture_requested_ && + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableUserMediaScreenCapturing)) { + // Add screen capturer source if it was requested. + devices.push_back(content::MediaStreamDevice( + content::MEDIA_SCREEN_VIDEO_CAPTURE, "", "Screen")); + } + callback_.Run(devices); } @@ -193,9 +211,9 @@ bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { const char* policy_name; ContentSettingsType settings_type; } device_checks[] = { - { has_audio_, prefs::kAudioCaptureAllowed, + { microphone_requested_, prefs::kAudioCaptureAllowed, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC }, - { has_video_, prefs::kVideoCaptureAllowed, + { webcam_requested_, prefs::kVideoCaptureAllowed, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA }, }; @@ -216,11 +234,14 @@ bool MediaStreamDevicesController::IsRequestAllowedByDefault() const { // settings allow the request by default. } + // TODO(sergeyu): Add content setting and UI notifications for screen + // capturing and use them when screen_capture_requested_==true. + return true; } bool MediaStreamDevicesController::IsRequestBlockedByDefault() const { - if (has_audio_ && + if (microphone_requested_ && profile_->GetHostContentSettingsMap()->GetContentSetting( request_.security_origin, request_.security_origin, @@ -229,7 +250,7 @@ bool MediaStreamDevicesController::IsRequestBlockedByDefault() const { return false; } - if (has_video_ && + if (webcam_requested_ && profile_->GetHostContentSettingsMap()->GetContentSetting( request_.security_origin, request_.security_origin, @@ -305,15 +326,15 @@ void MediaStreamDevicesController::SetPermission(bool allowed) const { ContentSetting content_setting = allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; - if (has_audio_) { - profile_->GetHostContentSettingsMap()->SetContentSetting( + if (microphone_requested_) { + profile_->GetHostContentSettingsMap()->SetContentSetting( primary_pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), content_setting); } - if (has_video_) { + if (webcam_requested_) { profile_->GetHostContentSettingsMap()->SetContentSetting( primary_pattern, ContentSettingsPattern::Wildcard(), diff --git a/chrome/browser/media/media_stream_devices_controller.h b/chrome/browser/media/media_stream_devices_controller.h index e67f8bf..0b8fa7b 100644 --- a/chrome/browser/media/media_stream_devices_controller.h +++ b/chrome/browser/media/media_stream_devices_controller.h @@ -31,8 +31,8 @@ class MediaStreamDevicesController { bool DismissInfoBarAndTakeActionOnSettings(); // Public methods to be called by MediaStreamInfoBarDelegate; - bool has_audio() const { return has_audio_; } - bool has_video() const { return has_video_; } + bool has_audio() const { return microphone_requested_; } + bool has_video() const { return webcam_requested_; } const std::string& GetSecurityOriginSpec() const; void Accept(bool update_content_setting); void Deny(bool update_content_setting); @@ -91,8 +91,10 @@ class MediaStreamDevicesController { // audio/video devices was granted or not. content::MediaResponseCallback callback_; - bool has_audio_; - bool has_video_; + bool microphone_requested_; + bool webcam_requested_; + bool screen_capture_requested_; + DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); }; diff --git a/content/browser/renderer_host/media/media_stream_manager.cc b/content/browser/renderer_host/media/media_stream_manager.cc index 0db4d65..a4f4653 100644 --- a/content/browser/renderer_host/media/media_stream_manager.cc +++ b/content/browser/renderer_host/media/media_stream_manager.cc @@ -539,25 +539,17 @@ void MediaStreamManager::StartEnumeration(DeviceRequest* request) { // Start monitoring the devices when doing the first enumeration. if (!monitoring_started_ && base::SystemMonitor::Get()) { StartMonitoring(); + } - if (IsAudioMediaType(request->options.audio_type)) { - request->SetState(request->options.audio_type, - MEDIA_REQUEST_STATE_REQUESTED); - } - if (IsVideoMediaType(request->options.video_type)) { - request->SetState(request->options.video_type, - MEDIA_REQUEST_STATE_REQUESTED); - } - } else { - for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { - const MediaStreamType stream_type = static_cast<MediaStreamType>(i); - if (Requested(request->options, stream_type)) { - request->SetState(stream_type, MEDIA_REQUEST_STATE_REQUESTED); - DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); - if (active_enumeration_ref_count_[stream_type] == 0) { - ++active_enumeration_ref_count_[stream_type]; - GetDeviceManager(stream_type)->EnumerateDevices(stream_type); - } + // Start enumeration for devices of all requested device types. + for (int i = MEDIA_NO_SERVICE + 1; i < NUM_MEDIA_TYPES; ++i) { + const MediaStreamType stream_type = static_cast<MediaStreamType>(i); + if (Requested(request->options, stream_type)) { + request->SetState(stream_type, MEDIA_REQUEST_STATE_REQUESTED); + DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); + if (active_enumeration_ref_count_[stream_type] == 0) { + ++active_enumeration_ref_count_[stream_type]; + GetDeviceManager(stream_type)->EnumerateDevices(stream_type); } } } diff --git a/content/browser/renderer_host/media/video_capture_manager.cc b/content/browser/renderer_host/media/video_capture_manager.cc index 16d1041..36d7eda 100644 --- a/content/browser/renderer_host/media/video_capture_manager.cc +++ b/content/browser/renderer_host/media/video_capture_manager.cc @@ -7,14 +7,18 @@ #include <set> #include "base/bind.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/stl_util.h" +#include "base/threading/sequenced_worker_pool.h" #include "content/browser/renderer_host/media/video_capture_controller.h" #include "content/browser/renderer_host/media/video_capture_controller_event_handler.h" #include "content/browser/renderer_host/media/web_contents_video_capture_device.h" #include "content/public/browser/browser_thread.h" +#include "content/public/common/content_switches.h" #include "content/public/common/media_stream_request.h" #include "media/video/capture/fake_video_capture_device.h" +#include "media/video/capture/screen/screen_capture_device.h" #include "media/video/capture/video_capture_device.h" namespace content { @@ -163,17 +167,32 @@ void VideoCaptureManager::OnOpen(int capture_session_id, media::FakeVideoCaptureDevice::Create(vc_device_name); } else { switch (device.device.type) { - case MEDIA_DEVICE_VIDEO_CAPTURE: + case MEDIA_DEVICE_VIDEO_CAPTURE: { video_capture_device = media::VideoCaptureDevice::Create(vc_device_name); break; - case MEDIA_TAB_VIDEO_CAPTURE: + } + case MEDIA_TAB_VIDEO_CAPTURE: { video_capture_device = WebContentsVideoCaptureDevice::Create( vc_device_name.unique_id); break; - default: + } + case MEDIA_SCREEN_VIDEO_CAPTURE: { +#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) + CHECK(CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableUserMediaScreenCapturing)); + scoped_refptr<base::SequencedWorkerPool> blocking_pool = + BrowserThread::GetBlockingPool(); + video_capture_device = new media::ScreenCaptureDevice( + blocking_pool->GetSequencedTaskRunner( + blocking_pool->GetSequenceToken())); +#endif // defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN) + break; + } + default: { NOTIMPLEMENTED(); break; + } } } if (!video_capture_device) { @@ -386,6 +405,10 @@ void VideoCaptureManager::GetAvailableDevices( } break; + case MEDIA_SCREEN_VIDEO_CAPTURE: + device_names->clear(); + break; + default: NOTREACHED(); break; diff --git a/content/common/media/media_stream_options.cc b/content/common/media/media_stream_options.cc index fba8cb4..001fb3e 100644 --- a/content/common/media/media_stream_options.cc +++ b/content/common/media/media_stream_options.cc @@ -11,6 +11,7 @@ namespace content { const char kMediaStreamSource[] = "chromeMediaSource"; const char kMediaStreamSourceId[] = "chromeMediaSourceId"; const char kMediaStreamSourceTab[] = "tab"; +const char kMediaStreamSourceScreen[] = "screen"; StreamOptions::StreamOptions() : audio_type(MEDIA_NO_SERVICE), diff --git a/content/common/media/media_stream_options.h b/content/common/media/media_stream_options.h index 9fe3114..2868829 100644 --- a/content/common/media/media_stream_options.h +++ b/content/common/media/media_stream_options.h @@ -18,6 +18,7 @@ namespace content { CONTENT_EXPORT extern const char kMediaStreamSource[]; CONTENT_EXPORT extern const char kMediaStreamSourceId[]; CONTENT_EXPORT extern const char kMediaStreamSourceTab[]; +CONTENT_EXPORT extern const char kMediaStreamSourceScreen[]; // Callback to deliver the result of a media request. |label| is the string // to identify the request, diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 5143fca..1c64a02 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -334,6 +334,10 @@ const char kEnablePrivilegedWebGLExtensions[] = const char kEnablePruneGpuCommandBuffers[] = "enable-prune-gpu-command-buffers"; +// Enable screen capturing support for MediaStream API. +const char kEnableUserMediaScreenCapturing[] = + "enable-usermedia-screen-capturing"; + // Enables TLS cached info extension. const char kEnableSSLCachedInfo[] = "enable-ssl-cached-info"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index 12b1c2a..e7a3658 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -111,6 +111,7 @@ extern const char kDisableMediaSource[]; extern const char kDisableWebMediaPlayerMS[]; CONTENT_EXPORT extern const char kUseFakeDeviceForMediaStream[]; extern const char kEnableMonitorProfile[]; +extern const char kEnableUserMediaScreenCapturing[]; extern const char kEnablePinch[]; extern const char kEnablePreparsedJsCaching[]; CONTENT_EXPORT extern const char kEnablePrivilegedWebGLExtensions[]; diff --git a/content/public/common/media_stream_request.cc b/content/public/common/media_stream_request.cc index 8dced44..4584ed7 100644 --- a/content/public/common/media_stream_request.cc +++ b/content/public/common/media_stream_request.cc @@ -15,7 +15,8 @@ bool IsAudioMediaType(MediaStreamType type) { bool IsVideoMediaType(MediaStreamType type) { return (type == content::MEDIA_DEVICE_VIDEO_CAPTURE || - type == content::MEDIA_TAB_VIDEO_CAPTURE); + type == content::MEDIA_TAB_VIDEO_CAPTURE || + type == content::MEDIA_SCREEN_VIDEO_CAPTURE); } MediaStreamDevice::MediaStreamDevice() : type(MEDIA_NO_SERVICE) {} diff --git a/content/public/common/media_stream_request.h b/content/public/common/media_stream_request.h index 5ff24e2..0118f3b 100644 --- a/content/public/common/media_stream_request.h +++ b/content/public/common/media_stream_request.h @@ -27,6 +27,9 @@ enum MediaStreamType { MEDIA_TAB_AUDIO_CAPTURE, MEDIA_TAB_VIDEO_CAPTURE, + // Capture content of the screen. + MEDIA_SCREEN_VIDEO_CAPTURE, + NUM_MEDIA_TYPES }; diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc index be60760..eed5f3b 100644 --- a/content/renderer/media/media_stream_impl.cc +++ b/content/renderer/media/media_stream_impl.cc @@ -10,10 +10,10 @@ #include "base/string_number_conversions.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" -#include "content/renderer/media/media_stream_extra_data.h" -#include "content/renderer/media/media_stream_source_extra_data.h" #include "content/renderer/media/media_stream_dependency_factory.h" #include "content/renderer/media/media_stream_dispatcher.h" +#include "content/renderer/media/media_stream_extra_data.h" +#include "content/renderer/media/media_stream_source_extra_data.h" #include "content/renderer/media/rtc_video_decoder.h" #include "content/renderer/media/rtc_video_renderer.h" #include "content/renderer/media/video_capture_impl_manager.h" @@ -44,27 +44,31 @@ std::string GetMandatoryStreamConstraint( return UTF16ToUTF8(value); } -void UpdateOptionsIfTabMediaRequest( +void UpdateRequestOptions( const WebKit::WebUserMediaRequest& user_media_request, StreamOptions* options) { - if (options->audio_type != content::MEDIA_NO_SERVICE && - GetMandatoryStreamConstraint(user_media_request.audioConstraints(), - kMediaStreamSource) == - kMediaStreamSourceTab) { - options->audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; - options->audio_device_id = GetMandatoryStreamConstraint( - user_media_request.audioConstraints(), - kMediaStreamSourceId); + if (options->audio_type != content::MEDIA_NO_SERVICE) { + std::string audio_stream_source = GetMandatoryStreamConstraint( + user_media_request.audioConstraints(), kMediaStreamSource); + if (audio_stream_source == kMediaStreamSourceTab) { + options->audio_type = content::MEDIA_TAB_AUDIO_CAPTURE; + options->audio_device_id = GetMandatoryStreamConstraint( + user_media_request.audioConstraints(), + kMediaStreamSourceId); + } } - if (options->video_type != content::MEDIA_NO_SERVICE && - GetMandatoryStreamConstraint(user_media_request.videoConstraints(), - kMediaStreamSource) == - kMediaStreamSourceTab) { - options->video_type = content::MEDIA_TAB_VIDEO_CAPTURE; - options->video_device_id = GetMandatoryStreamConstraint( - user_media_request.videoConstraints(), - kMediaStreamSourceId); + if (options->video_type != content::MEDIA_NO_SERVICE) { + std::string video_stream_source = GetMandatoryStreamConstraint( + user_media_request.videoConstraints(), kMediaStreamSource); + if (video_stream_source == kMediaStreamSourceTab) { + options->video_type = content::MEDIA_TAB_VIDEO_CAPTURE; + options->video_device_id = GetMandatoryStreamConstraint( + user_media_request.videoConstraints(), + kMediaStreamSourceId); + } else if (video_stream_source == kMediaStreamSourceScreen) { + options->video_type = content::MEDIA_SCREEN_VIDEO_CAPTURE; + } } } @@ -170,7 +174,7 @@ void MediaStreamImpl::requestUserMedia( frame = user_media_request.ownerDocument().frame(); DCHECK(frame); - UpdateOptionsIfTabMediaRequest(user_media_request, &options); + UpdateRequestOptions(user_media_request, &options); } DVLOG(1) << "MediaStreamImpl::requestUserMedia(" << request_id << ", [ " |