| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 71 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 72 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { | 72 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { |
| 73 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; | 73 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; |
| 74 #endif | 74 #endif |
| 75 } else { | 75 } else { |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void PermissionUtil::SetContentSettingAndRecordRevocation( | 81 PermissionUtil::ScopedRevocationReporter::ScopedRevocationReporter( |
| 82 Profile* profile, | 82 Profile* profile, |
| 83 const GURL& primary_url, | 83 const GURL& primary_url, |
| 84 const GURL& secondary_url, | 84 const GURL& secondary_url, |
| 85 ContentSettingsType content_type, | 85 ContentSettingsType content_type, |
| 86 std::string resource_identifier, | 86 PermissionSourceUI source_ui) |
| 87 ContentSetting setting) { | 87 : profile_(profile), |
| 88 primary_url_(primary_url), |
| 89 secondary_url_(secondary_url), |
| 90 content_type_(content_type), |
| 91 source_ui_(source_ui) { |
| 92 if (!primary_url_.is_valid() || |
| 93 (!secondary_url_.is_valid() && !secondary_url_.is_empty())) { |
| 94 is_initially_allowed_ = false; |
| 95 return; |
| 96 } |
| 88 HostContentSettingsMap* map = | 97 HostContentSettingsMap* map = |
| 89 HostContentSettingsMapFactory::GetForProfile(profile); | 98 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 90 ContentSetting previous_value = map->GetContentSetting( | 99 ContentSetting initial_content_setting = map->GetContentSetting( |
| 91 primary_url, secondary_url, content_type, resource_identifier); | 100 primary_url_, secondary_url_, content_type_, std::string()); |
| 101 is_initially_allowed_ = initial_content_setting == CONTENT_SETTING_ALLOW; |
| 102 } |
| 92 | 103 |
| 93 map->SetContentSettingDefaultScope(primary_url, secondary_url, content_type, | 104 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() { |
| 94 resource_identifier, setting); | 105 if (!is_initially_allowed_) |
| 95 | 106 return; |
| 96 ContentSetting final_value = map->GetContentSetting( | 107 HostContentSettingsMap* map = |
| 97 primary_url, secondary_url, content_type, resource_identifier); | 108 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 98 | 109 ContentSetting final_content_setting = map->GetContentSetting( |
| 99 if (previous_value == CONTENT_SETTING_ALLOW && | 110 primary_url_, secondary_url_, content_type_, std::string()); |
| 100 final_value != CONTENT_SETTING_ALLOW) { | 111 if (final_content_setting != CONTENT_SETTING_ALLOW) { |
| 101 PermissionType permission_type; | 112 PermissionType permission_type; |
| 102 if (PermissionUtil::GetPermissionType(content_type, &permission_type)) { | 113 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { |
| 103 // TODO(stefanocs): Report revocations from page action as PAGE_ACTION | 114 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, |
| 104 // source UI instead of SITE_SETTINGS source UI. | 115 primary_url_, profile_); |
| 105 PermissionUmaUtil::PermissionRevoked(permission_type, | |
| 106 PermissionSourceUI::SITE_SETTINGS, | |
| 107 primary_url, profile); | |
| 108 } | 116 } |
| 109 } | 117 } |
| 110 } | 118 } |
| OLD | NEW |