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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 } | 146 } |
147 | 147 |
148 void PermissionQueueController::CreateInfoBarRequest( | 148 void PermissionQueueController::CreateInfoBarRequest( |
149 const PermissionRequestID& id, | 149 const PermissionRequestID& id, |
150 const GURL& requesting_frame, | 150 const GURL& requesting_frame, |
151 const GURL& embedder, | 151 const GURL& embedder, |
152 const std::string& accept_button_label, | 152 const std::string& accept_button_label, |
153 PermissionDecidedCallback callback) { | 153 PermissionDecidedCallback callback) { |
154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
155 | 155 |
156 // We shouldn't get duplicate requests. | |
157 for (PendingInfobarRequests::const_iterator i( | |
158 pending_infobar_requests_.begin()); | |
159 i != pending_infobar_requests_.end(); ++i) | |
160 DCHECK(!i->id().Equals(id)); | |
161 | |
162 pending_infobar_requests_.push_back(PendingInfobarRequest( | 156 pending_infobar_requests_.push_back(PendingInfobarRequest( |
163 type_, id, requesting_frame, embedder, | 157 type_, id, requesting_frame, embedder, |
164 accept_button_label, callback)); | 158 accept_button_label, callback)); |
165 if (!AlreadyShowingInfoBarForTab(id)) | 159 if (!AlreadyShowingInfoBarForTab(id)) |
166 ShowQueuedInfoBarForTab(id); | 160 ShowQueuedInfoBarForTab(id); |
167 } | 161 } |
168 | 162 |
169 void PermissionQueueController::CancelInfoBarRequest( | 163 void PermissionQueueController::CancelInfoBarRequest( |
170 const PermissionRequestID& id) { | 164 const PermissionRequestID& id) { |
171 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
(...skipping 10 matching lines...) Expand all Loading... | |
182 } | 176 } |
183 } | 177 } |
184 | 178 |
185 void PermissionQueueController::OnPermissionSet( | 179 void PermissionQueueController::OnPermissionSet( |
186 const PermissionRequestID& id, | 180 const PermissionRequestID& id, |
187 const GURL& requesting_frame, | 181 const GURL& requesting_frame, |
188 const GURL& embedder, | 182 const GURL& embedder, |
189 bool update_content_setting, | 183 bool update_content_setting, |
190 bool allowed) { | 184 bool allowed) { |
191 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 185 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
192 | |
193 if (update_content_setting) | 186 if (update_content_setting) |
194 UpdateContentSetting(requesting_frame, embedder, allowed); | 187 UpdateContentSetting(requesting_frame, embedder, allowed); |
195 | 188 |
196 // Cancel this request first, then notify listeners. TODO(pkasting): Why | 189 // Cancel this request first, then notify listeners. TODO(pkasting): Why |
197 // is this order important? | 190 // is this order important? |
198 PendingInfobarRequests requests_to_notify; | 191 PendingInfobarRequests requests_to_notify; |
199 PendingInfobarRequests infobars_to_remove; | 192 PendingInfobarRequests infobars_to_remove; |
200 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 193 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
201 i != pending_infobar_requests_.end(); ) { | 194 i != pending_infobar_requests_.end(); ) { |
202 if (i->IsForPair(requesting_frame, embedder)) { | 195 if (i->IsForPair(requesting_frame, embedder)) { |
xhwang
2014/06/10 21:48:39
nit: See below about using a normal for loop. If y
| |
203 requests_to_notify.push_back(*i); | 196 requests_to_notify.push_back(*i); |
197 bool infobar_created = false; | |
204 if (i->id().Equals(id)) { | 198 if (i->id().Equals(id)) { |
205 // The infobar that called us is i->infobar(), and its delegate is | 199 // The infobar that called us is i->infobar(), and its delegate is |
206 // currently in either Accept() or Cancel(). This means that | 200 // currently in either Accept() or Cancel(). This means that |
207 // RemoveInfoBar() will be called later on, and that will trigger a | 201 // RemoveInfoBar() will be called later on, and that will trigger a |
208 // notification we're observing. | 202 // notification we're observing. |
209 ++i; | 203 infobar_created = true; |
210 } else if (i->has_infobar()) { | 204 } |
211 // This infobar is for the same frame/embedder pair, but in a different | 205 if (i->has_infobar()) { |
212 // tab. We should remove it now that we've got an answer for it. | 206 // This infobar is for the same frame/embedder pair. We should remove |
207 // it now that we've got an answer for it. | |
213 infobars_to_remove.push_back(*i); | 208 infobars_to_remove.push_back(*i); |
214 ++i; | 209 infobar_created = true; |
215 } else { | 210 } |
211 if (!infobar_created) { | |
216 // We haven't created an infobar yet, just remove the pending request. | 212 // We haven't created an infobar yet, just remove the pending request. |
217 i = pending_infobar_requests_.erase(i); | 213 i = pending_infobar_requests_.erase(i); |
214 } else { | |
215 ++i; | |
218 } | 216 } |
219 } else { | 217 } else { |
220 ++i; | 218 ++i; |
221 } | 219 } |
xhwang
2014/06/10 21:48:39
This for loop is crazy and can be improved. Since
| |
222 } | 220 } |
223 | 221 |
224 // Remove all infobars for the same |requesting_frame| and |embedder|. | 222 // Remove all infobars for the same |requesting_frame| and |embedder|. |
225 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); | 223 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); |
226 i != infobars_to_remove.end(); ++i) | 224 i != infobars_to_remove.end(); ++i) |
227 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); | 225 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); |
228 | 226 |
229 // Send out the permission notifications. | 227 // Send out the permission notifications. |
230 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); | 228 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); |
231 i != requests_to_notify.end(); ++i) | 229 i != requests_to_notify.end(); ++i) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 | 348 |
351 ContentSetting content_setting = | 349 ContentSetting content_setting = |
352 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 350 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
353 profile_->GetHostContentSettingsMap()->SetContentSetting( | 351 profile_->GetHostContentSettingsMap()->SetContentSetting( |
354 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 352 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
355 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 353 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
356 type_, | 354 type_, |
357 std::string(), | 355 std::string(), |
358 content_setting); | 356 content_setting); |
359 } | 357 } |
OLD | NEW |