| 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 "platform_verification_flow.h" | 5 #include "platform_verification_flow.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" | 11 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" |
| 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" | 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" |
| 13 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | 13 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" |
| 14 #include "chrome/browser/chromeos/login/user.h" | 14 #include "chrome/browser/chromeos/login/user.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/content_settings_pattern.h" |
| 18 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 19 #include "chromeos/attestation/attestation_flow.h" | 21 #include "chromeos/attestation/attestation_flow.h" |
| 20 #include "chromeos/cryptohome/async_method_caller.h" | 22 #include "chromeos/cryptohome/async_method_caller.h" |
| 21 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
| 24 #include "components/user_prefs/user_prefs.h" | 26 #include "components/user_prefs/user_prefs.h" |
| 25 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 28 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/url_constants.h" |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 35 const char kDefaultHttpsPort[] = "443"; |
| 36 |
| 32 // A callback method to handle DBus errors. | 37 // A callback method to handle DBus errors. |
| 33 void DBusCallback(const base::Callback<void(bool)>& on_success, | 38 void DBusCallback(const base::Callback<void(bool)>& on_success, |
| 34 const base::Closure& on_failure, | 39 const base::Closure& on_failure, |
| 35 chromeos::DBusMethodCallStatus call_status, | 40 chromeos::DBusMethodCallStatus call_status, |
| 36 bool result) { | 41 bool result) { |
| 37 if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS) { | 42 if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS) { |
| 38 on_success.Run(result); | 43 on_success.Run(result); |
| 39 } else { | 44 } else { |
| 40 LOG(ERROR) << "PlatformVerificationFlow: DBus call failed!"; | 45 LOG(ERROR) << "PlatformVerificationFlow: DBus call failed!"; |
| 41 on_failure.Run(); | 46 on_failure.Run(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 54 namespace chromeos { | 59 namespace chromeos { |
| 55 namespace attestation { | 60 namespace attestation { |
| 56 | 61 |
| 57 // A default implementation of the Delegate interface. | 62 // A default implementation of the Delegate interface. |
| 58 class DefaultDelegate : public PlatformVerificationFlow::Delegate { | 63 class DefaultDelegate : public PlatformVerificationFlow::Delegate { |
| 59 public: | 64 public: |
| 60 DefaultDelegate() {} | 65 DefaultDelegate() {} |
| 61 virtual ~DefaultDelegate() {} | 66 virtual ~DefaultDelegate() {} |
| 62 | 67 |
| 63 virtual void ShowConsentPrompt( | 68 virtual void ShowConsentPrompt( |
| 64 PlatformVerificationFlow::ConsentType type, | |
| 65 content::WebContents* web_contents, | 69 content::WebContents* web_contents, |
| 66 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) | 70 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) |
| 67 OVERRIDE { | 71 OVERRIDE { |
| 68 PlatformVerificationDialog::ShowDialog(web_contents, callback); | 72 PlatformVerificationDialog::ShowDialog(web_contents, callback); |
| 69 } | 73 } |
| 70 | 74 |
| 71 private: | 75 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); | 76 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); |
| 73 }; | 77 }; |
| 74 | 78 |
| 75 PlatformVerificationFlow::PlatformVerificationFlow() | 79 PlatformVerificationFlow::PlatformVerificationFlow() |
| 76 : attestation_flow_(NULL), | 80 : attestation_flow_(NULL), |
| 77 async_caller_(cryptohome::AsyncMethodCaller::GetInstance()), | 81 async_caller_(cryptohome::AsyncMethodCaller::GetInstance()), |
| 78 cryptohome_client_(DBusThreadManager::Get()->GetCryptohomeClient()), | 82 cryptohome_client_(DBusThreadManager::Get()->GetCryptohomeClient()), |
| 79 user_manager_(UserManager::Get()), | 83 user_manager_(UserManager::Get()), |
| 80 delegate_(NULL), | 84 delegate_(NULL), |
| 81 testing_prefs_(NULL), | 85 testing_prefs_(NULL), |
| 86 testing_content_settings_(NULL), |
| 82 weak_factory_(this) { | 87 weak_factory_(this) { |
| 83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 84 scoped_ptr<ServerProxy> attestation_ca_client(new AttestationCAClient()); | 89 scoped_ptr<ServerProxy> attestation_ca_client(new AttestationCAClient()); |
| 85 default_attestation_flow_.reset(new AttestationFlow( | 90 default_attestation_flow_.reset(new AttestationFlow( |
| 86 async_caller_, | 91 async_caller_, |
| 87 cryptohome_client_, | 92 cryptohome_client_, |
| 88 attestation_ca_client.Pass())); | 93 attestation_ca_client.Pass())); |
| 89 attestation_flow_ = default_attestation_flow_.get(); | 94 attestation_flow_ = default_attestation_flow_.get(); |
| 90 default_delegate_.reset(new DefaultDelegate()); | 95 default_delegate_.reset(new DefaultDelegate()); |
| 91 delegate_ = default_delegate_.get(); | 96 delegate_ = default_delegate_.get(); |
| 92 } | 97 } |
| 93 | 98 |
| 94 PlatformVerificationFlow::PlatformVerificationFlow( | 99 PlatformVerificationFlow::PlatformVerificationFlow( |
| 95 AttestationFlow* attestation_flow, | 100 AttestationFlow* attestation_flow, |
| 96 cryptohome::AsyncMethodCaller* async_caller, | 101 cryptohome::AsyncMethodCaller* async_caller, |
| 97 CryptohomeClient* cryptohome_client, | 102 CryptohomeClient* cryptohome_client, |
| 98 UserManager* user_manager, | 103 UserManager* user_manager, |
| 99 Delegate* delegate) | 104 Delegate* delegate) |
| 100 : attestation_flow_(attestation_flow), | 105 : attestation_flow_(attestation_flow), |
| 101 async_caller_(async_caller), | 106 async_caller_(async_caller), |
| 102 cryptohome_client_(cryptohome_client), | 107 cryptohome_client_(cryptohome_client), |
| 103 user_manager_(user_manager), | 108 user_manager_(user_manager), |
| 104 delegate_(delegate), | 109 delegate_(delegate), |
| 105 testing_prefs_(NULL), | 110 testing_prefs_(NULL), |
| 111 testing_content_settings_(NULL), |
| 106 weak_factory_(this) { | 112 weak_factory_(this) { |
| 107 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 108 } | 114 } |
| 109 | 115 |
| 110 PlatformVerificationFlow::~PlatformVerificationFlow() { | 116 PlatformVerificationFlow::~PlatformVerificationFlow() { |
| 111 } | 117 } |
| 112 | 118 |
| 113 void PlatformVerificationFlow::ChallengePlatformKey( | 119 void PlatformVerificationFlow::ChallengePlatformKey( |
| 114 content::WebContents* web_contents, | 120 content::WebContents* web_contents, |
| 115 const std::string& service_id, | 121 const std::string& service_id, |
| 116 const std::string& challenge, | 122 const std::string& challenge, |
| 117 const ChallengeCallback& callback) { | 123 const ChallengeCallback& callback) { |
| 118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 124 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 125 if (!GetURL(web_contents).is_valid()) { |
| 126 LOG(WARNING) << "PlatformVerificationFlow: Invalid URL."; |
| 127 ReportError(callback, INTERNAL_ERROR); |
| 128 return; |
| 129 } |
| 119 if (!IsAttestationEnabled(web_contents)) { | 130 if (!IsAttestationEnabled(web_contents)) { |
| 120 LOG(INFO) << "PlatformVerificationFlow: Feature disabled."; | 131 LOG(INFO) << "PlatformVerificationFlow: Feature disabled."; |
| 121 ReportError(callback, POLICY_REJECTED); | 132 ReportError(callback, POLICY_REJECTED); |
| 122 return; | 133 return; |
| 123 } | 134 } |
| 124 BoolDBusMethodCallback dbus_callback = base::Bind( | 135 BoolDBusMethodCallback dbus_callback = base::Bind( |
| 125 &DBusCallback, | 136 &DBusCallback, |
| 126 base::Bind(&PlatformVerificationFlow::CheckConsent, | 137 base::Bind(&PlatformVerificationFlow::CheckConsent, |
| 127 weak_factory_.GetWeakPtr(), | 138 weak_factory_.GetWeakPtr(), |
| 128 web_contents, | 139 web_contents, |
| 129 service_id, | 140 service_id, |
| 130 challenge, | 141 challenge, |
| 131 callback), | 142 callback), |
| 132 base::Bind(&ReportError, callback, INTERNAL_ERROR)); | 143 base::Bind(&ReportError, callback, INTERNAL_ERROR)); |
| 133 cryptohome_client_->TpmAttestationIsEnrolled(dbus_callback); | 144 cryptohome_client_->TpmAttestationIsEnrolled(dbus_callback); |
| 134 } | 145 } |
| 135 | 146 |
| 136 void PlatformVerificationFlow::CheckConsent(content::WebContents* web_contents, | 147 void PlatformVerificationFlow::CheckConsent(content::WebContents* web_contents, |
| 137 const std::string& service_id, | 148 const std::string& service_id, |
| 138 const std::string& challenge, | 149 const std::string& challenge, |
| 139 const ChallengeCallback& callback, | 150 const ChallengeCallback& callback, |
| 140 bool attestation_enrolled) { | 151 bool attestation_enrolled) { |
| 141 ConsentType consent_type = CONSENT_TYPE_NONE; | 152 PrefService* pref_service = GetPrefs(web_contents); |
| 142 if (!attestation_enrolled || IsFirstUse(web_contents)) { | 153 if (!pref_service) { |
| 143 consent_type = CONSENT_TYPE_ATTESTATION; | 154 LOG(ERROR) << "Failed to get user prefs."; |
| 144 } else if (IsAlwaysAskRequired(web_contents)) { | 155 ReportError(callback, INTERNAL_ERROR); |
| 145 consent_type = CONSENT_TYPE_ALWAYS; | 156 return; |
| 146 } | 157 } |
| 158 bool consent_required = ( |
| 159 // Consent required if attestation has never been enrolled on this device. |
| 160 !attestation_enrolled || |
| 161 // Consent required if this is the first use of attestation for content |
| 162 // protection on this device. |
| 163 !pref_service->GetBoolean(prefs::kRAConsentFirstTime) || |
| 164 // Consent required if consent has never been given for this domain. |
| 165 !GetDomainPref(GetContentSettings(web_contents), |
| 166 GetURL(web_contents), |
| 167 NULL)); |
| 168 |
| 147 Delegate::ConsentCallback consent_callback = base::Bind( | 169 Delegate::ConsentCallback consent_callback = base::Bind( |
| 148 &PlatformVerificationFlow::OnConsentResponse, | 170 &PlatformVerificationFlow::OnConsentResponse, |
| 149 weak_factory_.GetWeakPtr(), | 171 weak_factory_.GetWeakPtr(), |
| 150 web_contents, | 172 web_contents, |
| 151 service_id, | 173 service_id, |
| 152 challenge, | 174 challenge, |
| 153 callback, | 175 callback, |
| 154 consent_type); | 176 consent_required); |
| 155 if (consent_type == CONSENT_TYPE_NONE) { | 177 if (consent_required) |
| 178 delegate_->ShowConsentPrompt(web_contents, consent_callback); |
| 179 else |
| 156 consent_callback.Run(CONSENT_RESPONSE_NONE); | 180 consent_callback.Run(CONSENT_RESPONSE_NONE); |
| 157 } else { | |
| 158 delegate_->ShowConsentPrompt(consent_type, | |
| 159 web_contents, | |
| 160 consent_callback); | |
| 161 } | |
| 162 } | 181 } |
| 163 | 182 |
| 164 void PlatformVerificationFlow::RegisterProfilePrefs( | 183 void PlatformVerificationFlow::RegisterProfilePrefs( |
| 165 user_prefs::PrefRegistrySyncable* prefs) { | 184 user_prefs::PrefRegistrySyncable* prefs) { |
| 166 prefs->RegisterBooleanPref(prefs::kRAConsentFirstTime, | 185 prefs->RegisterBooleanPref(prefs::kRAConsentFirstTime, |
| 167 false, | 186 false, |
| 168 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 187 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 169 prefs->RegisterDictionaryPref( | |
| 170 prefs::kRAConsentDomains, | |
| 171 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 172 prefs->RegisterBooleanPref(prefs::kRAConsentAlways, | |
| 173 false, | |
| 174 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 175 } | 188 } |
| 176 | 189 |
| 177 void PlatformVerificationFlow::OnConsentResponse( | 190 void PlatformVerificationFlow::OnConsentResponse( |
| 178 content::WebContents* web_contents, | 191 content::WebContents* web_contents, |
| 179 const std::string& service_id, | 192 const std::string& service_id, |
| 180 const std::string& challenge, | 193 const std::string& challenge, |
| 181 const ChallengeCallback& callback, | 194 const ChallengeCallback& callback, |
| 182 ConsentType consent_type, | 195 bool consent_required, |
| 183 ConsentResponse consent_response) { | 196 ConsentResponse consent_response) { |
| 184 if (consent_type != CONSENT_TYPE_NONE) { | 197 if (consent_required) { |
| 185 if (consent_response == CONSENT_RESPONSE_NONE) { | 198 if (consent_response == CONSENT_RESPONSE_NONE) { |
| 186 // No user response - do not proceed and do not modify any settings. | 199 // No user response - do not proceed and do not modify any settings. |
| 187 LOG(WARNING) << "PlatformVerificationFlow: No response from user."; | 200 LOG(WARNING) << "PlatformVerificationFlow: No response from user."; |
| 188 ReportError(callback, USER_REJECTED); | 201 ReportError(callback, USER_REJECTED); |
| 189 return; | 202 return; |
| 190 } | 203 } |
| 191 if (!UpdateSettings(web_contents, consent_type, consent_response)) { | 204 if (!UpdateSettings(web_contents, consent_response)) { |
| 192 ReportError(callback, INTERNAL_ERROR); | 205 ReportError(callback, INTERNAL_ERROR); |
| 193 return; | 206 return; |
| 194 } | 207 } |
| 195 if (consent_response == CONSENT_RESPONSE_DENY) { | 208 if (consent_response == CONSENT_RESPONSE_DENY) { |
| 196 LOG(INFO) << "PlatformVerificationFlow: User rejected request."; | 209 LOG(INFO) << "PlatformVerificationFlow: User rejected request."; |
| 197 content::RecordAction( | 210 content::RecordAction( |
| 198 content::UserMetricsAction("PlatformVerificationRejected")); | 211 content::UserMetricsAction("PlatformVerificationRejected")); |
| 199 ReportError(callback, USER_REJECTED); | 212 ReportError(callback, USER_REJECTED); |
| 200 return; | 213 return; |
| 201 } else if (consent_response == CONSENT_RESPONSE_ALLOW) { | 214 } else if (consent_response == CONSENT_RESPONSE_ALLOW) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 content::WebContents* web_contents) { | 295 content::WebContents* web_contents) { |
| 283 if (testing_prefs_) | 296 if (testing_prefs_) |
| 284 return testing_prefs_; | 297 return testing_prefs_; |
| 285 return user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()); | 298 return user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()); |
| 286 } | 299 } |
| 287 | 300 |
| 288 const GURL& PlatformVerificationFlow::GetURL( | 301 const GURL& PlatformVerificationFlow::GetURL( |
| 289 content::WebContents* web_contents) { | 302 content::WebContents* web_contents) { |
| 290 if (!testing_url_.is_empty()) | 303 if (!testing_url_.is_empty()) |
| 291 return testing_url_; | 304 return testing_url_; |
| 292 return web_contents->GetLastCommittedURL(); | 305 const GURL& url = web_contents->GetLastCommittedURL(); |
| 306 if (!url.is_valid()) |
| 307 return web_contents->GetVisibleURL(); |
| 308 return url; |
| 293 } | 309 } |
| 294 | 310 |
| 295 User* PlatformVerificationFlow::GetUser(content::WebContents* web_contents) { | 311 User* PlatformVerificationFlow::GetUser(content::WebContents* web_contents) { |
| 296 if (!web_contents) | 312 if (!web_contents) |
| 297 return user_manager_->GetActiveUser(); | 313 return user_manager_->GetActiveUser(); |
| 298 return user_manager_->GetUserByProfile( | 314 return user_manager_->GetUserByProfile( |
| 299 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | 315 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
| 300 } | 316 } |
| 301 | 317 |
| 318 HostContentSettingsMap* PlatformVerificationFlow::GetContentSettings( |
| 319 content::WebContents* web_contents) { |
| 320 if (testing_content_settings_) |
| 321 return testing_content_settings_; |
| 322 return Profile::FromBrowserContext(web_contents->GetBrowserContext())-> |
| 323 GetHostContentSettingsMap(); |
| 324 } |
| 325 |
| 302 bool PlatformVerificationFlow::IsAttestationEnabled( | 326 bool PlatformVerificationFlow::IsAttestationEnabled( |
| 303 content::WebContents* web_contents) { | 327 content::WebContents* web_contents) { |
| 304 // Check the device policy for the feature. | 328 // Check the device policy for the feature. |
| 305 bool enabled_for_device = false; | 329 bool enabled_for_device = false; |
| 306 if (!CrosSettings::Get()->GetBoolean(kAttestationForContentProtectionEnabled, | 330 if (!CrosSettings::Get()->GetBoolean(kAttestationForContentProtectionEnabled, |
| 307 &enabled_for_device)) { | 331 &enabled_for_device)) { |
| 308 LOG(ERROR) << "Failed to get device setting."; | 332 LOG(ERROR) << "Failed to get device setting."; |
| 309 return false; | 333 return false; |
| 310 } | 334 } |
| 311 if (!enabled_for_device) | 335 if (!enabled_for_device) |
| 312 return false; | 336 return false; |
| 313 | 337 |
| 314 // Check the user preference for the feature. | 338 // Check the user preference for the feature. |
| 315 PrefService* pref_service = GetPrefs(web_contents); | 339 PrefService* pref_service = GetPrefs(web_contents); |
| 316 if (!pref_service) { | 340 if (!pref_service) { |
| 317 LOG(ERROR) << "Failed to get user prefs."; | 341 LOG(ERROR) << "Failed to get user prefs."; |
| 318 return false; | 342 return false; |
| 319 } | 343 } |
| 320 if (!pref_service->GetBoolean(prefs::kEnableDRM)) | 344 if (!pref_service->GetBoolean(prefs::kEnableDRM)) |
| 321 return false; | 345 return false; |
| 322 | 346 |
| 323 // Check the user preference for this domain. | 347 // Check the user preference for this domain. |
| 324 bool enabled_for_domain = false; | 348 bool enabled_for_domain = false; |
| 325 bool found = GetDomainPref(web_contents, &enabled_for_domain); | 349 bool found = GetDomainPref(GetContentSettings(web_contents), |
| 350 GetURL(web_contents), |
| 351 &enabled_for_domain); |
| 326 return (!found || enabled_for_domain); | 352 return (!found || enabled_for_domain); |
| 327 } | 353 } |
| 328 | 354 |
| 329 bool PlatformVerificationFlow::IsFirstUse(content::WebContents* web_contents) { | |
| 330 PrefService* pref_service = GetPrefs(web_contents); | |
| 331 if (!pref_service) { | |
| 332 LOG(ERROR) << "Failed to get user prefs."; | |
| 333 return true; | |
| 334 } | |
| 335 return !pref_service->GetBoolean(prefs::kRAConsentFirstTime); | |
| 336 } | |
| 337 | |
| 338 bool PlatformVerificationFlow::IsAlwaysAskRequired( | |
| 339 content::WebContents* web_contents) { | |
| 340 PrefService* pref_service = GetPrefs(web_contents); | |
| 341 if (!pref_service) { | |
| 342 LOG(ERROR) << "Failed to get user prefs."; | |
| 343 return true; | |
| 344 } | |
| 345 if (!pref_service->GetBoolean(prefs::kRAConsentAlways)) | |
| 346 return false; | |
| 347 // Show the consent UI if the user has not already explicitly allowed or | |
| 348 // denied for this domain. | |
| 349 return !GetDomainPref(web_contents, NULL); | |
| 350 } | |
| 351 | |
| 352 bool PlatformVerificationFlow::UpdateSettings( | 355 bool PlatformVerificationFlow::UpdateSettings( |
| 353 content::WebContents* web_contents, | 356 content::WebContents* web_contents, |
| 354 ConsentType consent_type, | |
| 355 ConsentResponse consent_response) { | 357 ConsentResponse consent_response) { |
| 356 PrefService* pref_service = GetPrefs(web_contents); | 358 PrefService* pref_service = GetPrefs(web_contents); |
| 357 if (!pref_service) { | 359 if (!pref_service) { |
| 358 LOG(ERROR) << "Failed to get user prefs."; | 360 LOG(ERROR) << "Failed to get user prefs."; |
| 359 return false; | 361 return false; |
| 360 } | 362 } |
| 361 if (consent_type == CONSENT_TYPE_ATTESTATION) { | 363 pref_service->SetBoolean(prefs::kRAConsentFirstTime, true); |
| 362 if (consent_response == CONSENT_RESPONSE_DENY) { | 364 RecordDomainConsent(GetContentSettings(web_contents), |
| 363 pref_service->SetBoolean(prefs::kEnableDRM, false); | 365 GetURL(web_contents), |
| 364 } else if (consent_response == CONSENT_RESPONSE_ALLOW) { | 366 (consent_response == CONSENT_RESPONSE_ALLOW)); |
| 365 pref_service->SetBoolean(prefs::kRAConsentFirstTime, true); | |
| 366 RecordDomainConsent(web_contents, true); | |
| 367 } else if (consent_response == CONSENT_RESPONSE_ALWAYS_ASK) { | |
| 368 pref_service->SetBoolean(prefs::kRAConsentFirstTime, true); | |
| 369 pref_service->SetBoolean(prefs::kRAConsentAlways, true); | |
| 370 RecordDomainConsent(web_contents, true); | |
| 371 } | |
| 372 } else if (consent_type == CONSENT_TYPE_ALWAYS) { | |
| 373 bool allowed = (consent_response == CONSENT_RESPONSE_ALLOW || | |
| 374 consent_response == CONSENT_RESPONSE_ALWAYS_ASK); | |
| 375 RecordDomainConsent(web_contents, allowed); | |
| 376 } | |
| 377 return true; | 367 return true; |
| 378 } | 368 } |
| 379 | 369 |
| 380 bool PlatformVerificationFlow::GetDomainPref( | 370 bool PlatformVerificationFlow::GetDomainPref( |
| 381 content::WebContents* web_contents, | 371 HostContentSettingsMap* content_settings, |
| 372 const GURL& url, |
| 382 bool* pref_value) { | 373 bool* pref_value) { |
| 383 PrefService* pref_service = GetPrefs(web_contents); | 374 CHECK(content_settings); |
| 384 CHECK(pref_service); | 375 CHECK(url.is_valid()); |
| 385 base::DictionaryValue::Iterator iter( | 376 ContentSetting setting = content_settings->GetContentSetting( |
| 386 *pref_service->GetDictionary(prefs::kRAConsentDomains)); | 377 url, |
| 387 const GURL& url = GetURL(web_contents); | 378 url, |
| 388 while (!iter.IsAtEnd()) { | 379 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, |
| 389 if (url.DomainIs(iter.key().c_str())) { | 380 std::string()); |
| 390 if (pref_value) { | 381 if (setting != CONTENT_SETTING_ALLOW && setting != CONTENT_SETTING_BLOCK) |
| 391 if (!iter.value().GetAsBoolean(pref_value)) { | 382 return false; |
| 392 LOG(ERROR) << "Unexpected pref type."; | 383 if (pref_value) |
| 393 *pref_value = false; | 384 *pref_value = (setting == CONTENT_SETTING_ALLOW); |
| 394 } | 385 return true; |
| 395 } | |
| 396 return true; | |
| 397 } | |
| 398 iter.Advance(); | |
| 399 } | |
| 400 return false; | |
| 401 } | 386 } |
| 402 | 387 |
| 403 void PlatformVerificationFlow::RecordDomainConsent( | 388 void PlatformVerificationFlow::RecordDomainConsent( |
| 404 content::WebContents* web_contents, | 389 HostContentSettingsMap* content_settings, |
| 390 const GURL& url, |
| 405 bool allow_domain) { | 391 bool allow_domain) { |
| 406 PrefService* pref_service = GetPrefs(web_contents); | 392 CHECK(content_settings); |
| 407 CHECK(pref_service); | 393 CHECK(url.is_valid()); |
| 408 DictionaryPrefUpdate updater(pref_service, prefs::kRAConsentDomains); | 394 // Build a pattern to represent scheme and host. |
| 409 const GURL& url = GetURL(web_contents); | 395 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
| 410 updater->SetBoolean(url.host(), allow_domain); | 396 ContentSettingsPattern::CreateBuilder(false)); |
| 397 builder->WithScheme(url.scheme()) |
| 398 ->WithDomainWildcard() |
| 399 ->WithHost(url.host()) |
| 400 ->WithPathWildcard(); |
| 401 if (!url.port().empty()) |
| 402 builder->WithPort(url.port()); |
| 403 else if (url.SchemeIs(content::kHttpsScheme)) |
| 404 builder->WithPort(kDefaultHttpsPort); |
| 405 else if (url.SchemeIs(content::kHttpScheme)) |
| 406 builder->WithPortWildcard(); |
| 407 ContentSettingsPattern pattern = builder->Build(); |
| 408 if (pattern.IsValid()) { |
| 409 ContentSetting setting = allow_domain ? CONTENT_SETTING_ALLOW |
| 410 : CONTENT_SETTING_BLOCK; |
| 411 content_settings->SetContentSetting( |
| 412 pattern, |
| 413 pattern, |
| 414 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, |
| 415 std::string(), |
| 416 setting); |
| 417 } else { |
| 418 LOG(WARNING) << "Not recording action: invalid URL pattern"; |
| 419 } |
| 411 } | 420 } |
| 412 | 421 |
| 413 } // namespace attestation | 422 } // namespace attestation |
| 414 } // namespace chromeos | 423 } // namespace chromeos |
| OLD | NEW |