Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_context_base.h" | 5 #include "chrome/browser/content_settings/permission_context_base.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" | 9 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" |
| 10 #include "chrome/browser/content_settings/permission_context_uma_util.h" | 10 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
| 11 #include "chrome/browser/content_settings/permission_queue_controller.h" | 11 #include "chrome/browser/content_settings/permission_queue_controller.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "components/content_settings/core/browser/content_settings_utils.h" | 15 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 16 #include "components/content_settings/core/browser/host_content_settings_map.h" | 16 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 17 #include "components/content_settings/core/common/permission_request_id.h" | 17 #include "components/content_settings/core/common/permission_request_id.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 | 20 |
| 21 #if defined(OS_CHROMEOS) | |
| 22 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | |
| 23 using chromeos::attestation::PlatformVerificationDialog; | |
| 24 using chromeos::attestation::PlatformVerificationFlow; | |
| 25 #endif | |
| 26 | |
| 27 PermissionContextBase::PermissionContextBase( | 21 PermissionContextBase::PermissionContextBase( |
| 28 Profile* profile, | 22 Profile* profile, |
| 29 const ContentSettingsType permission_type) | 23 const ContentSettingsType permission_type) |
| 30 : profile_(profile), | 24 : profile_(profile), |
| 31 permission_type_(permission_type), | 25 permission_type_(permission_type), |
| 32 weak_factory_(this) { | 26 weak_factory_(this) { |
| 33 permission_queue_controller_.reset( | 27 permission_queue_controller_.reset( |
| 34 new PermissionQueueController(profile_, permission_type_)); | 28 new PermissionQueueController(profile_, permission_type_)); |
| 29 | |
|
Jun Mukai
2015/02/05 02:08:14
nit: remove blank line
ddorwin
2015/02/05 02:23:24
?
xhwang
2015/02/05 02:49:34
Done.
xhwang
2015/02/05 02:49:34
Done.
| |
| 35 } | 30 } |
| 36 | 31 |
| 37 PermissionContextBase::~PermissionContextBase() { | 32 PermissionContextBase::~PermissionContextBase() { |
| 38 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 39 } | 34 } |
| 40 | 35 |
| 41 void PermissionContextBase::RequestPermission( | 36 void PermissionContextBase::RequestPermission( |
| 42 content::WebContents* web_contents, | 37 content::WebContents* web_contents, |
| 43 const PermissionRequestID& id, | 38 const PermissionRequestID& id, |
| 44 const GURL& requesting_frame, | 39 const GURL& requesting_frame, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 120 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 126 false /* persist */, true /* granted */); | 121 false /* persist */, true /* granted */); |
| 127 return; | 122 return; |
| 128 default: | 123 default: |
| 129 break; | 124 break; |
| 130 } | 125 } |
| 131 | 126 |
| 132 PermissionContextUmaUtil::PermissionRequested( | 127 PermissionContextUmaUtil::PermissionRequested( |
| 133 permission_type_, requesting_origin); | 128 permission_type_, requesting_origin); |
| 134 | 129 |
| 135 #if defined(OS_CHROMEOS) | |
| 136 // TODO(xhwang): This is to use the existing platform verification UI. Remove | |
| 137 // it when the infobar/bubble UI can satisfy our requirements. | |
| 138 if (permission_type_ == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { | |
| 139 PlatformVerificationDialog::ShowDialog( | |
| 140 web_contents, | |
| 141 base::Bind(&PermissionContextBase::OnPlatformVerificationResult, | |
| 142 weak_factory_.GetWeakPtr(), id, requesting_origin, | |
| 143 embedding_origin, callback)); | |
| 144 return; | |
| 145 } | |
| 146 #endif | |
| 147 | |
| 148 if (PermissionBubbleManager::Enabled()) { | 130 if (PermissionBubbleManager::Enabled()) { |
| 149 if (pending_bubbles_.get(id.ToString()) != NULL) | 131 if (pending_bubbles_.get(id.ToString()) != NULL) |
| 150 return; | 132 return; |
| 151 PermissionBubbleManager* bubble_manager = | 133 PermissionBubbleManager* bubble_manager = |
| 152 PermissionBubbleManager::FromWebContents(web_contents); | 134 PermissionBubbleManager::FromWebContents(web_contents); |
| 153 DCHECK(bubble_manager); | 135 DCHECK(bubble_manager); |
| 154 scoped_ptr<PermissionBubbleRequest> request_ptr( | 136 scoped_ptr<PermissionBubbleRequest> request_ptr( |
| 155 new PermissionBubbleRequestImpl( | 137 new PermissionBubbleRequestImpl( |
| 156 requesting_origin, user_gesture, permission_type_, | 138 requesting_origin, user_gesture, permission_type_, |
| 157 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 139 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 bool allowed) { | 223 bool allowed) { |
| 242 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 224 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); |
| 243 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); | 225 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); |
| 244 ContentSetting content_setting = | 226 ContentSetting content_setting = |
| 245 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 227 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 246 profile_->GetHostContentSettingsMap()->SetContentSetting( | 228 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 247 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), | 229 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), |
| 248 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), | 230 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), |
| 249 permission_type_, std::string(), content_setting); | 231 permission_type_, std::string(), content_setting); |
| 250 } | 232 } |
| 251 | |
| 252 #if defined(OS_CHROMEOS) | |
| 253 void PermissionContextBase::OnPlatformVerificationResult( | |
| 254 const PermissionRequestID& id, | |
| 255 const GURL& requesting_origin, | |
| 256 const GURL& embedding_origin, | |
| 257 const BrowserPermissionCallback& callback, | |
| 258 chromeos::attestation::PlatformVerificationFlow::ConsentResponse response) { | |
| 259 if (response == PlatformVerificationFlow::CONSENT_RESPONSE_NONE) { | |
| 260 // Deny request and do not save to content settings. | |
| 261 PermissionDecided(id, requesting_origin, embedding_origin, callback, | |
| 262 false, // Do not save to content settings. | |
| 263 false); // Do not allow the permission. | |
| 264 return; | |
| 265 } | |
| 266 | |
| 267 PermissionDecided( | |
| 268 id, requesting_origin, embedding_origin, callback, | |
| 269 true, // Save to content settings. | |
| 270 response == PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); | |
| 271 } | |
| 272 #endif | |
| OLD | NEW |