| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_context_base.h" | 5 #include "chrome/browser/permissions/permission_context_base.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "chrome/browser/permissions/permission_queue_controller.h" | 43 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 // static | 46 // static |
| 47 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = | 47 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = |
| 48 "PermissionsKillSwitch"; | 48 "PermissionsKillSwitch"; |
| 49 // static | 49 // static |
| 50 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = | 50 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = |
| 51 "blocked"; | 51 "blocked"; |
| 52 | 52 |
| 53 PermissionResult::PermissionResult(ContentSetting cs, |
| 54 PermissionStatusSource pss) |
| 55 : content_setting(cs), source(pss) {} |
| 56 |
| 57 PermissionResult::~PermissionResult() {} |
| 58 |
| 53 PermissionContextBase::PermissionContextBase( | 59 PermissionContextBase::PermissionContextBase( |
| 54 Profile* profile, | 60 Profile* profile, |
| 55 const content::PermissionType permission_type, | 61 const content::PermissionType permission_type, |
| 56 const ContentSettingsType content_settings_type) | 62 const ContentSettingsType content_settings_type) |
| 57 : profile_(profile), | 63 : profile_(profile), |
| 58 permission_type_(permission_type), | 64 permission_type_(permission_type), |
| 59 content_settings_type_(content_settings_type), | 65 content_settings_type_(content_settings_type), |
| 60 weak_factory_(this) { | 66 weak_factory_(this) { |
| 61 #if defined(OS_ANDROID) | 67 #if defined(OS_ANDROID) |
| 62 permission_queue_controller_.reset(new PermissionQueueController( | 68 permission_queue_controller_.reset(new PermissionQueueController( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 << embedding_origin << " (" << type_name | 110 << embedding_origin << " (" << type_name |
| 105 << " is not supported in popups)"; | 111 << " is not supported in popups)"; |
| 106 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 112 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 107 false /* persist */, CONTENT_SETTING_BLOCK); | 113 false /* persist */, CONTENT_SETTING_BLOCK); |
| 108 return; | 114 return; |
| 109 } | 115 } |
| 110 | 116 |
| 111 // Synchronously check the content setting to see if the user has already made | 117 // Synchronously check the content setting to see if the user has already made |
| 112 // a decision, or if the origin is under embargo. If so, respect that | 118 // a decision, or if the origin is under embargo. If so, respect that |
| 113 // decision. | 119 // decision. |
| 114 ContentSetting content_setting = | 120 PermissionResult result = |
| 115 GetPermissionStatus(requesting_origin, embedding_origin); | 121 GetPermissionStatus(requesting_origin, embedding_origin); |
| 116 if (content_setting == CONTENT_SETTING_ALLOW) { | 122 if (result.content_setting == CONTENT_SETTING_ALLOW) { |
| 117 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage( | 123 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage( |
| 118 requesting_origin, embedding_origin, content_settings_type_); | 124 requesting_origin, embedding_origin, content_settings_type_); |
| 119 } | 125 } |
| 120 | 126 |
| 121 if (content_setting == CONTENT_SETTING_ALLOW || | 127 if (result.content_setting == CONTENT_SETTING_ALLOW || |
| 122 content_setting == CONTENT_SETTING_BLOCK) { | 128 result.content_setting == CONTENT_SETTING_BLOCK) { |
| 123 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 129 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 124 false /* persist */, content_setting); | 130 false /* persist */, result.content_setting); |
| 125 return; | 131 return; |
| 126 } | 132 } |
| 127 | 133 |
| 128 // Asynchronously check whether the origin should be blocked from making this | 134 // Asynchronously check whether the origin should be blocked from making this |
| 129 // permission request. It may be on the Safe Browsing API blacklist, or it may | 135 // permission request. It may be on the Safe Browsing API blacklist, or it may |
| 130 // have been dismissed too many times in a row. If the origin is allowed to | 136 // have been dismissed too many times in a row. If the origin is allowed to |
| 131 // request, that request will be made to ContinueRequestPermission(). | 137 // request, that request will be made to ContinueRequestPermission(). |
| 132 PermissionDecisionAutoBlocker::GetForProfile(profile_)->UpdateEmbargoedStatus( | 138 PermissionDecisionAutoBlocker::GetForProfile(profile_)->UpdateEmbargoedStatus( |
| 133 permission_type_, requesting_origin, web_contents, | 139 permission_type_, requesting_origin, web_contents, |
| 134 base::Bind(&PermissionContextBase::ContinueRequestPermission, | 140 base::Bind(&PermissionContextBase::ContinueRequestPermission, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 157 return; | 163 return; |
| 158 } | 164 } |
| 159 | 165 |
| 160 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, | 166 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, |
| 161 embedding_origin, profile_); | 167 embedding_origin, profile_); |
| 162 | 168 |
| 163 DecidePermission(web_contents, id, requesting_origin, embedding_origin, | 169 DecidePermission(web_contents, id, requesting_origin, embedding_origin, |
| 164 user_gesture, callback); | 170 user_gesture, callback); |
| 165 } | 171 } |
| 166 | 172 |
| 167 ContentSetting PermissionContextBase::GetPermissionStatus( | 173 PermissionResult PermissionContextBase::GetPermissionStatus( |
| 168 const GURL& requesting_origin, | 174 const GURL& requesting_origin, |
| 169 const GURL& embedding_origin) const { | 175 const GURL& embedding_origin) const { |
| 170 // If the permission has been disabled through Finch, block all requests. | 176 // If the permission has been disabled through Finch, block all requests. |
| 171 if (IsPermissionKillSwitchOn()) | 177 if (IsPermissionKillSwitchOn()) { |
| 172 return CONTENT_SETTING_BLOCK; | 178 return PermissionResult(CONTENT_SETTING_BLOCK, |
| 179 PermissionStatusSource::KILL_SWITCH); |
| 180 } |
| 173 | 181 |
| 174 if (IsRestrictedToSecureOrigins() && | 182 if (IsRestrictedToSecureOrigins() && |
| 175 !content::IsOriginSecure(requesting_origin)) { | 183 !content::IsOriginSecure(requesting_origin)) { |
| 176 return CONTENT_SETTING_BLOCK; | 184 return PermissionResult(CONTENT_SETTING_BLOCK, |
| 185 PermissionStatusSource::INSECURE_ORIGIN); |
| 177 } | 186 } |
| 178 | 187 |
| 179 ContentSetting content_setting = | 188 ContentSetting content_setting = |
| 180 GetPermissionStatusInternal(requesting_origin, embedding_origin); | 189 GetPermissionStatusInternal(requesting_origin, embedding_origin); |
| 181 if (content_setting == CONTENT_SETTING_ASK && | 190 if (content_setting == CONTENT_SETTING_ASK && |
| 182 PermissionDecisionAutoBlocker::GetForProfile(profile_)->IsUnderEmbargo( | 191 PermissionDecisionAutoBlocker::GetForProfile(profile_)->IsUnderEmbargo( |
| 183 permission_type_, requesting_origin)) { | 192 permission_type_, requesting_origin)) { |
| 184 return CONTENT_SETTING_BLOCK; | 193 // TODO(raymes): Return the appropriate reason here, determined by |
| 194 // PermissionDecisionAutoBlocker. |
| 195 return PermissionResult(CONTENT_SETTING_BLOCK, |
| 196 PermissionStatusSource::UNSPECIFIED); |
| 185 } | 197 } |
| 186 return content_setting; | 198 |
| 199 // TODO(raymes): Return the appropriate reason here, determined by |
| 200 // GetPermissionStatusInternal. |
| 201 return PermissionResult(content_setting, PermissionStatusSource::UNSPECIFIED); |
| 187 } | 202 } |
| 188 | 203 |
| 189 void PermissionContextBase::ResetPermission( | 204 void PermissionContextBase::ResetPermission( |
| 190 const GURL& requesting_origin, | 205 const GURL& requesting_origin, |
| 191 const GURL& embedding_origin) { | 206 const GURL& embedding_origin) { |
| 192 HostContentSettingsMapFactory::GetForProfile(profile_) | 207 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 193 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 208 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
| 194 content_settings_type_, std::string(), | 209 content_settings_type_, std::string(), |
| 195 CONTENT_SETTING_DEFAULT); | 210 CONTENT_SETTING_DEFAULT); |
| 196 } | 211 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 382 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 368 content_setting == CONTENT_SETTING_BLOCK); | 383 content_setting == CONTENT_SETTING_BLOCK); |
| 369 DCHECK(!requesting_origin.SchemeIsFile()); | 384 DCHECK(!requesting_origin.SchemeIsFile()); |
| 370 DCHECK(!embedding_origin.SchemeIsFile()); | 385 DCHECK(!embedding_origin.SchemeIsFile()); |
| 371 | 386 |
| 372 HostContentSettingsMapFactory::GetForProfile(profile_) | 387 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 373 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 388 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
| 374 content_settings_type_, std::string(), | 389 content_settings_type_, std::string(), |
| 375 content_setting); | 390 content_setting); |
| 376 } | 391 } |
| OLD | NEW |