OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_queue_controller.h" | 5 #include "chrome/browser/permissions/permission_queue_controller.h" |
6 | 6 |
7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | 9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 pending_infobar_requests_.erase(i); | 202 pending_infobar_requests_.erase(i); |
203 return; | 203 return; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, | 207 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, |
208 const GURL& requesting_frame, | 208 const GURL& requesting_frame, |
209 const GURL& embedder, | 209 const GURL& embedder, |
210 bool user_gesture, | 210 bool user_gesture, |
211 bool update_content_setting, | 211 bool update_content_setting, |
212 bool allowed) { | 212 PermissionAction decision) { |
213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
214 | 214 |
215 // TODO(miguelg): move the permission persistence to | 215 // TODO(miguelg): move the permission persistence to |
216 // PermissionContextBase once all the types are moved there. | 216 // PermissionContextBase once all the types are moved there. |
217 PermissionRequestGestureType gesture_type = | 217 PermissionRequestGestureType gesture_type = |
218 user_gesture ? PermissionRequestGestureType::GESTURE | 218 user_gesture ? PermissionRequestGestureType::GESTURE |
219 : PermissionRequestGestureType::NO_GESTURE; | 219 : PermissionRequestGestureType::NO_GESTURE; |
220 if (update_content_setting) { | 220 switch (decision) { |
221 UpdateContentSetting(requesting_frame, embedder, allowed); | 221 case GRANTED: |
222 if (allowed) { | |
223 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, | 222 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, |
224 requesting_frame, profile_); | 223 requesting_frame, profile_); |
225 } else { | 224 break; |
| 225 case DENIED: |
226 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, | 226 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, |
227 requesting_frame, profile_); | 227 requesting_frame, profile_); |
228 } | 228 break; |
229 } else { | 229 case DISMISSED: |
230 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, | 230 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, |
231 requesting_frame, profile_); | 231 requesting_frame, profile_); |
| 232 break; |
| 233 default: |
| 234 NOTREACHED(); |
232 } | 235 } |
233 | 236 |
| 237 if (update_content_setting) |
| 238 UpdateContentSetting(requesting_frame, embedder, decision); |
| 239 |
234 // Cancel this request first, then notify listeners. TODO(pkasting): Why | 240 // Cancel this request first, then notify listeners. TODO(pkasting): Why |
235 // is this order important? | 241 // is this order important? |
236 PendingInfobarRequests requests_to_notify; | 242 PendingInfobarRequests requests_to_notify; |
237 PendingInfobarRequests infobars_to_remove; | 243 PendingInfobarRequests infobars_to_remove; |
238 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove; | 244 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove; |
239 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 245 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
240 i != pending_infobar_requests_.end(); ++i) { | 246 i != pending_infobar_requests_.end(); ++i) { |
241 if (!i->IsForPair(requesting_frame, embedder)) | 247 if (!i->IsForPair(requesting_frame, embedder)) |
242 continue; | 248 continue; |
243 requests_to_notify.push_back(*i); | 249 requests_to_notify.push_back(*i); |
(...skipping 16 matching lines...) Expand all Loading... |
260 infobars_to_remove.push_back(*i); | 266 infobars_to_remove.push_back(*i); |
261 } | 267 } |
262 | 268 |
263 // Remove all infobars for the same |requesting_frame| and |embedder|. | 269 // Remove all infobars for the same |requesting_frame| and |embedder|. |
264 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); | 270 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); |
265 i != infobars_to_remove.end(); ++i) | 271 i != infobars_to_remove.end(); ++i) |
266 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); | 272 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); |
267 | 273 |
268 // PermissionContextBase needs to know about the new ContentSetting value, | 274 // PermissionContextBase needs to know about the new ContentSetting value, |
269 // CONTENT_SETTING_DEFAULT being the value for nothing happened. The callers | 275 // CONTENT_SETTING_DEFAULT being the value for nothing happened. The callers |
270 // of ::OnPermissionSet passes { true, true } for allow, { true, false } for | 276 // of ::OnPermissionSet passes { bool, GRANTED } for allow, { bool, DENIED } |
271 // block and { false, * } for dismissed. The tuple being | 277 // for block and { false, DISMISSED } for dismissed. The tuple being |
272 // { update_content_setting, allowed }. | 278 // { update_content_setting, decision }. |
273 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; | 279 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
274 if (update_content_setting) { | 280 if (decision == GRANTED) |
275 content_setting = allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 281 content_setting = CONTENT_SETTING_ALLOW; |
276 } | 282 else if (decision == DENIED) |
| 283 content_setting = CONTENT_SETTING_BLOCK; |
| 284 else |
| 285 DCHECK_EQ(DISMISSED, decision); |
277 | 286 |
278 // Send out the permission notifications. | 287 // Send out the permission notifications. |
279 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); | 288 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); |
280 i != requests_to_notify.end(); ++i) | 289 i != requests_to_notify.end(); ++i) |
281 i->RunCallback(content_setting); | 290 i->RunCallback(content_setting); |
282 | 291 |
283 // Remove the pending requests in reverse order. | 292 // Remove the pending requests in reverse order. |
284 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) | 293 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) |
285 pending_infobar_requests_.erase(pending_requests_to_remove[i]); | 294 pending_infobar_requests_.erase(pending_requests_to_remove[i]); |
286 } | 295 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 content::Source<InfoBarService>(infobar_service))) { | 394 content::Source<InfoBarService>(infobar_service))) { |
386 registrar_.Remove(this, | 395 registrar_.Remove(this, |
387 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 396 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
388 content::Source<InfoBarService>(infobar_service)); | 397 content::Source<InfoBarService>(infobar_service)); |
389 } | 398 } |
390 } | 399 } |
391 | 400 |
392 void PermissionQueueController::UpdateContentSetting( | 401 void PermissionQueueController::UpdateContentSetting( |
393 const GURL& requesting_frame, | 402 const GURL& requesting_frame, |
394 const GURL& embedder, | 403 const GURL& embedder, |
395 bool allowed) { | 404 PermissionAction decision) { |
| 405 DCHECK(decision == GRANTED || decision == DENIED); |
396 if (requesting_frame.GetOrigin().SchemeIsFile()) { | 406 if (requesting_frame.GetOrigin().SchemeIsFile()) { |
397 // Chrome can be launched with --disable-web-security which allows | 407 // Chrome can be launched with --disable-web-security which allows |
398 // geolocation requests from file:// URLs. We don't want to store these | 408 // geolocation requests from file:// URLs. We don't want to store these |
399 // in the host content settings map. | 409 // in the host content settings map. |
400 return; | 410 return; |
401 } | 411 } |
402 | 412 |
403 ContentSetting content_setting = | 413 ContentSetting content_setting = |
404 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 414 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
405 | 415 |
406 HostContentSettingsMapFactory::GetForProfile(profile_) | 416 HostContentSettingsMapFactory::GetForProfile(profile_) |
407 ->SetContentSettingDefaultScope( | 417 ->SetContentSettingDefaultScope( |
408 requesting_frame.GetOrigin(), embedder.GetOrigin(), | 418 requesting_frame.GetOrigin(), embedder.GetOrigin(), |
409 content_settings_type_, std::string(), content_setting); | 419 content_settings_type_, std::string(), content_setting); |
410 } | 420 } |
OLD | NEW |