Chromium Code Reviews| Index: chrome/browser/media/media_capture_devices_dispatcher.cc |
| diff --git a/chrome/browser/media/media_capture_devices_dispatcher.cc b/chrome/browser/media/media_capture_devices_dispatcher.cc |
| index 5c223849626a46338b2a6e3498843a0828b28b1e..78feca7d0b514c2b6e952f519de34f9b735286b2 100644 |
| --- a/chrome/browser/media/media_capture_devices_dispatcher.cc |
| +++ b/chrome/browser/media/media_capture_devices_dispatcher.cc |
| @@ -4,16 +4,24 @@ |
| #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| +#include "base/command_line.h" |
| +#include "base/logging.h" |
| #include "base/prefs/pref_service.h" |
| +#include "base/utf_string_conversions.h" |
| #include "chrome/browser/media/audio_stream_indicator.h" |
| #include "chrome/browser/media/media_stream_capture_indicator.h" |
| #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| +#include "chrome/browser/ui/simple_message_box.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| #include "components/user_prefs/pref_registry_syncable.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/media_devices_monitor.h" |
| #include "content/public/common/media_stream_request.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| using content::BrowserThread; |
| using content::MediaStreamDevices; |
| @@ -36,8 +44,19 @@ const content::MediaStreamDevice* FindDefaultDeviceWithId( |
| return &(*devices.begin()); |
| }; |
| -} // namespace |
| +// This is a short-term solution to allow testing of the the Screen Capture API |
| +// with Google Hangouts in M27. |
| +// TODO(sergeyu): Remove this whitelist as soon as possible. |
| +bool IsOriginWhitelistedForScreenCapture(const GURL& origin) { |
| +#if defined(OFFICIAL_BUILD) |
| + return origin.spec() == "https://staging.talkgadget.google.com/" || |
| + origin.spec() == "https://plus.google.com/"; |
| +#else |
| + return false; |
| +#endif |
| +} |
| +} // namespace |
| MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { |
| return Singleton<MediaCaptureDevicesDispatcher>::get(); |
| @@ -95,6 +114,50 @@ MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { |
| return video_devices_; |
| } |
| +void MediaCaptureDevicesDispatcher::RequestAccess( |
| + content::WebContents* web_contents, |
| + const content::MediaStreamRequest& request, |
| + const content::MediaResponseCallback& callback) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + if (request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE) { |
|
Peter Kasting
2013/03/23 01:25:54
Nit: Consider reversing this and then early-return
Sergey Ulanov
2013/03/23 01:43:38
Done.
|
| + bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableUserMediaScreenCapturing) || |
| + IsOriginWhitelistedForScreenCapture(request.security_origin); |
| + // Deny request automatically in the following cases: |
| + // 1. Screen capturing is not enabled via command line switch. |
| + // 2. Audio capture was requested (it's not supported yet). |
| + // 3. Request from a page that was not loaded from a secure origin. |
| + if (!screen_capture_enabled || |
| + request.audio_type != content::MEDIA_NO_SERVICE || |
| + !request.security_origin.SchemeIsSecure()) { |
| + callback.Run(content::MediaStreamDevices()); |
| + return; |
| + } |
| + |
| + string16 application_name = UTF8ToUTF16(request.security_origin.spec()); |
| + |
|
Peter Kasting
2013/03/23 01:25:54
Nit: Extra blank line
Sergey Ulanov
2013/03/23 01:43:38
Done.
|
| + chrome::MessageBoxResult result = chrome::ShowMessageBox( |
| + NULL, |
| + l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE, |
| + application_name), |
| + l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT, |
| + application_name), |
| + chrome::MESSAGE_BOX_TYPE_QUESTION); |
| + |
| + if (result == chrome::MESSAGE_BOX_RESULT_YES) { |
|
Peter Kasting
2013/03/23 01:25:54
Nit: Simpler:
content::MediaStreamDevices devic
Sergey Ulanov
2013/03/23 01:43:38
Done.
Peter Kasting
2013/03/23 01:46:17
Patch 9 doesn't actually show a change here? I th
|
| + content::MediaStreamDevices devices; |
| + devices.push_back(content::MediaStreamDevice( |
| + content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); |
| + callback.Run(devices); |
| + } else { |
| + callback.Run(content::MediaStreamDevices()); |
| + } |
| + } else { |
| + MediaStreamInfoBarDelegate::Create(web_contents, request, callback); |
| + } |
| +} |
| + |
| void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( |
| Profile* profile, |
| bool audio, |