Chromium Code Reviews| 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/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 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 class PermissionQueueController::PendingInfobarRequest { | 39 class PermissionQueueController::PendingInfobarRequest { |
| 40 public: | 40 public: |
| 41 PendingInfobarRequest(ContentSettingsType type, | 41 PendingInfobarRequest(ContentSettingsType type, |
| 42 const PermissionRequestID& id, | 42 const PermissionRequestID& id, |
| 43 const GURL& requesting_frame, | 43 const GURL& requesting_frame, |
| 44 const GURL& embedder, | 44 const GURL& embedder, |
| 45 const std::string accept_button_label, | |
| 45 PermissionDecidedCallback callback); | 46 PermissionDecidedCallback callback); |
| 46 ~PendingInfobarRequest(); | 47 ~PendingInfobarRequest(); |
| 47 | 48 |
| 48 bool IsForPair(const GURL& requesting_frame, | 49 bool IsForPair(const GURL& requesting_frame, |
| 49 const GURL& embedder) const; | 50 const GURL& embedder) const; |
| 50 | 51 |
| 51 const PermissionRequestID& id() const { return id_; } | 52 const PermissionRequestID& id() const { return id_; } |
| 52 const GURL& requesting_frame() const { return requesting_frame_; } | 53 const GURL& requesting_frame() const { return requesting_frame_; } |
| 53 bool has_infobar() const { return !!infobar_; } | 54 bool has_infobar() const { return !!infobar_; } |
| 54 InfoBar* infobar() { return infobar_; } | 55 InfoBar* infobar() { return infobar_; } |
| 55 | 56 |
| 56 void RunCallback(bool allowed); | 57 void RunCallback(bool allowed); |
| 57 void CreateInfoBar(PermissionQueueController* controller, | 58 void CreateInfoBar(PermissionQueueController* controller, |
| 58 const std::string& display_languages); | 59 const std::string& display_languages); |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 ContentSettingsType type_; | 62 ContentSettingsType type_; |
| 62 PermissionRequestID id_; | 63 PermissionRequestID id_; |
| 63 GURL requesting_frame_; | 64 GURL requesting_frame_; |
| 64 GURL embedder_; | 65 GURL embedder_; |
| 65 PermissionDecidedCallback callback_; | 66 PermissionDecidedCallback callback_; |
| 66 InfoBar* infobar_; | 67 InfoBar* infobar_; |
| 68 std::string accept_button_label_; | |
|
bulach
2014/02/14 11:36:48
nit: move this after embedded, to keep the same or
acleung1
2014/02/21 21:18:01
Done.
| |
| 67 | 69 |
| 68 // Purposefully do not disable copying, as this is stored in STL containers. | 70 // Purposefully do not disable copying, as this is stored in STL containers. |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( | 73 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( |
| 72 ContentSettingsType type, | 74 ContentSettingsType type, |
| 73 const PermissionRequestID& id, | 75 const PermissionRequestID& id, |
| 74 const GURL& requesting_frame, | 76 const GURL& requesting_frame, |
| 75 const GURL& embedder, | 77 const GURL& embedder, |
| 78 const std::string accept_button_label, | |
| 76 PermissionDecidedCallback callback) | 79 PermissionDecidedCallback callback) |
| 77 : type_(type), | 80 : type_(type), |
| 78 id_(id), | 81 id_(id), |
| 79 requesting_frame_(requesting_frame), | 82 requesting_frame_(requesting_frame), |
| 80 embedder_(embedder), | 83 embedder_(embedder), |
| 81 callback_(callback), | 84 callback_(callback), |
| 82 infobar_(NULL) { | 85 infobar_(NULL), |
| 86 accept_button_label_(accept_button_label) { | |
| 83 } | 87 } |
| 84 | 88 |
| 85 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { | 89 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { |
| 86 } | 90 } |
| 87 | 91 |
| 88 bool PermissionQueueController::PendingInfobarRequest::IsForPair( | 92 bool PermissionQueueController::PendingInfobarRequest::IsForPair( |
| 89 const GURL& requesting_frame, | 93 const GURL& requesting_frame, |
| 90 const GURL& embedder) const { | 94 const GURL& embedder) const { |
| 91 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 95 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
| 92 } | 96 } |
| 93 | 97 |
| 94 void PermissionQueueController::PendingInfobarRequest::RunCallback( | 98 void PermissionQueueController::PendingInfobarRequest::RunCallback( |
| 95 bool allowed) { | 99 bool allowed) { |
| 96 callback_.Run(allowed); | 100 callback_.Run(allowed); |
| 97 } | 101 } |
| 98 | 102 |
| 99 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( | 103 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( |
| 100 PermissionQueueController* controller, | 104 PermissionQueueController* controller, |
| 101 const std::string& display_languages) { | 105 const std::string& display_languages) { |
| 102 // TODO(toyoshim): Remove following ContentType dependent code. | 106 // TODO(toyoshim): Remove following ContentType dependent code. |
| 103 // Also these InfoBarDelegate can share much more code each other. | 107 // Also these InfoBarDelegate can share much more code each other. |
| 104 // http://crbug.com/266743 | 108 // http://crbug.com/266743 |
| 105 switch (type_) { | 109 switch (type_) { |
| 106 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 110 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 107 infobar_ = GeolocationInfoBarDelegate::Create( | 111 infobar_ = GeolocationInfoBarDelegate::Create( |
| 108 GetInfoBarService(id_), controller, id_, requesting_frame_, | 112 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| 109 display_languages); | 113 display_languages, accept_button_label_); |
| 110 break; | 114 break; |
| 111 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 115 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 112 infobar_ = MidiPermissionInfoBarDelegate::Create( | 116 infobar_ = MidiPermissionInfoBarDelegate::Create( |
| 113 GetInfoBarService(id_), controller, id_, requesting_frame_, | 117 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| 114 display_languages); | 118 display_languages); |
| 115 break; | 119 break; |
| 116 #if defined(OS_ANDROID) | 120 #if defined(OS_ANDROID) |
| 117 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 121 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 118 infobar_ = ProtectedMediaIdentifierInfoBarDelegate::Create( | 122 infobar_ = ProtectedMediaIdentifierInfoBarDelegate::Create( |
| 119 GetInfoBarService(id_), controller, id_, requesting_frame_, | 123 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 138 // Cancel all outstanding requests. | 142 // Cancel all outstanding requests. |
| 139 in_shutdown_ = true; | 143 in_shutdown_ = true; |
| 140 while (!pending_infobar_requests_.empty()) | 144 while (!pending_infobar_requests_.empty()) |
| 141 CancelInfoBarRequest(pending_infobar_requests_.front().id()); | 145 CancelInfoBarRequest(pending_infobar_requests_.front().id()); |
| 142 } | 146 } |
| 143 | 147 |
| 144 void PermissionQueueController::CreateInfoBarRequest( | 148 void PermissionQueueController::CreateInfoBarRequest( |
| 145 const PermissionRequestID& id, | 149 const PermissionRequestID& id, |
| 146 const GURL& requesting_frame, | 150 const GURL& requesting_frame, |
| 147 const GURL& embedder, | 151 const GURL& embedder, |
| 152 const std::string accept_button_label, | |
| 148 PermissionDecidedCallback callback) { | 153 PermissionDecidedCallback callback) { |
| 149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 154 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 150 | 155 |
| 151 // We shouldn't get duplicate requests. | 156 // We shouldn't get duplicate requests. |
| 152 for (PendingInfobarRequests::const_iterator i( | 157 for (PendingInfobarRequests::const_iterator i( |
| 153 pending_infobar_requests_.begin()); | 158 pending_infobar_requests_.begin()); |
| 154 i != pending_infobar_requests_.end(); ++i) | 159 i != pending_infobar_requests_.end(); ++i) |
| 155 DCHECK(!i->id().Equals(id)); | 160 DCHECK(!i->id().Equals(id)); |
| 156 | 161 |
| 157 pending_infobar_requests_.push_back(PendingInfobarRequest( | 162 pending_infobar_requests_.push_back(PendingInfobarRequest( |
| 158 type_, id, requesting_frame, embedder, callback)); | 163 type_, id, requesting_frame, embedder, |
| 164 accept_button_label, callback)); | |
| 159 if (!AlreadyShowingInfoBarForTab(id)) | 165 if (!AlreadyShowingInfoBarForTab(id)) |
| 160 ShowQueuedInfoBarForTab(id); | 166 ShowQueuedInfoBarForTab(id); |
| 161 } | 167 } |
| 162 | 168 |
| 163 void PermissionQueueController::CancelInfoBarRequest( | 169 void PermissionQueueController::CancelInfoBarRequest( |
| 164 const PermissionRequestID& id) { | 170 const PermissionRequestID& id) { |
| 165 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 171 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 166 | 172 |
| 167 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); | 173 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); |
| 168 i != pending_infobar_requests_.end(); ++i) { | 174 i != pending_infobar_requests_.end(); ++i) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 379 |
| 374 ContentSetting content_setting = | 380 ContentSetting content_setting = |
| 375 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 381 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 376 profile_->GetHostContentSettingsMap()->SetContentSetting( | 382 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 377 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 383 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
| 378 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 384 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
| 379 type_, | 385 type_, |
| 380 std::string(), | 386 std::string(), |
| 381 content_setting); | 387 content_setting); |
| 382 } | 388 } |
| OLD | NEW |