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

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

Issue 1158813002: Use RenderFrameHost for ::RequestPermission() and ::CancelPermission(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fixes Created 5 years, 6 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/content_settings/permission_queue_controller.h" 5 #include "chrome/browser/content_settings/permission_queue_controller.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/content_settings/permission_context_uma_util.h" 9 #include "chrome/browser/content_settings/permission_context_uma_util.h"
10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/url_constants.h" 25 #include "content/public/common/url_constants.h"
26 26
27 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 27 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
28 #include "chrome/browser/media/protected_media_identifier_infobar_delegate.h" 28 #include "chrome/browser/media/protected_media_identifier_infobar_delegate.h"
29 #endif 29 #endif
30 30
31 namespace { 31 namespace {
32 32
33 InfoBarService* GetInfoBarService(const PermissionRequestID& id) { 33 InfoBarService* GetInfoBarService(const PermissionRequestID& id) {
34 content::WebContents* web_contents = 34 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
35 tab_util::GetWebContentsByID(id.render_process_id(), id.render_view_id()); 35 id.render_process_id(), id.render_frame_id());
36 return web_contents ? InfoBarService::FromWebContents(web_contents) : NULL; 36 return web_contents ? InfoBarService::FromWebContents(web_contents) : NULL;
37 } 37 }
38 38
39 bool ArePermissionRequestsForSameTab(
40 const PermissionRequestID& request,
41 const PermissionRequestID& other_request) {
42 content::WebContents* web_contents = tab_util::GetWebContentsByFrameID(
43 request.render_process_id(), request.render_frame_id());
44 content::WebContents* other_web_contents = tab_util::GetWebContentsByFrameID(
45 other_request.render_process_id(), other_request.render_frame_id());
46
47 return web_contents == other_web_contents;
39 } 48 }
40 49
50 } // anonymous namespace
41 51
42 class PermissionQueueController::PendingInfobarRequest { 52 class PermissionQueueController::PendingInfobarRequest {
43 public: 53 public:
44 PendingInfobarRequest(ContentSettingsType type, 54 PendingInfobarRequest(ContentSettingsType type,
45 const PermissionRequestID& id, 55 const PermissionRequestID& id,
46 const GURL& requesting_frame, 56 const GURL& requesting_frame,
47 const GURL& embedder, 57 const GURL& embedder,
48 const PermissionDecidedCallback& callback); 58 const PermissionDecidedCallback& callback);
49 ~PendingInfobarRequest(); 59 ~PendingInfobarRequest();
50 60
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!AlreadyShowingInfoBarForTab(id)) 174 if (!AlreadyShowingInfoBarForTab(id))
165 ShowQueuedInfoBarForTab(id); 175 ShowQueuedInfoBarForTab(id);
166 } 176 }
167 177
168 void PermissionQueueController::CancelInfoBarRequest( 178 void PermissionQueueController::CancelInfoBarRequest(
169 const PermissionRequestID& id) { 179 const PermissionRequestID& id) {
170 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 180 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
171 181
172 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); 182 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin());
173 i != pending_infobar_requests_.end(); ++i) { 183 i != pending_infobar_requests_.end(); ++i) {
174 if (i->id().Equals(id)) { 184 if (!i->id().Equals(id))
175 if (i->has_infobar()) 185 continue;
176 GetInfoBarService(id)->RemoveInfoBar(i->infobar()); 186
177 else 187 InfoBarService* infobar_service = GetInfoBarService(id);
178 pending_infobar_requests_.erase(i); 188 if (infobar_service && i->has_infobar())
179 return; 189 infobar_service->RemoveInfoBar(i->infobar());
180 } 190 else
191 pending_infobar_requests_.erase(i);
192 return;
181 } 193 }
182 } 194 }
183 195
184 void PermissionQueueController::OnPermissionSet( 196 void PermissionQueueController::OnPermissionSet(
185 const PermissionRequestID& id, 197 const PermissionRequestID& id,
186 const GURL& requesting_frame, 198 const GURL& requesting_frame,
187 const GURL& embedder, 199 const GURL& embedder,
188 bool update_content_setting, 200 bool update_content_setting,
189 bool allowed) { 201 bool allowed) {
190 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 202 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return; 292 return;
281 } 293 }
282 } 294 }
283 } 295 }
284 296
285 bool PermissionQueueController::AlreadyShowingInfoBarForTab( 297 bool PermissionQueueController::AlreadyShowingInfoBarForTab(
286 const PermissionRequestID& id) const { 298 const PermissionRequestID& id) const {
287 for (PendingInfobarRequests::const_iterator i( 299 for (PendingInfobarRequests::const_iterator i(
288 pending_infobar_requests_.begin()); 300 pending_infobar_requests_.begin());
289 i != pending_infobar_requests_.end(); ++i) { 301 i != pending_infobar_requests_.end(); ++i) {
290 if (i->id().IsForSameTabAs(id) && i->has_infobar()) 302 if (ArePermissionRequestsForSameTab(i->id(), id) && i->has_infobar())
291 return true; 303 return true;
292 } 304 }
293 return false; 305 return false;
294 } 306 }
295 307
296 void PermissionQueueController::ShowQueuedInfoBarForTab( 308 void PermissionQueueController::ShowQueuedInfoBarForTab(
297 const PermissionRequestID& id) { 309 const PermissionRequestID& id) {
298 DCHECK(!AlreadyShowingInfoBarForTab(id)); 310 DCHECK(!AlreadyShowingInfoBarForTab(id));
299 311
300 // We can get here for example during tab shutdown, when the InfoBarService is 312 // We can get here for example during tab shutdown, when the InfoBarService is
301 // removing all existing infobars, thus calling back to Observe(). In this 313 // removing all existing infobars, thus calling back to Observe(). In this
302 // case the service still exists, and is supplied as the source of the 314 // case the service still exists, and is supplied as the source of the
303 // notification we observed, but is no longer accessible from its WebContents. 315 // notification we observed, but is no longer accessible from its WebContents.
304 // In this case we should just go ahead and cancel further infobars for this 316 // In this case we should just go ahead and cancel further infobars for this
305 // tab instead of trying to access the service. 317 // tab instead of trying to access the service.
306 // 318 //
307 // Similarly, if we're being destroyed, we should also avoid showing further 319 // Similarly, if we're being destroyed, we should also avoid showing further
308 // infobars. 320 // infobars.
309 InfoBarService* infobar_service = GetInfoBarService(id); 321 InfoBarService* infobar_service = GetInfoBarService(id);
310 if (!infobar_service || in_shutdown_) { 322 if (!infobar_service || in_shutdown_) {
311 ClearPendingInfobarRequestsForTab(id); 323 ClearPendingInfobarRequestsForTab(id);
312 return; 324 return;
313 } 325 }
314 326
315 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); 327 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin();
316 i != pending_infobar_requests_.end(); ++i) { 328 i != pending_infobar_requests_.end(); ++i) {
317 if (i->id().IsForSameTabAs(id) && !i->has_infobar()) { 329 if (ArePermissionRequestsForSameTab(i->id(), id) && !i->has_infobar()) {
318 RegisterForInfoBarNotifications(infobar_service); 330 RegisterForInfoBarNotifications(infobar_service);
319 i->CreateInfoBar( 331 i->CreateInfoBar(
320 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 332 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
321 return; 333 return;
322 } 334 }
323 } 335 }
324 336
325 UnregisterForInfoBarNotifications(infobar_service); 337 UnregisterForInfoBarNotifications(infobar_service);
326 } 338 }
327 339
328 void PermissionQueueController::ClearPendingInfobarRequestsForTab( 340 void PermissionQueueController::ClearPendingInfobarRequestsForTab(
329 const PermissionRequestID& id) { 341 const PermissionRequestID& id) {
330 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); 342 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin();
331 i != pending_infobar_requests_.end(); ) { 343 i != pending_infobar_requests_.end(); ) {
332 if (i->id().IsForSameTabAs(id)) { 344 if (ArePermissionRequestsForSameTab(i->id(), id)) {
333 DCHECK(!i->has_infobar()); 345 DCHECK(!i->has_infobar());
334 i = pending_infobar_requests_.erase(i); 346 i = pending_infobar_requests_.erase(i);
335 } else { 347 } else {
336 ++i; 348 ++i;
337 } 349 }
338 } 350 }
339 } 351 }
340 352
341 void PermissionQueueController::RegisterForInfoBarNotifications( 353 void PermissionQueueController::RegisterForInfoBarNotifications(
342 InfoBarService* infobar_service) { 354 InfoBarService* infobar_service) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 ContentSettingsPattern::Wildcard() : 391 ContentSettingsPattern::Wildcard() :
380 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()); 392 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin());
381 393
382 profile_->GetHostContentSettingsMap()->SetContentSetting( 394 profile_->GetHostContentSettingsMap()->SetContentSetting(
383 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), 395 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()),
384 embedder_pattern, 396 embedder_pattern,
385 type_, 397 type_,
386 std::string(), 398 std::string(),
387 content_setting); 399 content_setting);
388 } 400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698