| 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 "apps/app_window.h" | 7 #include "apps/app_window.h" |
| 8 #include "apps/app_window_registry.h" | 8 #include "apps/app_window_registry.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass()); | 578 callback.Run(devices, content::MEDIA_DEVICE_TAB_CAPTURE_FAILURE, ui.Pass()); |
| 579 #endif // !defined(OS_ANDROID) | 579 #endif // !defined(OS_ANDROID) |
| 580 } | 580 } |
| 581 | 581 |
| 582 void MediaCaptureDevicesDispatcher:: | 582 void MediaCaptureDevicesDispatcher:: |
| 583 ProcessMediaAccessRequestFromPlatformAppOrExtension( | 583 ProcessMediaAccessRequestFromPlatformAppOrExtension( |
| 584 content::WebContents* web_contents, | 584 content::WebContents* web_contents, |
| 585 const content::MediaStreamRequest& request, | 585 const content::MediaStreamRequest& request, |
| 586 const content::MediaResponseCallback& callback, | 586 const content::MediaResponseCallback& callback, |
| 587 const extensions::Extension* extension) { | 587 const extensions::Extension* extension) { |
| 588 |
| 589 // TODO(vrk): This code is largely duplicated in |
| 590 // MediaStreamDevicesController::Accept(). Move this code into a shared method |
| 591 // between the two classes. |
| 592 |
| 593 bool audio_allowed = |
| 594 request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE && |
| 595 extension->permissions_data()->HasAPIPermission( |
| 596 extensions::APIPermission::kAudioCapture); |
| 597 bool video_allowed = |
| 598 request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE && |
| 599 extension->permissions_data()->HasAPIPermission( |
| 600 extensions::APIPermission::kVideoCapture); |
| 601 |
| 602 bool get_default_audio_device = audio_allowed; |
| 603 bool get_default_video_device = video_allowed; |
| 604 |
| 588 content::MediaStreamDevices devices; | 605 content::MediaStreamDevices devices; |
| 589 Profile* profile = | |
| 590 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | |
| 591 | 606 |
| 592 if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE && | 607 // Get the exact audio or video device if an id is specified. |
| 593 extension->permissions_data()->HasAPIPermission( | 608 if (audio_allowed && !request.requested_audio_device_id.empty()) { |
| 594 extensions::APIPermission::kAudioCapture)) { | 609 const content::MediaStreamDevice* audio_device = |
| 595 GetDefaultDevicesForProfile(profile, true, false, &devices); | 610 GetRequestedAudioDevice(request.requested_audio_device_id); |
| 611 if (audio_device) { |
| 612 devices.push_back(*audio_device); |
| 613 get_default_audio_device = false; |
| 614 } |
| 615 } |
| 616 if (video_allowed && !request.requested_video_device_id.empty()) { |
| 617 const content::MediaStreamDevice* video_device = |
| 618 GetRequestedVideoDevice(request.requested_video_device_id); |
| 619 if (video_device) { |
| 620 devices.push_back(*video_device); |
| 621 get_default_video_device = false; |
| 622 } |
| 596 } | 623 } |
| 597 | 624 |
| 598 if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE && | 625 // If either or both audio and video devices were requested but not |
| 599 extension->permissions_data()->HasAPIPermission( | 626 // specified by id, get the default devices. |
| 600 extensions::APIPermission::kVideoCapture)) { | 627 if (get_default_audio_device || get_default_video_device) { |
| 601 GetDefaultDevicesForProfile(profile, false, true, &devices); | 628 Profile* profile = |
| 629 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 630 GetDefaultDevicesForProfile(profile, |
| 631 get_default_audio_device, |
| 632 get_default_video_device, |
| 633 &devices); |
| 602 } | 634 } |
| 603 | 635 |
| 604 scoped_ptr<content::MediaStreamUI> ui; | 636 scoped_ptr<content::MediaStreamUI> ui; |
| 605 if (!devices.empty()) { | 637 if (!devices.empty()) { |
| 606 ui = media_stream_capture_indicator_->RegisterMediaStream( | 638 ui = media_stream_capture_indicator_->RegisterMediaStream( |
| 607 web_contents, devices); | 639 web_contents, devices); |
| 608 } | 640 } |
| 609 callback.Run( | 641 callback.Run( |
| 610 devices, | 642 devices, |
| 611 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : | 643 devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 | 1002 |
| 971 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( | 1003 void MediaCaptureDevicesDispatcher::SetTestAudioCaptureDevices( |
| 972 const MediaStreamDevices& devices) { | 1004 const MediaStreamDevices& devices) { |
| 973 test_audio_devices_ = devices; | 1005 test_audio_devices_ = devices; |
| 974 } | 1006 } |
| 975 | 1007 |
| 976 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( | 1008 void MediaCaptureDevicesDispatcher::SetTestVideoCaptureDevices( |
| 977 const MediaStreamDevices& devices) { | 1009 const MediaStreamDevices& devices) { |
| 978 test_video_devices_ = devices; | 1010 test_video_devices_ = devices; |
| 979 } | 1011 } |
| OLD | NEW |