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