| 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/permissions/permission_queue_controller.h" | 5 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | 9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // anonymous namespace | 47 } // anonymous namespace |
| 48 | 48 |
| 49 class PermissionQueueController::PendingInfobarRequest { | 49 class PermissionQueueController::PendingInfobarRequest { |
| 50 public: | 50 public: |
| 51 PendingInfobarRequest(content::PermissionType type, | 51 PendingInfobarRequest(content::PermissionType type, |
| 52 const PermissionRequestID& id, | 52 const PermissionRequestID& id, |
| 53 const GURL& requesting_frame, | 53 const GURL& requesting_frame, |
| 54 const GURL& embedder, | 54 const GURL& embedder, |
| 55 Profile* profile, |
| 55 const PermissionDecidedCallback& callback); | 56 const PermissionDecidedCallback& callback); |
| 56 ~PendingInfobarRequest(); | 57 ~PendingInfobarRequest(); |
| 57 | 58 |
| 58 bool IsForPair(const GURL& requesting_frame, | 59 bool IsForPair(const GURL& requesting_frame, |
| 59 const GURL& embedder) const; | 60 const GURL& embedder) const; |
| 60 | 61 |
| 61 const PermissionRequestID& id() const { return id_; } | 62 const PermissionRequestID& id() const { return id_; } |
| 62 const GURL& requesting_frame() const { return requesting_frame_; } | 63 const GURL& requesting_frame() const { return requesting_frame_; } |
| 63 bool has_infobar() const { return !!infobar_; } | 64 bool has_infobar() const { return !!infobar_; } |
| 64 infobars::InfoBar* infobar() { return infobar_; } | 65 infobars::InfoBar* infobar() { return infobar_; } |
| 65 | 66 |
| 66 void RunCallback(ContentSetting content_setting); | 67 void RunCallback(ContentSetting content_setting); |
| 67 void CreateInfoBar(PermissionQueueController* controller); | 68 void CreateInfoBar(PermissionQueueController* controller); |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 content::PermissionType type_; | 71 content::PermissionType type_; |
| 71 PermissionRequestID id_; | 72 PermissionRequestID id_; |
| 72 GURL requesting_frame_; | 73 GURL requesting_frame_; |
| 73 GURL embedder_; | 74 GURL embedder_; |
| 75 Profile* profile_; |
| 74 PermissionDecidedCallback callback_; | 76 PermissionDecidedCallback callback_; |
| 75 infobars::InfoBar* infobar_; | 77 infobars::InfoBar* infobar_; |
| 76 | 78 |
| 77 // Purposefully do not disable copying, as this is stored in STL containers. | 79 // Purposefully do not disable copying, as this is stored in STL containers. |
| 78 }; | 80 }; |
| 79 | 81 |
| 80 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( | 82 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( |
| 81 content::PermissionType type, | 83 content::PermissionType type, |
| 82 const PermissionRequestID& id, | 84 const PermissionRequestID& id, |
| 83 const GURL& requesting_frame, | 85 const GURL& requesting_frame, |
| 84 const GURL& embedder, | 86 const GURL& embedder, |
| 87 Profile* profile, |
| 85 const PermissionDecidedCallback& callback) | 88 const PermissionDecidedCallback& callback) |
| 86 : type_(type), | 89 : type_(type), |
| 87 id_(id), | 90 id_(id), |
| 88 requesting_frame_(requesting_frame), | 91 requesting_frame_(requesting_frame), |
| 89 embedder_(embedder), | 92 embedder_(embedder), |
| 93 profile_(profile), |
| 90 callback_(callback), | 94 callback_(callback), |
| 91 infobar_(NULL) {} | 95 infobar_(NULL) {} |
| 92 | 96 |
| 93 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { | 97 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool PermissionQueueController::PendingInfobarRequest::IsForPair( | 100 bool PermissionQueueController::PendingInfobarRequest::IsForPair( |
| 97 const GURL& requesting_frame, | 101 const GURL& requesting_frame, |
| 98 const GURL& embedder) const { | 102 const GURL& embedder) const { |
| 99 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 103 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 // will be destroyed. | 116 // will be destroyed. |
| 113 PermissionInfobarDelegate::PermissionSetCallback callback = | 117 PermissionInfobarDelegate::PermissionSetCallback callback = |
| 114 base::Bind(&PermissionQueueController::OnPermissionSet, | 118 base::Bind(&PermissionQueueController::OnPermissionSet, |
| 115 base::Unretained(controller), | 119 base::Unretained(controller), |
| 116 id_, | 120 id_, |
| 117 requesting_frame_, | 121 requesting_frame_, |
| 118 embedder_); | 122 embedder_); |
| 119 switch (type_) { | 123 switch (type_) { |
| 120 case content::PermissionType::GEOLOCATION: | 124 case content::PermissionType::GEOLOCATION: |
| 121 infobar_ = GeolocationInfoBarDelegateAndroid::Create( | 125 infobar_ = GeolocationInfoBarDelegateAndroid::Create( |
| 122 GetInfoBarService(id_), requesting_frame_, callback); | 126 GetInfoBarService(id_), requesting_frame_, profile_, callback); |
| 123 break; | 127 break; |
| 124 #if defined(ENABLE_NOTIFICATIONS) | 128 #if defined(ENABLE_NOTIFICATIONS) |
| 125 case content::PermissionType::NOTIFICATIONS: | 129 case content::PermissionType::NOTIFICATIONS: |
| 126 infobar_ = NotificationPermissionInfobarDelegate::Create( | 130 infobar_ = NotificationPermissionInfobarDelegate::Create( |
| 127 GetInfoBarService(id_), requesting_frame_, callback); | 131 GetInfoBarService(id_), requesting_frame_, profile_, callback); |
| 128 break; | 132 break; |
| 129 #endif // ENABLE_NOTIFICATIONS | 133 #endif // ENABLE_NOTIFICATIONS |
| 130 case content::PermissionType::MIDI_SYSEX: | 134 case content::PermissionType::MIDI_SYSEX: |
| 131 infobar_ = MidiPermissionInfoBarDelegateAndroid::Create( | 135 infobar_ = MidiPermissionInfoBarDelegateAndroid::Create( |
| 132 GetInfoBarService(id_), requesting_frame_, callback); | 136 GetInfoBarService(id_), requesting_frame_, profile_, callback); |
| 133 break; | 137 break; |
| 134 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 138 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 135 infobar_ = ProtectedMediaIdentifierInfoBarDelegateAndroid::Create( | 139 infobar_ = ProtectedMediaIdentifierInfoBarDelegateAndroid::Create( |
| 136 GetInfoBarService(id_), requesting_frame_, callback); | 140 GetInfoBarService(id_), requesting_frame_, profile_, callback); |
| 137 break; | 141 break; |
| 138 default: | 142 default: |
| 139 NOTREACHED(); | 143 NOTREACHED(); |
| 140 break; | 144 break; |
| 141 } | 145 } |
| 142 } | 146 } |
| 143 | 147 |
| 144 PermissionQueueController::PermissionQueueController( | 148 PermissionQueueController::PermissionQueueController( |
| 145 Profile* profile, | 149 Profile* profile, |
| 146 content::PermissionType permission_type, | 150 content::PermissionType permission_type, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 162 const GURL& requesting_frame, | 166 const GURL& requesting_frame, |
| 163 const GURL& embedder, | 167 const GURL& embedder, |
| 164 const PermissionDecidedCallback& callback) { | 168 const PermissionDecidedCallback& callback) { |
| 165 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 166 | 170 |
| 167 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || | 171 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || |
| 168 embedder.SchemeIs(content::kChromeUIScheme)) | 172 embedder.SchemeIs(content::kChromeUIScheme)) |
| 169 return; | 173 return; |
| 170 | 174 |
| 171 pending_infobar_requests_.push_back(PendingInfobarRequest( | 175 pending_infobar_requests_.push_back(PendingInfobarRequest( |
| 172 permission_type_, id, requesting_frame, embedder, callback)); | 176 permission_type_, id, requesting_frame, embedder, profile_, callback)); |
| 173 if (!AlreadyShowingInfoBarForTab(id)) | 177 if (!AlreadyShowingInfoBarForTab(id)) |
| 174 ShowQueuedInfoBarForTab(id); | 178 ShowQueuedInfoBarForTab(id); |
| 175 } | 179 } |
| 176 | 180 |
| 177 void PermissionQueueController::CancelInfoBarRequest( | 181 void PermissionQueueController::CancelInfoBarRequest( |
| 178 const PermissionRequestID& id) { | 182 const PermissionRequestID& id) { |
| 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 180 | 184 |
| 181 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); | 185 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); |
| 182 i != pending_infobar_requests_.end(); ++i) { | 186 i != pending_infobar_requests_.end(); ++i) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 389 } |
| 386 | 390 |
| 387 ContentSetting content_setting = | 391 ContentSetting content_setting = |
| 388 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 392 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 389 | 393 |
| 390 HostContentSettingsMapFactory::GetForProfile(profile_) | 394 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 391 ->SetContentSettingDefaultScope( | 395 ->SetContentSettingDefaultScope( |
| 392 requesting_frame.GetOrigin(), embedder.GetOrigin(), | 396 requesting_frame.GetOrigin(), embedder.GetOrigin(), |
| 393 content_settings_type_, std::string(), content_setting); | 397 content_settings_type_, std::string(), content_setting); |
| 394 } | 398 } |
| OLD | NEW |