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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { | 89 if (!requesting_origin.is_valid() || !embedding_origin.is_valid()) { |
90 std::string type_name = | 90 std::string type_name = |
91 content_settings::WebsiteSettingsRegistry::GetInstance() | 91 content_settings::WebsiteSettingsRegistry::GetInstance() |
92 ->Get(content_settings_type_) | 92 ->Get(content_settings_type_) |
93 ->name(); | 93 ->name(); |
94 | 94 |
95 DVLOG(1) << "Attempt to use " << type_name | 95 DVLOG(1) << "Attempt to use " << type_name |
96 << " from an invalid URL: " << requesting_origin << "," | 96 << " from an invalid URL: " << requesting_origin << "," |
97 << embedding_origin << " (" << type_name | 97 << embedding_origin << " (" << type_name |
98 << " is not supported in popups)"; | 98 << " is not supported in popups)"; |
99 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 99 NotifyPermissionSet(web_contents, id, requesting_origin, embedding_origin, |
100 false /* persist */, CONTENT_SETTING_BLOCK); | 100 callback, false /* persist */, CONTENT_SETTING_BLOCK); |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
104 ContentSetting content_setting = | 104 ContentSetting content_setting = |
105 GetPermissionStatus(requesting_origin, embedding_origin); | 105 GetPermissionStatus(requesting_origin, embedding_origin); |
106 if (content_setting == CONTENT_SETTING_ALLOW) { | 106 if (content_setting == CONTENT_SETTING_ALLOW) { |
107 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage( | 107 HostContentSettingsMapFactory::GetForProfile(profile_)->UpdateLastUsage( |
108 requesting_origin, embedding_origin, content_settings_type_); | 108 requesting_origin, embedding_origin, content_settings_type_); |
109 } | 109 } |
110 if (content_setting == CONTENT_SETTING_ALLOW || | 110 if (content_setting == CONTENT_SETTING_ALLOW || |
111 content_setting == CONTENT_SETTING_BLOCK) { | 111 content_setting == CONTENT_SETTING_BLOCK) { |
112 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 112 NotifyPermissionSet(web_contents, id, requesting_origin, embedding_origin, |
113 false /* persist */, content_setting); | 113 callback, false /* persist */, content_setting); |
114 return; | 114 return; |
115 } | 115 } |
116 | 116 |
117 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, | 117 PermissionUmaUtil::PermissionRequested(permission_type_, requesting_origin, |
118 embedding_origin, profile_); | 118 embedding_origin, profile_); |
119 | 119 |
120 DecidePermission(web_contents, id, requesting_origin, embedding_origin, | 120 DecidePermission(web_contents, id, requesting_origin, embedding_origin, |
121 user_gesture, callback); | 121 user_gesture, callback); |
122 } | 122 } |
123 | 123 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 PermissionRequestManager::FromWebContents(web_contents); | 196 PermissionRequestManager::FromWebContents(web_contents); |
197 // TODO(felt): sometimes |permission_request_manager| is null. This check is | 197 // TODO(felt): sometimes |permission_request_manager| is null. This check is |
198 // meant to prevent crashes. See crbug.com/457091. | 198 // meant to prevent crashes. See crbug.com/457091. |
199 if (!permission_request_manager) | 199 if (!permission_request_manager) |
200 return; | 200 return; |
201 | 201 |
202 std::unique_ptr<PermissionRequest> request_ptr = | 202 std::unique_ptr<PermissionRequest> request_ptr = |
203 base::MakeUnique<PermissionRequestImpl>( | 203 base::MakeUnique<PermissionRequestImpl>( |
204 requesting_origin, permission_type_, profile_, user_gesture, | 204 requesting_origin, permission_type_, profile_, user_gesture, |
205 base::Bind(&PermissionContextBase::PermissionDecided, | 205 base::Bind(&PermissionContextBase::PermissionDecided, |
206 weak_factory_.GetWeakPtr(), id, requesting_origin, | 206 weak_factory_.GetWeakPtr(), web_contents, id, |
207 embedding_origin, user_gesture, callback), | 207 requesting_origin, embedding_origin, user_gesture, |
| 208 callback), |
208 base::Bind(&PermissionContextBase::CleanUpRequest, | 209 base::Bind(&PermissionContextBase::CleanUpRequest, |
209 weak_factory_.GetWeakPtr(), id)); | 210 weak_factory_.GetWeakPtr(), id)); |
210 PermissionRequest* request = request_ptr.get(); | 211 PermissionRequest* request = request_ptr.get(); |
211 | 212 |
212 bool inserted = | 213 bool inserted = |
213 pending_requests_ | 214 pending_requests_ |
214 .insert(std::make_pair(id.ToString(), std::move(request_ptr))) | 215 .insert(std::make_pair(id.ToString(), std::move(request_ptr))) |
215 .second; | 216 .second; |
216 DCHECK(inserted) << "Duplicate id " << id.ToString(); | 217 DCHECK(inserted) << "Duplicate id " << id.ToString(); |
217 permission_request_manager->AddRequest(request); | 218 permission_request_manager->AddRequest(request); |
218 } else { | 219 } else { |
219 #if defined(OS_ANDROID) | 220 #if defined(OS_ANDROID) |
220 GetQueueController()->CreateInfoBarRequest( | 221 GetQueueController()->CreateInfoBarRequest( |
221 id, requesting_origin, embedding_origin, user_gesture, | 222 id, requesting_origin, embedding_origin, user_gesture, |
222 base::Bind(&PermissionContextBase::PermissionDecided, | 223 base::Bind(&PermissionContextBase::PermissionDecided, |
223 weak_factory_.GetWeakPtr(), id, requesting_origin, | 224 weak_factory_.GetWeakPtr(), web_contents, id, |
224 embedding_origin, user_gesture, callback, | 225 requesting_origin, embedding_origin, user_gesture, callback, |
225 // the queue controller takes care of persisting the | 226 // the queue controller takes care of persisting the |
226 // permission | 227 // permission |
227 false)); | 228 false)); |
228 #else | 229 #else |
229 NOTREACHED(); | 230 NOTREACHED(); |
230 #endif | 231 #endif |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
234 void PermissionContextBase::PermissionDecided( | 235 void PermissionContextBase::PermissionDecided( |
| 236 content::WebContents* web_contents, |
235 const PermissionRequestID& id, | 237 const PermissionRequestID& id, |
236 const GURL& requesting_origin, | 238 const GURL& requesting_origin, |
237 const GURL& embedding_origin, | 239 const GURL& embedding_origin, |
238 bool user_gesture, | 240 bool user_gesture, |
239 const BrowserPermissionCallback& callback, | 241 const BrowserPermissionCallback& callback, |
240 bool persist, | 242 bool persist, |
241 ContentSetting content_setting) { | 243 ContentSetting content_setting) { |
242 if (PermissionRequestManager::IsEnabled()) { | 244 if (PermissionRequestManager::IsEnabled()) { |
243 // Infobar persistence and its related UMA is tracked on the infobar | 245 // Infobar persistence and its related UMA is tracked on the infobar |
244 // controller directly. | 246 // controller directly. |
(...skipping 17 matching lines...) Expand all Loading... |
262 | 264 |
263 // Check if we should convert a dismiss decision into a block decision. This | 265 // Check if we should convert a dismiss decision into a block decision. This |
264 // is gated on enabling the kBlockPromptsIfDismissedOften feature. | 266 // is gated on enabling the kBlockPromptsIfDismissedOften feature. |
265 if (content_setting == CONTENT_SETTING_DEFAULT && | 267 if (content_setting == CONTENT_SETTING_DEFAULT && |
266 PermissionDecisionAutoBlocker::ShouldChangeDismissalToBlock( | 268 PermissionDecisionAutoBlocker::ShouldChangeDismissalToBlock( |
267 requesting_origin, permission_type_, profile_)) { | 269 requesting_origin, permission_type_, profile_)) { |
268 persist = true; | 270 persist = true; |
269 content_setting = CONTENT_SETTING_BLOCK; | 271 content_setting = CONTENT_SETTING_BLOCK; |
270 } | 272 } |
271 | 273 |
272 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 274 NotifyPermissionSet(web_contents, id, requesting_origin, embedding_origin, |
273 persist, content_setting); | 275 callback, persist, content_setting); |
274 } | 276 } |
275 | 277 |
276 #if defined(OS_ANDROID) | 278 #if defined(OS_ANDROID) |
277 PermissionQueueController* PermissionContextBase::GetQueueController() { | 279 PermissionQueueController* PermissionContextBase::GetQueueController() { |
278 return permission_queue_controller_.get(); | 280 return permission_queue_controller_.get(); |
279 } | 281 } |
280 #endif | 282 #endif |
281 | 283 |
282 Profile* PermissionContextBase::profile() const { | 284 Profile* PermissionContextBase::profile() const { |
283 return profile_; | 285 return profile_; |
284 } | 286 } |
285 | 287 |
286 void PermissionContextBase::NotifyPermissionSet( | 288 void PermissionContextBase::NotifyPermissionSet( |
| 289 content::WebContents* web_contents, |
287 const PermissionRequestID& id, | 290 const PermissionRequestID& id, |
288 const GURL& requesting_origin, | 291 const GURL& requesting_origin, |
289 const GURL& embedding_origin, | 292 const GURL& embedding_origin, |
290 const BrowserPermissionCallback& callback, | 293 const BrowserPermissionCallback& callback, |
291 bool persist, | 294 bool persist, |
292 ContentSetting content_setting) { | 295 ContentSetting content_setting) { |
293 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 296 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
294 | 297 |
295 if (persist) | 298 if (persist) |
296 UpdateContentSetting(requesting_origin, embedding_origin, content_setting); | 299 UpdateContentSetting(requesting_origin, embedding_origin, content_setting); |
(...skipping 21 matching lines...) Expand all Loading... |
318 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 321 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
319 content_setting == CONTENT_SETTING_BLOCK); | 322 content_setting == CONTENT_SETTING_BLOCK); |
320 DCHECK(!requesting_origin.SchemeIsFile()); | 323 DCHECK(!requesting_origin.SchemeIsFile()); |
321 DCHECK(!embedding_origin.SchemeIsFile()); | 324 DCHECK(!embedding_origin.SchemeIsFile()); |
322 | 325 |
323 HostContentSettingsMapFactory::GetForProfile(profile_) | 326 HostContentSettingsMapFactory::GetForProfile(profile_) |
324 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 327 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
325 content_settings_type_, std::string(), | 328 content_settings_type_, std::string(), |
326 content_setting); | 329 content_setting); |
327 } | 330 } |
OLD | NEW |