Chromium Code Reviews| 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), | |
| 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 } | |
| 88 HostContentSettingsMap* map = | 99 HostContentSettingsMap* map = |
| 89 HostContentSettingsMapFactory::GetForProfile(profile); | 100 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 90 ContentSetting previous_value = map->GetContentSetting( | 101 ContentSetting initial_content_setting = map->GetContentSetting( |
| 91 primary_url, secondary_url, content_type, resource_identifier); | 102 primary_url_, secondary_url_, content_type_, resource_identifier_); |
| 103 is_initially_allowed_ = (initial_content_setting == CONTENT_SETTING_ALLOW); | |
| 104 } | |
| 92 | 105 |
| 93 map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type, | 106 PermissionUtil::RevocationReporter::RevocationReporter( |
| 94 resource_identifier, setting); | 107 Profile* profile, |
| 108 const ContentSettingsPattern& primary_pattern, | |
| 109 const ContentSettingsPattern& secondary_pattern, | |
| 110 ContentSettingsType content_type, | |
| 111 std::string resource_identifier, | |
| 112 PermissionSourceUI source_ui) | |
| 113 : RevocationReporter( | |
| 114 profile, | |
| 115 GURL(primary_pattern.ToString()), | |
|
tsergeant
2016/07/21 01:32:52
Is this version of the constructor currently used?
stefanocs
2016/07/21 01:45:46
Not in this cl, but we are planning to use this fo
tsergeant
2016/07/21 07:10:56
Alright, sounds good to me.
| |
| 116 GURL((secondary_pattern == ContentSettingsPattern::Wildcard()) | |
| 117 ? primary_pattern.ToString() | |
| 118 : secondary_pattern.ToString()), | |
| 119 content_type, | |
| 120 resource_identifier, | |
| 121 source_ui) {} | |
| 95 | 122 |
| 96 ContentSetting final_value = map->GetContentSetting( | 123 PermissionUtil::RevocationReporter::~RevocationReporter() { |
| 97 primary_url, secondary_url, content_type, resource_identifier); | 124 if (!is_initially_allowed_) |
| 98 | 125 return; |
| 99 if (previous_value == CONTENT_SETTING_ALLOW && | 126 HostContentSettingsMap* map = |
| 100 final_value != CONTENT_SETTING_ALLOW) { | 127 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 128 ContentSetting final_content_setting = map->GetContentSetting( | |
| 129 primary_url_, secondary_url_, content_type_, resource_identifier_); | |
| 130 if (final_content_setting != CONTENT_SETTING_ALLOW) { | |
| 101 PermissionType permission_type; | 131 PermissionType permission_type; |
| 102 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) { | 132 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { |
| 103 // TODO(stefanocs): Report revocations from page action as PAGE_ACTION | 133 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, |
| 104 // source UI instead of SITE_SETTINGS source UI. | 134 primary_url_, profile_); |
| 105 PermissionUmaUtil::PermissionRevoked(permission_type, | |
| 106 PermissionSourceUI::SITE_SETTINGS, | |
| 107 primary_url, profile); | |
| 108 } | 135 } |
| 109 } | 136 } |
| 110 } | 137 } |
| OLD | NEW |