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" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
9 #include "chrome/browser/permissions/permission_uma_util.h" | 9 #include "chrome/browser/permissions/permission_uma_util.h" |
10 #include "components/content_settings/core/browser/host_content_settings_map.h" | 10 #include "components/content_settings/core/browser/host_content_settings_map.h" |
11 #include "content/public/browser/permission_type.h" | 11 #include "content/public/browser/permission_type.h" |
12 #include "url/gurl.h" | |
12 | 13 |
13 using content::PermissionType; | 14 using content::PermissionType; |
14 | 15 |
15 std::size_t PermissionTypeHash::operator()( | 16 std::size_t PermissionTypeHash::operator()( |
16 const content::PermissionType& type) const { | 17 const content::PermissionType& type) const { |
17 return static_cast<size_t>(type); | 18 return static_cast<size_t>(type); |
18 } | 19 } |
19 | 20 |
20 // The returned strings must match the RAPPOR metrics in rappor.xml, | 21 // The returned strings must match the RAPPOR metrics in rappor.xml, |
21 // and any Field Trial configs for the Permissions kill switch e.g. | 22 // and any Field Trial configs for the Permissions kill switch e.g. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 72 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
72 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { | 73 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { |
73 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; | 74 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; |
74 #endif | 75 #endif |
75 } else { | 76 } else { |
76 return false; | 77 return false; |
77 } | 78 } |
78 return true; | 79 return true; |
79 } | 80 } |
80 | 81 |
81 void PermissionUtil::SetContentSettingAndRecordRevocation( | 82 PermissionUtil::RevocationReporter::RevocationReporter( |
82 Profile* profile, | 83 Profile* profile, |
83 const GURL& primary_url, | 84 const GURL& primary_url, |
84 const GURL& secondary_url, | 85 const GURL& secondary_url, |
85 ContentSettingsType content_type, | 86 ContentSettingsType content_type, |
86 std::string resource_identifier, | 87 std::string resource_identifier, |
87 ContentSetting setting) { | 88 PermissionSourceUI source_ui) |
89 : profile_(profile), | |
raymes
2016/07/21 23:08:01
nit: Rather than passing the profile, should we pa
stefanocs
2016/07/22 00:44:28
We need the profile to check if the user opted int
| |
90 primary_url_(primary_url), | |
91 secondary_url_(secondary_url), | |
92 content_type_(content_type), | |
93 resource_identifier_(resource_identifier), | |
94 source_ui_(source_ui) { | |
95 if (!primary_url_.is_valid() || | |
96 (!secondary_url_.is_valid() && !secondary_url_.is_empty())) { | |
97 is_initially_allowed_ = false; | |
98 return; | |
99 } | |
88 HostContentSettingsMap* map = | 100 HostContentSettingsMap* map = |
89 HostContentSettingsMapFactory::GetForProfile(profile); | 101 HostContentSettingsMapFactory::GetForProfile(profile_); |
90 ContentSetting previous_value = map->GetContentSetting( | 102 ContentSetting initial_content_setting = map->GetContentSetting( |
91 primary_url, secondary_url, content_type, resource_identifier); | 103 primary_url_, secondary_url_, content_type_, resource_identifier_); |
104 is_initially_allowed_ = (initial_content_setting == CONTENT_SETTING_ALLOW); | |
raymes
2016/07/21 23:08:01
nit: no () needed
stefanocs
2016/07/22 00:44:28
Done.
| |
105 } | |
92 | 106 |
93 map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type, | 107 PermissionUtil::RevocationReporter::RevocationReporter( |
94 resource_identifier, setting); | 108 Profile* profile, |
109 const ContentSettingsPattern& primary_pattern, | |
110 const ContentSettingsPattern& secondary_pattern, | |
111 ContentSettingsType content_type, | |
112 std::string resource_identifier, | |
113 PermissionSourceUI source_ui) | |
114 : RevocationReporter( | |
115 profile, | |
116 GURL(primary_pattern.ToString()), | |
117 GURL((secondary_pattern == ContentSettingsPattern::Wildcard()) | |
118 ? primary_pattern.ToString() | |
119 : secondary_pattern.ToString()), | |
120 content_type, | |
121 resource_identifier, | |
122 source_ui) {} | |
raymes
2016/07/21 23:08:01
nit: can we leave this constructor out until the n
stefanocs
2016/07/22 00:44:28
Done.
| |
95 | 123 |
96 ContentSetting final_value = map->GetContentSetting( | 124 PermissionUtil::RevocationReporter::~RevocationReporter() { |
97 primary_url, secondary_url, content_type, resource_identifier); | 125 if (!is_initially_allowed_) |
98 | 126 return; |
99 if (previous_value == CONTENT_SETTING_ALLOW && | 127 HostContentSettingsMap* map = |
100 final_value != CONTENT_SETTING_ALLOW) { | 128 HostContentSettingsMapFactory::GetForProfile(profile_); |
129 ContentSetting final_content_setting = map->GetContentSetting( | |
130 primary_url_, secondary_url_, content_type_, resource_identifier_); | |
131 if (final_content_setting != CONTENT_SETTING_ALLOW) { | |
101 PermissionType permission_type; | 132 PermissionType permission_type; |
102 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) { | 133 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { |
103 // TODO(stefanocs): Report revocations from page action as PAGE_ACTION | 134 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, |
104 // source UI instead of SITE_SETTINGS source UI. | 135 primary_url_, profile_); |
105 PermissionUmaUtil::PermissionRevoked(permission_type, | |
106 PermissionSourceUI::SITE_SETTINGS, | |
107 primary_url, profile); | |
108 } | 136 } |
109 } | 137 } |
110 } | 138 } |
OLD | NEW |