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" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/public/browser/media_devices_monitor.h" | 28 #include "content/public/browser/media_devices_monitor.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
31 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
33 #include "content/public/common/media_stream_request.h" | 33 #include "content/public/common/media_stream_request.h" |
34 #include "extensions/common/constants.h" | 34 #include "extensions/common/constants.h" |
35 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
37 | 37 |
| 38 #if defined(USE_CRAS) |
| 39 #include "media/audio/cras/audio_manager_cras.h" |
| 40 #endif |
| 41 |
38 using content::BrowserThread; | 42 using content::BrowserThread; |
39 using content::MediaStreamDevices; | 43 using content::MediaStreamDevices; |
40 | 44 |
41 namespace { | 45 namespace { |
42 | 46 |
43 // Finds a device in |devices| that has |device_id|, or NULL if not found. | 47 // Finds a device in |devices| that has |device_id|, or NULL if not found. |
44 const content::MediaStreamDevice* FindDeviceWithId( | 48 const content::MediaStreamDevice* FindDeviceWithId( |
45 const content::MediaStreamDevices& devices, | 49 const content::MediaStreamDevices& devices, |
46 const std::string& device_id) { | 50 const std::string& device_id) { |
47 content::MediaStreamDevices::const_iterator iter = devices.begin(); | 51 content::MediaStreamDevices::const_iterator iter = devices.begin(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } else { | 190 } else { |
187 ProcessRegularMediaAccessRequest(web_contents, request, callback); | 191 ProcessRegularMediaAccessRequest(web_contents, request, callback); |
188 } | 192 } |
189 } | 193 } |
190 | 194 |
191 void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( | 195 void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( |
192 content::WebContents* web_contents, | 196 content::WebContents* web_contents, |
193 const content::MediaStreamRequest& request, | 197 const content::MediaStreamRequest& request, |
194 const content::MediaResponseCallback& callback, | 198 const content::MediaResponseCallback& callback, |
195 const extensions::Extension* extension) { | 199 const extensions::Extension* extension) { |
196 bool component_extension = | 200 const bool component_extension = |
197 extension && extension->location() == extensions::Manifest::COMPONENT; | 201 extension && extension->location() == extensions::Manifest::COMPONENT; |
198 | 202 |
199 content::MediaStreamDevices devices; | 203 content::MediaStreamDevices devices; |
200 | 204 |
201 bool screen_capture_enabled = | 205 const bool screen_capture_enabled = |
202 CommandLine::ForCurrentProcess()->HasSwitch( | 206 CommandLine::ForCurrentProcess()->HasSwitch( |
203 switches::kEnableUserMediaScreenCapturing) || | 207 switches::kEnableUserMediaScreenCapturing) || |
204 IsOriginWhitelistedForScreenCapture(request.security_origin); | 208 IsOriginWhitelistedForScreenCapture(request.security_origin); |
205 | 209 |
206 bool origin_is_secure = | 210 const bool origin_is_secure = |
207 request.security_origin.SchemeIsSecure() || | 211 request.security_origin.SchemeIsSecure() || |
208 request.security_origin.SchemeIs(extensions::kExtensionScheme) || | 212 request.security_origin.SchemeIs(extensions::kExtensionScheme) || |
209 CommandLine::ForCurrentProcess()->HasSwitch( | 213 CommandLine::ForCurrentProcess()->HasSwitch( |
210 switches::kAllowHttpScreenCapture); | 214 switches::kAllowHttpScreenCapture); |
211 | 215 |
| 216 const bool screen_video_capture_requested = |
| 217 request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE; |
| 218 |
| 219 const bool system_audio_capture_requested = |
| 220 request.audio_type == content::MEDIA_SYSTEM_AUDIO_CAPTURE; |
| 221 |
| 222 #if defined(USE_CRAS) |
| 223 const bool system_audio_capture_supported = true; |
| 224 #else |
| 225 const bool system_audio_capture_supported = false; |
| 226 #endif |
| 227 |
212 // Approve request only when the following conditions are met: | 228 // Approve request only when the following conditions are met: |
213 // 1. Screen capturing is enabled via command line switch or white-listed for | 229 // 1. Screen capturing is enabled via command line switch or white-listed for |
214 // the given origin. | 230 // the given origin. |
215 // 2. Request comes from a page with a secure origin or from an extension. | 231 // 2. Request comes from a page with a secure origin or from an extension. |
216 // 3. Video capture is requested for screen video. | 232 // 3. Video capture is requested for screen video. |
217 // 4. Audio capture is either not requested, or requested for system audio. | 233 // 4. Audio capture is either not requested, or requested for system audio. |
218 if (screen_capture_enabled && origin_is_secure && | 234 if (screen_capture_enabled && origin_is_secure && |
219 request.video_type == content::MEDIA_SCREEN_VIDEO_CAPTURE && | 235 screen_video_capture_requested && |
220 (request.audio_type == content::MEDIA_NO_SERVICE || | 236 (!system_audio_capture_requested || system_audio_capture_supported)) { |
221 request.audio_type == content::MEDIA_SYSTEM_AUDIO_CAPTURE)) { | |
222 // For component extensions, bypass message box. | 237 // For component extensions, bypass message box. |
223 bool user_approved = false; | 238 bool user_approved = false; |
224 if (!component_extension) { | 239 if (!component_extension) { |
225 string16 application_name = UTF8ToUTF16(request.security_origin.spec()); | 240 string16 application_name = UTF8ToUTF16(request.security_origin.spec()); |
226 string16 confirmation_text = l10n_util::GetStringFUTF16( | 241 string16 confirmation_text = l10n_util::GetStringFUTF16( |
227 request.audio_type == content::MEDIA_NO_SERVICE ? | 242 request.audio_type == content::MEDIA_NO_SERVICE ? |
228 IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT : | 243 IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TEXT : |
229 IDS_MEDIA_SCREEN_AND_AUDIO_CAPTURE_CONFIRMATION_TEXT, | 244 IDS_MEDIA_SCREEN_AND_AUDIO_CAPTURE_CONFIRMATION_TEXT, |
230 application_name); | 245 application_name); |
231 chrome::MessageBoxResult result = chrome::ShowMessageBox( | 246 chrome::MessageBoxResult result = chrome::ShowMessageBox( |
232 NULL, | 247 NULL, |
233 l10n_util::GetStringFUTF16( | 248 l10n_util::GetStringFUTF16( |
234 IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE, application_name), | 249 IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE, application_name), |
235 confirmation_text, | 250 confirmation_text, |
236 chrome::MESSAGE_BOX_TYPE_QUESTION); | 251 chrome::MESSAGE_BOX_TYPE_QUESTION); |
237 user_approved = (result == chrome::MESSAGE_BOX_RESULT_YES); | 252 user_approved = (result == chrome::MESSAGE_BOX_RESULT_YES); |
238 } | 253 } |
239 | 254 |
240 if (user_approved || component_extension) { | 255 if (user_approved || component_extension) { |
241 devices.push_back(content::MediaStreamDevice( | 256 devices.push_back(content::MediaStreamDevice( |
242 content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); | 257 content::MEDIA_SCREEN_VIDEO_CAPTURE, std::string(), "Screen")); |
243 if (request.audio_type == content::MEDIA_SYSTEM_AUDIO_CAPTURE) { | 258 if (system_audio_capture_requested) { |
| 259 #if defined(USE_CRAS) |
| 260 // Use the special loopback device ID for system audio capture. |
244 devices.push_back(content::MediaStreamDevice( | 261 devices.push_back(content::MediaStreamDevice( |
245 content::MEDIA_SYSTEM_AUDIO_CAPTURE, std::string(), std::string())); | 262 content::MEDIA_SYSTEM_AUDIO_CAPTURE, |
| 263 media::AudioManagerCras::kLoopbackDeviceId, |
| 264 "System Audio")); |
| 265 #endif |
246 } | 266 } |
247 } | 267 } |
248 } | 268 } |
249 | 269 |
250 scoped_ptr<content::MediaStreamUI> ui; | 270 scoped_ptr<content::MediaStreamUI> ui; |
251 // Unless we're being invoked from a component extension, register to display | 271 // Unless we're being invoked from a component extension, register to display |
252 // the notification for stream capture. | 272 // the notification for stream capture. |
253 if (!devices.empty() && !component_extension) { | 273 if (!devices.empty() && !component_extension) { |
254 // Use extension name as title for extensions and origin for drive-by web. | 274 // Use extension name as title for extensions and origin for drive-by web. |
255 std::string title; | 275 std::string title; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 state)); | 589 state)); |
570 } | 590 } |
571 | 591 |
572 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( | 592 void MediaCaptureDevicesDispatcher::OnCreatingAudioStreamOnUIThread( |
573 int render_process_id, | 593 int render_process_id, |
574 int render_view_id) { | 594 int render_view_id) { |
575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
576 FOR_EACH_OBSERVER(Observer, observers_, | 596 FOR_EACH_OBSERVER(Observer, observers_, |
577 OnCreatingAudioStream(render_process_id, render_view_id)); | 597 OnCreatingAudioStream(render_process_id, render_view_id)); |
578 } | 598 } |
OLD | NEW |