| 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/media_permission.h" | 5 #include "chrome/browser/media/media_permission.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 7 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 8 #include "chrome/browser/media/media_stream_device_permission_context.h" | 8 #include "chrome/browser/media/media_stream_device_permission_context.h" |
| 9 #include "chrome/browser/media/media_stream_device_permissions.h" | 9 #include "chrome/browser/media/media_stream_device_permissions.h" |
| 10 #include "chrome/browser/permissions/permission_context_base.h" | 10 #include "chrome/browser/permissions/permission_context_base.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 return content::PermissionType::AUDIO_CAPTURE; | 24 return content::PermissionType::AUDIO_CAPTURE; |
| 25 } else { | 25 } else { |
| 26 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, content_setting); | 26 DCHECK_EQ(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, content_setting); |
| 27 return content::PermissionType::VIDEO_CAPTURE; | 27 return content::PermissionType::VIDEO_CAPTURE; |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 MediaPermission::MediaPermission(ContentSettingsType content_type, | 33 MediaPermission::MediaPermission(ContentSettingsType content_type, |
| 34 bool is_insecure_pepper_request, | |
| 35 const GURL& requesting_origin, | 34 const GURL& requesting_origin, |
| 36 const GURL& embedding_origin, | 35 const GURL& embedding_origin, |
| 37 Profile* profile) | 36 Profile* profile) |
| 38 : content_type_(content_type), | 37 : content_type_(content_type), |
| 39 is_insecure_pepper_request_(is_insecure_pepper_request), | |
| 40 requesting_origin_(requesting_origin), | 38 requesting_origin_(requesting_origin), |
| 41 embedding_origin_(embedding_origin), | 39 embedding_origin_(embedding_origin), |
| 42 profile_(profile) {} | 40 profile_(profile) {} |
| 43 | 41 |
| 44 ContentSetting MediaPermission::GetPermissionStatus( | 42 ContentSetting MediaPermission::GetPermissionStatus( |
| 45 content::MediaStreamRequestResult* denial_reason) const { | 43 content::MediaStreamRequestResult* denial_reason) const { |
| 46 // Deny the request if the security origin is empty, this happens with | 44 // Deny the request if the security origin is empty, this happens with |
| 47 // file access without |--allow-file-access-from-files| flag. | 45 // file access without |--allow-file-access-from-files| flag. |
| 48 if (requesting_origin_.is_empty()) { | 46 if (requesting_origin_.is_empty()) { |
| 49 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; | 47 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if (!HasAvailableDevices(device_id)) { | 88 if (!HasAvailableDevices(device_id)) { |
| 91 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; | 89 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; |
| 92 return CONTENT_SETTING_BLOCK; | 90 return CONTENT_SETTING_BLOCK; |
| 93 } | 91 } |
| 94 | 92 |
| 95 return GetPermissionStatus(denial_reason); | 93 return GetPermissionStatus(denial_reason); |
| 96 } | 94 } |
| 97 | 95 |
| 98 ContentSetting MediaPermission::GetStoredContentSetting( | 96 ContentSetting MediaPermission::GetStoredContentSetting( |
| 99 MediaStreamDevicePermissionContext* media_device_permission_context) const { | 97 MediaStreamDevicePermissionContext* media_device_permission_context) const { |
| 100 if (is_insecure_pepper_request_) { | 98 return media_device_permission_context->GetPermissionStatus( |
| 101 return media_device_permission_context | 99 requesting_origin_, embedding_origin_); |
| 102 ->GetPermissionStatusAllowingInsecureForPepper(requesting_origin_, | |
| 103 embedding_origin_); | |
| 104 } else { | |
| 105 return media_device_permission_context->GetPermissionStatus( | |
| 106 requesting_origin_, embedding_origin_); | |
| 107 } | |
| 108 } | 100 } |
| 109 | 101 |
| 110 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { | 102 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { |
| 111 const content::MediaStreamDevices* devices = nullptr; | 103 const content::MediaStreamDevices* devices = nullptr; |
| 112 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 104 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 113 devices = | 105 devices = |
| 114 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); | 106 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); |
| 115 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 107 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 116 devices = | 108 devices = |
| 117 &MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); | 109 &MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 128 return false; | 120 return false; |
| 129 | 121 |
| 130 // Note: we check device_id before dereferencing devices. If the requested | 122 // Note: we check device_id before dereferencing devices. If the requested |
| 131 // device id is non-empty, then the corresponding device list must not be | 123 // device id is non-empty, then the corresponding device list must not be |
| 132 // NULL. | 124 // NULL. |
| 133 if (!device_id.empty() && !devices->FindById(device_id)) | 125 if (!device_id.empty() && !devices->FindById(device_id)) |
| 134 return false; | 126 return false; |
| 135 | 127 |
| 136 return true; | 128 return true; |
| 137 } | 129 } |
| OLD | NEW |