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

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

Powered by Google App Engine
This is Rietveld 408576698