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

Side by Side Diff: chrome/browser/content_settings/permission_queue_controller.cc

Issue 322203003: Allow duplicate infobar requests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify the for loop without changing the logic Created 6 years, 6 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 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
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
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;
193 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove;
200 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); 194 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin();
201 i != pending_infobar_requests_.end(); ) { 195 i != pending_infobar_requests_.end(); ++i) {
202 if (i->IsForPair(requesting_frame, embedder)) { 196 if (!i->IsForPair(requesting_frame, embedder))
203 requests_to_notify.push_back(*i); 197 continue;
xhwang 2014/06/11 00:17:40 You can have here: if (!i->has_infobar()) { pen
qinmin 2014/06/11 00:42:35 Done.
204 if (i->id().Equals(id)) { 198 requests_to_notify.push_back(*i);
205 // The infobar that called us is i->infobar(), and its delegate is 199 if (i->id().Equals(id) && i->has_infobar()) {
206 // currently in either Accept() or Cancel(). This means that 200 // The infobar that called us is i->infobar(), and its delegate is
207 // RemoveInfoBar() will be called later on, and that will trigger a 201 // currently in either Accept() or Cancel(). This means that
208 // notification we're observing. 202 // RemoveInfoBar() will be called later on, and that will trigger a
209 ++i; 203 // notification we're observing.
210 } else if (i->has_infobar()) { 204 continue;
211 // This infobar is for the same frame/embedder pair, but in a different 205 }
212 // tab. We should remove it now that we've got an answer for it. 206 if (i->has_infobar()) {
213 infobars_to_remove.push_back(*i); 207 // This infobar is for the same frame/embedder pair, but in a different
214 ++i; 208 // tab. We should remove it now that we've got an answer for it.
215 } else { 209 infobars_to_remove.push_back(*i);
216 // We haven't created an infobar yet, just remove the pending request.
217 i = pending_infobar_requests_.erase(i);
218 }
219 } else { 210 } else {
220 ++i; 211 // We haven't created an infobar yet, just record the pending request
212 // index and remove it later.
213 pending_requests_to_remove.push_back(i);
221 } 214 }
222 } 215 }
223 216
224 // Remove all infobars for the same |requesting_frame| and |embedder|. 217 // Remove all infobars for the same |requesting_frame| and |embedder|.
225 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); 218 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin();
226 i != infobars_to_remove.end(); ++i) 219 i != infobars_to_remove.end(); ++i)
227 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); 220 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar());
228 221
229 // Send out the permission notifications. 222 // Send out the permission notifications.
230 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); 223 for (PendingInfobarRequests::iterator i = requests_to_notify.begin();
231 i != requests_to_notify.end(); ++i) 224 i != requests_to_notify.end(); ++i)
232 i->RunCallback(allowed); 225 i->RunCallback(allowed);
226
227 // Remove the pending requests in reverse order.
228 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i)
229 pending_infobar_requests_.erase(pending_requests_to_remove[i]);
233 } 230 }
234 231
235 void PermissionQueueController::Observe( 232 void PermissionQueueController::Observe(
236 int type, 233 int type,
237 const content::NotificationSource& source, 234 const content::NotificationSource& source,
238 const content::NotificationDetails& details) { 235 const content::NotificationDetails& details) {
239 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 236 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
240 // We will receive this notification for all infobar closures, so we need to 237 // We will receive this notification for all infobar closures, so we need to
241 // check whether this is the geolocation infobar we're tracking. Note that the 238 // check whether this is the geolocation infobar we're tracking. Note that the
242 // InfoBarContainer (if any) may have received this notification before us and 239 // InfoBarContainer (if any) may have received this notification before us and
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 347
351 ContentSetting content_setting = 348 ContentSetting content_setting =
352 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 349 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
353 profile_->GetHostContentSettingsMap()->SetContentSetting( 350 profile_->GetHostContentSettingsMap()->SetContentSetting(
354 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), 351 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()),
355 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), 352 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()),
356 type_, 353 type_,
357 std::string(), 354 std::string(),
358 content_setting); 355 content_setting);
359 } 356 }
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