Chromium Code Reviews| 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 "build/build_config.h" | |
| 7 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/permissions/permission_dialog_delegate.h" | 11 #include "chrome/browser/permissions/permission_dialog_delegate.h" |
| 11 #include "chrome/browser/permissions/permission_infobar_delegate.h" | 12 #include "chrome/browser/permissions/permission_infobar_delegate.h" |
| 12 #include "chrome/browser/permissions/permission_request.h" | 13 #include "chrome/browser/permissions/permission_request.h" |
| 13 #include "chrome/browser/permissions/permission_request_id.h" | 14 #include "chrome/browser/permissions/permission_request_id.h" |
| 14 #include "chrome/browser/permissions/permission_uma_util.h" | 15 #include "chrome/browser/permissions/permission_uma_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 const GURL& requesting_frame, | 58 const GURL& requesting_frame, |
| 58 const GURL& embedder, | 59 const GURL& embedder, |
| 59 bool user_gesture, | 60 bool user_gesture, |
| 60 Profile* profile, | 61 Profile* profile, |
| 61 const PermissionDecidedCallback& callback); | 62 const PermissionDecidedCallback& callback); |
| 62 ~PendingInfobarRequest(); | 63 ~PendingInfobarRequest(); |
| 63 | 64 |
| 64 bool IsForPair(const GURL& requesting_frame, | 65 bool IsForPair(const GURL& requesting_frame, |
| 65 const GURL& embedder) const; | 66 const GURL& embedder) const; |
| 66 | 67 |
| 68 PermissionRequestType request_type() const { | |
| 69 switch (type_) { | |
| 70 case content::PermissionType::GEOLOCATION: | |
| 71 return PermissionRequestType::PERMISSION_GEOLOCATION; | |
| 72 #if defined(ENABLE_NOTIFICATIONS) | |
| 73 case content::PermissionType::NOTIFICATIONS: | |
| 74 return PermissionRequestType::PERMISSION_NOTIFICATIONS; | |
| 75 #endif | |
| 76 case content::PermissionType::MIDI_SYSEX: | |
| 77 return PermissionRequestType::PERMISSION_MIDI_SYSEX; | |
| 78 case content::PermissionType::PUSH_MESSAGING: | |
| 79 return PermissionRequestType::PERMISSION_PUSH_MESSAGING; | |
| 80 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 81 return PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER; | |
|
benwells
2016/11/10 03:24:28
This switch already exists pretty much in permissi
dominickn
2016/11/10 04:27:07
Done.
| |
| 82 default: | |
| 83 NOTREACHED(); | |
| 84 return PermissionRequestType::UNKNOWN; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 PermissionRequestGestureType gesture_type() const { | |
| 89 return PermissionUtil::GetGestureType(user_gesture_); | |
| 90 } | |
| 91 | |
| 67 const PermissionRequestID& id() const { return id_; } | 92 const PermissionRequestID& id() const { return id_; } |
| 68 const GURL& requesting_frame() const { return requesting_frame_; } | 93 const GURL& requesting_frame() const { return requesting_frame_; } |
| 69 bool has_gesture() const { return user_gesture_; } | 94 bool has_gesture() const { return user_gesture_; } |
| 70 bool has_infobar() const { return !!infobar_; } | 95 bool has_infobar() const { return !!infobar_; } |
| 71 bool has_dialog() const { return has_dialog_; } | 96 bool has_dialog() const { return has_dialog_; } |
| 72 infobars::InfoBar* infobar() { return infobar_; } | 97 infobars::InfoBar* infobar() { return infobar_; } |
| 73 | 98 |
| 74 void RunCallback(ContentSetting content_setting); | 99 void RunCallback(ContentSetting content_setting); |
| 75 void CreatePrompt(PermissionQueueController* controller, bool show_dialog); | 100 void CreatePrompt(PermissionQueueController* controller, bool show_dialog); |
| 76 | 101 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 227 } |
| 203 | 228 |
| 204 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, | 229 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, |
| 205 const GURL& requesting_frame, | 230 const GURL& requesting_frame, |
| 206 const GURL& embedder, | 231 const GURL& embedder, |
| 207 bool user_gesture, | 232 bool user_gesture, |
| 208 bool update_content_setting, | 233 bool update_content_setting, |
| 209 PermissionAction decision) { | 234 PermissionAction decision) { |
| 210 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 235 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 211 | 236 |
| 212 // TODO(miguelg): move the permission persistence to | 237 // TODO(miguelg): move the permission persistence to |
|
benwells
2016/11/10 03:24:28
is this TODO still valid? Maybe it should move som
dominickn
2016/11/10 04:27:07
Moved down to the update content setting call.
| |
| 213 // PermissionContextBase once all the types are moved there. | 238 // PermissionContextBase once all the types are moved there. |
| 239 PermissionRequestType request_type = | |
| 240 PermissionUtil::GetRequestType(permission_type_); | |
| 214 PermissionRequestGestureType gesture_type = | 241 PermissionRequestGestureType gesture_type = |
| 215 user_gesture ? PermissionRequestGestureType::GESTURE | 242 PermissionUtil::GetGestureType(user_gesture); |
| 216 : PermissionRequestGestureType::NO_GESTURE; | |
| 217 switch (decision) { | 243 switch (decision) { |
| 218 case GRANTED: | 244 case GRANTED: |
| 219 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, | 245 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, |
| 220 requesting_frame, profile_); | 246 requesting_frame, profile_); |
| 247 PermissionUmaUtil::RecordPermissionPromptAccepted(request_type, | |
| 248 gesture_type); | |
| 221 break; | 249 break; |
| 222 case DENIED: | 250 case DENIED: |
| 223 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, | 251 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, |
| 224 requesting_frame, profile_); | 252 requesting_frame, profile_); |
| 253 PermissionUmaUtil::RecordPermissionPromptDenied(request_type, | |
| 254 gesture_type); | |
| 225 break; | 255 break; |
| 226 case DISMISSED: | 256 case DISMISSED: |
| 227 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, | 257 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, |
| 228 requesting_frame, profile_); | 258 requesting_frame, profile_); |
| 229 break; | 259 break; |
| 230 default: | 260 default: |
| 231 NOTREACHED(); | 261 NOTREACHED(); |
| 232 } | 262 } |
| 233 | 263 |
| 234 if (update_content_setting) | 264 if (update_content_setting) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 384 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
| 355 i != pending_infobar_requests_.end(); ++i) { | 385 i != pending_infobar_requests_.end(); ++i) { |
| 356 if (ArePermissionRequestsForSameTab(i->id(), id) && !i->has_infobar()) { | 386 if (ArePermissionRequestsForSameTab(i->id(), id) && !i->has_infobar()) { |
| 357 // When using modal permission prompts, Java controls the display queue, | 387 // When using modal permission prompts, Java controls the display queue, |
| 358 // so infobar notifications are not relevant. | 388 // so infobar notifications are not relevant. |
| 359 bool show_dialog = | 389 bool show_dialog = |
| 360 PermissionDialogDelegate::ShouldShowDialog(i->has_gesture()); | 390 PermissionDialogDelegate::ShouldShowDialog(i->has_gesture()); |
| 361 if (!show_dialog) | 391 if (!show_dialog) |
| 362 RegisterForInfoBarNotifications(infobar_service); | 392 RegisterForInfoBarNotifications(infobar_service); |
| 363 | 393 |
| 394 PermissionUmaUtil::RecordPermissionPromptShown(i->request_type(), | |
| 395 i->gesture_type()); | |
| 364 i->CreatePrompt(this, show_dialog); | 396 i->CreatePrompt(this, show_dialog); |
| 365 return; | 397 return; |
| 366 } | 398 } |
| 367 } | 399 } |
| 368 | 400 |
| 369 UnregisterForInfoBarNotifications(infobar_service); | 401 UnregisterForInfoBarNotifications(infobar_service); |
| 370 } | 402 } |
| 371 | 403 |
| 372 void PermissionQueueController::ClearPendingInfobarRequestsForTab( | 404 void PermissionQueueController::ClearPendingInfobarRequestsForTab( |
| 373 const PermissionRequestID& id) { | 405 const PermissionRequestID& id) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 } | 449 } |
| 418 | 450 |
| 419 ContentSetting content_setting = | 451 ContentSetting content_setting = |
| 420 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 452 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 421 | 453 |
| 422 HostContentSettingsMapFactory::GetForProfile(profile_) | 454 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 423 ->SetContentSettingDefaultScope( | 455 ->SetContentSettingDefaultScope( |
| 424 requesting_frame.GetOrigin(), embedder.GetOrigin(), | 456 requesting_frame.GetOrigin(), embedder.GetOrigin(), |
| 425 content_settings_type_, std::string(), content_setting); | 457 content_settings_type_, std::string(), content_setting); |
| 426 } | 458 } |
| OLD | NEW |