| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_BROWSER_SSL_SSL_HOST_STATE_H_ | 5 #ifndef CONTENT_BROWSER_SSL_SSL_HOST_STATE_H_ |
| 6 #define CONTENT_BROWSER_SSL_SSL_HOST_STATE_H_ | 6 #define CONTENT_BROWSER_SSL_SSL_HOST_STATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/notification_registrar.h" | |
| 19 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 20 #include "net/base/x509_certificate.h" | 19 #include "net/base/x509_certificate.h" |
| 21 | 20 |
| 22 namespace content { | |
| 23 class BrowserContext; | |
| 24 } | |
| 25 | |
| 26 // SSLHostState | 21 // SSLHostState |
| 27 // | 22 // |
| 28 // The SSLHostState encapulates the host-specific state for SSL errors. For | 23 // The SSLHostState encapulates the host-specific state for SSL errors. For |
| 29 // example, SSLHostState remembers whether the user has whitelisted a | 24 // example, SSLHostState remembers whether the user has whitelisted a |
| 30 // particular broken cert for use with particular host. We separate this state | 25 // particular broken cert for use with particular host. We separate this state |
| 31 // from the SSLManager because this state is shared across many navigation | 26 // from the SSLManager because this state is shared across many navigation |
| 32 // controllers. | 27 // controllers. |
| 33 | 28 |
| 34 class CONTENT_EXPORT SSLHostState | 29 class CONTENT_EXPORT SSLHostState |
| 35 : public content::NotificationObserver, | 30 : NON_EXPORTED_BASE(public content::BrowserContext::UserData), |
| 36 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 31 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
| 37 public: | 32 public: |
| 38 static SSLHostState* GetFor(content::BrowserContext* browser_context); | 33 static SSLHostState* GetFor(content::BrowserContext* browser_context); |
| 39 | 34 |
| 40 explicit SSLHostState(content::BrowserContext* browser_context); | 35 SSLHostState(); |
| 41 virtual ~SSLHostState(); | 36 virtual ~SSLHostState(); |
| 42 | 37 |
| 43 // Records that a host has run insecure content. | 38 // Records that a host has run insecure content. |
| 44 void HostRanInsecureContent(const std::string& host, int pid); | 39 void HostRanInsecureContent(const std::string& host, int pid); |
| 45 | 40 |
| 46 // Returns whether the specified host ran insecure content. | 41 // Returns whether the specified host ran insecure content. |
| 47 bool DidHostRunInsecureContent(const std::string& host, int pid) const; | 42 bool DidHostRunInsecureContent(const std::string& host, int pid) const; |
| 48 | 43 |
| 49 // Records that |cert| is permitted to be used for |host| in the future. | 44 // Records that |cert| is permitted to be used for |host| in the future. |
| 50 void DenyCertForHost(net::X509Certificate* cert, const std::string& host); | 45 void DenyCertForHost(net::X509Certificate* cert, const std::string& host); |
| 51 | 46 |
| 52 // Records that |cert| is not permitted to be used for |host| in the future. | 47 // Records that |cert| is not permitted to be used for |host| in the future. |
| 53 void AllowCertForHost(net::X509Certificate* cert, const std::string& host); | 48 void AllowCertForHost(net::X509Certificate* cert, const std::string& host); |
| 54 | 49 |
| 55 // Queries whether |cert| is allowed or denied for |host|. | 50 // Queries whether |cert| is allowed or denied for |host|. |
| 56 net::CertPolicy::Judgment QueryPolicy( | 51 net::CertPolicy::Judgment QueryPolicy( |
| 57 net::X509Certificate* cert, const std::string& host); | 52 net::X509Certificate* cert, const std::string& host); |
| 58 | 53 |
| 59 private: | 54 private: |
| 60 virtual void Observe(int type, | |
| 61 const content::NotificationSource& source, | |
| 62 const content::NotificationDetails& details) OVERRIDE; | |
| 63 | |
| 64 // A BrokenHostEntry is a pair of (host, process_id) that indicates the host | 55 // A BrokenHostEntry is a pair of (host, process_id) that indicates the host |
| 65 // contains insecure content in that renderer process. | 56 // contains insecure content in that renderer process. |
| 66 typedef std::pair<std::string, int> BrokenHostEntry; | 57 typedef std::pair<std::string, int> BrokenHostEntry; |
| 67 | 58 |
| 68 // Hosts which have been contaminated with insecure content in the | 59 // Hosts which have been contaminated with insecure content in the |
| 69 // specified process. Note that insecure content can travel between | 60 // specified process. Note that insecure content can travel between |
| 70 // same-origin frames in one processs but cannot jump between processes. | 61 // same-origin frames in one processs but cannot jump between processes. |
| 71 std::set<BrokenHostEntry> ran_insecure_content_hosts_; | 62 std::set<BrokenHostEntry> ran_insecure_content_hosts_; |
| 72 | 63 |
| 73 // Certificate policies for each host. | 64 // Certificate policies for each host. |
| 74 std::map<std::string, net::CertPolicy> cert_policy_for_host_; | 65 std::map<std::string, net::CertPolicy> cert_policy_for_host_; |
| 75 | 66 |
| 76 content::NotificationRegistrar registrar_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(SSLHostState); | 67 DISALLOW_COPY_AND_ASSIGN(SSLHostState); |
| 79 }; | 68 }; |
| 80 | 69 |
| 81 #endif // CONTENT_BROWSER_SSL_SSL_HOST_STATE_H_ | 70 #endif // CONTENT_BROWSER_SSL_SSL_HOST_STATE_H_ |
| OLD | NEW |