| 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/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/sha1.h" | 11 #include "base/sha1.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 15 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| 16 #include "chrome/browser/media/audio_stream_indicator.h" | 16 #include "chrome/browser/media/audio_stream_indicator.h" |
| 17 #include "chrome/browser/media/desktop_streams_registry.h" | 17 #include "chrome/browser/media/desktop_streams_registry.h" |
| 18 #include "chrome/browser/media/media_stream_capture_indicator.h" | 18 #include "chrome/browser/media/media_stream_capture_indicator.h" |
| 19 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 19 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/screen_capture_notification_ui.h" | 21 #include "chrome/browser/ui/screen_capture_notification_ui.h" |
| 22 #include "chrome/browser/ui/simple_message_box.h" | 22 #include "chrome/browser/ui/simple_message_box.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/desktop_media_id.h" |
| 27 #include "content/public/browser/media_devices_monitor.h" | 28 #include "content/public/browser/media_devices_monitor.h" |
| 28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 30 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
| 31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 32 #include "content/public/common/desktop_media_id.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 "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 37 #include "media/audio/audio_manager_base.h" | 37 #include "media/audio/audio_manager_base.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 39 | 39 |
| 40 #if defined(OS_CHROMEOS) |
| 41 #include "ash/shell.h" |
| 42 #endif // defined(OS_CHROMEOS) |
| 43 |
| 40 using content::BrowserThread; | 44 using content::BrowserThread; |
| 41 using content::MediaStreamDevices; | 45 using content::MediaStreamDevices; |
| 42 | 46 |
| 43 namespace { | 47 namespace { |
| 44 | 48 |
| 45 // Finds a device in |devices| that has |device_id|, or NULL if not found. | 49 // Finds a device in |devices| that has |device_id|, or NULL if not found. |
| 46 const content::MediaStreamDevice* FindDeviceWithId( | 50 const content::MediaStreamDevice* FindDeviceWithId( |
| 47 const content::MediaStreamDevices& devices, | 51 const content::MediaStreamDevices& devices, |
| 48 const std::string& device_id) { | 52 const std::string& device_id) { |
| 49 content::MediaStreamDevices::const_iterator iter = devices.begin(); | 53 content::MediaStreamDevices::const_iterator iter = devices.begin(); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 const content::MediaResponseCallback& callback, | 265 const content::MediaResponseCallback& callback, |
| 262 const extensions::Extension* extension) { | 266 const extensions::Extension* extension) { |
| 263 content::MediaStreamDevices devices; | 267 content::MediaStreamDevices devices; |
| 264 scoped_ptr<content::MediaStreamUI> ui; | 268 scoped_ptr<content::MediaStreamUI> ui; |
| 265 | 269 |
| 266 if (request.video_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) { | 270 if (request.video_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 267 callback.Run(devices, ui.Pass()); | 271 callback.Run(devices, ui.Pass()); |
| 268 return; | 272 return; |
| 269 } | 273 } |
| 270 | 274 |
| 271 // First check if Desktop Capture API (i.e. | 275 // If the device id wasn't specified then this is a screen capture request |
| 272 // chrome.desktopCapture.chooseDesktopMedia()) was used to generate device Id. | 276 // (i.e. chooseDesktopMedia() API wasn't used to generate device id). |
| 277 if (request.requested_video_device_id.empty()) { |
| 278 ProcessScreenCaptureAccessRequest( |
| 279 web_contents, request, callback, extension); |
| 280 return; |
| 281 } |
| 282 |
| 283 // Resolve DesktopMediaID for the specified device id. |
| 273 content::DesktopMediaID media_id = | 284 content::DesktopMediaID media_id = |
| 274 GetDesktopStreamsRegistry()->RequestMediaForStreamId( | 285 GetDesktopStreamsRegistry()->RequestMediaForStreamId( |
| 275 request.requested_video_device_id, request.render_process_id, | 286 request.requested_video_device_id, request.render_process_id, |
| 276 request.render_view_id, request.security_origin); | 287 request.render_view_id, request.security_origin); |
| 277 | 288 |
| 278 // If the id wasn't generated using Desktop Capture API then process it as a | 289 // Received invalid device id. |
| 279 // screen capture request. | |
| 280 if (media_id.type == content::DesktopMediaID::TYPE_NONE) { | 290 if (media_id.type == content::DesktopMediaID::TYPE_NONE) { |
| 281 ProcessScreenCaptureAccessRequest( | 291 callback.Run(devices, ui.Pass()); |
| 282 web_contents, request, callback, extension); | |
| 283 return; | 292 return; |
| 284 } | 293 } |
| 285 | 294 |
| 286 bool loopback_audio_supported = false; | 295 bool loopback_audio_supported = false; |
| 287 #if defined(USE_CRAS) || defined(OS_WIN) | 296 #if defined(USE_CRAS) || defined(OS_WIN) |
| 288 // Currently loopback audio capture is supported only on Windows and ChromeOS. | 297 // Currently loopback audio capture is supported only on Windows and ChromeOS. |
| 289 loopback_audio_supported = true; | 298 loopback_audio_supported = true; |
| 290 #endif | 299 #endif |
| 291 | 300 |
| 292 // Audio is only supported for screen capture streams. | 301 // Audio is only supported for screen capture streams. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 305 void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( | 314 void MediaCaptureDevicesDispatcher::ProcessScreenCaptureAccessRequest( |
| 306 content::WebContents* web_contents, | 315 content::WebContents* web_contents, |
| 307 const content::MediaStreamRequest& request, | 316 const content::MediaStreamRequest& request, |
| 308 const content::MediaResponseCallback& callback, | 317 const content::MediaResponseCallback& callback, |
| 309 const extensions::Extension* extension) { | 318 const extensions::Extension* extension) { |
| 310 content::MediaStreamDevices devices; | 319 content::MediaStreamDevices devices; |
| 311 scoped_ptr<content::MediaStreamUI> ui; | 320 scoped_ptr<content::MediaStreamUI> ui; |
| 312 | 321 |
| 313 DCHECK_EQ(request.video_type, content::MEDIA_DESKTOP_VIDEO_CAPTURE); | 322 DCHECK_EQ(request.video_type, content::MEDIA_DESKTOP_VIDEO_CAPTURE); |
| 314 | 323 |
| 315 content::DesktopMediaID media_id = | |
| 316 content::DesktopMediaID::Parse(request.requested_video_device_id); | |
| 317 if (media_id.is_null()) { | |
| 318 LOG(ERROR) << "Invalid desktop media ID: " | |
| 319 << request.requested_video_device_id; | |
| 320 callback.Run(devices, ui.Pass()); | |
| 321 return; | |
| 322 } | |
| 323 | |
| 324 // Only screen capture can be requested without using desktop media picker. | |
| 325 if (media_id.type != content::DesktopMediaID::TYPE_SCREEN) { | |
| 326 LOG(ERROR) << "Unsupported desktop media ID: " | |
| 327 << request.requested_video_device_id; | |
| 328 callback.Run(devices, ui.Pass()); | |
| 329 return; | |
| 330 } | |
| 331 | |
| 332 bool loopback_audio_supported = false; | 324 bool loopback_audio_supported = false; |
| 333 #if defined(USE_CRAS) || defined(OS_WIN) | 325 #if defined(USE_CRAS) || defined(OS_WIN) |
| 334 // Currently loopback audio capture is supported only on Windows and ChromeOS. | 326 // Currently loopback audio capture is supported only on Windows and ChromeOS. |
| 335 loopback_audio_supported = true; | 327 loopback_audio_supported = true; |
| 336 #endif | 328 #endif |
| 337 | 329 |
| 338 const bool component_extension = | 330 const bool component_extension = |
| 339 extension && extension->location() == extensions::Manifest::COMPONENT; | 331 extension && extension->location() == extensions::Manifest::COMPONENT; |
| 340 | 332 |
| 341 const bool screen_capture_enabled = | 333 const bool screen_capture_enabled = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 chrome::MessageBoxResult result = chrome::ShowMessageBox( | 367 chrome::MessageBoxResult result = chrome::ShowMessageBox( |
| 376 NULL, | 368 NULL, |
| 377 l10n_util::GetStringFUTF16( | 369 l10n_util::GetStringFUTF16( |
| 378 IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE, application_name), | 370 IDS_MEDIA_SCREEN_CAPTURE_CONFIRMATION_TITLE, application_name), |
| 379 confirmation_text, | 371 confirmation_text, |
| 380 chrome::MESSAGE_BOX_TYPE_QUESTION); | 372 chrome::MESSAGE_BOX_TYPE_QUESTION); |
| 381 user_approved = (result == chrome::MESSAGE_BOX_RESULT_YES); | 373 user_approved = (result == chrome::MESSAGE_BOX_RESULT_YES); |
| 382 } | 374 } |
| 383 | 375 |
| 384 if (user_approved || component_extension) { | 376 if (user_approved || component_extension) { |
| 377 content::DesktopMediaID screen_id; |
| 378 #if defined(OS_CHROMEOS) |
| 379 screen_id = content::DesktopMediaID::RegisterAuraWindow( |
| 380 ash::Shell::GetInstance()->GetPrimaryRootWindow()); |
| 381 #else // defined(OS_CHROMEOS) |
| 382 screen_id = |
| 383 content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, 0); |
| 384 #endif // !defined(OS_CHROMEOS) |
| 385 |
| 385 bool capture_audio = | 386 bool capture_audio = |
| 386 (request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && | 387 (request.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE && |
| 387 loopback_audio_supported); | 388 loopback_audio_supported); |
| 388 | 389 |
| 389 // Unless we're being invoked from a component extension, register to | 390 // Unless we're being invoked from a component extension, register to |
| 390 // display the notification for stream capture. | 391 // display the notification for stream capture. |
| 391 bool display_notification = !component_extension; | 392 bool display_notification = !component_extension; |
| 392 | 393 |
| 393 ui = GetDevicesForDesktopCapture(devices, media_id, capture_audio, | 394 ui = GetDevicesForDesktopCapture(devices, screen_id, capture_audio, |
| 394 display_notification, application_title); | 395 display_notification, application_title); |
| 395 } | 396 } |
| 396 } | 397 } |
| 397 | 398 |
| 398 callback.Run(devices, ui.Pass()); | 399 callback.Run(devices, ui.Pass()); |
| 399 } | 400 } |
| 400 | 401 |
| 401 void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest( | 402 void MediaCaptureDevicesDispatcher::ProcessTabCaptureAccessRequest( |
| 402 content::WebContents* web_contents, | 403 content::WebContents* web_contents, |
| 403 const content::MediaStreamRequest& request, | 404 const content::MediaStreamRequest& request, |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 int render_view_id) { | 763 int render_view_id) { |
| 763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 764 FOR_EACH_OBSERVER(Observer, observers_, | 765 FOR_EACH_OBSERVER(Observer, observers_, |
| 765 OnCreatingAudioStream(render_process_id, render_view_id)); | 766 OnCreatingAudioStream(render_process_id, render_view_id)); |
| 766 } | 767 } |
| 767 | 768 |
| 768 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { | 769 bool MediaCaptureDevicesDispatcher::IsDesktopCaptureInProgress() { |
| 769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 770 return desktop_capture_sessions_.size() > 0; | 771 return desktop_capture_sessions_.size() > 0; |
| 771 } | 772 } |
| OLD | NEW |