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

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: Move delegate creation and dispatch into constructor 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 <utility>
8
7 #include "build/build_config.h" 9 #include "build/build_config.h"
8 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h"
9 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" 12 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h"
11 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro id.h" 13 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro id.h"
12 #include "chrome/browser/notifications/notification_permission_infobar_delegate. h" 14 #include "chrome/browser/notifications/notification_permission_infobar_delegate. h"
13 #include "chrome/browser/permissions/permission_request.h" 15 #include "chrome/browser/permissions/permission_request.h"
14 #include "chrome/browser/permissions/permission_uma_util.h" 16 #include "chrome/browser/permissions/permission_uma_util.h"
15 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
16 #include "components/infobars/core/infobar.h" 18 #include "components/infobars/core/infobar.h"
17 #include "components/url_formatter/elide_url.h" 19 #include "components/url_formatter/elide_url.h"
20 #include "content/public/browser/web_contents.h"
18 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
19 22
20 // static 23 // static
21 infobars::InfoBar* PermissionInfoBarDelegate::Create( 24 infobars::InfoBar* PermissionInfoBarDelegate::Create(
25 InfoBarService* infobar_service,
22 content::PermissionType type, 26 content::PermissionType type,
23 InfoBarService* infobar_service, 27 const GURL& requesting_frame,
28 bool user_gesture,
29 Profile* profile,
30 const PermissionSetCallback& callback) {
31 std::unique_ptr<PermissionInfoBarDelegate> delegate =
32 PermissionInfoBarDelegate::CreateDelegate(
33 type, requesting_frame, user_gesture, profile, callback);
34
35 if (!delegate)
36 return nullptr;
37
38 return infobar_service->AddInfoBar(
39 CreatePermissionInfoBar(std::move(delegate)));
40 }
41
42 // static
43 std::unique_ptr<PermissionInfoBarDelegate>
44 PermissionInfoBarDelegate::CreateDelegate(
45 content::PermissionType type,
24 const GURL& requesting_frame, 46 const GURL& requesting_frame,
25 bool user_gesture, 47 bool user_gesture,
26 Profile* profile, 48 Profile* profile,
27 const PermissionSetCallback& callback) { 49 const PermissionSetCallback& callback) {
28 switch (type) { 50 switch (type) {
29 case content::PermissionType::GEOLOCATION: 51 case content::PermissionType::GEOLOCATION:
30 return infobar_service->AddInfoBar( 52 return std::unique_ptr<PermissionInfoBarDelegate>(
31 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
32 new GeolocationInfoBarDelegateAndroid( 53 new GeolocationInfoBarDelegateAndroid(
33 requesting_frame, user_gesture, profile, callback)))); 54 requesting_frame, user_gesture, profile, callback));
34 #if defined(ENABLE_NOTIFICATIONS) 55 #if defined(ENABLE_NOTIFICATIONS)
35 case content::PermissionType::NOTIFICATIONS: 56 case content::PermissionType::NOTIFICATIONS:
36 case content::PermissionType::PUSH_MESSAGING: 57 case content::PermissionType::PUSH_MESSAGING:
37 return infobar_service->AddInfoBar( 58 return std::unique_ptr<PermissionInfoBarDelegate>(
38 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>( 59 new NotificationPermissionInfoBarDelegate(
39 new NotificationPermissionInfoBarDelegate( 60 requesting_frame, user_gesture, profile, callback));
40 requesting_frame, user_gesture, profile, callback))));
41 #endif // ENABLE_NOTIFICATIONS 61 #endif // ENABLE_NOTIFICATIONS
42 case content::PermissionType::MIDI_SYSEX: 62 case content::PermissionType::MIDI_SYSEX:
43 return infobar_service->AddInfoBar( 63 return std::unique_ptr<PermissionInfoBarDelegate>(
44 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
45 new MidiPermissionInfoBarDelegateAndroid( 64 new MidiPermissionInfoBarDelegateAndroid(
46 requesting_frame, user_gesture, profile, callback)))); 65 requesting_frame, user_gesture, profile, callback));
47 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 66 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
48 return infobar_service->AddInfoBar( 67 return std::unique_ptr<PermissionInfoBarDelegate>(
49 CreatePermissionInfoBar(std::unique_ptr<PermissionInfoBarDelegate>(
50 new ProtectedMediaIdentifierInfoBarDelegateAndroid( 68 new ProtectedMediaIdentifierInfoBarDelegateAndroid(
51 requesting_frame, user_gesture, profile, callback)))); 69 requesting_frame, user_gesture, profile, callback));
52 default: 70 default:
53 NOTREACHED(); 71 NOTREACHED();
54 return nullptr; 72 return nullptr;
55 } 73 }
56 } 74 }
57 75
58 PermissionInfoBarDelegate::~PermissionInfoBarDelegate() { 76 PermissionInfoBarDelegate::~PermissionInfoBarDelegate() {
59 if (!action_taken_) { 77 if (!action_taken_) {
60 PermissionUmaUtil::PermissionIgnored( 78 PermissionUmaUtil::PermissionIgnored(
61 permission_type_, 79 permission_type_,
62 user_gesture_ ? PermissionRequestGestureType::GESTURE 80 user_gesture_ ? PermissionRequestGestureType::GESTURE
63 : PermissionRequestGestureType::NO_GESTURE, 81 : PermissionRequestGestureType::NO_GESTURE,
64 requesting_origin_, profile_); 82 requesting_origin_, profile_);
65 } 83 }
66 } 84 }
67 85
68 std::vector<int> PermissionInfoBarDelegate::content_settings() const { 86 std::vector<int> PermissionInfoBarDelegate::content_settings() const {
69 return std::vector<int>{content_settings_type_}; 87 return std::vector<int>{content_settings_type_};
70 } 88 }
71 89
72 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const { 90 bool PermissionInfoBarDelegate::ShouldShowPersistenceToggle() const {
73 return (permission_type_ == content::PermissionType::GEOLOCATION || 91 return (permission_type_ == content::PermissionType::GEOLOCATION ||
74 permission_type_ == content::PermissionType::AUDIO_CAPTURE || 92 permission_type_ == content::PermissionType::AUDIO_CAPTURE ||
75 permission_type_ == content::PermissionType::VIDEO_CAPTURE) && 93 permission_type_ == content::PermissionType::VIDEO_CAPTURE) &&
76 PermissionUtil::ShouldShowPersistenceToggle(); 94 PermissionUtil::ShouldShowPersistenceToggle();
77 } 95 }
78 96
97 bool PermissionInfoBarDelegate::Accept() {
98 bool update_content_setting = true;
99 if (ShouldShowPersistenceToggle()) {
100 update_content_setting = persist_;
101 PermissionUmaUtil::PermissionPromptAcceptedWithPersistenceToggle(
102 permission_type_, persist_);
103 }
104
105 SetPermission(update_content_setting, GRANTED);
106 return true;
107 }
108
109 bool PermissionInfoBarDelegate::Cancel() {
110 bool update_content_setting = true;
111 if (ShouldShowPersistenceToggle()) {
112 update_content_setting = persist_;
113 PermissionUmaUtil::PermissionPromptDeniedWithPersistenceToggle(
114 permission_type_, persist_);
115 }
116
117 SetPermission(update_content_setting, DENIED);
118 return true;
119 }
120
121 void PermissionInfoBarDelegate::InfoBarDismissed() {
122 SetPermission(false, DISMISSED);
123 }
124
125 base::string16 PermissionInfoBarDelegate::GetButtonLabel(
126 InfoBarButton button) const {
127 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PERMISSION_ALLOW
128 : IDS_PERMISSION_DENY);
129 }
130
79 base::string16 PermissionInfoBarDelegate::GetMessageText() const { 131 base::string16 PermissionInfoBarDelegate::GetMessageText() const {
80 return l10n_util::GetStringFUTF16( 132 return l10n_util::GetStringFUTF16(
81 GetMessageResourceId(), 133 GetMessageResourceId(),
82 url_formatter::FormatUrlForSecurityDisplay( 134 url_formatter::FormatUrlForSecurityDisplay(
83 requesting_origin_, 135 requesting_origin_,
84 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); 136 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
85 } 137 }
86 138
87 PermissionInfoBarDelegate::PermissionInfoBarDelegate( 139 PermissionInfoBarDelegate::PermissionInfoBarDelegate(
88 const GURL& requesting_origin, 140 const GURL& requesting_origin,
89 content::PermissionType permission_type, 141 content::PermissionType permission_type,
90 ContentSettingsType content_settings_type, 142 ContentSettingsType content_settings_type,
91 bool user_gesture, 143 bool user_gesture,
92 Profile* profile, 144 Profile* profile,
93 const PermissionSetCallback& callback) 145 const PermissionSetCallback& callback)
94 : requesting_origin_(requesting_origin), 146 : requesting_origin_(requesting_origin),
95 permission_type_(permission_type), 147 permission_type_(permission_type),
96 content_settings_type_(content_settings_type), 148 content_settings_type_(content_settings_type),
97 profile_(profile), 149 profile_(profile),
98 callback_(callback), 150 callback_(callback),
99 action_taken_(false), 151 action_taken_(false),
100 user_gesture_(user_gesture), 152 user_gesture_(user_gesture),
101 persist_(true) {} 153 persist_(true) {}
102 154
103 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType() 155 infobars::InfoBarDelegate::Type PermissionInfoBarDelegate::GetInfoBarType()
104 const { 156 const {
105 return PAGE_ACTION_TYPE; 157 return PAGE_ACTION_TYPE;
106 } 158 }
107 159
108 void PermissionInfoBarDelegate::InfoBarDismissed() {
109 SetPermission(false, DISMISSED);
110 }
111
112 PermissionInfoBarDelegate* 160 PermissionInfoBarDelegate*
113 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() { 161 PermissionInfoBarDelegate::AsPermissionInfoBarDelegate() {
114 return this; 162 return this;
115 } 163 }
116 164
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, 165 void PermissionInfoBarDelegate::SetPermission(bool update_content_setting,
148 PermissionAction decision) { 166 PermissionAction decision) {
149 action_taken_ = true; 167 action_taken_ = true;
150 callback_.Run(update_content_setting, decision); 168 callback_.Run(update_content_setting, decision);
151 } 169 }
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