OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/ssl/ssl_host_state_impl.h" |
| 6 |
| 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" |
| 9 #include "content/public/browser/browser_context.h" |
| 10 #include "net/http/http_transaction_factory.h" |
| 11 #include "net/url_request/url_request_context.h" |
| 12 #include "net/url_request/url_request_context_getter.h" |
| 13 |
| 14 const char kKeyName[] = "content_ssl_host_state"; |
| 15 |
| 16 namespace content { |
| 17 |
| 18 SSLHostState* SSLHostState::GetFor(BrowserContext* context) { |
| 19 SSLHostStateImpl* rv = |
| 20 static_cast<SSLHostStateImpl*>(context->GetUserData(kKeyName)); |
| 21 if (!rv) { |
| 22 rv = new SSLHostStateImpl(); |
| 23 context->SetUserData(kKeyName, rv); |
| 24 } |
| 25 return rv; |
| 26 } |
| 27 |
| 28 SSLHostStateImpl::SSLHostStateImpl() { |
| 29 } |
| 30 |
| 31 SSLHostStateImpl::~SSLHostStateImpl() { |
| 32 } |
| 33 |
| 34 void SSLHostStateImpl::HostRanInsecureContent(const std::string& host, |
| 35 int pid) { |
| 36 DCHECK(CalledOnValidThread()); |
| 37 ran_insecure_content_hosts_.insert(BrokenHostEntry(host, pid)); |
| 38 } |
| 39 |
| 40 bool SSLHostStateImpl::DidHostRunInsecureContent(const std::string& host, |
| 41 int pid) const { |
| 42 DCHECK(CalledOnValidThread()); |
| 43 return !!ran_insecure_content_hosts_.count(BrokenHostEntry(host, pid)); |
| 44 } |
| 45 |
| 46 void SSLHostStateImpl::DenyCertForHost(net::X509Certificate* cert, |
| 47 const std::string& host, |
| 48 net::CertStatus error) { |
| 49 DCHECK(CalledOnValidThread()); |
| 50 |
| 51 cert_policy_for_host_[host].Deny(cert, error); |
| 52 } |
| 53 |
| 54 void SSLHostStateImpl::AllowCertForHost(net::X509Certificate* cert, |
| 55 const std::string& host, |
| 56 net::CertStatus error) { |
| 57 DCHECK(CalledOnValidThread()); |
| 58 |
| 59 cert_policy_for_host_[host].Allow(cert, error); |
| 60 } |
| 61 |
| 62 void SSLHostStateImpl::Clear() { |
| 63 DCHECK(CalledOnValidThread()); |
| 64 |
| 65 cert_policy_for_host_.clear(); |
| 66 } |
| 67 |
| 68 void SSLHostStateImpl::RevokeAllowAndDenyPreferences(const std::string& host) { |
| 69 DCHECK(CalledOnValidThread()); |
| 70 |
| 71 cert_policy_for_host_.erase(cert_policy_for_host_.find(host)); |
| 72 } |
| 73 |
| 74 bool SSLHostStateImpl::HasAllowedOrDeniedCert(const std::string& host) { |
| 75 DCHECK(CalledOnValidThread()); |
| 76 |
| 77 return cert_policy_for_host_[host].HasAllowedCert() || |
| 78 cert_policy_for_host_[host].HasDeniedCert(); |
| 79 } |
| 80 |
| 81 net::CertPolicy::Judgment SSLHostStateImpl::QueryPolicy( |
| 82 net::X509Certificate* cert, |
| 83 const std::string& host, |
| 84 net::CertStatus error) { |
| 85 DCHECK(CalledOnValidThread()); |
| 86 |
| 87 return cert_policy_for_host_[host].Check(cert, error); |
| 88 } |
| 89 |
| 90 } // namespace content |
OLD | NEW |