Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: chrome/browser/permissions/permission_context_base.cc

Issue 2686463002: Add a source to the result of PermissionContextBase::GetPermissionStatus (Closed)
Patch Set: Add a source to the result of PermissionContextBase::GetPermissionStatus Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 23 matching lines...) Expand all
158 return; 164 return;
159 } 165 }
160 166
161 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, 167 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin,
162 embedding_origin, profile_); 168 embedding_origin, profile_);
163 169
164 DecidePermission(web_contents, id, requesting_origin, embedding_origin, 170 DecidePermission(web_contents, id, requesting_origin, embedding_origin,
165 user_gesture, callback); 171 user_gesture, callback);
166 } 172 }
167 173
168 ContentSetting PermissionContextBase::GetPermissionStatus( 174 PermissionResult PermissionContextBase::GetPermissionStatus(
169 const GURL& requesting_origin, 175 const GURL& requesting_origin,
170 const GURL& embedding_origin) const { 176 const GURL& embedding_origin) const {
177 // TODO(raymes): Ensure we return appropriate decision reasons in the
178 // PermissionResult. We should add these as each is needed.
179
171 // If the permission has been disabled through Finch, block all requests. 180 // If the permission has been disabled through Finch, block all requests.
172 if (IsPermissionKillSwitchOn()) 181 if (IsPermissionKillSwitchOn()) {
173 return CONTENT_SETTING_BLOCK; 182 return PermissionResult(CONTENT_SETTING_BLOCK,
183 PermissionStatusSource::UNSPECIFIED);
184 }
174 185
175 if (IsRestrictedToSecureOrigins() && 186 if (IsRestrictedToSecureOrigins() &&
176 !content::IsOriginSecure(requesting_origin)) { 187 !content::IsOriginSecure(requesting_origin)) {
177 return CONTENT_SETTING_BLOCK; 188 return PermissionResult(CONTENT_SETTING_BLOCK,
189 PermissionStatusSource::UNSPECIFIED);
178 } 190 }
179 191
180 ContentSetting content_setting = 192 ContentSetting content_setting =
181 GetPermissionStatusInternal(requesting_origin, embedding_origin); 193 GetPermissionStatusInternal(requesting_origin, embedding_origin);
182 if (content_setting == CONTENT_SETTING_ASK && 194 if (content_setting == CONTENT_SETTING_ASK &&
183 PermissionDecisionAutoBlocker::GetForProfile(profile_)->IsUnderEmbargo( 195 PermissionDecisionAutoBlocker::GetForProfile(profile_)->IsUnderEmbargo(
184 permission_type_, requesting_origin)) { 196 permission_type_, requesting_origin)) {
185 return CONTENT_SETTING_BLOCK; 197 return PermissionResult(CONTENT_SETTING_BLOCK,
198 PermissionStatusSource::UNSPECIFIED);
186 } 199 }
187 return content_setting; 200
201 return PermissionResult(content_setting, PermissionStatusSource::UNSPECIFIED);
188 } 202 }
189 203
190 void PermissionContextBase::ResetPermission( 204 void PermissionContextBase::ResetPermission(
191 const GURL& requesting_origin, 205 const GURL& requesting_origin,
192 const GURL& embedding_origin) { 206 const GURL& embedding_origin) {
193 HostContentSettingsMapFactory::GetForProfile(profile_) 207 HostContentSettingsMapFactory::GetForProfile(profile_)
194 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, 208 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin,
195 content_settings_type_, std::string(), 209 content_settings_type_, std::string(),
196 CONTENT_SETTING_DEFAULT); 210 CONTENT_SETTING_DEFAULT);
197 } 211 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 382 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
369 content_setting == CONTENT_SETTING_BLOCK); 383 content_setting == CONTENT_SETTING_BLOCK);
370 DCHECK(!requesting_origin.SchemeIsFile()); 384 DCHECK(!requesting_origin.SchemeIsFile());
371 DCHECK(!embedding_origin.SchemeIsFile()); 385 DCHECK(!embedding_origin.SchemeIsFile());
372 386
373 HostContentSettingsMapFactory::GetForProfile(profile_) 387 HostContentSettingsMapFactory::GetForProfile(profile_)
374 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, 388 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin,
375 content_settings_type_, std::string(), 389 content_settings_type_, std::string(),
376 content_setting); 390 content_setting);
377 } 391 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_context_base.h ('k') | chrome/browser/permissions/permission_context_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698