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

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

Issue 11644059: Change infobar creation to use a public static Create() method on the infobar delegate classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/geolocation_infobar_queue_controller.h" 5 #include "chrome/browser/geolocation/geolocation_infobar_queue_controller.h"
6 6
7 #include "chrome/browser/api/infobars/infobar_service.h" 7 #include "chrome/browser/api/infobars/infobar_service.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate.h" 9 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate.h"
10 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_factor y.h"
11 #include "chrome/browser/infobars/infobar.h" 10 #include "chrome/browser/infobars/infobar.h"
12 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/tab_util.h" 13 #include "chrome/browser/tab_contents/tab_util.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/content_settings.h" 15 #include "chrome/common/content_settings.h"
17 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
18 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h" 18 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
(...skipping 23 matching lines...) Expand all
44 const GURL& embedder, 43 const GURL& embedder,
45 PermissionDecidedCallback callback); 44 PermissionDecidedCallback callback);
46 ~PendingInfoBarRequest(); 45 ~PendingInfoBarRequest();
47 46
48 bool IsForPair(const GURL& requesting_frame, 47 bool IsForPair(const GURL& requesting_frame,
49 const GURL& embedder) const; 48 const GURL& embedder) const;
50 49
51 const GeolocationPermissionRequestID& id() const { return id_; } 50 const GeolocationPermissionRequestID& id() const { return id_; }
52 const GURL& requesting_frame() const { return requesting_frame_; } 51 const GURL& requesting_frame() const { return requesting_frame_; }
53 bool has_infobar_delegate() const { return !!infobar_delegate_; } 52 bool has_infobar_delegate() const { return !!infobar_delegate_; }
54 GeolocationConfirmInfoBarDelegate* infobar_delegate() { 53 InfoBarDelegate* infobar_delegate() { return infobar_delegate_; }
55 return infobar_delegate_;
56 }
57 54
58 void RunCallback(bool allowed); 55 void RunCallback(bool allowed);
59 void CreateInfoBarDelegate(GeolocationInfoBarQueueController* controller, 56 void CreateInfoBarDelegate(GeolocationInfoBarQueueController* controller,
60 const std::string& display_languages); 57 const std::string& display_languages);
61 58
62 private: 59 private:
63 GeolocationPermissionRequestID id_; 60 GeolocationPermissionRequestID id_;
64 GURL requesting_frame_; 61 GURL requesting_frame_;
65 GURL embedder_; 62 GURL embedder_;
66 PermissionDecidedCallback callback_; 63 PermissionDecidedCallback callback_;
67 GeolocationConfirmInfoBarDelegate* infobar_delegate_; 64 InfoBarDelegate* infobar_delegate_;
68 65
69 // Purposefully do not disable copying, as this is stored in STL containers. 66 // Purposefully do not disable copying, as this is stored in STL containers.
70 }; 67 };
71 68
72 GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest( 69 GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest(
73 const GeolocationPermissionRequestID& id, 70 const GeolocationPermissionRequestID& id,
74 const GURL& requesting_frame, 71 const GURL& requesting_frame,
75 const GURL& embedder, 72 const GURL& embedder,
76 PermissionDecidedCallback callback) 73 PermissionDecidedCallback callback)
77 : id_(id), 74 : id_(id),
(...skipping 14 matching lines...) Expand all
92 } 89 }
93 90
94 void GeolocationInfoBarQueueController::PendingInfoBarRequest::RunCallback( 91 void GeolocationInfoBarQueueController::PendingInfoBarRequest::RunCallback(
95 bool allowed) { 92 bool allowed) {
96 callback_.Run(allowed); 93 callback_.Run(allowed);
97 } 94 }
98 95
99 void GeolocationInfoBarQueueController::PendingInfoBarRequest:: 96 void GeolocationInfoBarQueueController::PendingInfoBarRequest::
100 CreateInfoBarDelegate(GeolocationInfoBarQueueController* controller, 97 CreateInfoBarDelegate(GeolocationInfoBarQueueController* controller,
101 const std::string& display_languages) { 98 const std::string& display_languages) {
102 infobar_delegate_ = GeolocationConfirmInfoBarDelegateFactory::Create( 99 infobar_delegate_ = GeolocationConfirmInfoBarDelegate::Create(
103 GetInfoBarService(id_), controller, id_, requesting_frame_, 100 GetInfoBarService(id_), controller, id_, requesting_frame_,
104 display_languages); 101 display_languages);
105 102
106 } 103 }
107 104
108 105
109 // GeolocationInfoBarQueueController ------------------------------------------ 106 // GeolocationInfoBarQueueController ------------------------------------------
110 107
111 GeolocationInfoBarQueueController::GeolocationInfoBarQueueController( 108 GeolocationInfoBarQueueController::GeolocationInfoBarQueueController(
112 Profile* profile) 109 Profile* profile)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // caused the delegate to be deleted, so it's not safe to dereference the 217 // caused the delegate to be deleted, so it's not safe to dereference the
221 // contents of the delegate. The address of the delegate, however, is OK to 218 // contents of the delegate. The address of the delegate, however, is OK to
222 // use to find the PendingInfoBarRequest to remove because 219 // use to find the PendingInfoBarRequest to remove because
223 // pending_infobar_requests_ will not have received any new entries between 220 // pending_infobar_requests_ will not have received any new entries between
224 // the NotificationService's call to InfoBarContainer::Observe and this 221 // the NotificationService's call to InfoBarContainer::Observe and this
225 // method. 222 // method.
226 InfoBarDelegate* delegate = 223 InfoBarDelegate* delegate =
227 content::Details<InfoBarRemovedDetails>(details)->first; 224 content::Details<InfoBarRemovedDetails>(details)->first;
228 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 225 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
229 i != pending_infobar_requests_.end(); ++i) { 226 i != pending_infobar_requests_.end(); ++i) {
230 GeolocationConfirmInfoBarDelegate* confirm_delegate = i->infobar_delegate(); 227 InfoBarDelegate* confirm_delegate = i->infobar_delegate();
231 if (confirm_delegate == delegate) { 228 if (confirm_delegate == delegate) {
232 GeolocationPermissionRequestID id(i->id()); 229 GeolocationPermissionRequestID id(i->id());
233 pending_infobar_requests_.erase(i); 230 pending_infobar_requests_.erase(i);
234 ShowQueuedInfoBarForTab(id); 231 ShowQueuedInfoBarForTab(id);
235 return; 232 return;
236 } 233 }
237 } 234 }
238 } 235 }
239 236
240 bool GeolocationInfoBarQueueController::AlreadyShowingInfoBarForTab( 237 bool GeolocationInfoBarQueueController::AlreadyShowingInfoBarForTab(
(...skipping 22 matching lines...) Expand all
263 ClearPendingInfoBarRequestsForTab(id); 260 ClearPendingInfoBarRequestsForTab(id);
264 return; 261 return;
265 } 262 }
266 263
267 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 264 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
268 i != pending_infobar_requests_.end(); ++i) { 265 i != pending_infobar_requests_.end(); ++i) {
269 if (i->id().IsForSameTabAs(id) && !i->has_infobar_delegate()) { 266 if (i->id().IsForSameTabAs(id) && !i->has_infobar_delegate()) {
270 RegisterForInfoBarNotifications(infobar_service); 267 RegisterForInfoBarNotifications(infobar_service);
271 i->CreateInfoBarDelegate( 268 i->CreateInfoBarDelegate(
272 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 269 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
273 infobar_service->AddInfoBar(i->infobar_delegate());
274 return; 270 return;
275 } 271 }
276 } 272 }
277 273
278 UnregisterForInfoBarNotifications(infobar_service); 274 UnregisterForInfoBarNotifications(infobar_service);
279 } 275 }
280 276
281 void GeolocationInfoBarQueueController::ClearPendingInfoBarRequestsForTab( 277 void GeolocationInfoBarQueueController::ClearPendingInfoBarRequestsForTab(
282 const GeolocationPermissionRequestID& id) { 278 const GeolocationPermissionRequestID& id) {
283 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 279 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
(...skipping 19 matching lines...) Expand all
303 void GeolocationInfoBarQueueController::UnregisterForInfoBarNotifications( 299 void GeolocationInfoBarQueueController::UnregisterForInfoBarNotifications(
304 InfoBarService* infobar_service) { 300 InfoBarService* infobar_service) {
305 if (registrar_.IsRegistered( 301 if (registrar_.IsRegistered(
306 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 302 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
307 content::Source<InfoBarService>(infobar_service))) { 303 content::Source<InfoBarService>(infobar_service))) {
308 registrar_.Remove(this, 304 registrar_.Remove(this,
309 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 305 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
310 content::Source<InfoBarService>(infobar_service)); 306 content::Source<InfoBarService>(infobar_service));
311 } 307 }
312 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698