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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 !!infobar_; }
54 InfoBarDelegate* infobar() { return infobar_; } 54 InfoBar* infobar() { return infobar_; }
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 InfoBarDelegate* infobar_; 66 InfoBar* infobar_;
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)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 189
190 // Cancel this request first, then notify listeners. TODO(pkasting): Why 190 // Cancel this request first, then notify listeners. TODO(pkasting): Why
191 // is this order important? 191 // is this order important?
192 PendingInfoBarRequests requests_to_notify; 192 PendingInfoBarRequests requests_to_notify;
193 PendingInfoBarRequests infobars_to_remove; 193 PendingInfoBarRequests infobars_to_remove;
194 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 194 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
195 i != pending_infobar_requests_.end(); ) { 195 i != pending_infobar_requests_.end(); ) {
196 if (i->IsForPair(requesting_frame, embedder)) { 196 if (i->IsForPair(requesting_frame, embedder)) {
197 requests_to_notify.push_back(*i); 197 requests_to_notify.push_back(*i);
198 if (i->id().Equals(id)) { 198 if (i->id().Equals(id)) {
199 // The infobar that called us is i->infobar(), and it's currently in 199 // The infobar that called us is i->infobar(), and its delegate is
200 // either Accept() or Cancel(). This means that RemoveInfoBar() will be 200 // currently in either Accept() or Cancel(). This means that
201 // called later on, and that will trigger a notification we're 201 // RemoveInfoBar() will be called later on, and that will trigger a
202 // observing. 202 // notification we're observing.
203 ++i; 203 ++i;
204 } else if (i->has_infobar()) { 204 } else if (i->has_infobar()) {
205 // This infobar is for the same frame/embedder pair, but in a different 205 // 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. 206 // tab. We should remove it now that we've got an answer for it.
207 infobars_to_remove.push_back(*i); 207 infobars_to_remove.push_back(*i);
208 ++i; 208 ++i;
209 } else { 209 } else {
210 // We haven't created an infobar yet, just remove the pending request. 210 // We haven't created an infobar yet, just remove the pending request.
211 i = pending_infobar_requests_.erase(i); 211 i = pending_infobar_requests_.erase(i);
212 } 212 }
(...skipping 20 matching lines...) Expand all
233 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); 233 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type);
234 // We will receive this notification for all infobar closures, so we need to 234 // 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 235 // 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 236 // 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 237 // 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 238 // contents of the infobar. The address of the infobar, however, is OK to
239 // use to find the PendingInfoBarRequest to remove because 239 // use to find the PendingInfoBarRequest to remove because
240 // pending_infobar_requests_ will not have received any new entries between 240 // pending_infobar_requests_ will not have received any new entries between
241 // the NotificationService's call to InfoBarContainer::Observe and this 241 // the NotificationService's call to InfoBarContainer::Observe and this
242 // method. 242 // method.
243 InfoBarDelegate* infobar = 243 InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first;
244 content::Details<InfoBar::RemovedDetails>(details)->first;
245 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); 244 for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin();
246 i != pending_infobar_requests_.end(); ++i) { 245 i != pending_infobar_requests_.end(); ++i) {
247 if (i->infobar() == infobar) { 246 if (i->infobar() == infobar) {
248 PermissionRequestID id(i->id()); 247 PermissionRequestID id(i->id());
249 pending_infobar_requests_.erase(i); 248 pending_infobar_requests_.erase(i);
250 ShowQueuedInfoBarForTab(id); 249 ShowQueuedInfoBarForTab(id);
251 return; 250 return;
252 } 251 }
253 } 252 }
254 } 253 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 343
345 ContentSetting content_setting = 344 ContentSetting content_setting =
346 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 345 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
347 profile_->GetHostContentSettingsMap()->SetContentSetting( 346 profile_->GetHostContentSettingsMap()->SetContentSetting(
348 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), 347 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()),
349 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), 348 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()),
350 type_, 349 type_,
351 std::string(), 350 std::string(),
352 content_setting); 351 content_setting);
353 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698