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

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

Issue 2446063002: Implement a modal permission dialog on Android gated by a feature. (Closed)
Patch Set: Allow user gesture requirement to be overridden by variations Created 4 years, 1 month 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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" 8 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h"
9 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" 10 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h"
11 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro id.h" 11 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro id.h"
12 #include "chrome/browser/notifications/notification_permission_infobar_delegate. h" 12 #include "chrome/browser/notifications/notification_permission_infobar_delegate. h"
13 #include "chrome/browser/permissions/permission_request.h" 13 #include "chrome/browser/permissions/permission_request.h"
14 #include "chrome/browser/permissions/permission_uma_util.h" 14 #include "chrome/browser/permissions/permission_uma_util.h"
15 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "components/infobars/core/infobar.h" 16 #include "components/infobars/core/infobar.h"
17 #include "components/url_formatter/elide_url.h" 17 #include "components/url_formatter/elide_url.h"
18 #include "content/public/browser/web_contents.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 20
20 // static 21 // static
21 infobars::InfoBar* PermissionInfoBarDelegate::Create( 22 infobars::InfoBar* PermissionInfoBarDelegate::Create(
22 content::PermissionType type, 23 content::PermissionType type,
23 InfoBarService* infobar_service, 24 InfoBarService* infobar_service,
24 const GURL& requesting_frame, 25 const GURL& requesting_frame,
25 bool user_gesture, 26 bool user_gesture,
26 Profile* profile, 27 Profile* profile,
27 const PermissionSetCallback& callback) { 28 const PermissionSetCallback& callback) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return std::vector<int>{content_settings_type_}; 70 return std::vector<int>{content_settings_type_};
70 } 71 }
71 72
72 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { 73 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
73 return (permission_type_ == content::PermissionType::GEOLOCATION || 74 return (permission_type_ == content::PermissionType::GEOLOCATION ||
74 permission_type_ == content::PermissionType::AUDIO_CAPTURE || 75 permission_type_ == content::PermissionType::AUDIO_CAPTURE ||
75 permission_type_ == content::PermissionType::VIDEO_CAPTURE) && 76 permission_type_ == content::PermissionType::VIDEO_CAPTURE) &&
76 PermissionUtil::ShouldShowPersistenceToggle(); 77 PermissionUtil::ShouldShowPersistenceToggle();
77 } 78 }
78 79
80 bool PermissionInfoBarDelegate::Accept() {
81 bool update_content_setting = true;
82 if (ShouldShowPersistenceToggle()) {
83 update_content_setting = persist_;
84 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
85 permission_type_, persist_);
86 }
87
88 SetPermission(update_content_setting, GRANTED);
89 return true;
90 }
91
92 bool PermissionInfoBarDelegate::Cancel() {
93 bool update_content_setting = true;
94 if (ShouldShowPersistenceToggle()) {
95 update_content_setting = persist_;
96 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
97 permission_type_, persist_);
98 }
99
100 SetPermission(update_content_setting, DENIED);
101 return true;
102 }
103
104 void PermissionInfoBarDelegate::InfoBarDismissed() {
105 SetPermission(false, DISMISSED);
106 }
107
108 base::string16 PermissionInfoBarDelegate::GetButtonLabel(
109 InfoBarButton button) const {
110 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW
111 : IDS_PERMISSION_DENY);
112 }
113
79 base::string16 PermissionInfoBarDelegate::GetMessageText() const { 114 base::string16 PermissionInfoBarDelegate::GetMessageText() const {
80 return l10n_util::GetStringFUTF16( 115 return l10n_util::GetStringFUTF16(
81 GetMessageResourceId(), 116 GetMessageResourceId(),
82 url_formatter::FormatUrlForSecurityDisplay( 117 url_formatter::FormatUrlForSecurityDisplay(
83 requesting_origin_, 118 requesting_origin_,
84 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 119 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
85 } 120 }
86 121
87 PermissionInfoBarDelegate::PermissionInfoBarDelegate( 122 PermissionInfoBarDelegate::PermissionInfoBarDelegate(
88 const GURL& requesting_origin, 123 const GURL& requesting_origin,
89 content::PermissionType permission_type, 124 content::PermissionType permission_type,
90 ContentSettingsType content_settings_type, 125 ContentSettingsType content_settings_type,
91 bool user_gesture, 126 bool user_gesture,
92 Profile* profile, 127 Profile* profile,
93 const PermissionSetCallback& callback) 128 const PermissionSetCallback& callback)
94 : requesting_origin_(requesting_origin), 129 : requesting_origin_(requesting_origin),
95 permission_type_(permission_type), 130 permission_type_(permission_type),
96 content_settings_type_(content_settings_type), 131 content_settings_type_(content_settings_type),
97 profile_(profile), 132 profile_(profile),
98 callback_(callback), 133 callback_(callback),
99 action_taken_(false), 134 action_taken_(false),
100 user_gesture_(user_gesture), 135 user_gesture_(user_gesture),
101 persist_(true) {} 136 persist_(true) {}
102 137
103 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType() 138 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType()
104 const { 139 const {
105 return PAGE_ACTION_TYPE; 140 return PAGE_ACTION_TYPE;
106 } 141 }
107 142
108 void PermissionInfoBarDelegate::InfoBarDismissed() {
109 SetPermission(false, DISMISSED);
110 }
111
112 PermissionInfoBarDelegate* 143 PermissionInfoBarDelegate*
113 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() { 144 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() {
114 return this; 145 return this;
115 } 146 }
116 147
117 base::string16 PermissionInfoBarDelegate::GetButtonLabel(
118 InfoBarButton button) const {
119 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
120 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
121 }
122
123 bool PermissionInfoBarDelegate::Accept() {
124 bool update_content_setting = true;
125 if (ShouldShowPersistenceToggle()) {
126 update_content_setting = persist_;
127 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
128 permission_type_, persist_);
129 }
130
131 SetPermission(update_content_setting, GRANTED);
132 return true;
133 }
134
135 bool PermissionInfoBarDelegate::Cancel() {
136 bool update_content_setting = true;
137 if (ShouldShowPersistenceToggle()) {
138 update_content_setting = persist_;
139 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
140 permission_type_, persist_);
141 }
142
143 SetPermission(update_content_setting, DENIED);
144 return true;
145 }
146
147 void PermissionInfoBarDelegate::SetPermission(bool update_content_setting, 148 void PermissionInfoBarDelegate::SetPermission(bool update_content_setting,
148 PermissionAction decision) { 149 PermissionAction decision) {
149 action_taken_ = true; 150 action_taken_ = true;
150 callback_.Run(update_content_setting, decision); 151 callback_.Run(update_content_setting, decision);
151 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698