Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Side by Side Diff: chrome/browser/permissions/permission_infobar_delegate.cc

Issue 2250053002: Clean up the PermissionInfoBarDelegate hierarchy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-infobar-remember-decision
Patch Set: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_);
raymes 2016/08/18 00:58:43 :( I don't think this was in the last CL when I re
dominickn 2016/08/18 01:06:11 It's a bit sad that the ignore metrics are recorde
raymes 2016/08/18 01:17:44 Thanks - yeah the code in that last CL didn't evol
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 return (permission_type_ == content::PermissionType::GEOLOCATION) &&
47 if (permission_type_ == content::PermissionType::GEOLOCATION) { 45 PermissionUtil::ShouldShowPersistenceToggle();
48 return base::FeatureList::IsEnabled(
49 features::kDisplayPersistenceToggleInPermissionPrompts);
50 }
51 return false;
52 } 46 }
53 47
54 base::string16 PermissionInfobarDelegate::GetMessageText() const { 48 base::string16 PermissionInfoBarDelegate::GetMessageText() const {
55 return l10n_util::GetStringFUTF16( 49 return l10n_util::GetStringFUTF16(
56 GetMessageResourceId(), 50 GetMessageResourceId(),
57 url_formatter::FormatUrlForSecurityDisplay( 51 url_formatter::FormatUrlForSecurityDisplay(
58 requesting_origin_, 52 requesting_origin_,
59 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 53 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
60 } 54 }
61 55
62 infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType() 56 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType()
63 const { 57 const {
64 return PAGE_ACTION_TYPE; 58 return PAGE_ACTION_TYPE;
65 } 59 }
66 60
67 void PermissionInfobarDelegate::InfoBarDismissed() { 61 void PermissionInfoBarDelegate::InfoBarDismissed() {
68 SetPermission(false, DISMISSED); 62 SetPermission(false, DISMISSED);
69 } 63 }
70 64
71 PermissionInfobarDelegate* 65 PermissionInfoBarDelegate*
72 PermissionInfobarDelegate::AsPermissionInfobarDelegate() { 66 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() {
73 return this; 67 return this;
74 } 68 }
75 69
76 base::string16 PermissionInfobarDelegate::GetButtonLabel( 70 base::string16 PermissionInfoBarDelegate::GetButtonLabel(
77 InfoBarButton button) const { 71 InfoBarButton button) const {
78 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 72 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
79 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); 73 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
80 } 74 }
81 75
82 bool PermissionInfobarDelegate::Accept() { 76 bool PermissionInfoBarDelegate::Accept() {
83 bool update_content_setting = true; 77 bool update_content_setting = true;
84 if (ShouldShowPersistenceToggle()) { 78 if (ShouldShowPersistenceToggle()) {
85 update_content_setting = persist_; 79 update_content_setting = persist_;
86 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle( 80 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
87 permission_type_, persist_); 81 permission_type_, persist_);
88 } 82 }
89 83
90 SetPermission(update_content_setting, GRANTED); 84 SetPermission(update_content_setting, GRANTED);
91 return true; 85 return true;
92 } 86 }
93 87
94 bool PermissionInfobarDelegate::Cancel() { 88 bool PermissionInfoBarDelegate::Cancel() {
95 bool update_content_setting = true; 89 bool update_content_setting = true;
96 if (ShouldShowPersistenceToggle()) { 90 if (ShouldShowPersistenceToggle()) {
97 update_content_setting = persist_; 91 update_content_setting = persist_;
98 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle( 92 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
99 permission_type_, persist_); 93 permission_type_, persist_);
100 } 94 }
101 95
102 SetPermission(update_content_setting, DENIED); 96 SetPermission(update_content_setting, DENIED);
103 return true; 97 return true;
104 } 98 }
105 99
106 void PermissionInfobarDelegate::SetPermission(bool update_content_setting, 100 void PermissionInfoBarDelegate::SetPermission(bool update_content_setting,
107 PermissionAction decision) { 101 PermissionAction decision) {
108 action_taken_ = true; 102 action_taken_ = true;
109 callback_.Run(update_content_setting, decision); 103 callback_.Run(update_content_setting, decision);
110 } 104 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_infobar_delegate.h ('k') | chrome/browser/permissions/permission_queue_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698