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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 << " is not supported in popups)"; | 105 << " is not supported in popups)"; |
106 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 106 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
107 false /* persist */, CONTENT_SETTING_BLOCK); | 107 false /* persist */, CONTENT_SETTING_BLOCK); |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 // Synchronously check the content setting to see if the user has already made | 111 // 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 | 112 // a decision, or if the origin is under embargo. If so, respect that |
113 // decision. | 113 // decision. |
114 ContentSetting content_setting = | 114 ContentSetting content_setting = |
115 GetPermissionStatus(requesting_origin, embedding_origin); | 115 GetPermissionStatus(requesting_origin, embedding_origin); |
raymes
2017/02/03 19:56:20
I think we want to record that it was embargoed he
| |
116 if (content_setting == CONTENT_SETTING_ALLOW) { | 116 if (content_setting == CONTENT_SETTING_ALLOW) { |
117 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage( | 117 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage( |
118 requesting_origin, embedding_origin, content_settings_type_); | 118 requesting_origin, embedding_origin, content_settings_type_); |
119 } | 119 } |
120 | 120 |
121 if (content_setting == CONTENT_SETTING_ALLOW || | 121 if (content_setting == CONTENT_SETTING_ALLOW || |
122 content_setting == CONTENT_SETTING_BLOCK) { | 122 content_setting == CONTENT_SETTING_BLOCK) { |
123 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 123 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
124 false /* persist */, content_setting); | 124 false /* persist */, content_setting); |
125 return; | 125 return; |
(...skipping 10 matching lines...) Expand all Loading... | |
136 requesting_origin, embedding_origin, user_gesture, callback)); | 136 requesting_origin, embedding_origin, user_gesture, callback)); |
137 } | 137 } |
138 | 138 |
139 void PermissionContextBase::ContinueRequestPermission( | 139 void PermissionContextBase::ContinueRequestPermission( |
140 content::WebContents* web_contents, | 140 content::WebContents* web_contents, |
141 const PermissionRequestID& id, | 141 const PermissionRequestID& id, |
142 const GURL& requesting_origin, | 142 const GURL& requesting_origin, |
143 const GURL& embedding_origin, | 143 const GURL& embedding_origin, |
144 bool user_gesture, | 144 bool user_gesture, |
145 const BrowserPermissionCallback& callback, | 145 const BrowserPermissionCallback& callback, |
146 bool permission_blocked) { | 146 bool permission_blocked) { |
raymes
2017/02/03 19:56:20
If we pass in the reason for the permission being
| |
147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 147 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
148 if (permission_blocked) { | 148 if (permission_blocked) { |
149 // TODO(meredithl): Add UMA metrics here. | 149 // TODO(meredithl): Add UMA metrics here. |
150 web_contents->GetMainFrame()->AddMessageToConsole( | 150 web_contents->GetMainFrame()->AddMessageToConsole( |
151 content::CONSOLE_MESSAGE_LEVEL_INFO, | 151 content::CONSOLE_MESSAGE_LEVEL_INFO, |
152 base::StringPrintf( | 152 base::StringPrintf( |
153 "%s permission has been auto-blocked.", | 153 "%s permission has been auto-blocked.", |
154 PermissionUtil::GetPermissionString(permission_type_).c_str())); | 154 PermissionUtil::GetPermissionString(permission_type_).c_str())); |
155 // Permission has been automatically blocked. | 155 // Permission has been automatically blocked. |
156 callback.Run(CONTENT_SETTING_BLOCK); | 156 callback.Run(CONTENT_SETTING_BLOCK); |
157 return; | 157 return; |
158 } | 158 } |
159 | 159 |
160 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, | 160 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, |
161 embedding_origin, profile_); | 161 embedding_origin, profile_); |
162 | 162 |
163 DecidePermission(web_contents, id, requesting_origin, embedding_origin, | 163 DecidePermission(web_contents, id, requesting_origin, embedding_origin, |
164 user_gesture, callback); | 164 user_gesture, callback); |
165 } | 165 } |
166 | 166 |
167 ContentSetting PermissionContextBase::GetPermissionStatus( | 167 ContentSetting PermissionContextBase::GetPermissionStatus( |
168 const GURL& requesting_origin, | 168 const GURL& requesting_origin, |
169 const GURL& embedding_origin) const { | 169 const GURL& embedding_origin) const { |
raymes
2017/02/03 19:56:20
I think we might want to have a version of this fu
| |
170 // If the permission has been disabled through Finch, block all requests. | 170 // If the permission has been disabled through Finch, block all requests. |
171 if (IsPermissionKillSwitchOn()) | 171 if (IsPermissionKillSwitchOn()) |
172 return CONTENT_SETTING_BLOCK; | 172 return CONTENT_SETTING_BLOCK; |
173 | 173 |
174 if (IsRestrictedToSecureOrigins() && | 174 if (IsRestrictedToSecureOrigins() && |
175 !content::IsOriginSecure(requesting_origin)) { | 175 !content::IsOriginSecure(requesting_origin)) { |
176 return CONTENT_SETTING_BLOCK; | 176 return CONTENT_SETTING_BLOCK; |
177 } | 177 } |
178 | 178 |
179 ContentSetting content_setting = | 179 ContentSetting content_setting = |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, | 308 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, |
309 requesting_origin, profile_); | 309 requesting_origin, profile_); |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
313 if (content_setting == CONTENT_SETTING_DEFAULT && | 313 if (content_setting == CONTENT_SETTING_DEFAULT && |
314 PermissionDecisionAutoBlocker::GetForProfile(profile_) | 314 PermissionDecisionAutoBlocker::GetForProfile(profile_) |
315 ->RecordDismissAndEmbargo(requesting_origin, permission_type_)) { | 315 ->RecordDismissAndEmbargo(requesting_origin, permission_type_)) { |
316 // The permission has been embargoed, so it is blocked for this permission | 316 // The permission has been embargoed, so it is blocked for this permission |
317 // request, but not persisted. | 317 // request, but not persisted. |
318 content_setting = CONTENT_SETTING_BLOCK; | 318 content_setting = CONTENT_SETTING_BLOCK; |
raymes
2017/02/03 19:56:20
This is slightly orthogonal to this CL, but I thin
| |
319 } else { | |
320 // If a decision was made, and it did not exceed the number of allowable | |
321 // dismissals, then it cannot have been embargoed. | |
322 PermissionUmaUtil::RecordPermissionEmbargoReason( | |
323 PermissionEmbargoReason::NOT_EMBARGOED); | |
319 } | 324 } |
320 | 325 |
321 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 326 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
322 persist, content_setting); | 327 persist, content_setting); |
323 } | 328 } |
324 | 329 |
325 #if defined(OS_ANDROID) | 330 #if defined(OS_ANDROID) |
326 PermissionQueueController* PermissionContextBase::GetQueueController() { | 331 PermissionQueueController* PermissionContextBase::GetQueueController() { |
327 return permission_queue_controller_.get(); | 332 return permission_queue_controller_.get(); |
328 } | 333 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 372 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
368 content_setting == CONTENT_SETTING_BLOCK); | 373 content_setting == CONTENT_SETTING_BLOCK); |
369 DCHECK(!requesting_origin.SchemeIsFile()); | 374 DCHECK(!requesting_origin.SchemeIsFile()); |
370 DCHECK(!embedding_origin.SchemeIsFile()); | 375 DCHECK(!embedding_origin.SchemeIsFile()); |
371 | 376 |
372 HostContentSettingsMapFactory::GetForProfile(profile_) | 377 HostContentSettingsMapFactory::GetForProfile(profile_) |
373 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 378 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
374 content_settings_type_, std::string(), | 379 content_settings_type_, std::string(), |
375 content_setting); | 380 content_setting); |
376 } | 381 } |
OLD | NEW |