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

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

Issue 2226633002: Add a feature to display a persistence toggle for permission prompts on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits, verbal change to make it geolocation-only 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"
7 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" 8 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
8 #include "chrome/browser/permissions/permission_request.h" 9 #include "chrome/browser/permissions/permission_request.h"
9 #include "chrome/browser/permissions/permission_uma_util.h" 10 #include "chrome/browser/permissions/permission_uma_util.h"
11 #include "chrome/common/chrome_features.h"
10 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
11 #include "components/infobars/core/infobar.h"
12 #include "components/url_formatter/elide_url.h" 13 #include "components/url_formatter/elide_url.h"
13 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
14 15
15 PermissionInfobarDelegate::~PermissionInfobarDelegate() { 16 PermissionInfobarDelegate::~PermissionInfobarDelegate() {
16 if (!action_taken_) { 17 if (!action_taken_) {
17 PermissionDecisionAutoBlocker(profile_).RecordIgnore(requesting_origin_, 18 PermissionDecisionAutoBlocker(profile_).RecordIgnore(requesting_origin_,
18 permission_type_); 19 permission_type_);
19 20
20 PermissionUmaUtil::PermissionIgnored( 21 PermissionUmaUtil::PermissionIgnored(
21 permission_type_, 22 permission_type_,
22 user_gesture_ ? PermissionRequestGestureType::GESTURE 23 user_gesture_ ? PermissionRequestGestureType::GESTURE
23 : PermissionRequestGestureType::NO_GESTURE, 24 : PermissionRequestGestureType::NO_GESTURE,
24 requesting_origin_, profile_); 25 requesting_origin_, profile_);
25 } 26 }
26 } 27 }
27 28
28 PermissionInfobarDelegate::PermissionInfobarDelegate( 29 PermissionInfobarDelegate::PermissionInfobarDelegate(
29 const GURL& requesting_origin, 30 const GURL& requesting_origin,
30 content::PermissionType permission_type, 31 content::PermissionType permission_type,
31 ContentSettingsType content_settings_type, 32 ContentSettingsType content_settings_type,
32 bool user_gesture, 33 bool user_gesture,
33 Profile* profile, 34 Profile* profile,
34 const base::Callback<void(bool, bool)>& callback) 35 const PermissionSetCallback& callback)
35 : requesting_origin_(requesting_origin), 36 : requesting_origin_(requesting_origin),
36 action_taken_(false),
37 permission_type_(permission_type), 37 permission_type_(permission_type),
38 content_settings_type_(content_settings_type), 38 content_settings_type_(content_settings_type),
39 profile_(profile),
40 callback_(callback),
41 action_taken_(false),
39 user_gesture_(user_gesture), 42 user_gesture_(user_gesture),
40 profile_(profile), 43 persist_(true) {}
41 callback_(callback) {} 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;
52 }
42 53
43 base::string16 PermissionInfobarDelegate::GetMessageText() const { 54 base::string16 PermissionInfobarDelegate::GetMessageText() const {
44 return l10n_util::GetStringFUTF16( 55 return l10n_util::GetStringFUTF16(
45 GetMessageResourceId(), 56 GetMessageResourceId(),
46 url_formatter::FormatUrlForSecurityDisplay( 57 url_formatter::FormatUrlForSecurityDisplay(
47 requesting_origin_, 58 requesting_origin_,
48 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 59 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
49 } 60 }
50 61
51 infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType() 62 infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType()
52 const { 63 const {
53 return PAGE_ACTION_TYPE; 64 return PAGE_ACTION_TYPE;
54 } 65 }
55 66
56 void PermissionInfobarDelegate::InfoBarDismissed() { 67 void PermissionInfobarDelegate::InfoBarDismissed() {
57 SetPermission(false, false); 68 SetPermission(false, DISMISSED);
58 } 69 }
59 70
60 PermissionInfobarDelegate* 71 PermissionInfobarDelegate*
61 PermissionInfobarDelegate::AsPermissionInfobarDelegate() { 72 PermissionInfobarDelegate::AsPermissionInfobarDelegate() {
62 return this; 73 return this;
63 } 74 }
64 75
65 base::string16 PermissionInfobarDelegate::GetButtonLabel( 76 base::string16 PermissionInfobarDelegate::GetButtonLabel(
66 InfoBarButton button) const { 77 InfoBarButton button) const {
67 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 78 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
68 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY); 79 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
69 } 80 }
70 81
71 bool PermissionInfobarDelegate::Accept() { 82 bool PermissionInfobarDelegate::Accept() {
72 SetPermission(true, true); 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);
73 return true; 91 return true;
74 } 92 }
75 93
76 bool PermissionInfobarDelegate::Cancel() { 94 bool PermissionInfobarDelegate::Cancel() {
77 SetPermission(true, false); 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);
78 return true; 103 return true;
79 } 104 }
80 105
81 void PermissionInfobarDelegate::SetPermission(bool update_content_setting, 106 void PermissionInfobarDelegate::SetPermission(bool update_content_setting,
82 bool allowed) { 107 PermissionAction decision) {
83 action_taken_ = true; 108 action_taken_ = true;
84 callback_.Run(update_content_setting, allowed); 109 callback_.Run(update_content_setting, decision);
85 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698