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