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