Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 5 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 8 #include "base/logging.h" | |
| 7 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/browser/media/audio_stream_indicator.h" | 11 #include "chrome/browser/media/audio_stream_indicator.h" |
| 9 #include "chrome/browser/media/media_stream_capture_indicator.h" | 12 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 10 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 13 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | |
| 16 #include "chrome/browser/ui/simple_message_box.h" | |
| 17 #include "chrome/common/chrome_switches.h" | |
| 12 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 13 #include "components/user_prefs/pref_registry_syncable.h" | 19 #include "components/user_prefs/pref_registry_syncable.h" |
| 14 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/media_devices_monitor.h" | 21 #include "content/public/browser/media_devices_monitor.h" |
| 16 #include "content/public/common/media_stream_request.h" | 22 #include "content/public/common/media_stream_request.h" |
| 23 #include "grit/generated_resources.h" | |
| 24 #include "ui/base/l10n/l10n_util.h" | |
| 17 | 25 |
| 18 using content::BrowserThread; | 26 using content::BrowserThread; |
| 19 using content::MediaStreamDevices; | 27 using content::MediaStreamDevices; |
| 20 | 28 |
| 21 namespace { | 29 namespace { |
| 22 | 30 |
| 23 const content::MediaStreamDevice* FindDefaultDeviceWithId( | 31 const content::MediaStreamDevice* FindDefaultDeviceWithId( |
| 24 const content::MediaStreamDevices& devices, | 32 const content::MediaStreamDevices& devices, |
| 25 const std::string& device_id) { | 33 const std::string& device_id) { |
| 26 if (devices.empty()) | 34 if (devices.empty()) |
| 27 return NULL; | 35 return NULL; |
| 28 | 36 |
| 29 content::MediaStreamDevices::const_iterator iter = devices.begin(); | 37 content::MediaStreamDevices::const_iterator iter = devices.begin(); |
| 30 for (; iter != devices.end(); ++iter) { | 38 for (; iter != devices.end(); ++iter) { |
| 31 if (iter->id == device_id) { | 39 if (iter->id == device_id) { |
| 32 return &(*iter); | 40 return &(*iter); |
| 33 } | 41 } |
| 34 } | 42 } |
| 35 | 43 |
| 36 return &(*devices.begin()); | 44 return &(*devices.begin()); |
| 37 }; | 45 }; |
| 38 | 46 |
| 47 // This is a short-term solution to allow testing of the the Screen Capture API | |
| 48 // with Google Hangouts in M27. | |
| 49 // TODO(sergeyu): Remove this whitelist as soon as possible. | |
| 50 bool IsOriginWhitelistedForScreenCapture(const GURL& origin) { | |
| 51 #if defined(OFFICIAL_BUILD) | |
| 52 return origin.spec() == "https://staging.talkgadget.google.com/" || | |
| 53 origin.spec() == "https://plus.google.com/"; | |
| 54 #else | |
| 55 return false; | |
| 56 #endif | |
| 57 } | |
| 58 | |
| 39 } // namespace | 59 } // namespace |
| 40 | 60 |
| 41 | |
| 42 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { | 61 MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { |
| 43 return Singleton<MediaCaptureDevicesDispatcher>::get(); | 62 return Singleton<MediaCaptureDevicesDispatcher>::get(); |
| 44 } | 63 } |
| 45 | 64 |
| 46 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() | 65 MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() |
| 47 : devices_enumerated_(false), | 66 : devices_enumerated_(false), |
| 48 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), | 67 media_stream_capture_indicator_(new MediaStreamCaptureIndicator()), |
| 49 audio_stream_indicator_(new AudioStreamIndicator()) {} | 68 audio_stream_indicator_(new AudioStreamIndicator()) {} |
| 50 | 69 |
| 51 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} | 70 MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 if (!devices_enumerated_) { | 108 if (!devices_enumerated_) { |
| 90 BrowserThread::PostTask( | 109 BrowserThread::PostTask( |
| 91 BrowserThread::IO, FROM_HERE, | 110 BrowserThread::IO, FROM_HERE, |
| 92 base::Bind(&content::EnsureMonitorCaptureDevices)); | 111 base::Bind(&content::EnsureMonitorCaptureDevices)); |
| 93 devices_enumerated_ = true; | 112 devices_enumerated_ = true; |
| 94 } | 113 } |
| 95 return video_devices_; | 114 return video_devices_; |
| 96 } | 115 } |
| 97 | 116 |
| 117 void MediaCaptureDevicesDispatcher::RequestAccess( | |
| 118 content::WebContents* web_contents, | |
| 119 const content::MediaStreamRequest& request, | |
| 120 const content::MediaResponseCallback& callback) { | |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 122 | |
| 123 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.
| |
| 124 bool screen_capture_enabled = CommandLine::ForCurrentProcess()->HasSwitch( | |
| 125 switches::kEnableUserMediaScreenCapturing) || | |
| 126 IsOriginWhitelistedForScreenCapture(request.security_origin); | |
| 127 // Deny request automatically in the following cases: | |
| 128 // 1. Screen capturing is not enabled via command line switch. | |
| 129 // 2. Audio capture was requested (it's not supported yet). | |
| 130 // 3. Request from a page that was not loaded from a secure origin. | |
| 131 if (!screen_capture_enabled || | |
| 132 request.audio_type != content::MEDIA_NO_SERVICE || | |
| 133 !request.security_origin.SchemeIsSecure()) { | |
| 134 callback.Run(content::MediaStreamDevices()); | |
| 135 return; | |
| 136 } | |
| 137 | |
| 138 string16 application_name = UTF8ToUTF16(request.security_origin.spec()); | |
| 139 | |
|
Peter Kasting
2013/03/23 01:25:54
Nit: Extra blank line
Sergey Ulanov
2013/03/23 01:43:38
Done.
| |
| 140 chrome::MessageBoxResult result = chrome::ShowMessageBox( | |
| 141 NULL, | |
| 142 l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE, | |
| 143 application_name), | |
| 144 l10n_util::GetStringFUTF16(IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT, | |
| 145 application_name), | |
| 146 chrome::MESSAGE_BOX_TYPE_QUESTION); | |
| 147 | |
| 148 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
| |
| 149 content::MediaStreamDevices devices; | |
| 150 devices.push_back(content::MediaStreamDevice( | |
| 151 content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); | |
| 152 callback.Run(devices); | |
| 153 } else { | |
| 154 callback.Run(content::MediaStreamDevices()); | |
| 155 } | |
| 156 } else { | |
| 157 MediaStreamInfoBarDelegate::Create(web_contents, request, callback); | |
| 158 } | |
| 159 } | |
| 160 | |
| 98 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( | 161 void MediaCaptureDevicesDispatcher::GetDefaultDevicesForProfile( |
| 99 Profile* profile, | 162 Profile* profile, |
| 100 bool audio, | 163 bool audio, |
| 101 bool video, | 164 bool video, |
| 102 content::MediaStreamDevices* devices) { | 165 content::MediaStreamDevices* devices) { |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 104 DCHECK(audio || video); | 167 DCHECK(audio || video); |
| 105 | 168 |
| 106 PrefService* prefs = profile->GetPrefs(); | 169 PrefService* prefs = profile->GetPrefs(); |
| 107 std::string default_device; | 170 std::string default_device; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 int render_process_id, | 296 int render_process_id, |
| 234 int render_view_id, | 297 int render_view_id, |
| 235 const content::MediaStreamDevice& device, | 298 const content::MediaStreamDevice& device, |
| 236 content::MediaRequestState state) { | 299 content::MediaRequestState state) { |
| 237 FOR_EACH_OBSERVER(Observer, observers_, | 300 FOR_EACH_OBSERVER(Observer, observers_, |
| 238 OnRequestUpdate(render_process_id, | 301 OnRequestUpdate(render_process_id, |
| 239 render_view_id, | 302 render_view_id, |
| 240 device, | 303 device, |
| 241 state)); | 304 state)); |
| 242 } | 305 } |
| OLD | NEW |