| 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_permission_context.h" | |
| 9 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" | 8 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" |
| 10 #include "chrome/browser/permissions/permission_context_base.h" | 9 #include "chrome/browser/permissions/permission_context_base.h" |
| 11 #include "chrome/browser/permissions/permission_manager.h" | 10 #include "chrome/browser/permissions/permission_manager.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 14 #include "content/public/browser/permission_manager.h" | 13 #include "content/public/browser/permission_manager.h" |
| 15 #include "content/public/browser/permission_type.h" | 14 #include "content/public/browser/permission_type.h" |
| 16 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
| 17 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 17 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat
us.mojom.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 content::PermissionType ContentSettingsTypeToPermission( | 21 content::PermissionType ContentSettingsTypeToPermission( |
| 22 ContentSettingsType content_setting) { | 22 ContentSettingsType content_setting) { |
| 23 if (content_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 23 if (content_setting == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 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; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 ContentSetting MediaPermission::GetPermissionStatus( | 42 ContentSetting MediaPermission::GetPermissionStatus( |
| 43 content::MediaStreamRequestResult* denial_reason) const { | 43 content::MediaStreamRequestResult* denial_reason) const { |
| 44 // 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 |
| 45 // file access without |--allow-file-access-from-files| flag. | 45 // file access without |--allow-file-access-from-files| flag. |
| 46 if (requesting_origin_.is_empty()) { | 46 if (requesting_origin_.is_empty()) { |
| 47 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; | 47 *denial_reason = content::MEDIA_DEVICE_INVALID_SECURITY_ORIGIN; |
| 48 return CONTENT_SETTING_BLOCK; | 48 return CONTENT_SETTING_BLOCK; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Use the Permission Context to find out if the kill switch is on. Set the | |
| 52 // denial reason to kill switch. | |
| 53 content::PermissionType permission_type = | 51 content::PermissionType permission_type = |
| 54 ContentSettingsTypeToPermission(content_type_); | 52 ContentSettingsTypeToPermission(content_type_); |
| 55 // TODO(raymes): This calls into GetPermissionContext which is a private | 53 PermissionManager* permission_manager = PermissionManager::Get(profile_); |
| 56 // member of PermissionManager. Remove this call when this class is refactored | |
| 57 // into a PermissionContext. See crbug.com/596786. | |
| 58 PermissionContextBase* permission_context = | |
| 59 PermissionManager::Get(profile_)->GetPermissionContext(permission_type); | |
| 60 | 54 |
| 61 if (!permission_context) { | 55 // Find out if the kill switch is on. Set the denial reason to kill switch. |
| 62 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 56 if (permission_manager->IsPermissionKillSwitchOn(permission_type)) { |
| 63 return CONTENT_SETTING_BLOCK; | |
| 64 } | |
| 65 | |
| 66 MediaStreamDevicePermissionContext* media_device_permission_context = | |
| 67 static_cast<MediaStreamDevicePermissionContext*>(permission_context); | |
| 68 | |
| 69 if (media_device_permission_context->IsPermissionKillSwitchOn()) { | |
| 70 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; | 57 *denial_reason = content::MEDIA_DEVICE_KILL_SWITCH_ON; |
| 71 return CONTENT_SETTING_BLOCK; | 58 return CONTENT_SETTING_BLOCK; |
| 72 } | 59 } |
| 73 | 60 |
| 74 // Check policy and content settings. | 61 // Check policy and content settings. |
| 75 ContentSetting result = | 62 blink::mojom::PermissionStatus status = |
| 76 GetStoredContentSetting(media_device_permission_context); | 63 permission_manager->GetPermissionStatus( |
| 77 if (result == CONTENT_SETTING_BLOCK) | 64 permission_type, requesting_origin_, embedding_origin_); |
| 78 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; | 65 switch (status) { |
| 66 case blink::mojom::PermissionStatus::DENIED: |
| 67 *denial_reason = content::MEDIA_DEVICE_PERMISSION_DENIED; |
| 68 return CONTENT_SETTING_BLOCK; |
| 69 case blink::mojom::PermissionStatus::ASK: |
| 70 return CONTENT_SETTING_ASK; |
| 71 case blink::mojom::PermissionStatus::GRANTED: |
| 72 return CONTENT_SETTING_ALLOW; |
| 73 } |
| 79 | 74 |
| 80 return result; | 75 NOTREACHED(); |
| 76 return CONTENT_SETTING_BLOCK; |
| 81 } | 77 } |
| 82 | 78 |
| 83 ContentSetting MediaPermission::GetPermissionStatusWithDeviceRequired( | 79 ContentSetting MediaPermission::GetPermissionStatusWithDeviceRequired( |
| 84 const std::string& device_id, | 80 const std::string& device_id, |
| 85 content::MediaStreamRequestResult* denial_reason) const { | 81 content::MediaStreamRequestResult* denial_reason) const { |
| 86 // Deny the request if there is no device attached to the OS of the requested | 82 // Deny the request if there is no device attached to the OS of the requested |
| 87 // type. | 83 // type. |
| 88 if (!HasAvailableDevices(device_id)) { | 84 if (!HasAvailableDevices(device_id)) { |
| 89 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; | 85 *denial_reason = content::MEDIA_DEVICE_NO_HARDWARE; |
| 90 return CONTENT_SETTING_BLOCK; | 86 return CONTENT_SETTING_BLOCK; |
| 91 } | 87 } |
| 92 | 88 |
| 93 return GetPermissionStatus(denial_reason); | 89 return GetPermissionStatus(denial_reason); |
| 94 } | 90 } |
| 95 | 91 |
| 96 ContentSetting MediaPermission::GetStoredContentSetting( | |
| 97 MediaStreamDevicePermissionContext* media_device_permission_context) const { | |
| 98 return media_device_permission_context->GetPermissionStatus( | |
| 99 requesting_origin_, embedding_origin_); | |
| 100 } | |
| 101 | |
| 102 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { | 92 bool MediaPermission::HasAvailableDevices(const std::string& device_id) const { |
| 103 const content::MediaStreamDevices* devices = nullptr; | 93 const content::MediaStreamDevices* devices = nullptr; |
| 104 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { | 94 if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 105 devices = | 95 devices = |
| 106 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); | 96 &MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); |
| 107 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 97 } else if (content_type_ == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 108 devices = | 98 devices = |
| 109 &MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); | 99 &MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); |
| 110 } else { | 100 } else { |
| 111 NOTREACHED(); | 101 NOTREACHED(); |
| 112 } | 102 } |
| 113 | 103 |
| 114 // TODO(tommi): It's kind of strange to have this here since if we fail this | 104 // TODO(tommi): It's kind of strange to have this here since if we fail this |
| 115 // test, there'll be a UI shown that indicates to the user that access to | 105 // test, there'll be a UI shown that indicates to the user that access to |
| 116 // non-existing audio/video devices has been denied. The user won't have | 106 // non-existing audio/video devices has been denied. The user won't have |
| 117 // any way to change that but there will be a UI shown which indicates that | 107 // any way to change that but there will be a UI shown which indicates that |
| 118 // access is blocked. | 108 // access is blocked. |
| 119 if (devices->empty()) | 109 if (devices->empty()) |
| 120 return false; | 110 return false; |
| 121 | 111 |
| 122 // Note: we check device_id before dereferencing devices. If the requested | 112 // Note: we check device_id before dereferencing devices. If the requested |
| 123 // device id is non-empty, then the corresponding device list must not be | 113 // device id is non-empty, then the corresponding device list must not be |
| 124 // NULL. | 114 // NULL. |
| 125 if (!device_id.empty() && !devices->FindById(device_id)) | 115 if (!device_id.empty() && !devices->FindById(device_id)) |
| 126 return false; | 116 return false; |
| 127 | 117 |
| 128 return true; | 118 return true; |
| 129 } | 119 } |
| OLD | NEW |