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/permission_context_uma_util.h" | 9 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" | 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 class PermissionQueueController::PendingInfobarRequest { | 42 class PermissionQueueController::PendingInfobarRequest { |
43 public: | 43 public: |
44 PendingInfobarRequest(ContentSettingsType type, | 44 PendingInfobarRequest(ContentSettingsType type, |
45 const PermissionRequestID& id, | 45 const PermissionRequestID& id, |
46 const GURL& requesting_frame, | 46 const GURL& requesting_frame, |
47 const GURL& embedder, | 47 const GURL& embedder, |
48 PermissionDecidedCallback callback); | 48 const PermissionDecidedCallback& callback); |
49 ~PendingInfobarRequest(); | 49 ~PendingInfobarRequest(); |
50 | 50 |
51 bool IsForPair(const GURL& requesting_frame, | 51 bool IsForPair(const GURL& requesting_frame, |
52 const GURL& embedder) const; | 52 const GURL& embedder) const; |
53 | 53 |
54 const PermissionRequestID& id() const { return id_; } | 54 const PermissionRequestID& id() const { return id_; } |
55 const GURL& requesting_frame() const { return requesting_frame_; } | 55 const GURL& requesting_frame() const { return requesting_frame_; } |
56 bool has_infobar() const { return !!infobar_; } | 56 bool has_infobar() const { return !!infobar_; } |
57 infobars::InfoBar* infobar() { return infobar_; } | 57 infobars::InfoBar* infobar() { return infobar_; } |
58 | 58 |
59 void RunCallback(bool allowed); | 59 void RunCallback(ContentSetting content_setting); |
60 void CreateInfoBar(PermissionQueueController* controller, | 60 void CreateInfoBar(PermissionQueueController* controller, |
61 const std::string& display_languages); | 61 const std::string& display_languages); |
62 | 62 |
63 private: | 63 private: |
64 ContentSettingsType type_; | 64 ContentSettingsType type_; |
65 PermissionRequestID id_; | 65 PermissionRequestID id_; |
66 GURL requesting_frame_; | 66 GURL requesting_frame_; |
67 GURL embedder_; | 67 GURL embedder_; |
68 PermissionDecidedCallback callback_; | 68 PermissionDecidedCallback callback_; |
69 infobars::InfoBar* infobar_; | 69 infobars::InfoBar* infobar_; |
70 | 70 |
71 // Purposefully do not disable copying, as this is stored in STL containers. | 71 // Purposefully do not disable copying, as this is stored in STL containers. |
72 }; | 72 }; |
73 | 73 |
74 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( | 74 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( |
75 ContentSettingsType type, | 75 ContentSettingsType type, |
76 const PermissionRequestID& id, | 76 const PermissionRequestID& id, |
77 const GURL& requesting_frame, | 77 const GURL& requesting_frame, |
78 const GURL& embedder, | 78 const GURL& embedder, |
79 PermissionDecidedCallback callback) | 79 const PermissionDecidedCallback& callback) |
80 : type_(type), | 80 : type_(type), |
81 id_(id), | 81 id_(id), |
82 requesting_frame_(requesting_frame), | 82 requesting_frame_(requesting_frame), |
83 embedder_(embedder), | 83 embedder_(embedder), |
84 callback_(callback), | 84 callback_(callback), |
85 infobar_(NULL) { | 85 infobar_(NULL) { |
86 } | 86 } |
87 | 87 |
88 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { | 88 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { |
89 } | 89 } |
90 | 90 |
91 bool PermissionQueueController::PendingInfobarRequest::IsForPair( | 91 bool PermissionQueueController::PendingInfobarRequest::IsForPair( |
92 const GURL& requesting_frame, | 92 const GURL& requesting_frame, |
93 const GURL& embedder) const { | 93 const GURL& embedder) const { |
94 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 94 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
95 } | 95 } |
96 | 96 |
97 void PermissionQueueController::PendingInfobarRequest::RunCallback( | 97 void PermissionQueueController::PendingInfobarRequest::RunCallback( |
98 bool allowed) { | 98 ContentSetting content_setting) { |
99 callback_.Run(allowed); | 99 callback_.Run(content_setting); |
100 } | 100 } |
101 | 101 |
102 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( | 102 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( |
103 PermissionQueueController* controller, | 103 PermissionQueueController* controller, |
104 const std::string& display_languages) { | 104 const std::string& display_languages) { |
105 switch (type_) { | 105 switch (type_) { |
106 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 106 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
107 infobar_ = GeolocationInfoBarDelegate::Create( | 107 infobar_ = GeolocationInfoBarDelegate::Create( |
108 GetInfoBarService(id_), controller, id_, requesting_frame_, | 108 GetInfoBarService(id_), controller, id_, requesting_frame_, |
109 display_languages); | 109 display_languages); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Cancel all outstanding requests. | 145 // Cancel all outstanding requests. |
146 in_shutdown_ = true; | 146 in_shutdown_ = true; |
147 while (!pending_infobar_requests_.empty()) | 147 while (!pending_infobar_requests_.empty()) |
148 CancelInfoBarRequest(pending_infobar_requests_.front().id()); | 148 CancelInfoBarRequest(pending_infobar_requests_.front().id()); |
149 } | 149 } |
150 | 150 |
151 void PermissionQueueController::CreateInfoBarRequest( | 151 void PermissionQueueController::CreateInfoBarRequest( |
152 const PermissionRequestID& id, | 152 const PermissionRequestID& id, |
153 const GURL& requesting_frame, | 153 const GURL& requesting_frame, |
154 const GURL& embedder, | 154 const GURL& embedder, |
155 PermissionDecidedCallback callback) { | 155 const PermissionDecidedCallback& callback) { |
156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
157 | 157 |
158 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || | 158 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || |
159 embedder.SchemeIs(content::kChromeUIScheme)) | 159 embedder.SchemeIs(content::kChromeUIScheme)) |
160 return; | 160 return; |
161 | 161 |
162 pending_infobar_requests_.push_back(PendingInfobarRequest( | 162 pending_infobar_requests_.push_back(PendingInfobarRequest( |
163 type_, id, requesting_frame, embedder, callback)); | 163 type_, id, requesting_frame, embedder, callback)); |
164 if (!AlreadyShowingInfoBarForTab(id)) | 164 if (!AlreadyShowingInfoBarForTab(id)) |
165 ShowQueuedInfoBarForTab(id); | 165 ShowQueuedInfoBarForTab(id); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // This infobar is for the same frame/embedder pair, but in a different | 228 // This infobar is for the same frame/embedder pair, but in a different |
229 // tab. We should remove it now that we've got an answer for it. | 229 // tab. We should remove it now that we've got an answer for it. |
230 infobars_to_remove.push_back(*i); | 230 infobars_to_remove.push_back(*i); |
231 } | 231 } |
232 | 232 |
233 // Remove all infobars for the same |requesting_frame| and |embedder|. | 233 // Remove all infobars for the same |requesting_frame| and |embedder|. |
234 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); | 234 for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); |
235 i != infobars_to_remove.end(); ++i) | 235 i != infobars_to_remove.end(); ++i) |
236 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); | 236 GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); |
237 | 237 |
| 238 // PermissionContextBase needs to know about the new ContentSetting value, |
| 239 // CONTENT_SETTING_DEFAULT being the value for nothing happened. The callers |
| 240 // of ::OnPermissionSet passes { true, true } for allow, { true, false } for |
| 241 // block and { false, * } for dismissed. The tuple being |
| 242 // { update_content_setting, allowed }. |
| 243 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
| 244 if (update_content_setting) { |
| 245 content_setting = allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 246 } |
| 247 |
238 // Send out the permission notifications. | 248 // Send out the permission notifications. |
239 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); | 249 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); |
240 i != requests_to_notify.end(); ++i) | 250 i != requests_to_notify.end(); ++i) |
241 i->RunCallback(allowed); | 251 i->RunCallback(content_setting); |
242 | 252 |
243 // Remove the pending requests in reverse order. | 253 // Remove the pending requests in reverse order. |
244 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) | 254 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) |
245 pending_infobar_requests_.erase(pending_requests_to_remove[i]); | 255 pending_infobar_requests_.erase(pending_requests_to_remove[i]); |
246 } | 256 } |
247 | 257 |
248 void PermissionQueueController::Observe( | 258 void PermissionQueueController::Observe( |
249 int type, | 259 int type, |
250 const content::NotificationSource& source, | 260 const content::NotificationSource& source, |
251 const content::NotificationDetails& details) { | 261 const content::NotificationDetails& details) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 ContentSettingsPattern::Wildcard() : | 379 ContentSettingsPattern::Wildcard() : |
370 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()); | 380 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()); |
371 | 381 |
372 profile_->GetHostContentSettingsMap()->SetContentSetting( | 382 profile_->GetHostContentSettingsMap()->SetContentSetting( |
373 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 383 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
374 embedder_pattern, | 384 embedder_pattern, |
375 type_, | 385 type_, |
376 std::string(), | 386 std::string(), |
377 content_setting); | 387 content_setting); |
378 } | 388 } |
OLD | NEW |