diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 65ea4b94be9c..e38770024de4 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -159,7 +159,6 @@ void MediaCaptureDevicesDispatcher::OnAudioStreamStopped( void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( int render_process_id, int render_view_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } } // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 2b7510939dd4..b55e73844f9b 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -6,6 +6,7 @@ #include "browser/media/media_capture_devices_dispatcher.h" +#include "content/public/browser/desktop_media_id.h" #include "content/public/common/media_stream_request.h" namespace brightray { @@ -47,6 +48,15 @@ MediaStreamDevicesController::~MediaStreamDevicesController() { } bool MediaStreamDevicesController::TakeAction() { + // Do special handling of desktop screen cast. + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || + request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + HandleUserMediaRequest(); + return true; + } + // Deny the request if there is no device attached to the OS. if (!HasAnyAvailableDevice()) { Deny(); @@ -147,4 +157,44 @@ void MediaStreamDevicesController::Deny() { scoped_ptr()); } +void MediaStreamDevicesController::HandleUserMediaRequest() { + content::MediaStreamDevices devices; + + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_TAB_AUDIO_CAPTURE, "", "")); + } + if (request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_TAB_VIDEO_CAPTURE, "", "")); + } + if (request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_LOOPBACK_AUDIO_CAPTURE, "loopback", "System Audio")); + } + if (request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + content::DesktopMediaID screen_id; + // If the device id wasn't specified then this is a screen capture request + // (i.e. chooseDesktopMedia() API wasn't used to generate device id). + if (request_.requested_video_device_id.empty()) { + screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, + -1 /* kFullDesktopScreenId */); + } else { + screen_id = + content::DesktopMediaID::Parse(request_.requested_video_device_id); + } + + devices.push_back( + content::MediaStreamDevice(content::MEDIA_DESKTOP_VIDEO_CAPTURE, + screen_id.ToString(), "Screen")); + } + + content::MediaResponseCallback cb = callback_; + callback_.Reset(); + cb.Run(devices, + devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : + content::MEDIA_DEVICE_OK, + scoped_ptr()); +} + } // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index 9100fa4e27ee..e77af4770271 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -26,6 +26,9 @@ class MediaStreamDevicesController { void Deny(); private: + // Handle the request of desktop or tab screen cast. + void HandleUserMediaRequest(); + // The original request for access to devices. const content::MediaStreamRequest request_;