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

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: nits 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;
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->has_infobar()) {
206 // currently in either Accept() or Cancel(). This means that 200 // We haven't created an infobar yet, just record the pending request
207 // RemoveInfoBar() will be called later on, and that will trigger a 201 // index and remove it later.
208 // notification we're observing. 202 pending_requests_to_remove.push_back(i);
209 ++i; 203 continue;
210 } else if (i->has_infobar()) {
211 // This infobar is for the same frame/embedder pair, but in a different
212 // tab. We should remove it now that we've got an answer for it.
213 infobars_to_remove.push_back(*i);
214 ++i;
215 } else {
216 // We haven't created an infobar yet, just remove the pending request.
217 i = pending_infobar_requests_.erase(i);
218 }
219 } else {
220 ++i;
221 } 204 }
205 if (i->id().Equals(id)) {
206 // The infobar that called us is i->infobar(), and its delegate is
207 // currently in either Accept() or Cancel(). This means that
208 // RemoveInfoBar() will be called later on, and that will trigger a
209 // notification we're observing.
210 continue;
211 }
212
213 // This infobar is for the same frame/embedder pair, but in a different
214 // tab. We should remove it now that we've got an answer for it.
215 infobars_to_remove.push_back(*i);
222 } 216 }
223 217
224 // Remove all infobars for the same |requesting_frame| and |embedder|. 218 // Remove all infobars for the same |requesting_frame| and |embedder|.
225 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); 219 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin();
226 i != infobars_to_remove.end(); ++i) 220 i != infobars_to_remove.end(); ++i)
227 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); 221 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar());
228 222
229 // Send out the permission notifications. 223 // Send out the permission notifications.
230 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); 224 for (PendingInfobarRequests::iterator i = requests_to_notify.begin();
231 i != requests_to_notify.end(); ++i) 225 i != requests_to_notify.end(); ++i)
232 i->RunCallback(allowed); 226 i->RunCallback(allowed);
227
228 // Remove the pending requests in reverse order.
229 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i)
230 pending_infobar_requests_.erase(pending_requests_to_remove[i]);
233 } 231 }
234 232
235 void PermissionQueueController::Observe( 233 void PermissionQueueController::Observe(
236 int type, 234 int type,
237 const content::NotificationSource& source, 235 const content::NotificationSource& source,
238 const content::NotificationDetails& details) { 236 const content::NotificationDetails& details) {
239 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 237 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
240 // We will receive this notification for all infobar closures, so we need to 238 // 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 239 // 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 240 // InfoBarContainer (if any) may have received this notification before us and
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
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