| 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_infobar_delegate.h" | 5 #include "chrome/browser/permissions/permission_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 PermissionInfoBarDelegate::~PermissionInfoBarDelegate() {} |
| 8 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | |
| 9 #include "chrome/browser/permissions/permission_request.h" | |
| 10 #include "chrome/browser/permissions/permission_uma_util.h" | |
| 11 #include "chrome/common/chrome_features.h" | |
| 12 #include "chrome/grit/generated_resources.h" | |
| 13 #include "components/url_formatter/elide_url.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 | 8 |
| 16 PermissionInfobarDelegate::~PermissionInfobarDelegate() { | 9 PermissionInfoBarDelegate::PermissionInfoBarDelegate( |
| 17 if (!action_taken_) { | 10 const GURL& requesting_origin) |
| 18 PermissionDecisionAutoBlocker(profile_).RecordIgnore(requesting_origin_, | 11 : requesting_origin_(requesting_origin), persist_(true) {} |
| 19 permission_type_); | |
| 20 | 12 |
| 21 PermissionUmaUtil::PermissionIgnored( | 13 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { |
| 22 permission_type_, | |
| 23 user_gesture_ ? PermissionRequestGestureType::GESTURE | |
| 24 : PermissionRequestGestureType::NO_GESTURE, | |
| 25 requesting_origin_, profile_); | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 PermissionInfobarDelegate::PermissionInfobarDelegate( | |
| 30 const GURL& requesting_origin, | |
| 31 content::PermissionType permission_type, | |
| 32 ContentSettingsType content_settings_type, | |
| 33 bool user_gesture, | |
| 34 Profile* profile, | |
| 35 const PermissionSetCallback& callback) | |
| 36 : requesting_origin_(requesting_origin), | |
| 37 permission_type_(permission_type), | |
| 38 content_settings_type_(content_settings_type), | |
| 39 profile_(profile), | |
| 40 callback_(callback), | |
| 41 action_taken_(false), | |
| 42 user_gesture_(user_gesture), | |
| 43 persist_(true) {} | |
| 44 | |
| 45 bool PermissionInfobarDelegate::ShouldShowPersistenceToggle() const { | |
| 46 // Only show the persistence toggle for geolocation. | |
| 47 if (permission_type_ == content::PermissionType::GEOLOCATION) { | |
| 48 return base::FeatureList::IsEnabled( | |
| 49 features::kDisplayPersistenceToggleInPermissionPrompts); | |
| 50 } | |
| 51 return false; | 14 return false; |
| 52 } | 15 } |
| 53 | 16 |
| 54 base::string16 PermissionInfobarDelegate::GetMessageText() const { | 17 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType() |
| 55 return l10n_util::GetStringFUTF16( | |
| 56 GetMessageResourceId(), | |
| 57 url_formatter::FormatUrlForSecurityDisplay( | |
| 58 requesting_origin_, | |
| 59 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | |
| 60 } | |
| 61 | |
| 62 infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType() | |
| 63 const { | 18 const { |
| 64 return PAGE_ACTION_TYPE; | 19 return PAGE_ACTION_TYPE; |
| 65 } | 20 } |
| 66 | 21 |
| 67 void PermissionInfobarDelegate::InfoBarDismissed() { | 22 PermissionInfoBarDelegate* |
| 68 SetPermission(false, DISMISSED); | 23 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() { |
| 69 } | |
| 70 | |
| 71 PermissionInfobarDelegate* | |
| 72 PermissionInfobarDelegate::AsPermissionInfobarDelegate() { | |
| 73 return this; | 24 return this; |
| 74 } | 25 } |
| 75 | |
| 76 base::string16 PermissionInfobarDelegate::GetButtonLabel( | |
| 77 InfoBarButton button) const { | |
| 78 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
| 79 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); | |
| 80 } | |
| 81 | |
| 82 bool PermissionInfobarDelegate::Accept() { | |
| 83 bool update_content_setting = true; | |
| 84 if (ShouldShowPersistenceToggle()) { | |
| 85 update_content_setting = persist_; | |
| 86 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( | |
| 87 permission_type_, persist_); | |
| 88 } | |
| 89 | |
| 90 SetPermission(update_content_setting, GRANTED); | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 bool PermissionInfobarDelegate::Cancel() { | |
| 95 bool update_content_setting = true; | |
| 96 if (ShouldShowPersistenceToggle()) { | |
| 97 update_content_setting = persist_; | |
| 98 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( | |
| 99 permission_type_, persist_); | |
| 100 } | |
| 101 | |
| 102 SetPermission(update_content_setting, DENIED); | |
| 103 return true; | |
| 104 } | |
| 105 | |
| 106 void PermissionInfobarDelegate::SetPermission(bool update_content_setting, | |
| 107 PermissionAction decision) { | |
| 108 action_taken_ = true; | |
| 109 callback_.Run(update_content_setting, decision); | |
| 110 } | |
| OLD | NEW |