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/permissions/permission_util.h" | 5 #include "chrome/browser/permissions/permission_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/permissions/permission_uma_util.h" |
| 10 #include "components/content_settings/core/browser/host_content_settings_map.h" |
8 #include "content/public/browser/permission_type.h" | 11 #include "content/public/browser/permission_type.h" |
9 | 12 |
10 using content::PermissionType; | 13 using content::PermissionType; |
11 | 14 |
12 // The returned strings must match the RAPPOR metrics in rappor.xml, | 15 // The returned strings must match the RAPPOR metrics in rappor.xml, |
13 // and any Field Trial configs for the Permissions kill switch e.g. | 16 // and any Field Trial configs for the Permissions kill switch e.g. |
14 // Permissions.Action.Geolocation etc.. | 17 // Permissions.Action.Geolocation etc.. |
15 std::string PermissionUtil::GetPermissionString( | 18 std::string PermissionUtil::GetPermissionString( |
16 content::PermissionType permission) { | 19 content::PermissionType permission) { |
17 switch (permission) { | 20 switch (permission) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 *out = PermissionType::BACKGROUND_SYNC; | 65 *out = PermissionType::BACKGROUND_SYNC; |
63 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 66 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
64 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { | 67 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { |
65 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; | 68 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; |
66 #endif | 69 #endif |
67 } else { | 70 } else { |
68 return false; | 71 return false; |
69 } | 72 } |
70 return true; | 73 return true; |
71 } | 74 } |
| 75 |
| 76 void PermissionUtil::SetContentSettingAndRecordRevocation( |
| 77 Profile* profile, |
| 78 const GURL& primary_url, |
| 79 const GURL& secondary_url, |
| 80 ContentSettingsType content_type, |
| 81 std::string resource_identifier, |
| 82 ContentSetting setting) { |
| 83 HostContentSettingsMap* map = |
| 84 HostContentSettingsMapFactory::GetForProfile(profile); |
| 85 ContentSetting previous_value = map->GetContentSetting( |
| 86 primary_url, secondary_url, content_type, resource_identifier); |
| 87 |
| 88 map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type, |
| 89 resource_identifier, setting); |
| 90 |
| 91 ContentSetting final_value = map->GetContentSetting( |
| 92 primary_url, secondary_url, content_type, resource_identifier); |
| 93 |
| 94 if (previous_value == CONTENT_SETTING_ALLOW && |
| 95 final_value != CONTENT_SETTING_ALLOW) { |
| 96 PermissionType permission_type; |
| 97 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) { |
| 98 PermissionUmaUtil::PermissionRevoked(permission_type, primary_url); |
| 99 } |
| 100 } |
| 101 } |
OLD | NEW |