OLD | NEW |
---|---|
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/content_settings/host_content_settings_map.h" | 7 #include "chrome/browser/content_settings/host_content_settings_map.h" |
8 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate.h" | 8 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate.h" |
9 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_factor y.h" | 9 #include "chrome/browser/geolocation/geolocation_confirm_infobar_delegate_factor y.h" |
10 #include "chrome/browser/infobars/infobar.h" | 10 #include "chrome/browser/infobars/infobar.h" |
11 #include "chrome/browser/infobars/infobar_tab_helper.h" | 11 #include "chrome/browser/infobars/infobar_tab_helper.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/tab_contents/tab_util.h" | 14 #include "chrome/browser/tab_contents/tab_util.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/content_settings.h" | 16 #include "chrome/common/content_settings.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/geolocation.h" | |
19 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 | 24 |
24 using content::BrowserThread; | 25 using content::BrowserThread; |
25 using content::WebContents; | 26 using content::WebContents; |
26 | 27 |
27 // GeolocationInfoBarQueueController::PendingInfoBarRequest ------------------- | 28 // GeolocationInfoBarQueueController::PendingInfoBarRequest ------------------- |
28 | 29 |
29 struct GeolocationInfoBarQueueController::PendingInfoBarRequest { | 30 struct GeolocationInfoBarQueueController::PendingInfoBarRequest { |
30 public: | 31 public: |
31 PendingInfoBarRequest(int render_process_id, | 32 PendingInfoBarRequest(const content::GeolocationPermissionRequestID& id, |
32 int render_view_id, | |
33 int bridge_id, | |
34 const GURL& requesting_frame, | 33 const GURL& requesting_frame, |
35 const GURL& embedder, | 34 const GURL& embedder, |
36 PermissionDecidedCallback callback); | 35 PermissionDecidedCallback callback); |
37 | 36 |
38 bool IsForTab(int p_render_process_id, int p_render_view_id) const; | |
39 bool IsForPair(const GURL& p_requesting_frame, | 37 bool IsForPair(const GURL& p_requesting_frame, |
40 const GURL& p_embedder) const; | 38 const GURL& p_embedder) const; |
41 bool Equals(int p_render_process_id, | |
42 int p_render_view_id, | |
43 int p_bridge_id) const; | |
44 | 39 |
45 int render_process_id; | 40 content::GeolocationPermissionRequestID id; |
46 int render_view_id; | |
47 int bridge_id; | |
48 GURL requesting_frame; | 41 GURL requesting_frame; |
49 GURL embedder; | 42 GURL embedder; |
50 PermissionDecidedCallback callback; | 43 PermissionDecidedCallback callback; |
51 GeolocationConfirmInfoBarDelegate* infobar_delegate; | 44 GeolocationConfirmInfoBarDelegate* infobar_delegate; |
52 }; | 45 }; |
53 | 46 |
54 GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest( | 47 GeolocationInfoBarQueueController::PendingInfoBarRequest::PendingInfoBarRequest( |
55 int render_process_id, | 48 const content::GeolocationPermissionRequestID& id, |
56 int render_view_id, | |
57 int bridge_id, | |
58 const GURL& requesting_frame, | 49 const GURL& requesting_frame, |
59 const GURL& embedder, | 50 const GURL& embedder, |
60 PermissionDecidedCallback callback) | 51 PermissionDecidedCallback callback) |
61 : render_process_id(render_process_id), | 52 : id(id), |
62 render_view_id(render_view_id), | |
63 bridge_id(bridge_id), | |
64 requesting_frame(requesting_frame), | 53 requesting_frame(requesting_frame), |
65 embedder(embedder), | 54 embedder(embedder), |
66 callback(callback), | 55 callback(callback), |
67 infobar_delegate(NULL) { | 56 infobar_delegate(NULL) { |
68 } | 57 } |
69 | 58 |
70 bool GeolocationInfoBarQueueController::PendingInfoBarRequest::IsForTab( | |
71 int p_render_process_id, | |
72 int p_render_view_id) const { | |
73 return (render_process_id == p_render_process_id) && | |
74 (render_view_id == p_render_view_id); | |
75 } | |
76 | |
77 bool GeolocationInfoBarQueueController::PendingInfoBarRequest::IsForPair( | 59 bool GeolocationInfoBarQueueController::PendingInfoBarRequest::IsForPair( |
78 const GURL& p_requesting_frame, | 60 const GURL& p_requesting_frame, |
79 const GURL& p_embedder) const { | 61 const GURL& p_embedder) const { |
80 return (requesting_frame == p_requesting_frame) && (embedder == p_embedder); | 62 return (requesting_frame == p_requesting_frame) && (embedder == p_embedder); |
81 } | 63 } |
82 | 64 |
83 bool GeolocationInfoBarQueueController::PendingInfoBarRequest::Equals( | |
84 int p_render_process_id, | |
85 int p_render_view_id, | |
86 int p_bridge_id) const { | |
87 return IsForTab(p_render_process_id, p_render_view_id) && | |
88 (bridge_id == p_bridge_id); | |
89 } | |
90 | |
91 | |
92 // GeolocationInfoBarQueueController::RequestEquals --------------------------- | |
93 | |
94 // Useful predicate for checking PendingInfoBarRequest equality. | |
95 class GeolocationInfoBarQueueController::RequestEquals | |
96 : public std::unary_function<PendingInfoBarRequest, bool> { | |
97 public: | |
98 RequestEquals(int render_process_id, int render_view_id, int bridge_id); | |
99 | |
100 bool operator()(const PendingInfoBarRequest& request) const; | |
101 | |
102 private: | |
103 int render_process_id_; | |
104 int render_view_id_; | |
105 int bridge_id_; | |
106 }; | |
107 | |
108 GeolocationInfoBarQueueController::RequestEquals::RequestEquals( | |
109 int render_process_id, | |
110 int render_view_id, | |
111 int bridge_id) | |
112 : render_process_id_(render_process_id), | |
113 render_view_id_(render_view_id), | |
114 bridge_id_(bridge_id) { | |
115 } | |
116 | |
117 bool GeolocationInfoBarQueueController::RequestEquals::operator()( | |
118 const PendingInfoBarRequest& request) const { | |
119 return request.Equals(render_process_id_, render_view_id_, bridge_id_); | |
120 } | |
121 | 65 |
122 // GeolocationInfoBarQueueController ------------------------------------------ | 66 // GeolocationInfoBarQueueController ------------------------------------------ |
123 | 67 |
124 GeolocationInfoBarQueueController::GeolocationInfoBarQueueController( | 68 GeolocationInfoBarQueueController::GeolocationInfoBarQueueController( |
125 Profile* profile) | 69 Profile* profile) |
126 : profile_(profile) { | 70 : profile_(profile) { |
127 } | 71 } |
128 | 72 |
129 GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() { | 73 GeolocationInfoBarQueueController::~GeolocationInfoBarQueueController() { |
130 } | 74 } |
131 | 75 |
132 void GeolocationInfoBarQueueController::CreateInfoBarRequest( | 76 void GeolocationInfoBarQueueController::CreateInfoBarRequest( |
133 int render_process_id, | 77 const content::GeolocationPermissionRequestID& id, |
134 int render_view_id, | |
135 int bridge_id, | |
136 const GURL& requesting_frame, | 78 const GURL& requesting_frame, |
137 const GURL& embedder, | 79 const GURL& embedder, |
138 PermissionDecidedCallback callback) { | 80 PermissionDecidedCallback callback) { |
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
140 | 82 |
141 // We shouldn't get duplicate requests. | 83 // We shouldn't get duplicate requests. |
142 DCHECK(std::find_if(pending_infobar_requests_.begin(), | 84 for (PendingInfoBarRequests::const_iterator i( |
143 pending_infobar_requests_.end(), | 85 pending_infobar_requests_.begin()); |
144 RequestEquals(render_process_id, render_view_id, bridge_id)) == | 86 i != pending_infobar_requests_.end(); ++i) |
145 pending_infobar_requests_.end()); | 87 DCHECK(!i->id.Equals(id)); |
146 | 88 |
147 InfoBarTabHelper* helper = GetInfoBarHelper(render_process_id, | 89 pending_infobar_requests_.push_back(PendingInfoBarRequest( |
148 render_view_id); | 90 id, requesting_frame, embedder, callback)); |
149 if (!helper) { | 91 if (!AlreadyShowingInfoBarForTab(id) && !ShowQueuedInfoBarForTab(id)) { |
150 // We won't be able to create any infobars, shortcut and remove any pending | 92 // We can only get here if there's no InfoBarTabHelper. |
151 // requests. | 93 ClearPendingInfoBarRequestsForTab(id); |
152 ClearPendingInfoBarRequestsForTab(render_process_id, render_view_id); | |
153 return; | |
154 } | 94 } |
155 pending_infobar_requests_.push_back(PendingInfoBarRequest(render_process_id, | |
156 render_view_id, bridge_id, requesting_frame, embedder, callback)); | |
157 if (!AlreadyShowingInfoBar(render_process_id, render_view_id)) | |
158 ShowQueuedInfoBar(render_process_id, render_view_id, helper); | |
159 } | 95 } |
160 | 96 |
161 void GeolocationInfoBarQueueController::CancelInfoBarRequest( | 97 void GeolocationInfoBarQueueController::CancelInfoBarRequest( |
162 int render_process_id, | 98 const content::GeolocationPermissionRequestID& id) { |
163 int render_view_id, | |
164 int bridge_id) { | |
165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
166 | 100 |
167 PendingInfoBarRequests::iterator i = std::find_if( | 101 for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin()); |
168 pending_infobar_requests_.begin(), pending_infobar_requests_.end(), | 102 i != pending_infobar_requests_.end(); ++i) { |
169 RequestEquals(render_process_id, render_view_id, bridge_id)); | 103 if (i->id.Equals(id)) { |
170 // TODO(pkasting): Can this conditional become a DCHECK()? | 104 if (i->infobar_delegate) |
171 if (i == pending_infobar_requests_.end()) | 105 GetInfoBarHelper(id)->RemoveInfoBar(i->infobar_delegate); |
172 return; | 106 else |
173 InfoBarDelegate* delegate = i->infobar_delegate; | 107 pending_infobar_requests_.erase(i); |
174 if (!delegate) { | 108 return; |
175 pending_infobar_requests_.erase(i); | 109 } |
176 return; | |
177 } | 110 } |
178 InfoBarTabHelper* helper = GetInfoBarHelper(render_process_id, | |
179 render_view_id); | |
180 helper->RemoveInfoBar(delegate); | |
181 } | 111 } |
182 | 112 |
183 void GeolocationInfoBarQueueController::OnPermissionSet( | 113 void GeolocationInfoBarQueueController::OnPermissionSet( |
184 int render_process_id, | 114 const content::GeolocationPermissionRequestID& id, |
185 int render_view_id, | |
186 int bridge_id, | |
187 const GURL& requesting_frame, | 115 const GURL& requesting_frame, |
188 const GURL& embedder, | 116 const GURL& embedder, |
189 bool update_content_setting, | 117 bool update_content_setting, |
190 bool allowed) { | 118 bool allowed) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
120 | |
192 if (update_content_setting) { | 121 if (update_content_setting) { |
193 ContentSetting content_setting = | 122 ContentSetting content_setting = |
194 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 123 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
195 profile_->GetHostContentSettingsMap()->SetContentSetting( | 124 profile_->GetHostContentSettingsMap()->SetContentSetting( |
196 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 125 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
197 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 126 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
198 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 127 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
199 std::string(), | 128 std::string(), |
200 content_setting); | 129 content_setting); |
201 } | 130 } |
131 | |
202 // Cancel this request first, then notify listeners. TODO(pkasting): Why | 132 // Cancel this request first, then notify listeners. TODO(pkasting): Why |
203 // is this order important? | 133 // is this order important? |
204 PendingInfoBarRequests requests_to_notify; | 134 PendingInfoBarRequests requests_to_notify; |
205 PendingInfoBarRequests infobars_to_remove; | 135 PendingInfoBarRequests infobars_to_remove; |
206 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 136 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
207 i != pending_infobar_requests_.end(); ) { | 137 i != pending_infobar_requests_.end(); ) { |
208 if (i->IsForPair(requesting_frame, embedder)) { | 138 if (i->IsForPair(requesting_frame, embedder)) { |
209 requests_to_notify.push_back(*i); | 139 requests_to_notify.push_back(*i); |
210 if (i->Equals(render_process_id, render_view_id, bridge_id)) { | 140 if (i->id.Equals(id)) { |
211 // The delegate that called us is i, and it's currently in either | 141 // The delegate that called us is i, and it's currently in either |
212 // Accept() or Cancel(). This means that the owning InfoBar will call | 142 // Accept() or Cancel(). This means that the owning InfoBar will call |
213 // RemoveInfoBar() later on, and that will trigger a notification we're | 143 // RemoveInfoBar() later on, and that will trigger a notification we're |
214 // observing. | 144 // observing. |
215 ++i; | 145 ++i; |
216 } else if (i->infobar_delegate) { | 146 } else if (i->infobar_delegate) { |
217 // This InfoBar is for the same frame/embedder pair, but in a different | 147 // This InfoBar is for the same frame/embedder pair, but in a different |
218 // tab. We should remove it now that we've got an answer for it. | 148 // tab. We should remove it now that we've got an answer for it. |
219 infobars_to_remove.push_back(*i); | 149 infobars_to_remove.push_back(*i); |
220 ++i; | 150 ++i; |
221 } else { | 151 } else { |
222 // We haven't created an InfoBar yet, just remove the pending request. | 152 // We haven't created an InfoBar yet, just remove the pending request. |
223 i = pending_infobar_requests_.erase(i); | 153 i = pending_infobar_requests_.erase(i); |
224 } | 154 } |
225 } else { | 155 } else { |
226 ++i; | 156 ++i; |
227 } | 157 } |
228 } | 158 } |
229 | 159 |
230 // Remove all InfoBars for the same |requesting_frame| and |embedder|. | 160 // Remove all InfoBars for the same |requesting_frame| and |embedder|. |
231 for (PendingInfoBarRequests::iterator i = infobars_to_remove.begin(); | 161 for (PendingInfoBarRequests::iterator i = infobars_to_remove.begin(); |
232 i != infobars_to_remove.end(); ++i ) { | 162 i != infobars_to_remove.end(); ++i ) |
233 InfoBarTabHelper* helper = GetInfoBarHelper(i->render_process_id, | 163 GetInfoBarHelper(i->id)->RemoveInfoBar(i->infobar_delegate); |
234 i->render_view_id); | |
235 helper->RemoveInfoBar(i->infobar_delegate); | |
236 } | |
237 | 164 |
238 // Send out the permission notifications. | 165 // Send out the permission notifications. |
239 for (PendingInfoBarRequests::iterator i = requests_to_notify.begin(); | 166 for (PendingInfoBarRequests::iterator i = requests_to_notify.begin(); |
240 i != requests_to_notify.end(); ++i ) { | 167 i != requests_to_notify.end(); ++i) |
241 i->callback.Run(allowed); | 168 i->callback.Run(allowed); |
242 } | |
243 } | 169 } |
244 | 170 |
245 void GeolocationInfoBarQueueController::Observe( | 171 void GeolocationInfoBarQueueController::Observe( |
246 int type, | 172 int type, |
247 const content::NotificationSource& source, | 173 const content::NotificationSource& source, |
248 const content::NotificationDetails& details) { | 174 const content::NotificationDetails& details) { |
249 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 175 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
250 // We will receive this notification for all infobar closures, so we need to | 176 // We will receive this notification for all infobar closures, so we need to |
251 // check whether this is the geolocation infobar we're tracking. Note that the | 177 // check whether this is the geolocation infobar we're tracking. Note that the |
252 // InfoBarContainer (if any) may have received this notification before us and | 178 // InfoBarContainer (if any) may have received this notification before us and |
253 // caused the delegate to be deleted, so it's not safe to dereference the | 179 // caused the delegate to be deleted, so it's not safe to dereference the |
254 // contents of the delegate. The address of the delegate, however, is OK to | 180 // contents of the delegate. The address of the delegate, however, is OK to |
255 // use to find the PendingInfoBarRequest to remove because | 181 // use to find the PendingInfoBarRequest to remove because |
256 // pending_infobar_requests_ will not have received any new entries between | 182 // pending_infobar_requests_ will not have received any new entries between |
257 // the NotificationService's call to InfoBarContainer::Observe and this | 183 // the NotificationService's call to InfoBarContainer::Observe and this |
258 // method. | 184 // method. |
259 InfoBarDelegate* delegate = | 185 InfoBarDelegate* delegate = |
260 content::Details<InfoBarRemovedDetails>(details)->first; | 186 content::Details<InfoBarRemovedDetails>(details)->first; |
261 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 187 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
262 i != pending_infobar_requests_.end(); ++i) { | 188 i != pending_infobar_requests_.end(); ++i) { |
263 GeolocationConfirmInfoBarDelegate* confirm_delegate = i->infobar_delegate; | 189 GeolocationConfirmInfoBarDelegate* confirm_delegate = i->infobar_delegate; |
264 if (confirm_delegate == delegate) { | 190 if (confirm_delegate == delegate) { |
265 InfoBarTabHelper* helper = | 191 content::GeolocationPermissionRequestID id = i->id; |
266 content::Source<InfoBarTabHelper>(source).ptr(); | |
267 int render_process_id = i->render_process_id; | |
268 int render_view_id = i->render_view_id; | |
269 pending_infobar_requests_.erase(i); | 192 pending_infobar_requests_.erase(i); |
270 ShowQueuedInfoBar(render_process_id, render_view_id, helper); | 193 DCHECK_EQ(content::Source<InfoBarTabHelper>(source).ptr(), |
194 GetInfoBarHelper(id)); | |
195 ShowQueuedInfoBarForTab(id); | |
271 return; | 196 return; |
272 } | 197 } |
273 } | 198 } |
274 } | 199 } |
275 | 200 |
276 GeolocationConfirmInfoBarDelegate* | 201 GeolocationConfirmInfoBarDelegate* |
277 GeolocationInfoBarQueueController::CreateInfoBarDelegate( | 202 GeolocationInfoBarQueueController::CreateInfoBarDelegate( |
278 InfoBarTabHelper* infobar_helper, | 203 InfoBarTabHelper* infobar_helper, |
279 GeolocationInfoBarQueueController* controller, | 204 GeolocationInfoBarQueueController* controller, |
280 int render_process_id, | 205 const content::GeolocationPermissionRequestID& id, |
281 int render_view_id, | 206 const GURL& requesting_frame_url, |
282 int bridge_id, | 207 const std::string& display_languages) { |
283 const GURL& requesting_frame_url, | |
284 const std::string& display_languages) { | |
285 return GeolocationConfirmInfoBarDelegateFactory::Create( | 208 return GeolocationConfirmInfoBarDelegateFactory::Create( |
286 infobar_helper, controller, render_process_id, render_view_id, bridge_id, | 209 infobar_helper, controller, id, requesting_frame_url, display_languages); |
287 requesting_frame_url, display_languages); | |
288 } | 210 } |
289 | 211 |
290 void GeolocationInfoBarQueueController::ShowQueuedInfoBar( | 212 bool GeolocationInfoBarQueueController::AlreadyShowingInfoBarForTab( |
291 int render_process_id, | 213 const content::GeolocationPermissionRequestID& id) { |
292 int render_view_id, | |
293 InfoBarTabHelper* helper) { | |
294 DCHECK(helper); | |
295 DCHECK(!AlreadyShowingInfoBar(render_process_id, render_view_id)); | |
296 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 214 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
297 i != pending_infobar_requests_.end(); ++i) { | 215 i != pending_infobar_requests_.end(); ++i) { |
298 if (i->IsForTab(render_process_id, render_view_id) && | 216 if (i->id.IsForSameTabAs(id) && i->infobar_delegate) |
299 !i->infobar_delegate) { | 217 return true; |
218 } | |
219 return false; | |
220 } | |
221 | |
222 bool GeolocationInfoBarQueueController::ShowQueuedInfoBarForTab( | |
223 const content::GeolocationPermissionRequestID& id) { | |
224 DCHECK(!AlreadyShowingInfoBarForTab(id)); | |
225 | |
226 InfoBarTabHelper* helper = GetInfoBarHelper(id); | |
227 if (!helper) | |
228 return false; | |
229 | |
230 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | |
231 i != pending_infobar_requests_.end(); ++i) { | |
232 if (i->id.IsForSameTabAs(id) && !i->infobar_delegate) { | |
300 RegisterForInfoBarNotifications(helper); | 233 RegisterForInfoBarNotifications(helper); |
301 i->infobar_delegate = CreateInfoBarDelegate( | 234 i->infobar_delegate = CreateInfoBarDelegate( |
302 helper, this, render_process_id, | 235 helper, this, i->id, i->requesting_frame, |
303 render_view_id, i->bridge_id, i->requesting_frame, | |
304 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 236 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
305 helper->AddInfoBar(i->infobar_delegate); | 237 helper->AddInfoBar(i->infobar_delegate); |
306 return; | 238 return true; |
307 } | 239 } |
308 } | 240 } |
241 | |
309 UnregisterForInfoBarNotifications(helper); | 242 UnregisterForInfoBarNotifications(helper); |
243 return false; | |
310 } | 244 } |
311 | 245 |
312 void GeolocationInfoBarQueueController::ClearPendingInfoBarRequestsForTab( | 246 void GeolocationInfoBarQueueController::ClearPendingInfoBarRequestsForTab( |
313 int render_process_id, | 247 const content::GeolocationPermissionRequestID& id) { |
314 int render_view_id) { | |
315 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 248 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); |
316 i != pending_infobar_requests_.end(); ) { | 249 i != pending_infobar_requests_.end(); ) { |
317 if (i->IsForTab(render_process_id, render_view_id)) | 250 if (i->id.IsForSameTabAs(id)) |
318 i = pending_infobar_requests_.erase(i); | 251 i = pending_infobar_requests_.erase(i); |
319 else | 252 else |
320 ++i; | 253 ++i; |
321 } | 254 } |
322 } | 255 } |
323 | 256 |
324 InfoBarTabHelper* GeolocationInfoBarQueueController::GetInfoBarHelper( | 257 InfoBarTabHelper* GeolocationInfoBarQueueController::GetInfoBarHelper( |
John Knottenbelt
2012/10/24 10:59:10
Can this be a non-member function local to this fi
Peter Kasting
2012/10/24 19:50:48
I think so. Will change.
| |
325 int render_process_id, | 258 const content::GeolocationPermissionRequestID& id) { |
326 int render_view_id) { | |
327 WebContents* web_contents = | 259 WebContents* web_contents = |
328 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 260 tab_util::GetWebContentsByID(id.render_process_id, id.render_view_id); |
329 return web_contents ? InfoBarTabHelper::FromWebContents(web_contents) : NULL; | 261 return web_contents ? InfoBarTabHelper::FromWebContents(web_contents) : NULL; |
330 } | 262 } |
331 | 263 |
332 bool GeolocationInfoBarQueueController::AlreadyShowingInfoBar( | |
333 int render_process_id, | |
334 int render_view_id) { | |
335 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | |
336 i != pending_infobar_requests_.end(); ++i) { | |
337 if (i->IsForTab(render_process_id, render_view_id) && i->infobar_delegate) | |
338 return true; | |
339 } | |
340 return false; | |
341 } | |
342 | |
343 void GeolocationInfoBarQueueController::RegisterForInfoBarNotifications( | 264 void GeolocationInfoBarQueueController::RegisterForInfoBarNotifications( |
344 InfoBarTabHelper* helper) { | 265 InfoBarTabHelper* helper) { |
345 if (!registrar_.IsRegistered( | 266 if (!registrar_.IsRegistered( |
346 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 267 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
347 content::Source<InfoBarTabHelper>(helper))) { | 268 content::Source<InfoBarTabHelper>(helper))) { |
348 registrar_.Add(this, | 269 registrar_.Add(this, |
349 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 270 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
350 content::Source<InfoBarTabHelper>(helper)); | 271 content::Source<InfoBarTabHelper>(helper)); |
351 } | 272 } |
352 } | 273 } |
353 | 274 |
354 void GeolocationInfoBarQueueController::UnregisterForInfoBarNotifications( | 275 void GeolocationInfoBarQueueController::UnregisterForInfoBarNotifications( |
355 InfoBarTabHelper* helper) { | 276 InfoBarTabHelper* helper) { |
356 if (registrar_.IsRegistered( | 277 if (registrar_.IsRegistered( |
357 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 278 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
358 content::Source<InfoBarTabHelper>(helper))) { | 279 content::Source<InfoBarTabHelper>(helper))) { |
359 registrar_.Remove(this, | 280 registrar_.Remove(this, |
360 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 281 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
361 content::Source<InfoBarTabHelper>(helper)); | 282 content::Source<InfoBarTabHelper>(helper)); |
362 } | 283 } |
363 } | 284 } |
OLD | NEW |