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

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

Issue 2723983004: Add PermissionManager::GetPermissionStatusForFrame function (Closed)
Patch Set: Add PermissionManager::GetPermissionStatusForFrame function Created 3 years, 9 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 << embedding_origin << " (" << type_name 111 << embedding_origin << " (" << type_name
112 << " is not supported in popups)"; 112 << " is not supported in popups)";
113 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 113 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
114 false /* persist */, CONTENT_SETTING_BLOCK); 114 false /* persist */, CONTENT_SETTING_BLOCK);
115 return; 115 return;
116 } 116 }
117 117
118 // Synchronously check the content setting to see if the user has already made 118 // Synchronously check the content setting to see if the user has already made
119 // a decision, or if the origin is under embargo. If so, respect that 119 // a decision, or if the origin is under embargo. If so, respect that
120 // decision. 120 // decision.
121 PermissionResult result = 121 // TODO(raymes): Pass in the RenderFrameHost of the request here.
122 GetPermissionStatus(requesting_origin, embedding_origin); 122 PermissionResult result = GetPermissionStatus(
123 nullptr /* render_frame_host */, requesting_origin, embedding_origin);
123 124
124 if (result.content_setting == CONTENT_SETTING_ALLOW || 125 if (result.content_setting == CONTENT_SETTING_ALLOW ||
125 result.content_setting == CONTENT_SETTING_BLOCK) { 126 result.content_setting == CONTENT_SETTING_BLOCK) {
126 if (result.source == PermissionStatusSource::KILL_SWITCH) { 127 if (result.source == PermissionStatusSource::KILL_SWITCH) {
127 // Block the request and log to the developer console. 128 // Block the request and log to the developer console.
128 LogPermissionBlockedMessage(web_contents, 129 LogPermissionBlockedMessage(web_contents,
129 kPermissionBlockedKillSwitchMessage, 130 kPermissionBlockedKillSwitchMessage,
130 content_settings_type_); 131 content_settings_type_);
131 callback.Run(CONTENT_SETTING_BLOCK); 132 callback.Run(CONTENT_SETTING_BLOCK);
132 return; 133 return;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 PermissionUmaUtil::PermissionRequested( 183 PermissionUmaUtil::PermissionRequested(
183 content_settings_type_, requesting_origin, embedding_origin, profile_); 184 content_settings_type_, requesting_origin, embedding_origin, profile_);
184 PermissionUmaUtil::RecordEmbargoPromptSuppression( 185 PermissionUmaUtil::RecordEmbargoPromptSuppression(
185 PermissionEmbargoStatus::NOT_EMBARGOED); 186 PermissionEmbargoStatus::NOT_EMBARGOED);
186 187
187 DecidePermission(web_contents, id, requesting_origin, embedding_origin, 188 DecidePermission(web_contents, id, requesting_origin, embedding_origin,
188 user_gesture, callback); 189 user_gesture, callback);
189 } 190 }
190 191
191 PermissionResult PermissionContextBase::GetPermissionStatus( 192 PermissionResult PermissionContextBase::GetPermissionStatus(
193 content::RenderFrameHost* render_frame_host,
192 const GURL& requesting_origin, 194 const GURL& requesting_origin,
193 const GURL& embedding_origin) const { 195 const GURL& embedding_origin) const {
194 // If the permission has been disabled through Finch, block all requests. 196 // If the permission has been disabled through Finch, block all requests.
195 if (IsPermissionKillSwitchOn()) { 197 if (IsPermissionKillSwitchOn()) {
196 return PermissionResult(CONTENT_SETTING_BLOCK, 198 return PermissionResult(CONTENT_SETTING_BLOCK,
197 PermissionStatusSource::KILL_SWITCH); 199 PermissionStatusSource::KILL_SWITCH);
198 } 200 }
199 201
200 if (IsRestrictedToSecureOrigins() && 202 if (IsRestrictedToSecureOrigins() &&
201 !content::IsOriginSecure(requesting_origin)) { 203 !content::IsOriginSecure(requesting_origin)) {
202 return PermissionResult(CONTENT_SETTING_BLOCK, 204 return PermissionResult(CONTENT_SETTING_BLOCK,
203 PermissionStatusSource::UNSPECIFIED); 205 PermissionStatusSource::UNSPECIFIED);
204 } 206 }
205 207
206 ContentSetting content_setting = 208 ContentSetting content_setting = GetPermissionStatusInternal(
207 GetPermissionStatusInternal(requesting_origin, embedding_origin); 209 render_frame_host, requesting_origin, embedding_origin);
208 if (content_setting == CONTENT_SETTING_ASK) { 210 if (content_setting == CONTENT_SETTING_ASK) {
209 PermissionResult result = 211 PermissionResult result =
210 PermissionDecisionAutoBlocker::GetForProfile(profile_) 212 PermissionDecisionAutoBlocker::GetForProfile(profile_)
211 ->GetEmbargoResult(requesting_origin, content_settings_type_); 213 ->GetEmbargoResult(requesting_origin, content_settings_type_);
212 DCHECK(result.content_setting == CONTENT_SETTING_ASK || 214 DCHECK(result.content_setting == CONTENT_SETTING_ASK ||
213 result.content_setting == CONTENT_SETTING_BLOCK); 215 result.content_setting == CONTENT_SETTING_BLOCK);
214 return result; 216 return result;
215 } 217 }
216 218
217 return PermissionResult(content_setting, PermissionStatusSource::UNSPECIFIED); 219 return PermissionResult(content_setting, PermissionStatusSource::UNSPECIFIED);
(...skipping 30 matching lines...) Expand all
248 250
249 bool PermissionContextBase::IsPermissionKillSwitchOn() const { 251 bool PermissionContextBase::IsPermissionKillSwitchOn() const {
250 const std::string param = variations::GetVariationParamValue( 252 const std::string param = variations::GetVariationParamValue(
251 kPermissionsKillSwitchFieldStudy, 253 kPermissionsKillSwitchFieldStudy,
252 PermissionUtil::GetPermissionString(content_settings_type_)); 254 PermissionUtil::GetPermissionString(content_settings_type_));
253 255
254 return param == kPermissionsKillSwitchBlockedValue; 256 return param == kPermissionsKillSwitchBlockedValue;
255 } 257 }
256 258
257 ContentSetting PermissionContextBase::GetPermissionStatusInternal( 259 ContentSetting PermissionContextBase::GetPermissionStatusInternal(
260 content::RenderFrameHost* render_frame_host,
258 const GURL& requesting_origin, 261 const GURL& requesting_origin,
259 const GURL& embedding_origin) const { 262 const GURL& embedding_origin) const {
260 return HostContentSettingsMapFactory::GetForProfile(profile_) 263 return HostContentSettingsMapFactory::GetForProfile(profile_)
261 ->GetContentSetting(requesting_origin, embedding_origin, 264 ->GetContentSetting(requesting_origin, embedding_origin,
262 content_settings_storage_type(), std::string()); 265 content_settings_storage_type(), std::string());
263 } 266 }
264 267
265 void PermissionContextBase::DecidePermission( 268 void PermissionContextBase::DecidePermission(
266 content::WebContents* web_contents, 269 content::WebContents* web_contents,
267 const PermissionRequestID& id, 270 const PermissionRequestID& id,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 content_settings_storage_type(), 408 content_settings_storage_type(),
406 std::string(), content_setting); 409 std::string(), content_setting);
407 } 410 }
408 411
409 ContentSettingsType PermissionContextBase::content_settings_storage_type() 412 ContentSettingsType PermissionContextBase::content_settings_storage_type()
410 const { 413 const {
411 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) 414 if (content_settings_type_ == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING)
412 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS; 415 return CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
413 return content_settings_type_; 416 return content_settings_type_;
414 } 417 }
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