| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/webrtc/media_permission.h" | 5 #include "chrome/browser/media/webrtc/media_permission.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 7 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| 9 #include "chrome/browser/permissions/permission_context_base.h" | 9 #include "chrome/browser/permissions/permission_context_base.h" |
| 10 #include "chrome/browser/permissions/permission_manager.h" | 10 #include "chrome/browser/permissions/permission_manager.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Check policy and content settings. | 108 // Check policy and content settings. |
| 109 ContentSetting content_setting = | 109 ContentSetting content_setting = |
| 110 permission_manager | 110 permission_manager |
| 111 ->GetPermissionStatus(content_type_, requesting_origin_, | 111 ->GetPermissionStatus(content_type_, requesting_origin_, |
| 112 embedding_origin_) | 112 embedding_origin_) |
| 113 .content_setting; | 113 .content_setting; |
| 114 if (content_setting == CONTENT_SETTING_BLOCK) | 114 if (content_setting == CONTENT_SETTING_BLOCK) |
| 115 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 115 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| 116 return content_setting; | 116 return content_setting; |
| 117 } | 117 } |
| 118 | |
| 119 ContentSetting MediaPermission::GetPermissionStatusWithDeviceRequired( | |
| 120 const std::string& device_id, | |
| 121 content::MediaStreamRequestResult* denial_reason) const { | |
| 122 // Deny the request if there is no device attached to the OS of the requested | |
| 123 // type. | |
| 124 if (!HasAvailableDevices(device_id)) { | |
| 125 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; | |
| 126 return CONTENT_SETTING_BLOCK; | |
| 127 } | |
| 128 | |
| 129 return GetPermissionStatus(denial_reason); | |
| 130 } | |
| 131 | |
| 132 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { | |
| 133 const content::MediaStreamDevices* devices = nullptr; | |
| 134 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | |
| 135 devices = | |
| 136 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); | |
| 137 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | |
| 138 devices = | |
| 139 &MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); | |
| 140 } else { | |
| 141 NOTREACHED(); | |
| 142 } | |
| 143 | |
| 144 // TODO(tommi): It's kind of strange to have this here since if we fail this | |
| 145 // test, there'll be a UI shown that indicates to the user that access to | |
| 146 // non-existing audio/video devices has been denied. The user won't have | |
| 147 // any way to change that but there will be a UI shown which indicates that | |
| 148 // access is blocked. | |
| 149 if (devices->empty()) | |
| 150 return false; | |
| 151 | |
| 152 // Note: we check device_id before dereferencing devices. If the requested | |
| 153 // device id is non-empty, then the corresponding device list must not be | |
| 154 // NULL. | |
| 155 if (!device_id.empty() && !devices->FindById(device_id)) | |
| 156 return false; | |
| 157 | |
| 158 return true; | |
| 159 } | |
| OLD | NEW |