| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 118 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 update_content_setting = |
| 246 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 247 } |
| 248 |
| 238 // Send out the permission notifications. | 249 // Send out the permission notifications. |
| 239 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); | 250 for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); |
| 240 i != requests_to_notify.end(); ++i) | 251 i != requests_to_notify.end(); ++i) |
| 241 i->RunCallback(allowed); | 252 i->RunCallback(content_setting); |
| 242 | 253 |
| 243 // Remove the pending requests in reverse order. | 254 // Remove the pending requests in reverse order. |
| 244 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) | 255 for (int i = pending_requests_to_remove.size() - 1; i >= 0; --i) |
| 245 pending_infobar_requests_.erase(pending_requests_to_remove[i]); | 256 pending_infobar_requests_.erase(pending_requests_to_remove[i]); |
| 246 } | 257 } |
| 247 | 258 |
| 248 void PermissionQueueController::Observe( | 259 void PermissionQueueController::Observe( |
| 249 int type, | 260 int type, |
| 250 const content::NotificationSource& source, | 261 const content::NotificationSource& source, |
| 251 const content::NotificationDetails& details) { | 262 const content::NotificationDetails& details) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 ContentSettingsPattern::Wildcard() : | 380 ContentSettingsPattern::Wildcard() : |
| 370 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()); | 381 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()); |
| 371 | 382 |
| 372 profile_->GetHostContentSettingsMap()->SetContentSetting( | 383 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 373 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 384 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
| 374 embedder_pattern, | 385 embedder_pattern, |
| 375 type_, | 386 type_, |
| 376 std::string(), | 387 std::string(), |
| 377 content_setting); | 388 content_setting); |
| 378 } | 389 } |
| OLD | NEW |