| 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/content_settings/permission_context_uma_util.h" |
| 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" | 11 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/media/midi_permission_infobar_delegate.h" | 13 #include "chrome/browser/media/midi_permission_infobar_delegate.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/services/gcm/push_messaging_infobar_delegate.h" | 15 #include "chrome/browser/services/gcm/push_messaging_infobar_delegate.h" |
| 15 #include "chrome/browser/tab_contents/tab_util.h" | 16 #include "chrome/browser/tab_contents/tab_util.h" |
| 16 #include "chrome/common/content_settings.h" | 17 #include "chrome/common/content_settings.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "components/infobars/core/infobar.h" | 19 #include "components/infobars/core/infobar.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 99 } |
| 99 | 100 |
| 100 void PermissionQueueController::PendingInfobarRequest::RunCallback( | 101 void PermissionQueueController::PendingInfobarRequest::RunCallback( |
| 101 bool allowed) { | 102 bool allowed) { |
| 102 callback_.Run(allowed); | 103 callback_.Run(allowed); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( | 106 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( |
| 106 PermissionQueueController* controller, | 107 PermissionQueueController* controller, |
| 107 const std::string& display_languages) { | 108 const std::string& display_languages) { |
| 108 // TODO(toyoshim): Remove following ContentType dependent code. | |
| 109 // Also these InfoBarDelegate can share much more code each other. | |
| 110 // http://crbug.com/266743 | |
| 111 switch (type_) { | 109 switch (type_) { |
| 112 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 110 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 113 infobar_ = GeolocationInfoBarDelegate::Create( | 111 infobar_ = GeolocationInfoBarDelegate::Create( |
| 114 GetInfoBarService(id_), controller, id_, requesting_frame_, | 112 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| 115 display_languages, accept_button_label_); | 113 display_languages, accept_button_label_); |
| 116 break; | 114 break; |
| 117 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 115 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
| 118 infobar_ = MidiPermissionInfoBarDelegate::Create( | 116 infobar_ = MidiPermissionInfoBarDelegate::Create( |
| 119 GetInfoBarService(id_), controller, id_, requesting_frame_, | 117 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| 120 display_languages); | 118 display_languages, type_); |
| 121 break; | 119 break; |
| 122 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: | 120 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: |
| 123 infobar_ = gcm::PushMessagingInfoBarDelegate::Create( | 121 infobar_ = gcm::PushMessagingInfoBarDelegate::Create( |
| 124 GetInfoBarService(id_), controller, id_, requesting_frame_, | 122 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| 125 display_languages); | 123 display_languages, type_); |
| 126 break; | 124 break; |
| 127 #if defined(OS_ANDROID) | 125 #if defined(OS_ANDROID) |
| 128 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: | 126 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: |
| 129 infobar_ = ProtectedMediaIdentifierInfoBarDelegate::Create( | 127 infobar_ = ProtectedMediaIdentifierInfoBarDelegate::Create( |
| 130 GetInfoBarService(id_), controller, id_, requesting_frame_, | 128 GetInfoBarService(id_), controller, id_, requesting_frame_, |
| 131 display_languages); | 129 display_languages); |
| 132 break; | 130 break; |
| 133 #endif | 131 #endif |
| 134 default: | 132 default: |
| 135 NOTREACHED(); | 133 NOTREACHED(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 185 } |
| 188 } | 186 } |
| 189 | 187 |
| 190 void PermissionQueueController::OnPermissionSet( | 188 void PermissionQueueController::OnPermissionSet( |
| 191 const PermissionRequestID& id, | 189 const PermissionRequestID& id, |
| 192 const GURL& requesting_frame, | 190 const GURL& requesting_frame, |
| 193 const GURL& embedder, | 191 const GURL& embedder, |
| 194 bool update_content_setting, | 192 bool update_content_setting, |
| 195 bool allowed) { | 193 bool allowed) { |
| 196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 194 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 197 if (update_content_setting) | 195 |
| 196 // TODO(miguelg): move the permission persistence to |
| 197 // PermissionContextBase once all the types are moved there. |
| 198 if (update_content_setting) { |
| 198 UpdateContentSetting(requesting_frame, embedder, allowed); | 199 UpdateContentSetting(requesting_frame, embedder, allowed); |
| 200 if (allowed) |
| 201 PermissionContextUmaUtil::PermissionGranted(type_); |
| 202 else |
| 203 PermissionContextUmaUtil::PermissionDenied(type_); |
| 204 } else { |
| 205 PermissionContextUmaUtil::PermissionDismissed(type_); |
| 206 } |
| 199 | 207 |
| 200 // Cancel this request first, then notify listeners. TODO(pkasting): Why | 208 // Cancel this request first, then notify listeners. TODO(pkasting): Why |
| 201 // is this order important? | 209 // is this order important? |
| 202 PendingInfobarRequests requests_to_notify; | 210 PendingInfobarRequests requests_to_notify; |
| 203 PendingInfobarRequests infobars_to_remove; | 211 PendingInfobarRequests infobars_to_remove; |
| 204 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove; | 212 std::vector<PendingInfobarRequests::iterator> pending_requests_to_remove; |
| 205 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 213 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
| 206 i != pending_infobar_requests_.end(); ++i) { | 214 i != pending_infobar_requests_.end(); ++i) { |
| 207 if (!i->IsForPair(requesting_frame, embedder)) | 215 if (!i->IsForPair(requesting_frame, embedder)) |
| 208 continue; | 216 continue; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 367 |
| 360 ContentSetting content_setting = | 368 ContentSetting content_setting = |
| 361 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 369 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 362 profile_->GetHostContentSettingsMap()->SetContentSetting( | 370 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 363 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 371 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
| 364 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 372 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
| 365 type_, | 373 type_, |
| 366 std::string(), | 374 std::string(), |
| 367 content_setting); | 375 content_setting); |
| 368 } | 376 } |
| OLD | NEW |