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/ssl/chrome_ssl_host_state_delegate.h" | 5 #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/callback.h" | |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/guid.h" | 15 #include "base/guid.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/time/clock.h" | 19 #include "base/time/clock.h" |
| 19 #include "base/time/default_clock.h" | 20 #include "base/time/default_clock.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "base/values.h" | 22 #include "base/values.h" |
| 22 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // Set the new pattern. | 133 // Set the new pattern. |
| 133 if (value) { | 134 if (value) { |
| 134 map->SetWebsiteSettingDefaultScope( | 135 map->SetWebsiteSettingDefaultScope( |
| 135 url, GURL(), CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, | 136 url, GURL(), CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, |
| 136 std::string(), std::move(value)); | 137 std::string(), std::move(value)); |
| 137 } | 138 } |
| 138 } | 139 } |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 | 142 |
| 143 bool HostFilterToPatternFilter( | |
| 144 const base::Callback<bool(const std::string&)>& host_filter, | |
| 145 const ContentSettingsPattern& primary_pattern, | |
| 146 const ContentSettingsPattern& secondary_pattern) { | |
| 147 // We only store data for "https://<host>" primary patterns, so we can convert | |
| 148 // them directly to a URL. The secondary pattern is unused. | |
| 149 GURL url(primary_pattern.ToString()); | |
| 150 DCHECK(url.is_valid()); | |
|
estark
2016/08/30 01:52:16
Just checking that this DCHECK really is a DCHECK
msramek
2016/08/30 14:39:41
Oh, the shame! The DCHECK is wrong, thanks for cat
raymes
2016/08/30 23:32:00
Hmm, this file is dealing with CONTENT_SETTINGS_TY
msramek
2016/08/31 13:43:11
...correct. I panicked and searched for the wrong
| |
| 151 return host_filter.Run(url.host()); | |
| 152 } | |
| 153 | |
| 142 } // namespace | 154 } // namespace |
| 143 | 155 |
| 144 // This helper function gets the dictionary of certificate fingerprints to | 156 // This helper function gets the dictionary of certificate fingerprints to |
| 145 // errors of certificates that have been accepted by the user from the content | 157 // errors of certificates that have been accepted by the user from the content |
| 146 // dictionary that has been passed in. The returned pointer is owned by the the | 158 // dictionary that has been passed in. The returned pointer is owned by the the |
| 147 // argument dict that is passed in. | 159 // argument dict that is passed in. |
| 148 // | 160 // |
| 149 // If create_entries is set to |DO_NOT_CREATE_DICTIONARY_ENTRIES|, | 161 // If create_entries is set to |DO_NOT_CREATE_DICTIONARY_ENTRIES|, |
| 150 // GetValidCertDecisionsDict will return NULL if there is anything invalid about | 162 // GetValidCertDecisionsDict will return NULL if there is anything invalid about |
| 151 // the setting, such as an invalid version or invalid value types (in addition | 163 // the setting, such as an invalid version or invalid value types (in addition |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 kDefaultSSLCertDecisionVersion); | 318 kDefaultSSLCertDecisionVersion); |
| 307 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), ALLOWED); | 319 cert_dict->SetIntegerWithoutPathExpansion(GetKey(cert, error), ALLOWED); |
| 308 | 320 |
| 309 // The map takes ownership of the value, so it is released in the call to | 321 // The map takes ownership of the value, so it is released in the call to |
| 310 // SetWebsiteSettingDefaultScope. | 322 // SetWebsiteSettingDefaultScope. |
| 311 map->SetWebsiteSettingDefaultScope(url, GURL(), | 323 map->SetWebsiteSettingDefaultScope(url, GURL(), |
| 312 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, | 324 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, |
| 313 std::string(), std::move(value)); | 325 std::string(), std::move(value)); |
| 314 } | 326 } |
| 315 | 327 |
| 316 void ChromeSSLHostStateDelegate::Clear() { | 328 void ChromeSSLHostStateDelegate::Clear( |
| 329 const base::Callback<bool(const std::string&)>& host_filter) { | |
| 330 // Convert host matching to content settings pattern matching. Content | |
| 331 // settings deletion is done synchronously on the UI thread, so we can use | |
| 332 // |host_filter| by reference. | |
| 333 base::Callback<bool(const ContentSettingsPattern& primary_pattern, | |
| 334 const ContentSettingsPattern& secondary_pattern)> | |
| 335 pattern_filter; | |
| 336 if (!host_filter.is_null()) { | |
| 337 pattern_filter = | |
| 338 base::Bind(&HostFilterToPatternFilter, base::ConstRef(host_filter)); | |
| 339 } | |
| 340 | |
| 317 HostContentSettingsMapFactory::GetForProfile(profile_) | 341 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 318 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS); | 342 ->ClearSettingsForOneTypeWithPredicate( |
| 343 CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS, pattern_filter); | |
| 319 } | 344 } |
| 320 | 345 |
| 321 content::SSLHostStateDelegate::CertJudgment | 346 content::SSLHostStateDelegate::CertJudgment |
| 322 ChromeSSLHostStateDelegate::QueryPolicy(const std::string& host, | 347 ChromeSSLHostStateDelegate::QueryPolicy(const std::string& host, |
| 323 const net::X509Certificate& cert, | 348 const net::X509Certificate& cert, |
| 324 net::CertStatus error, | 349 net::CertStatus error, |
| 325 bool* expired_previous_decision) { | 350 bool* expired_previous_decision) { |
| 326 HostContentSettingsMap* map = | 351 HostContentSettingsMap* map = |
| 327 HostContentSettingsMapFactory::GetForProfile(profile_); | 352 HostContentSettingsMapFactory::GetForProfile(profile_); |
| 328 GURL url = GetSecureGURLForHost(host); | 353 GURL url = GetSecureGURLForHost(host); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 case CERT_ERRORS_CONTENT: | 484 case CERT_ERRORS_CONTENT: |
| 460 return !!ran_content_with_cert_errors_hosts_.count( | 485 return !!ran_content_with_cert_errors_hosts_.count( |
| 461 BrokenHostEntry(host, child_id)); | 486 BrokenHostEntry(host, child_id)); |
| 462 } | 487 } |
| 463 NOTREACHED(); | 488 NOTREACHED(); |
| 464 return false; | 489 return false; |
| 465 } | 490 } |
| 466 void ChromeSSLHostStateDelegate::SetClock(std::unique_ptr<base::Clock> clock) { | 491 void ChromeSSLHostStateDelegate::SetClock(std::unique_ptr<base::Clock> clock) { |
| 467 clock_.reset(clock.release()); | 492 clock_.reset(clock.release()); |
| 468 } | 493 } |
| OLD | NEW |