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

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

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase + include content_settings_types.h more Created 3 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_queue_controller.h" 5 #include "chrome/browser/permissions/permission_queue_controller.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 content::WebContents* other_web_contents = tab_util::GetWebContentsByFrameID( 47 content::WebContents* other_web_contents = tab_util::GetWebContentsByFrameID(
48 other_request.render_process_id(), other_request.render_frame_id()); 48 other_request.render_process_id(), other_request.render_frame_id());
49 49
50 return web_contents == other_web_contents; 50 return web_contents == other_web_contents;
51 } 51 }
52 52
53 } // anonymous namespace 53 } // anonymous namespace
54 54
55 class PermissionQueueController::PendingInfobarRequest { 55 class PermissionQueueController::PendingInfobarRequest {
56 public: 56 public:
57 PendingInfobarRequest(content::PermissionType type, 57 PendingInfobarRequest(ContentSettingsType type,
58 const PermissionRequestID& id, 58 const PermissionRequestID& id,
59 const GURL& requesting_frame, 59 const GURL& requesting_frame,
60 const GURL& embedder, 60 const GURL& embedder,
61 bool user_gesture, 61 bool user_gesture,
62 Profile* profile, 62 Profile* profile,
63 const PermissionDecidedCallback& callback); 63 const PermissionDecidedCallback& callback);
64 ~PendingInfobarRequest(); 64 ~PendingInfobarRequest();
65 65
66 bool IsForPair(const GURL& requesting_frame, 66 bool IsForPair(const GURL& requesting_frame,
67 const GURL& embedder) const; 67 const GURL& embedder) const;
(...skipping 10 matching lines...) Expand all
78 const GURL& requesting_frame() const { return requesting_frame_; } 78 const GURL& requesting_frame() const { return requesting_frame_; }
79 bool has_gesture() const { return user_gesture_; } 79 bool has_gesture() const { return user_gesture_; }
80 bool has_infobar() const { return !!infobar_; } 80 bool has_infobar() const { return !!infobar_; }
81 bool has_dialog() const { return has_dialog_; } 81 bool has_dialog() const { return has_dialog_; }
82 infobars::InfoBar* infobar() { return infobar_; } 82 infobars::InfoBar* infobar() { return infobar_; }
83 83
84 void RunCallback(ContentSetting content_setting); 84 void RunCallback(ContentSetting content_setting);
85 void CreatePrompt(PermissionQueueController* controller, bool show_dialog); 85 void CreatePrompt(PermissionQueueController* controller, bool show_dialog);
86 86
87 private: 87 private:
88 content::PermissionType type_; 88 ContentSettingsType type_;
89 PermissionRequestID id_; 89 PermissionRequestID id_;
90 GURL requesting_frame_; 90 GURL requesting_frame_;
91 GURL embedder_; 91 GURL embedder_;
92 bool user_gesture_; 92 bool user_gesture_;
93 Profile* profile_; 93 Profile* profile_;
94 PermissionDecidedCallback callback_; 94 PermissionDecidedCallback callback_;
95 infobars::InfoBar* infobar_; 95 infobars::InfoBar* infobar_;
96 bool has_dialog_; 96 bool has_dialog_;
97 97
98 // Purposefully do not disable copying, as this is stored in STL containers. 98 // Purposefully do not disable copying, as this is stored in STL containers.
99 }; 99 };
100 100
101 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( 101 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest(
102 content::PermissionType type, 102 ContentSettingsType type,
103 const PermissionRequestID& id, 103 const PermissionRequestID& id,
104 const GURL& requesting_frame, 104 const GURL& requesting_frame,
105 const GURL& embedder, 105 const GURL& embedder,
106 bool user_gesture, 106 bool user_gesture,
107 Profile* profile, 107 Profile* profile,
108 const PermissionDecidedCallback& callback) 108 const PermissionDecidedCallback& callback)
109 : type_(type), 109 : type_(type),
110 id_(id), 110 id_(id),
111 requesting_frame_(requesting_frame), 111 requesting_frame_(requesting_frame),
112 embedder_(embedder), 112 embedder_(embedder),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 callback); 153 callback);
154 } else { 154 } else {
155 infobar_ = PermissionInfoBarDelegate::Create( 155 infobar_ = PermissionInfoBarDelegate::Create(
156 GetInfoBarService(id_), type_, requesting_frame_, user_gesture_, 156 GetInfoBarService(id_), type_, requesting_frame_, user_gesture_,
157 profile_, callback); 157 profile_, callback);
158 } 158 }
159 } 159 }
160 160
161 PermissionQueueController::PermissionQueueController( 161 PermissionQueueController::PermissionQueueController(
162 Profile* profile, 162 Profile* profile,
163 content::PermissionType permission_type,
164 ContentSettingsType content_settings_type) 163 ContentSettingsType content_settings_type)
165 : profile_(profile), 164 : profile_(profile),
166 permission_type_(permission_type),
167 content_settings_type_(content_settings_type), 165 content_settings_type_(content_settings_type),
168 in_shutdown_(false) {} 166 in_shutdown_(false) {}
169 167
170 PermissionQueueController::~PermissionQueueController() { 168 PermissionQueueController::~PermissionQueueController() {
171 // Cancel all outstanding requests. 169 // Cancel all outstanding requests.
172 in_shutdown_ = true; 170 in_shutdown_ = true;
173 while (!pending_infobar_requests_.empty()) 171 while (!pending_infobar_requests_.empty())
174 CancelInfoBarRequest(pending_infobar_requests_.front().id()); 172 CancelInfoBarRequest(pending_infobar_requests_.front().id());
175 } 173 }
176 174
177 void PermissionQueueController::CreateInfoBarRequest( 175 void PermissionQueueController::CreateInfoBarRequest(
178 const PermissionRequestID& id, 176 const PermissionRequestID& id,
179 const GURL& requesting_frame, 177 const GURL& requesting_frame,
180 const GURL& embedder, 178 const GURL& embedder,
181 bool user_gesture, 179 bool user_gesture,
182 const PermissionDecidedCallback& callback) { 180 const PermissionDecidedCallback& callback) {
183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 181 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
184 182
185 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || 183 if (requesting_frame.SchemeIs(content::kChromeUIScheme) ||
186 embedder.SchemeIs(content::kChromeUIScheme)) 184 embedder.SchemeIs(content::kChromeUIScheme))
187 return; 185 return;
188 186
189 pending_infobar_requests_.push_back( 187 pending_infobar_requests_.push_back(
190 PendingInfobarRequest(permission_type_, id, requesting_frame, embedder, 188 PendingInfobarRequest(content_settings_type_, id, requesting_frame,
191 user_gesture, profile_, callback)); 189 embedder, user_gesture, profile_, callback));
192 if (!AlreadyShowingInfoBarForTab(id)) 190 if (!AlreadyShowingInfoBarForTab(id))
193 ShowQueuedInfoBarForTab(id); 191 ShowQueuedInfoBarForTab(id);
194 } 192 }
195 193
196 void PermissionQueueController::CancelInfoBarRequest( 194 void PermissionQueueController::CancelInfoBarRequest(
197 const PermissionRequestID& id) { 195 const PermissionRequestID& id) {
198 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 196 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
199 197
200 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); 198 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin());
201 i != pending_infobar_requests_.end(); ++i) { 199 i != pending_infobar_requests_.end(); ++i) {
(...skipping 11 matching lines...) Expand all
213 211
214 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, 212 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id,
215 const GURL& requesting_frame, 213 const GURL& requesting_frame,
216 const GURL& embedder, 214 const GURL& embedder,
217 bool user_gesture, 215 bool user_gesture,
218 bool update_content_setting, 216 bool update_content_setting,
219 PermissionAction decision) { 217 PermissionAction decision) {
220 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 218 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
221 219
222 PermissionRequestType request_type = 220 PermissionRequestType request_type =
223 PermissionUtil::GetRequestType(permission_type_); 221 PermissionUtil::GetRequestType(content_settings_type_);
224 PermissionRequestGestureType gesture_type = 222 PermissionRequestGestureType gesture_type =
225 PermissionUtil::GetGestureType(user_gesture); 223 PermissionUtil::GetGestureType(user_gesture);
226 switch (decision) { 224 switch (decision) {
227 case GRANTED: 225 case GRANTED:
228 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, 226 PermissionUmaUtil::PermissionGranted(content_settings_type_, gesture_type,
229 requesting_frame, profile_); 227 requesting_frame, profile_);
230 PermissionUmaUtil::RecordPermissionPromptAccepted(request_type, 228 PermissionUmaUtil::RecordPermissionPromptAccepted(request_type,
231 gesture_type); 229 gesture_type);
232 PermissionUmaUtil::RecordPermissionEmbargoStatus( 230 PermissionUmaUtil::RecordPermissionEmbargoStatus(
233 PermissionEmbargoStatus::NOT_EMBARGOED); 231 PermissionEmbargoStatus::NOT_EMBARGOED);
234 break; 232 break;
235 case DENIED: 233 case DENIED:
236 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, 234 PermissionUmaUtil::PermissionDenied(content_settings_type_, gesture_type,
237 requesting_frame, profile_); 235 requesting_frame, profile_);
238 PermissionUmaUtil::RecordPermissionPromptDenied(request_type, 236 PermissionUmaUtil::RecordPermissionPromptDenied(request_type,
239 gesture_type); 237 gesture_type);
240 PermissionUmaUtil::RecordPermissionEmbargoStatus( 238 PermissionUmaUtil::RecordPermissionEmbargoStatus(
241 PermissionEmbargoStatus::NOT_EMBARGOED); 239 PermissionEmbargoStatus::NOT_EMBARGOED);
242 break; 240 break;
243 case DISMISSED: 241 case DISMISSED:
244 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, 242 PermissionUmaUtil::PermissionDismissed(
245 requesting_frame, profile_); 243 content_settings_type_, gesture_type, requesting_frame, profile_);
246 if (PermissionDecisionAutoBlocker::GetForProfile(profile_) 244 if (PermissionDecisionAutoBlocker::GetForProfile(profile_)
247 ->RecordDismissAndEmbargo(requesting_frame, permission_type_)) { 245 ->RecordDismissAndEmbargo(requesting_frame,
246 content_settings_type_)) {
248 PermissionUmaUtil::RecordPermissionEmbargoStatus( 247 PermissionUmaUtil::RecordPermissionEmbargoStatus(
249 PermissionEmbargoStatus::REPEATED_DISMISSALS); 248 PermissionEmbargoStatus::REPEATED_DISMISSALS);
250 } else { 249 } else {
251 PermissionUmaUtil::RecordPermissionEmbargoStatus( 250 PermissionUmaUtil::RecordPermissionEmbargoStatus(
252 PermissionEmbargoStatus::NOT_EMBARGOED); 251 PermissionEmbargoStatus::NOT_EMBARGOED);
253 } 252 }
254 break; 253 break;
255 default: 254 default:
256 NOTREACHED(); 255 NOTREACHED();
257 } 256 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 if (requesting_frame.GetOrigin().SchemeIsFile()) { 440 if (requesting_frame.GetOrigin().SchemeIsFile()) {
442 // Chrome can be launched with --disable-web-security which allows 441 // Chrome can be launched with --disable-web-security which allows
443 // geolocation requests from file:// URLs. We don't want to store these 442 // geolocation requests from file:// URLs. We don't want to store these
444 // in the host content settings map. 443 // in the host content settings map.
445 return; 444 return;
446 } 445 }
447 446
448 ContentSetting content_setting = 447 ContentSetting content_setting =
449 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 448 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
450 449
450 // TODO(timloh): Remove this logic when push and notification permissions
451 // are reconciled, see crbug.com/563297.
452 ContentSettingsType type_for_map = content_settings_type_;
453 if (type_for_map == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING)
454 type_for_map = CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
451 HostContentSettingsMapFactory::GetForProfile(profile_) 455 HostContentSettingsMapFactory::GetForProfile(profile_)
452 ->SetContentSettingDefaultScope( 456 ->SetContentSettingDefaultScope(
453 requesting_frame.GetOrigin(), embedder.GetOrigin(), 457 requesting_frame.GetOrigin(), embedder.GetOrigin(),
454 content_settings_type_, std::string(), content_setting); 458 type_for_map, std::string(), content_setting);
455 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698