| 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 "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
| 18 #include "content/browser/browser_main_loop.h" | 18 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/browser/media/audio_stream_monitor.h" | 19 #include "content/browser/media/audio_stream_monitor.h" |
| 20 #include "content/browser/media/capture/audio_mirroring_manager.h" | 20 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 21 #include "content/browser/media/media_devices_permission_checker.h" |
| 21 #include "content/browser/media/media_internals.h" | 22 #include "content/browser/media/media_internals.h" |
| 22 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 23 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 24 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 24 #include "content/browser/renderer_host/media/media_stream_manager.h" | 25 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | |
| 26 #include "content/browser/renderer_host/render_widget_host_impl.h" | 26 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 27 #include "content/common/media/audio_messages.h" | 27 #include "content/common/media/audio_messages.h" |
| 28 #include "content/public/browser/content_browser_client.h" | 28 #include "content/public/browser/content_browser_client.h" |
| 29 #include "content/public/browser/media_device_id.h" | 29 #include "content/public/browser/media_device_id.h" |
| 30 #include "content/public/browser/media_observer.h" | 30 #include "content/public/browser/media_observer.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
| 33 #include "media/audio/audio_device_description.h" | 33 #include "media/audio/audio_device_description.h" |
| 34 #include "media/audio/audio_streams_tracker.h" | 34 #include "media/audio/audio_streams_tracker.h" |
| 35 #include "media/base/audio_bus.h" | 35 #include "media/base/audio_bus.h" |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 // Ignore check for default device, which is always authorized. | 697 // Ignore check for default device, which is always authorized. |
| 698 if (!media::AudioDeviceDescription::IsDefaultDevice(device_id) && | 698 if (!media::AudioDeviceDescription::IsDefaultDevice(device_id) && |
| 699 !MediaStreamManager::IsOriginAllowed(render_process_id_, | 699 !MediaStreamManager::IsOriginAllowed(render_process_id_, |
| 700 security_origin)) { | 700 security_origin)) { |
| 701 content::bad_message::ReceivedBadMessage(this, | 701 content::bad_message::ReceivedBadMessage(this, |
| 702 bad_message::ARH_UNAUTHORIZED_URL); | 702 bad_message::ARH_UNAUTHORIZED_URL); |
| 703 return; | 703 return; |
| 704 } | 704 } |
| 705 | 705 |
| 706 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { | 706 if (media::AudioDeviceDescription::IsDefaultDevice(device_id)) { |
| 707 AccessChecked(nullptr, device_id, security_origin, stream_id, | 707 AccessChecked(device_id, security_origin, stream_id, auth_start_time, true); |
| 708 auth_start_time, true); | |
| 709 } else { | 708 } else { |
| 710 // Check that MediaStream device permissions have been granted, | 709 // Check that device permissions have been granted for nondefault devices. |
| 711 // hence the use of a MediaStreamUIProxy. | 710 MediaDevicesPermissionChecker permission_checker; |
| 712 std::unique_ptr<MediaStreamUIProxy> ui_proxy = MediaStreamUIProxy::Create(); | 711 permission_checker.CheckPermission( |
| 713 | 712 MEDIA_DEVICE_TYPE_AUDIO_OUTPUT, render_process_id_, render_frame_id, |
| 714 // Use MEDIA_DEVICE_AUDIO_CAPTURE instead of MEDIA_DEVICE_AUDIO_OUTPUT | 713 security_origin, |
| 715 // because MediaStreamUIProxy::CheckAccess does not currently support | 714 base::Bind(&AudioRendererHost::AccessChecked, this, device_id, |
| 716 // MEDIA_DEVICE_AUDIO_OUTPUT. | 715 security_origin, stream_id, auth_start_time)); |
| 717 // TODO(guidou): Change to MEDIA_DEVICE_AUDIO_OUTPUT when support becomes | |
| 718 // available. http://crbug.com/498675 | |
| 719 ui_proxy->CheckAccess( | |
| 720 security_origin, MEDIA_DEVICE_AUDIO_CAPTURE, render_process_id_, | |
| 721 render_frame_id, | |
| 722 base::Bind(&AudioRendererHost::AccessChecked, this, | |
| 723 base::Passed(&ui_proxy), device_id, security_origin, | |
| 724 stream_id, auth_start_time)); | |
| 725 } | 716 } |
| 726 } | 717 } |
| 727 | 718 |
| 728 void AudioRendererHost::AccessChecked( | 719 void AudioRendererHost::AccessChecked( |
| 729 std::unique_ptr<MediaStreamUIProxy> ui_proxy, | |
| 730 const std::string& device_id, | 720 const std::string& device_id, |
| 731 const url::Origin& security_origin, | 721 const url::Origin& security_origin, |
| 732 int stream_id, | 722 int stream_id, |
| 733 base::TimeTicks auth_start_time, | 723 base::TimeTicks auth_start_time, |
| 734 bool have_access) { | 724 bool have_access) { |
| 735 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 725 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 736 | 726 |
| 737 const auto& auth_data = authorizations_.find(stream_id); | 727 const auto& auth_data = authorizations_.find(stream_id); |
| 738 if (auth_data == authorizations_.end()) { | 728 if (auth_data == authorizations_.end()) { |
| 739 // A close request was received while access check was in progress. | 729 // A close request was received while access check was in progress. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 std::string() /* matched_device_id */)); | 831 std::string() /* matched_device_id */)); |
| 842 } | 832 } |
| 843 | 833 |
| 844 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 834 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 845 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 835 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 846 const auto& i = authorizations_.find(stream_id); | 836 const auto& i = authorizations_.find(stream_id); |
| 847 return i != authorizations_.end(); | 837 return i != authorizations_.end(); |
| 848 } | 838 } |
| 849 | 839 |
| 850 } // namespace content | 840 } // namespace content |
| OLD | NEW |