OLD | NEW |
---|---|
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/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" | 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 const GURL& requesting_frame, | 43 const GURL& requesting_frame, |
44 const GURL& embedder, | 44 const GURL& embedder, |
45 PermissionDecidedCallback callback); | 45 PermissionDecidedCallback callback); |
46 ~PendingInfoBarRequest(); | 46 ~PendingInfoBarRequest(); |
47 | 47 |
48 bool IsForPair(const GURL& requesting_frame, | 48 bool IsForPair(const GURL& requesting_frame, |
49 const GURL& embedder) const; | 49 const GURL& embedder) const; |
50 | 50 |
51 const PermissionRequestID& id() const { return id_; } | 51 const PermissionRequestID& id() const { return id_; } |
52 const GURL& requesting_frame() const { return requesting_frame_; } | 52 const GURL& requesting_frame() const { return requesting_frame_; } |
53 bool has_infobar() const { return !!infobar_; } | 53 bool has_infobar() const { return !!info_bar_; } |
ddorwin
2014/01/07 19:07:14
Why the change to a two-part name? See comment bel
Kibeom Kim (inactive)
2014/01/07 19:31:24
(previous comments: https://codereview.chromium.or
| |
54 InfoBar* infobar() { return infobar_; } | 54 InfoBar* infobar() { return info_bar_; } |
55 | 55 |
56 void RunCallback(bool allowed); | 56 void RunCallback(bool allowed); |
57 void CreateInfoBar(PermissionQueueController* controller, | 57 void CreateInfoBar(PermissionQueueController* controller, |
58 const std::string& display_languages); | 58 const std::string& display_languages); |
59 | 59 |
60 private: | 60 private: |
61 ContentSettingsType type_; | 61 ContentSettingsType type_; |
62 PermissionRequestID id_; | 62 PermissionRequestID id_; |
63 GURL requesting_frame_; | 63 GURL requesting_frame_; |
64 GURL embedder_; | 64 GURL embedder_; |
65 PermissionDecidedCallback callback_; | 65 PermissionDecidedCallback callback_; |
66 InfoBar* infobar_; | 66 InfoBar* info_bar_; |
67 | 67 |
68 // Purposefully do not disable copying, as this is stored in STL containers. | 68 // Purposefully do not disable copying, as this is stored in STL containers. |
69 }; | 69 }; |
70 | 70 |
71 PermissionQueueController::PendingInfoBarRequest::PendingInfoBarRequest( | 71 PermissionQueueController::PendingInfoBarRequest::PendingInfoBarRequest( |
72 ContentSettingsType type, | 72 ContentSettingsType type, |
73 const PermissionRequestID& id, | 73 const PermissionRequestID& id, |
74 const GURL& requesting_frame, | 74 const GURL& requesting_frame, |
75 const GURL& embedder, | 75 const GURL& embedder, |
76 PermissionDecidedCallback callback) | 76 PermissionDecidedCallback callback) |
77 : type_(type), | 77 : type_(type), |
78 id_(id), | 78 id_(id), |
79 requesting_frame_(requesting_frame), | 79 requesting_frame_(requesting_frame), |
80 embedder_(embedder), | 80 embedder_(embedder), |
81 callback_(callback), | 81 callback_(callback), |
82 infobar_(NULL) { | 82 info_bar_(NULL) { |
83 } | 83 } |
84 | 84 |
85 PermissionQueueController::PendingInfoBarRequest::~PendingInfoBarRequest() { | 85 PermissionQueueController::PendingInfoBarRequest::~PendingInfoBarRequest() { |
86 } | 86 } |
87 | 87 |
88 bool PermissionQueueController::PendingInfoBarRequest::IsForPair( | 88 bool PermissionQueueController::PendingInfoBarRequest::IsForPair( |
89 const GURL& requesting_frame, | 89 const GURL& requesting_frame, |
90 const GURL& embedder) const { | 90 const GURL& embedder) const { |
91 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 91 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
92 } | 92 } |
93 | 93 |
94 void PermissionQueueController::PendingInfoBarRequest::RunCallback( | 94 void PermissionQueueController::PendingInfoBarRequest::RunCallback( |
95 bool allowed) { | 95 bool allowed) { |
96 callback_.Run(allowed); | 96 callback_.Run(allowed); |
97 } | 97 } |
98 | 98 |
99 void PermissionQueueController::PendingInfoBarRequest::CreateInfoBar( | 99 void PermissionQueueController::PendingInfoBarRequest::CreateInfoBar( |
100 PermissionQueueController* controller, | 100 PermissionQueueController* controller, |
101 const std::string& display_languages) { | 101 const std::string& display_languages) { |
102 // TODO(toyoshim): Remove following ContentType dependent code. | 102 // TODO(toyoshim): Remove following ContentType dependent code. |
103 // Also these InfoBarDelegate can share much more code each other. | 103 // Also these InfoBarDelegate can share much more code each other. |
104 // http://crbug.com/266743 | 104 // http://crbug.com/266743 |
105 switch (type_) { | 105 switch (type_) { |
106 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 106 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
107 infobar_ = GeolocationInfoBarDelegate::Create( | 107 info_bar_ = GeolocationInfoBarDelegate::Create( |
108 GetInfoBarService(id_), controller, id_, requesting_frame_, | 108 GetInfoBarService(id_), controller, id_, requesting_frame_, |
109 display_languages); | 109 display_languages); |
110 break; | 110 break; |
111 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 111 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
112 infobar_ = MIDIPermissionInfoBarDelegate::Create( | 112 info_bar_ = MIDIPermissionInfoBarDelegate::Create( |
113 GetInfoBarService(id_), controller, id_, requesting_frame_, | 113 GetInfoBarService(id_), controller, id_, requesting_frame_, |
114 display_languages); | 114 display_languages); |
115 break; | 115 break; |
116 #if defined(OS_ANDROID) | 116 #if defined(OS_ANDROID) |
117 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 117 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
118 infobar_ = ProtectedMediaIdentifierInfoBarDelegate::Create( | 118 info_bar_ = ProtectedMediaIdentifierInfoBarDelegate::Create( |
119 GetInfoBarService(id_), controller, id_, requesting_frame_, | 119 GetInfoBarService(id_), controller, id_, requesting_frame_, |
120 display_languages); | 120 display_languages); |
121 break; | 121 break; |
122 #endif | 122 #endif |
123 default: | 123 default: |
124 NOTREACHED(); | 124 NOTREACHED(); |
125 break; | 125 break; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 | 129 |
130 PermissionQueueController::PermissionQueueController(Profile* profile, | 130 PermissionQueueController::PermissionQueueController(Profile* profile, |
131 ContentSettingsType type) | 131 ContentSettingsType type) |
132 : profile_(profile), | 132 : profile_(profile), |
133 type_(type), | 133 type_(type), |
134 in_shutdown_(false) { | 134 in_shutdown_(false) { |
135 } | 135 } |
136 | 136 |
137 PermissionQueueController::~PermissionQueueController() { | 137 PermissionQueueController::~PermissionQueueController() { |
138 // Cancel all outstanding requests. | 138 // Cancel all outstanding requests. |
139 in_shutdown_ = true; | 139 in_shutdown_ = true; |
140 while (!pending_infobar_requests_.empty()) | 140 while (!pending_info_bar_requests_.empty()) |
141 CancelInfoBarRequest(pending_infobar_requests_.front().id()); | 141 CancelInfoBarRequest(pending_info_bar_requests_.front().id()); |
142 } | 142 } |
143 | 143 |
144 void PermissionQueueController::CreateInfoBarRequest( | 144 void PermissionQueueController::CreateInfoBarRequest( |
145 const PermissionRequestID& id, | 145 const PermissionRequestID& id, |
146 const GURL& requesting_frame, | 146 const GURL& requesting_frame, |
147 const GURL& embedder, | 147 const GURL& embedder, |
148 PermissionDecidedCallback callback) { | 148 PermissionDecidedCallback callback) { |
149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
150 | 150 |
151 // We shouldn't get duplicate requests. | 151 // We shouldn't get duplicate requests. |
152 for (PendingInfoBarRequests::const_iterator i( | 152 for (PendingInfoBarRequests::const_iterator i( |
153 pending_infobar_requests_.begin()); | 153 pending_info_bar_requests_.begin()); |
154 i != pending_infobar_requests_.end(); ++i) | 154 i != pending_info_bar_requests_.end(); ++i) |
155 DCHECK(!i->id().Equals(id)); | 155 DCHECK(!i->id().Equals(id)); |
156 | 156 |
157 pending_infobar_requests_.push_back(PendingInfoBarRequest( | 157 pending_info_bar_requests_.push_back(PendingInfoBarRequest( |
158 type_, id, requesting_frame, embedder, callback)); | 158 type_, id, requesting_frame, embedder, callback)); |
159 if (!AlreadyShowingInfoBarForTab(id)) | 159 if (!AlreadyShowingInfoBarForTab(id)) |
160 ShowQueuedInfoBarForTab(id); | 160 ShowQueuedInfoBarForTab(id); |
161 } | 161 } |
162 | 162 |
163 void PermissionQueueController::CancelInfoBarRequest( | 163 void PermissionQueueController::CancelInfoBarRequest( |
164 const PermissionRequestID& id) { | 164 const PermissionRequestID& id) { |
165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
166 | 166 |
167 for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin()); | 167 for (PendingInfoBarRequests::iterator i(pending_info_bar_requests_.begin()); |
168 i != pending_infobar_requests_.end(); ++i) { | 168 i != pending_info_bar_requests_.end(); ++i) { |
169 if (i->id().Equals(id)) { | 169 if (i->id().Equals(id)) { |
170 if (i->has_infobar()) | 170 if (i->has_infobar()) |
171 GetInfoBarService(id)->RemoveInfoBar(i->infobar()); | 171 GetInfoBarService(id)->RemoveInfoBar(i->infobar()); |
172 else | 172 else |
173 pending_infobar_requests_.erase(i); | 173 pending_info_bar_requests_.erase(i); |
174 return; | 174 return; |
175 } | 175 } |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void PermissionQueueController::CancelInfoBarRequests(int group_id) { | |
180 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
181 | |
182 // If we remove an info bar in the following loop, the next pending info bar | |
ddorwin
2014/01/07 19:07:14
nit: "info bar" is inconsistent with description a
Kibeom Kim (inactive)
2014/01/07 19:31:24
Done.
| |
183 // will be shown. Therefore, we erase all the pending info bars first and | |
184 // remove an info bar later. | |
185 PendingInfoBarRequests info_bar_requests_to_cancel; | |
186 for (PendingInfoBarRequests::iterator i = pending_info_bar_requests_.begin(); | |
187 i != pending_info_bar_requests_.end();) { | |
188 if (i->id().group_id() == group_id) { | |
189 if (i->has_infobar()) { | |
190 // |i| will be erased from |pending_info_bar_requests_| | |
191 // in |PermissionQueueController::Observe| when the info bar is removed. | |
192 info_bar_requests_to_cancel.push_back(*i); | |
193 ++i; | |
194 } else { | |
195 i = pending_info_bar_requests_.erase(i); | |
196 } | |
197 } else { | |
198 ++i; | |
199 } | |
200 } | |
201 | |
202 for (PendingInfoBarRequests::iterator i = info_bar_requests_to_cancel.begin(); | |
203 i != info_bar_requests_to_cancel.end(); | |
204 ++i) | |
markusheintz_
2014/01/07 12:22:45
nit: I know there exist several opinions on this,
Kibeom Kim (inactive)
2014/01/07 19:31:24
Done.
| |
205 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); | |
206 } | |
207 | |
179 void PermissionQueueController::OnPermissionSet( | 208 void PermissionQueueController::OnPermissionSet( |
180 const PermissionRequestID& id, | 209 const PermissionRequestID& id, |
181 const GURL& requesting_frame, | 210 const GURL& requesting_frame, |
182 const GURL& embedder, | 211 const GURL& embedder, |
183 bool update_content_setting, | 212 bool update_content_setting, |
184 bool allowed) { | 213 bool allowed) { |
185 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 214 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
186 | 215 |
187 if (update_content_setting) | 216 if (update_content_setting) |
188 UpdateContentSetting(requesting_frame, embedder, allowed); | 217 UpdateContentSetting(requesting_frame, embedder, allowed); |
189 | 218 |
190 // Cancel this request first, then notify listeners. TODO(pkasting): Why | 219 // Cancel this request first, then notify listeners. TODO(pkasting): Why |
191 // is this order important? | 220 // is this order important? |
192 PendingInfoBarRequests requests_to_notify; | 221 PendingInfoBarRequests requests_to_notify; |
193 PendingInfoBarRequests infobars_to_remove; | 222 PendingInfoBarRequests info_bars_to_remove; |
194 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 223 for (PendingInfoBarRequests::iterator i = pending_info_bar_requests_.begin(); |
195 i != pending_infobar_requests_.end(); ) { | 224 i != pending_info_bar_requests_.end(); ) { |
196 if (i->IsForPair(requesting_frame, embedder)) { | 225 if (i->IsForPair(requesting_frame, embedder)) { |
197 requests_to_notify.push_back(*i); | 226 requests_to_notify.push_back(*i); |
198 if (i->id().Equals(id)) { | 227 if (i->id().Equals(id)) { |
199 // The infobar that called us is i->infobar(), and its delegate is | 228 // The infobar that called us is i->infobar(), and its delegate is |
200 // currently in either Accept() or Cancel(). This means that | 229 // currently in either Accept() or Cancel(). This means that |
201 // RemoveInfoBar() will be called later on, and that will trigger a | 230 // RemoveInfoBar() will be called later on, and that will trigger a |
202 // notification we're observing. | 231 // notification we're observing. |
203 ++i; | 232 ++i; |
204 } else if (i->has_infobar()) { | 233 } else if (i->has_infobar()) { |
205 // This infobar is for the same frame/embedder pair, but in a different | 234 // This infobar is for the same frame/embedder pair, but in a different |
206 // tab. We should remove it now that we've got an answer for it. | 235 // tab. We should remove it now that we've got an answer for it. |
207 infobars_to_remove.push_back(*i); | 236 info_bars_to_remove.push_back(*i); |
208 ++i; | 237 ++i; |
209 } else { | 238 } else { |
210 // We haven't created an infobar yet, just remove the pending request. | 239 // We haven't created an infobar yet, just remove the pending request. |
211 i = pending_infobar_requests_.erase(i); | 240 i = pending_info_bar_requests_.erase(i); |
212 } | 241 } |
213 } else { | 242 } else { |
214 ++i; | 243 ++i; |
215 } | 244 } |
216 } | 245 } |
217 | 246 |
218 // Remove all infobars for the same |requesting_frame| and |embedder|. | 247 // Remove all infobars for the same |requesting_frame| and |embedder|. |
219 for (PendingInfoBarRequests::iterator i = infobars_to_remove.begin(); | 248 for (PendingInfoBarRequests::iterator i = info_bars_to_remove.begin(); |
220 i != infobars_to_remove.end(); ++i) | 249 i != info_bars_to_remove.end(); ++i) |
221 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); | 250 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); |
222 | 251 |
223 // Send out the permission notifications. | 252 // Send out the permission notifications. |
224 for (PendingInfoBarRequests::iterator i = requests_to_notify.begin(); | 253 for (PendingInfoBarRequests::iterator i = requests_to_notify.begin(); |
225 i != requests_to_notify.end(); ++i) | 254 i != requests_to_notify.end(); ++i) |
226 i->RunCallback(allowed); | 255 i->RunCallback(allowed); |
227 } | 256 } |
228 | 257 |
229 void PermissionQueueController::Observe( | 258 void PermissionQueueController::Observe( |
230 int type, | 259 int type, |
231 const content::NotificationSource& source, | 260 const content::NotificationSource& source, |
232 const content::NotificationDetails& details) { | 261 const content::NotificationDetails& details) { |
233 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 262 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
234 // We will receive this notification for all infobar closures, so we need to | 263 // We will receive this notification for all infobar closures, so we need to |
235 // check whether this is the geolocation infobar we're tracking. Note that the | 264 // check whether this is the geolocation infobar we're tracking. Note that the |
236 // InfoBarContainer (if any) may have received this notification before us and | 265 // InfoBarContainer (if any) may have received this notification before us and |
237 // caused the infobar to be deleted, so it's not safe to dereference the | 266 // caused the infobar to be deleted, so it's not safe to dereference the |
238 // contents of the infobar. The address of the infobar, however, is OK to | 267 // contents of the infobar. The address of the infobar, however, is OK to |
239 // use to find the PendingInfoBarRequest to remove because | 268 // use to find the PendingInfoBarRequest to remove because |
240 // pending_infobar_requests_ will not have received any new entries between | 269 // pending_infobar_requests_ will not have received any new entries between |
241 // the NotificationService's call to InfoBarContainer::Observe and this | 270 // the NotificationService's call to InfoBarContainer::Observe and this |
242 // method. | 271 // method. |
243 InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first; | 272 InfoBar* info_bar = content::Details<InfoBar::RemovedDetails>(details)->first; |
244 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 273 for (PendingInfoBarRequests::iterator i = pending_info_bar_requests_.begin(); |
245 i != pending_infobar_requests_.end(); ++i) { | 274 i != pending_info_bar_requests_.end(); ++i) { |
246 if (i->infobar() == infobar) { | 275 if (i->infobar() == info_bar) { |
247 PermissionRequestID id(i->id()); | 276 PermissionRequestID id(i->id()); |
248 pending_infobar_requests_.erase(i); | 277 pending_info_bar_requests_.erase(i); |
249 ShowQueuedInfoBarForTab(id); | 278 ShowQueuedInfoBarForTab(id); |
250 return; | 279 return; |
251 } | 280 } |
252 } | 281 } |
253 } | 282 } |
254 | 283 |
255 bool PermissionQueueController::AlreadyShowingInfoBarForTab( | 284 bool PermissionQueueController::AlreadyShowingInfoBarForTab( |
256 const PermissionRequestID& id) const { | 285 const PermissionRequestID& id) const { |
257 for (PendingInfoBarRequests::const_iterator i( | 286 for (PendingInfoBarRequests::const_iterator i( |
258 pending_infobar_requests_.begin()); | 287 pending_info_bar_requests_.begin()); |
259 i != pending_infobar_requests_.end(); ++i) { | 288 i != pending_info_bar_requests_.end(); ++i) { |
260 if (i->id().IsForSameTabAs(id) && i->has_infobar()) | 289 if (i->id().IsForSameTabAs(id) && i->has_infobar()) |
261 return true; | 290 return true; |
262 } | 291 } |
263 return false; | 292 return false; |
264 } | 293 } |
265 | 294 |
266 void PermissionQueueController::ShowQueuedInfoBarForTab( | 295 void PermissionQueueController::ShowQueuedInfoBarForTab( |
267 const PermissionRequestID& id) { | 296 const PermissionRequestID& id) { |
268 DCHECK(!AlreadyShowingInfoBarForTab(id)); | 297 DCHECK(!AlreadyShowingInfoBarForTab(id)); |
269 | 298 |
270 // We can get here for example during tab shutdown, when the InfoBarService is | 299 // We can get here for example during tab shutdown, when the InfoBarService is |
271 // removing all existing infobars, thus calling back to Observe(). In this | 300 // removing all existing infobars, thus calling back to Observe(). In this |
272 // case the service still exists, and is supplied as the source of the | 301 // case the service still exists, and is supplied as the source of the |
273 // notification we observed, but is no longer accessible from its WebContents. | 302 // notification we observed, but is no longer accessible from its WebContents. |
274 // In this case we should just go ahead and cancel further infobars for this | 303 // In this case we should just go ahead and cancel further infobars for this |
275 // tab instead of trying to access the service. | 304 // tab instead of trying to access the service. |
276 // | 305 // |
277 // Similarly, if we're being destroyed, we should also avoid showing further | 306 // Similarly, if we're being destroyed, we should also avoid showing further |
278 // infobars. | 307 // infobars. |
279 InfoBarService* infobar_service = GetInfoBarService(id); | 308 InfoBarService* info_bar_service = GetInfoBarService(id); |
280 if (!infobar_service || in_shutdown_) { | 309 if (!info_bar_service || in_shutdown_) { |
281 ClearPendingInfoBarRequestsForTab(id); | 310 ClearPendingInfoBarRequestsForTab(id); |
282 return; | 311 return; |
283 } | 312 } |
284 | 313 |
285 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 314 for (PendingInfoBarRequests::iterator i = pending_info_bar_requests_.begin(); |
286 i != pending_infobar_requests_.end(); ++i) { | 315 i != pending_info_bar_requests_.end(); ++i) { |
287 if (i->id().IsForSameTabAs(id) && !i->has_infobar()) { | 316 if (i->id().IsForSameTabAs(id) && !i->has_infobar()) { |
288 RegisterForInfoBarNotifications(infobar_service); | 317 RegisterForInfoBarNotifications(info_bar_service); |
289 i->CreateInfoBar( | 318 i->CreateInfoBar( |
290 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 319 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
291 return; | 320 return; |
292 } | 321 } |
293 } | 322 } |
294 | 323 |
295 UnregisterForInfoBarNotifications(infobar_service); | 324 UnregisterForInfoBarNotifications(info_bar_service); |
296 } | 325 } |
297 | 326 |
298 void PermissionQueueController::ClearPendingInfoBarRequestsForTab( | 327 void PermissionQueueController::ClearPendingInfoBarRequestsForTab( |
299 const PermissionRequestID& id) { | 328 const PermissionRequestID& id) { |
300 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); | 329 for (PendingInfoBarRequests::iterator i = pending_info_bar_requests_.begin(); |
301 i != pending_infobar_requests_.end(); ) { | 330 i != pending_info_bar_requests_.end(); ) { |
302 if (i->id().IsForSameTabAs(id)) { | 331 if (i->id().IsForSameTabAs(id)) { |
303 DCHECK(!i->has_infobar()); | 332 DCHECK(!i->has_infobar()); |
304 i = pending_infobar_requests_.erase(i); | 333 i = pending_info_bar_requests_.erase(i); |
305 } else { | 334 } else { |
306 ++i; | 335 ++i; |
307 } | 336 } |
308 } | 337 } |
309 } | 338 } |
310 | 339 |
311 void PermissionQueueController::RegisterForInfoBarNotifications( | 340 void PermissionQueueController::RegisterForInfoBarNotifications( |
312 InfoBarService* infobar_service) { | 341 InfoBarService* info_bar_service) { |
313 if (!registrar_.IsRegistered( | 342 if (!registrar_.IsRegistered( |
314 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 343 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
315 content::Source<InfoBarService>(infobar_service))) { | 344 content::Source<InfoBarService>(info_bar_service))) { |
316 registrar_.Add(this, | 345 registrar_.Add(this, |
317 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 346 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
318 content::Source<InfoBarService>(infobar_service)); | 347 content::Source<InfoBarService>(info_bar_service)); |
319 } | 348 } |
320 } | 349 } |
321 | 350 |
322 void PermissionQueueController::UnregisterForInfoBarNotifications( | 351 void PermissionQueueController::UnregisterForInfoBarNotifications( |
323 InfoBarService* infobar_service) { | 352 InfoBarService* info_bar_service) { |
324 if (registrar_.IsRegistered( | 353 if (registrar_.IsRegistered( |
325 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 354 this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
326 content::Source<InfoBarService>(infobar_service))) { | 355 content::Source<InfoBarService>(info_bar_service))) { |
327 registrar_.Remove(this, | 356 registrar_.Remove(this, |
328 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 357 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
329 content::Source<InfoBarService>(infobar_service)); | 358 content::Source<InfoBarService>(info_bar_service)); |
330 } | 359 } |
331 } | 360 } |
332 | 361 |
333 void PermissionQueueController::UpdateContentSetting( | 362 void PermissionQueueController::UpdateContentSetting( |
334 const GURL& requesting_frame, | 363 const GURL& requesting_frame, |
335 const GURL& embedder, | 364 const GURL& embedder, |
336 bool allowed) { | 365 bool allowed) { |
337 if (requesting_frame.GetOrigin().SchemeIsFile()) { | 366 if (requesting_frame.GetOrigin().SchemeIsFile()) { |
338 // Chrome can be launched with --disable-web-security which allows | 367 // Chrome can be launched with --disable-web-security which allows |
339 // geolocation requests from file:// URLs. We don't want to store these | 368 // geolocation requests from file:// URLs. We don't want to store these |
340 // in the host content settings map. | 369 // in the host content settings map. |
341 return; | 370 return; |
342 } | 371 } |
343 | 372 |
344 ContentSetting content_setting = | 373 ContentSetting content_setting = |
345 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 374 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
346 profile_->GetHostContentSettingsMap()->SetContentSetting( | 375 profile_->GetHostContentSettingsMap()->SetContentSetting( |
347 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 376 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
348 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 377 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
349 type_, | 378 type_, |
350 std::string(), | 379 std::string(), |
351 content_setting); | 380 content_setting); |
352 } | 381 } |
OLD | NEW |