| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/media/media_devices_permission_checker.h" | 5 #include "content/browser/media/media_devices_permission_checker.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/feature_list.h" |
| 12 #include "content/browser/frame_host/render_frame_host_delegate.h" | 13 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 13 #include "content/browser/frame_host/render_frame_host_impl.h" | 14 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 14 #include "content/common/media/media_devices.h" | 15 #include "content/common/media/media_devices.h" |
| 15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "content/public/common/content_features.h" |
| 18 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 19 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 20 #include "url/origin.h" | 22 #include "url/origin.h" |
| 21 | 23 |
| 22 namespace content { | 24 namespace content { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 MediaDevicesManager::BoolDeviceTypes DoCheckPermissionsOnUIThread( | 28 MediaDevicesManager::BoolDeviceTypes DoCheckPermissionsOnUIThread( |
| 27 MediaDevicesManager::BoolDeviceTypes requested_device_types, | 29 MediaDevicesManager::BoolDeviceTypes requested_device_types, |
| 28 int render_process_id, | 30 int render_process_id, |
| 29 int render_frame_id) { | 31 int render_frame_id) { |
| 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 31 RenderFrameHostImpl* frame_host = | 33 RenderFrameHostImpl* frame_host = |
| 32 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 34 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
| 33 | 35 |
| 34 // If there is no |frame_host|, return false for all permissions. | 36 // If there is no |frame_host|, return false for all permissions. |
| 35 if (!frame_host) | 37 if (!frame_host) |
| 36 return MediaDevicesManager::BoolDeviceTypes(); | 38 return MediaDevicesManager::BoolDeviceTypes(); |
| 37 | 39 |
| 38 RenderFrameHostDelegate* delegate = frame_host->delegate(); | 40 RenderFrameHostDelegate* delegate = frame_host->delegate(); |
| 39 GURL origin = frame_host->GetLastCommittedOrigin().GetURL(); | 41 GURL origin = frame_host->GetLastCommittedOrigin().GetURL(); |
| 40 | 42 |
| 41 // Currently, the MEDIA_DEVICE_AUDIO_CAPTURE permission is used for | 43 MediaDevicesManager::BoolDeviceTypes result; |
| 42 // both audio input and output. | 44 bool audio_permission = |
| 45 delegate->CheckMediaAccessPermission(origin, MEDIA_DEVICE_AUDIO_CAPTURE); |
| 46 bool mic_feature_policy = true; |
| 47 bool camera_feature_policy = true; |
| 48 if (base::FeatureList::IsEnabled(features::kUseFeaturePolicyForPermissions)) { |
| 49 mic_feature_policy = frame_host->IsFeatureEnabled( |
| 50 blink::WebFeaturePolicyFeature::kMicrophone); |
| 51 camera_feature_policy = |
| 52 frame_host->IsFeatureEnabled(blink::WebFeaturePolicyFeature::kCamera); |
| 53 } |
| 54 |
| 55 // Speakers. |
| 43 // TODO(guidou): use specific permission for audio output when it becomes | 56 // TODO(guidou): use specific permission for audio output when it becomes |
| 44 // available. See http://crbug.com/556542. | 57 // available. See http://crbug.com/556542. |
| 45 bool has_audio_permission = | 58 result[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = |
| 46 (requested_device_types[MEDIA_DEVICE_TYPE_AUDIO_INPUT] || | 59 requested_device_types[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] && |
| 47 requested_device_types[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT]) && | 60 audio_permission; |
| 48 delegate->CheckMediaAccessPermission(origin, MEDIA_DEVICE_AUDIO_CAPTURE); | |
| 49 | 61 |
| 50 MediaDevicesManager::BoolDeviceTypes result; | 62 // Mic. |
| 51 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = has_audio_permission; | 63 result[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = |
| 52 result[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = has_audio_permission; | 64 requested_device_types[MEDIA_DEVICE_TYPE_AUDIO_INPUT] && |
| 65 audio_permission && mic_feature_policy; |
| 66 |
| 67 // Camera. |
| 53 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = | 68 result[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = |
| 54 requested_device_types[MEDIA_DEVICE_TYPE_VIDEO_INPUT] && | 69 requested_device_types[MEDIA_DEVICE_TYPE_VIDEO_INPUT] && |
| 55 delegate->CheckMediaAccessPermission(origin, MEDIA_DEVICE_VIDEO_CAPTURE); | 70 delegate->CheckMediaAccessPermission(origin, |
| 71 MEDIA_DEVICE_VIDEO_CAPTURE) && |
| 72 camera_feature_policy; |
| 56 | 73 |
| 57 return result; | 74 return result; |
| 58 } | 75 } |
| 59 | 76 |
| 60 bool CheckSinglePermissionOnUIThread(MediaDeviceType device_type, | 77 bool CheckSinglePermissionOnUIThread(MediaDeviceType device_type, |
| 61 int render_process_id, | 78 int render_process_id, |
| 62 int render_frame_id) { | 79 int render_frame_id) { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 80 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 64 MediaDevicesManager::BoolDeviceTypes requested; | 81 MediaDevicesManager::BoolDeviceTypes requested; |
| 65 requested[device_type] = true; | 82 requested[device_type] = true; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 140 } |
| 124 | 141 |
| 125 BrowserThread::PostTaskAndReplyWithResult( | 142 BrowserThread::PostTaskAndReplyWithResult( |
| 126 BrowserThread::UI, FROM_HERE, | 143 BrowserThread::UI, FROM_HERE, |
| 127 base::BindOnce(&DoCheckPermissionsOnUIThread, requested, | 144 base::BindOnce(&DoCheckPermissionsOnUIThread, requested, |
| 128 render_process_id, render_frame_id), | 145 render_process_id, render_frame_id), |
| 129 std::move(callback)); | 146 std::move(callback)); |
| 130 } | 147 } |
| 131 | 148 |
| 132 } // namespace content | 149 } // namespace content |
| OLD | NEW |