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

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: 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"
23 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/chrome_notification_types.h"
tfarina 2012/02/28 23:20:58 nit: sort, should be before extension.h
John Knottenbelt 2012/03/01 10:10:49 Done.
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
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
104 // Called by Observe in response to NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED.
105 // It'll display a new InfoBar if there's any request pending for this tab.
106 void OnInfoBarClosed(int render_process_id,
107 int render_view_id,
108 int bridge_id);
109
107 // Shows the first pending infobar for this tab. 110 // Shows the first pending infobar for this tab.
108 void ShowQueuedInfoBar(int render_process_id, int render_view_id); 111 void ShowQueuedInfoBar(int render_process_id, int render_view_id);
109 112
110 // Cancels an InfoBar request and returns the next iterator position. 113 // Cancels an InfoBar request and returns the next iterator position.
111 PendingInfoBarRequests::iterator CancelInfoBarRequestInternal( 114 PendingInfoBarRequests::iterator CancelInfoBarRequestInternal(
112 PendingInfoBarRequests::iterator i); 115 PendingInfoBarRequests::iterator i);
113 116
114 content::NotificationRegistrar registrar_; 117 content::NotificationRegistrar registrar_;
115 118
116 ChromeGeolocationPermissionContext* const geolocation_permission_context_; 119 ChromeGeolocationPermissionContext* const geolocation_permission_context_;
(...skipping 10 matching lines...) Expand all
127 public: 130 public:
128 GeolocationConfirmInfoBarDelegate( 131 GeolocationConfirmInfoBarDelegate(
129 InfoBarTabHelper* infobar_helper, 132 InfoBarTabHelper* infobar_helper,
130 GeolocationInfoBarQueueController* controller, 133 GeolocationInfoBarQueueController* controller,
131 int render_process_id, 134 int render_process_id,
132 int render_view_id, 135 int render_view_id,
133 int bridge_id, 136 int bridge_id,
134 const GURL& requesting_frame_url, 137 const GURL& requesting_frame_url,
135 const std::string& display_languages); 138 const std::string& display_languages);
136 139
140 int render_process_id() const { return render_process_id_; }
141 int render_view_id() const { return render_view_id_; }
142
137 private: 143 private:
138 virtual ~GeolocationConfirmInfoBarDelegate();
139 144
140 // ConfirmInfoBarDelegate: 145 // ConfirmInfoBarDelegate:
141 virtual bool ShouldExpire( 146 virtual bool ShouldExpire(
142 const content::LoadCommittedDetails& details) const OVERRIDE; 147 const content::LoadCommittedDetails& details) const OVERRIDE;
143 virtual gfx::Image* GetIcon() const OVERRIDE; 148 virtual gfx::Image* GetIcon() const OVERRIDE;
144 virtual Type GetInfoBarType() const OVERRIDE; 149 virtual Type GetInfoBarType() const OVERRIDE;
145 virtual string16 GetMessageText() const OVERRIDE; 150 virtual string16 GetMessageText() const OVERRIDE;
146 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 151 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
147 virtual bool Accept() OVERRIDE; 152 virtual bool Accept() OVERRIDE;
148 virtual bool Cancel() OVERRIDE; 153 virtual bool Cancel() OVERRIDE;
(...skipping 28 matching lines...) Expand all
177 render_view_id_(render_view_id), 182 render_view_id_(render_view_id),
178 bridge_id_(bridge_id), 183 bridge_id_(bridge_id),
179 requesting_frame_url_(requesting_frame_url), 184 requesting_frame_url_(requesting_frame_url),
180 display_languages_(display_languages) { 185 display_languages_(display_languages) {
181 const NavigationEntry* committed_entry = 186 const NavigationEntry* committed_entry =
182 infobar_helper->web_contents()->GetController().GetLastCommittedEntry(); 187 infobar_helper->web_contents()->GetController().GetLastCommittedEntry();
183 committed_contents_unique_id_ = committed_entry ? 188 committed_contents_unique_id_ = committed_entry ?
184 committed_entry->GetUniqueID() : 0; 189 committed_entry->GetUniqueID() : 0;
185 } 190 }
186 191
187 GeolocationConfirmInfoBarDelegate::~GeolocationConfirmInfoBarDelegate() {
188 controller_->OnInfoBarClosed(render_process_id_, render_view_id_,
189 bridge_id_);
190 }
191
192 bool GeolocationConfirmInfoBarDelegate::ShouldExpire( 192 bool GeolocationConfirmInfoBarDelegate::ShouldExpire(
193 const content::LoadCommittedDetails& details) const { 193 const content::LoadCommittedDetails& details) const {
194 if (details.did_replace_entry || !details.is_navigation_to_different_page()) 194 if (details.did_replace_entry || !details.is_navigation_to_different_page())
195 return false; 195 return false;
196 return committed_contents_unique_id_ != details.entry->GetUniqueID() || 196 return committed_contents_unique_id_ != details.entry->GetUniqueID() ||
197 content::PageTransitionStripQualifier( 197 content::PageTransitionStripQualifier(
198 details.entry->GetTransitionType()) == 198 details.entry->GetTransitionType()) ==
199 content::PAGE_TRANSITION_RELOAD; 199 content::PAGE_TRANSITION_RELOAD;
200 } 200 }
201 201
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 copied_request.render_process_id, copied_request.render_view_id, 455 copied_request.render_process_id, copied_request.render_view_id,
456 copied_request.bridge_id, copied_request.requesting_frame, 456 copied_request.bridge_id, copied_request.requesting_frame,
457 copied_request.callback, allowed); 457 copied_request.callback, allowed);
458 } else { 458 } else {
459 ++i; 459 ++i;
460 } 460 }
461 } 461 }
462 } 462 }
463 463
464 void GeolocationInfoBarQueueController::Observe( 464 void GeolocationInfoBarQueueController::Observe(
465 int type, const content::NotificationSource& source, 465 int type, const content::NotificationSource& source,
Peter Kasting 2012/02/28 19:34:59 Nit: While here, one arg per line
John Knottenbelt 2012/03/01 10:10:49 Done.
466 const content::NotificationDetails& details) { 466 const content::NotificationDetails& details) {
467 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 467 registrar_.Remove(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
bulach 2012/02/28 17:20:34 as we chatted, I think we also need this one.. thi
Peter Kasting 2012/02/28 19:34:59 No, we don't want to keep this. If the web conten
bulach 2012/02/29 11:29:29 thanks for the details, and sorry I wasn't clear.
Peter Kasting 2012/02/29 20:47:54 The pending requests should be cleared as well, be
bulach 2012/03/01 11:19:32 got it, thanks for the clarification.
Peter Kasting 2012/02/28 19:34:59 This code will be reached when any infobar is remo
468 source); 468 source);
469 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 469 InfoBarRemovedDetails* removed_details =
470 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 470 content::Details<InfoBarRemovedDetails>(details).ptr();
471 i != pending_infobar_requests_.end();) { 471 GeolocationConfirmInfoBarDelegate* delegate =
472 if (i->infobar_delegate == NULL && 472 static_cast<GeolocationConfirmInfoBarDelegate*>(removed_details->first);
473 web_contents == tab_util::GetWebContentsByID(i->render_process_id, 473 ShowQueuedInfoBar(delegate->render_process_id(), delegate->render_view_id());
474 i->render_view_id)) {
475 i = pending_infobar_requests_.erase(i);
476 } else {
477 ++i;
478 }
479 }
480 } 474 }
481 475
482 void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id, 476 void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id,
483 int render_view_id) { 477 int render_view_id) {
484 WebContents* tab_contents = 478 WebContents* tab_contents =
485 tab_util::GetWebContentsByID(render_process_id, render_view_id); 479 tab_util::GetWebContentsByID(render_process_id, render_view_id);
486 TabContentsWrapper* wrapper = NULL; 480 TabContentsWrapper* wrapper = NULL;
487 if (tab_contents) 481 if (tab_contents)
488 wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); 482 wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents);
489 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 483 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
490 i != pending_infobar_requests_.end(); ) { 484 i != pending_infobar_requests_.end(); ) {
491 if (i->IsForTab(render_process_id, render_view_id)) { 485 if (i->IsForTab(render_process_id, render_view_id)) {
492 if (!wrapper) { 486 if (!wrapper) {
493 i = pending_infobar_requests_.erase(i); 487 i = pending_infobar_requests_.erase(i);
494 continue; 488 continue;
495 } 489 }
496 490
491 InfoBarTabHelper *helper = wrapper->infobar_tab_helper();
bulach 2012/02/28 17:20:34 nit: s/r *helper/r* helper/
John Knottenbelt 2012/03/01 10:10:49 Done.
492
497 if (!i->infobar_delegate) { 493 if (!i->infobar_delegate) {
498 if (!registrar_.IsRegistered( 494 if (!registrar_.IsRegistered(
Peter Kasting 2012/02/28 19:34:59 If infobars are disabled, you'll add a listener fo
499 this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 495 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
500 content::Source<WebContents>(tab_contents))) { 496 content::Source<InfoBarTabHelper>(helper))) {
501 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 497 registrar_.Add(
502 content::Source<WebContents>(tab_contents)); 498 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
bulach 2012/02/28 17:20:34 as above, we may need to keep this too..
499 content::Source<InfoBarTabHelper>(helper));
503 } 500 }
504 i->infobar_delegate = new GeolocationConfirmInfoBarDelegate( 501 i->infobar_delegate = new GeolocationConfirmInfoBarDelegate(
505 wrapper->infobar_tab_helper(), this, render_process_id, 502 helper, this, render_process_id,
506 render_view_id, i->bridge_id, i->requesting_frame, 503 render_view_id, i->bridge_id, i->requesting_frame,
507 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 504 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
508 wrapper->infobar_tab_helper()->AddInfoBar(i->infobar_delegate); 505 wrapper->infobar_tab_helper()->AddInfoBar(i->infobar_delegate);
509 } 506 }
510 break; 507 break;
511 } 508 }
512 ++i; 509 ++i;
513 } 510 }
514 } 511 }
515 512
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 BrowserThread::UI, FROM_HERE, 659 BrowserThread::UI, FROM_HERE,
663 base::Bind( 660 base::Bind(
664 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, 661 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest,
665 this, render_process_id, render_view_id, bridge_id)); 662 this, render_process_id, render_view_id, bridge_id));
666 return; 663 return;
667 } 664 }
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
669 geolocation_infobar_queue_controller_->CancelInfoBarRequest(render_process_id, 666 geolocation_infobar_queue_controller_->CancelInfoBarRequest(render_process_id,
670 render_view_id, bridge_id); 667 render_view_id, bridge_id);
671 } 668 }
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