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

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context.cc

Issue 9491009: Show queued geolocation InfoBars when InfoBar is hidden. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Requested changes. Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/geolocation/chrome_geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/content_settings/host_content_settings_map.h" 13 #include "chrome/browser/content_settings/host_content_settings_map.h"
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/google/google_util.h" 16 #include "chrome/browser/google/google_util.h"
17 #include "chrome/browser/infobars/infobar.h"
17 #include "chrome/browser/infobars/infobar_tab_helper.h" 18 #include "chrome/browser/infobars/infobar_tab_helper.h"
18 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
21 #include "chrome/browser/tab_contents/tab_util.h" 22 #include "chrome/browser/tab_contents/tab_util.h"
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
24 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
25 #include "content/browser/renderer_host/render_view_host.h" 27 #include "content/browser/renderer_host/render_view_host.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/navigation_details.h" 29 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/navigation_entry.h" 30 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/notification_details.h"
29 #include "content/public/browser/notification_registrar.h" 32 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
31 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
32 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
33 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
34 #include "grit/locale_settings.h" 37 #include "grit/locale_settings.h"
35 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
36 #include "grit/theme_resources_standard.h" 39 #include "grit/theme_resources_standard.h"
37 #include "net/base/net_util.h" 40 #include "net/base/net_util.h"
38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 int bridge_id, 73 int bridge_id,
71 const GURL& requesting_frame, 74 const GURL& requesting_frame,
72 const GURL& emebedder, 75 const GURL& emebedder,
73 base::Callback<void(bool)> callback); 76 base::Callback<void(bool)> callback);
74 77
75 // Cancels a specific infobar request. 78 // Cancels a specific infobar request.
76 void CancelInfoBarRequest(int render_process_id, 79 void CancelInfoBarRequest(int render_process_id,
77 int render_view_id, 80 int render_view_id,
78 int bridge_id); 81 int bridge_id);
79 82
80 // Called by the InfoBarDelegate to notify it's closed. It'll display a new
81 // InfoBar if there's any request pending for this tab.
82 void OnInfoBarClosed(int render_process_id,
83 int render_view_id,
84 int bridge_id);
85
86 // Called by the InfoBarDelegate to notify permission has been set. 83 // Called by the InfoBarDelegate to notify permission has been set.
87 // It'll notify and dismiss any other pending InfoBar request for the same 84 // It'll notify and dismiss any other pending InfoBar request for the same
88 // |requesting_frame| and embedder. 85 // |requesting_frame| and embedder.
89 void OnPermissionSet(int render_process_id, 86 void OnPermissionSet(int render_process_id,
90 int render_view_id, 87 int render_view_id,
91 int bridge_id, 88 int bridge_id,
92 const GURL& requesting_frame, 89 const GURL& requesting_frame,
93 const GURL& embedder, 90 const GURL& embedder,
94 bool allowed); 91 bool allowed);
95 92
96 // content::NotificationObserver 93 // content::NotificationObserver (NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED)
tfarina 2012/03/01 16:14:23 nit: we usually don't specify in which notificatio
John Knottenbelt 2012/03/02 11:47:26 Done.
97 virtual void Observe(int type, 94 virtual void Observe(int type,
98 const content::NotificationSource& source, 95 const content::NotificationSource& source,
99 const content::NotificationDetails& details); 96 const content::NotificationDetails& details);
100 97
101 private: 98 private:
102 struct PendingInfoBarRequest; 99 struct PendingInfoBarRequest;
103 class RequestEquals; 100 class RequestEquals;
104 101
105 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests; 102 typedef std::vector<PendingInfoBarRequest> PendingInfoBarRequests;
106 103
(...skipping 20 matching lines...) Expand all
127 public: 124 public:
128 GeolocationConfirmInfoBarDelegate( 125 GeolocationConfirmInfoBarDelegate(
129 InfoBarTabHelper* infobar_helper, 126 InfoBarTabHelper* infobar_helper,
130 GeolocationInfoBarQueueController* controller, 127 GeolocationInfoBarQueueController* controller,
131 int render_process_id, 128 int render_process_id,
132 int render_view_id, 129 int render_view_id,
133 int bridge_id, 130 int bridge_id,
134 const GURL& requesting_frame_url, 131 const GURL& requesting_frame_url,
135 const std::string& display_languages); 132 const std::string& display_languages);
136 133
134 int render_process_id() const { return render_process_id_; }
135 int render_view_id() const { return render_view_id_; }
136
137 private: 137 private:
138 virtual ~GeolocationConfirmInfoBarDelegate();
139 138
140 // ConfirmInfoBarDelegate: 139 // ConfirmInfoBarDelegate:
141 virtual bool ShouldExpire( 140 virtual bool ShouldExpire(
142 const content::LoadCommittedDetails& details) const OVERRIDE; 141 const content::LoadCommittedDetails& details) const OVERRIDE;
143 virtual gfx::Image* GetIcon() const OVERRIDE; 142 virtual gfx::Image* GetIcon() const OVERRIDE;
144 virtual Type GetInfoBarType() const OVERRIDE; 143 virtual Type GetInfoBarType() const OVERRIDE;
145 virtual string16 GetMessageText() const OVERRIDE; 144 virtual string16 GetMessageText() const OVERRIDE;
146 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 145 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
147 virtual bool Accept() OVERRIDE; 146 virtual bool Accept() OVERRIDE;
148 virtual bool Cancel() OVERRIDE; 147 virtual bool Cancel() OVERRIDE;
(...skipping 28 matching lines...) Expand all
177 render_view_id_(render_view_id), 176 render_view_id_(render_view_id),
178 bridge_id_(bridge_id), 177 bridge_id_(bridge_id),
179 requesting_frame_url_(requesting_frame_url), 178 requesting_frame_url_(requesting_frame_url),
180 display_languages_(display_languages) { 179 display_languages_(display_languages) {
181 const NavigationEntry* committed_entry = 180 const NavigationEntry* committed_entry =
182 infobar_helper->web_contents()->GetController().GetLastCommittedEntry(); 181 infobar_helper->web_contents()->GetController().GetLastCommittedEntry();
183 committed_contents_unique_id_ = committed_entry ? 182 committed_contents_unique_id_ = committed_entry ?
184 committed_entry->GetUniqueID() : 0; 183 committed_entry->GetUniqueID() : 0;
185 } 184 }
186 185
187 GeolocationConfirmInfoBarDelegate::~GeolocationConfirmInfoBarDelegate() {
188 controller_->OnInfoBarClosed(render_process_id_, render_view_id_,
189 bridge_id_);
190 }
191
192 bool GeolocationConfirmInfoBarDelegate::ShouldExpire( 186 bool GeolocationConfirmInfoBarDelegate::ShouldExpire(
193 const content::LoadCommittedDetails& details) const { 187 const content::LoadCommittedDetails& details) const {
194 if (details.did_replace_entry || !details.is_navigation_to_different_page()) 188 if (details.did_replace_entry || !details.is_navigation_to_different_page())
195 return false; 189 return false;
196 return committed_contents_unique_id_ != details.entry->GetUniqueID() || 190 return committed_contents_unique_id_ != details.entry->GetUniqueID() ||
197 content::PageTransitionStripQualifier( 191 content::PageTransitionStripQualifier(
198 details.entry->GetTransitionType()) == 192 details.entry->GetTransitionType()) ==
199 content::PAGE_TRANSITION_RELOAD; 193 content::PAGE_TRANSITION_RELOAD;
200 } 194 }
201 195
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 bool Equals(int p_render_process_id, 269 bool Equals(int p_render_process_id,
276 int p_render_view_id, 270 int p_render_view_id,
277 int p_bridge_id) const; 271 int p_bridge_id) const;
278 272
279 int render_process_id; 273 int render_process_id;
280 int render_view_id; 274 int render_view_id;
281 int bridge_id; 275 int bridge_id;
282 GURL requesting_frame; 276 GURL requesting_frame;
283 GURL embedder; 277 GURL embedder;
284 base::Callback<void(bool)> callback; 278 base::Callback<void(bool)> callback;
285 InfoBarDelegate* infobar_delegate; 279 GeolocationConfirmInfoBarDelegate* infobar_delegate;
286 }; 280 };
287 281
288 GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest( 282 GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest(
289 int render_process_id, 283 int render_process_id,
290 int render_view_id, 284 int render_view_id,
291 int bridge_id, 285 int bridge_id,
292 const GURL& requesting_frame, 286 const GURL& requesting_frame,
293 const GURL& embedder, 287 const GURL& embedder,
294 base::Callback<void(bool)> callback) 288 base::Callback<void(bool)> callback)
295 : render_process_id(render_process_id), 289 : render_process_id(render_process_id),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 : render_process_id_(render_process_id), 340 : render_process_id_(render_process_id),
347 render_view_id_(render_view_id), 341 render_view_id_(render_view_id),
348 bridge_id_(bridge_id) { 342 bridge_id_(bridge_id) {
349 } 343 }
350 344
351 bool GeolocationInfoBarQueueController::RequestEquals::operator()( 345 bool GeolocationInfoBarQueueController::RequestEquals::operator()(
352 const PendingInfoBarRequest& request) const { 346 const PendingInfoBarRequest& request) const {
353 return request.Equals(render_process_id_, render_view_id_, bridge_id_); 347 return request.Equals(render_process_id_, render_view_id_, bridge_id_);
354 } 348 }
355 349
356
357 // GeolocationInfoBarQueueController ------------------------------------------ 350 // GeolocationInfoBarQueueController ------------------------------------------
358 351
359 GeolocationInfoBarQueueController::GeolocationInfoBarQueueController( 352 GeolocationInfoBarQueueController::GeolocationInfoBarQueueController(
360 ChromeGeolocationPermissionContext* geolocation_permission_context, 353 ChromeGeolocationPermissionContext* geolocation_permission_context,
361 Profile* profile) 354 Profile* profile)
362 : geolocation_permission_context_(geolocation_permission_context), 355 : geolocation_permission_context_(geolocation_permission_context),
363 profile_(profile) { 356 profile_(profile) {
364 } 357 }
365 358
366 GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() { 359 GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() {
(...skipping 26 matching lines...) Expand all
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
394 387
395 PendingInfoBarRequests::iterator i = std::find_if( 388 PendingInfoBarRequests::iterator i = std::find_if(
396 pending_infobar_requests_.begin(), pending_infobar_requests_.end(), 389 pending_infobar_requests_.begin(), pending_infobar_requests_.end(),
397 RequestEquals(render_process_id, render_view_id, bridge_id)); 390 RequestEquals(render_process_id, render_view_id, bridge_id));
398 // TODO(pkasting): Can this conditional become a DCHECK()? 391 // TODO(pkasting): Can this conditional become a DCHECK()?
399 if (i != pending_infobar_requests_.end()) 392 if (i != pending_infobar_requests_.end())
400 CancelInfoBarRequestInternal(i); 393 CancelInfoBarRequestInternal(i);
401 } 394 }
402 395
403 void GeolocationInfoBarQueueController::OnInfoBarClosed(int render_process_id,
404 int render_view_id,
405 int bridge_id) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
407
408 PendingInfoBarRequests::iterator i = std::find_if(
409 pending_infobar_requests_.begin(), pending_infobar_requests_.end(),
410 RequestEquals(render_process_id, render_view_id, bridge_id));
411 if (i != pending_infobar_requests_.end())
412 pending_infobar_requests_.erase(i);
413
414 ShowQueuedInfoBar(render_process_id, render_view_id);
415 }
416
417 void GeolocationInfoBarQueueController::OnPermissionSet( 396 void GeolocationInfoBarQueueController::OnPermissionSet(
418 int render_process_id, 397 int render_process_id,
419 int render_view_id, 398 int render_view_id,
420 int bridge_id, 399 int bridge_id,
421 const GURL& requesting_frame, 400 const GURL& requesting_frame,
422 const GURL& embedder, 401 const GURL& embedder,
423 bool allowed) { 402 bool allowed) {
424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
425 404
426 ContentSetting content_setting = 405 ContentSetting content_setting =
(...skipping 28 matching lines...) Expand all
455 copied_request.render_process_id, copied_request.render_view_id, 434 copied_request.render_process_id, copied_request.render_view_id,
456 copied_request.bridge_id, copied_request.requesting_frame, 435 copied_request.bridge_id, copied_request.requesting_frame,
457 copied_request.callback, allowed); 436 copied_request.callback, allowed);
458 } else { 437 } else {
459 ++i; 438 ++i;
460 } 439 }
461 } 440 }
462 } 441 }
463 442
464 void GeolocationInfoBarQueueController::Observe( 443 void GeolocationInfoBarQueueController::Observe(
465 int type, const content::NotificationSource& source, 444 int type,
445 const content::NotificationSource& source,
466 const content::NotificationDetails& details) { 446 const content::NotificationDetails& details) {
467 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
Peter Kasting 2012/03/01 19:46:54 Nit: I don't think this DCHECK is all that importa
John Knottenbelt 2012/03/02 11:47:26 Done.
John Knottenbelt 2012/03/02 11:47:26 Done.
468 source); 448 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED);
Peter Kasting 2012/03/01 19:46:54 Nit: Can be DCHECK_EQ(expected, actual)
John Knottenbelt 2012/03/02 11:47:26 Done.
469 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 449 // It's possible that we receive this notification for a non-geolocation
450 // confirm info bar. We need to check that the infobar delegate
Peter Kasting 2012/03/01 19:46:54 Nit: Nix "confirm". Actually, "We will receive th
John Knottenbelt 2012/03/02 11:47:26 Done.
451 // corresponds to the one we think is showing.
452 InfoBarRemovedDetails* removed_details =
Peter Kasting 2012/03/01 19:46:54 Nit: Can inline this into the next line
John Knottenbelt 2012/03/02 11:47:26 Done.
453 content::Details<InfoBarRemovedDetails>(details).ptr();
454 InfoBarDelegate* delegate = removed_details->first;
470 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 455 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
471 i != pending_infobar_requests_.end();) { 456 i != pending_infobar_requests_.end(); ++i) {
472 if (i->infobar_delegate == NULL && 457 GeolocationConfirmInfoBarDelegate* confirm_delegate = i->infobar_delegate;
473 web_contents == tab_util::GetWebContentsByID(i->render_process_id, 458 if (confirm_delegate == delegate) {
474 i->render_view_id)) { 459 pending_infobar_requests_.erase(i);
475 i = pending_infobar_requests_.erase(i); 460 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
476 } else { 461 source);
477 ++i; 462 ShowQueuedInfoBar(confirm_delegate->render_process_id(),
463 confirm_delegate->render_view_id());
464 return;
478 } 465 }
479 } 466 }
480 } 467 }
481 468
482 void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id, 469 void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id,
483 int render_view_id) { 470 int render_view_id) {
484 WebContents* tab_contents = 471 WebContents* tab_contents =
485 tab_util::GetWebContentsByID(render_process_id, render_view_id); 472 tab_util::GetWebContentsByID(render_process_id, render_view_id);
486 TabContentsWrapper* wrapper = NULL; 473 TabContentsWrapper* wrapper = NULL;
487 if (tab_contents) 474 if (tab_contents)
488 wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); 475 wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
489 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 476 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
490 i != pending_infobar_requests_.end(); ) { 477 i != pending_infobar_requests_.end(); ) {
491 if (i->IsForTab(render_process_id, render_view_id)) { 478 if (i->IsForTab(render_process_id, render_view_id)) {
492 if (!wrapper) { 479 if (!wrapper) {
493 i = pending_infobar_requests_.erase(i); 480 i = pending_infobar_requests_.erase(i);
494 continue; 481 continue;
495 } 482 }
496 483
484 InfoBarTabHelper* helper = wrapper->infobar_tab_helper();
tfarina 2012/03/01 16:14:23 nit: Move this into the if below and use it in lin
John Knottenbelt 2012/03/02 11:47:26 Done.
485
497 if (!i->infobar_delegate) { 486 if (!i->infobar_delegate) {
498 if (!registrar_.IsRegistered( 487 DCHECK(!registrar_.IsRegistered(
499 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 488 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
500 content::Source<WebContents>(tab_contents))) { 489 content::Source<InfoBarTabHelper>(helper)));
501 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 490 registrar_.Add(
502 content::Source<WebContents>(tab_contents)); 491 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
503 } 492 content::Source<InfoBarTabHelper>(helper));
504 i->infobar_delegate = new GeolocationConfirmInfoBarDelegate( 493 i->infobar_delegate = new GeolocationConfirmInfoBarDelegate(
505 wrapper->infobar_tab_helper(), this, render_process_id, 494 helper, this, render_process_id,
506 render_view_id, i->bridge_id, i->requesting_frame, 495 render_view_id, i->bridge_id, i->requesting_frame,
507 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 496 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
508 wrapper->infobar_tab_helper()->AddInfoBar(i->infobar_delegate); 497 wrapper->infobar_tab_helper()->AddInfoBar(i->infobar_delegate);
509 } 498 }
510 break; 499 break;
511 } 500 }
512 ++i; 501 ++i;
513 } 502 }
514 } 503 }
515 504
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 BrowserThread::UI, FROM_HERE, 651 BrowserThread::UI, FROM_HERE,
663 base::Bind( 652 base::Bind(
664 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, 653 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest,
665 this, render_process_id, render_view_id, bridge_id)); 654 this, render_process_id, render_view_id, bridge_id));
666 return; 655 return;
667 } 656 }
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
669 geolocation_infobar_queue_controller_->CancelInfoBarRequest(render_process_id, 658 geolocation_infobar_queue_controller_->CancelInfoBarRequest(render_process_id,
670 render_view_id, bridge_id); 659 render_view_id, bridge_id);
671 } 660 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698