OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_SSL_SSL_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SSL_SSL_MANAGER_H_ |
6 #define CHROME_BROWSER_SSL_SSL_MANAGER_H_ | 6 #define CHROME_BROWSER_SSL_SSL_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // The SSLManager SSLManager controls the SSL UI elements in a TabContents. It | 31 // The SSLManager SSLManager controls the SSL UI elements in a TabContents. It |
32 // listens for various events that influence when these elements should or | 32 // listens for various events that influence when these elements should or |
33 // should not be displayed and adjusts them accordingly. | 33 // should not be displayed and adjusts them accordingly. |
34 // | 34 // |
35 // There is one SSLManager per tab. | 35 // There is one SSLManager per tab. |
36 // The security state (secure/insecure) is stored in the navigation entry. | 36 // The security state (secure/insecure) is stored in the navigation entry. |
37 // Along with it are stored any SSL error code and the associated cert. | 37 // Along with it are stored any SSL error code and the associated cert. |
38 | 38 |
39 class SSLManager : public NotificationObserver { | 39 class SSLManager : public NotificationObserver { |
40 public: | 40 public: |
41 // Construct an SSLManager for the specified tab. | |
42 // If |delegate| is NULL, SSLPolicy::GetDefaultPolicy() is used. | |
43 explicit SSLManager(NavigationController* controller); | |
44 ~SSLManager(); | |
45 | |
46 SSLPolicy* policy() { return policy_.get(); } | |
47 SSLPolicyBackend* backend() { return &backend_; } | |
48 | |
49 // The navigation controller associated with this SSLManager. The | |
50 // NavigationController is guaranteed to outlive the SSLManager. | |
51 NavigationController* controller() { return controller_; } | |
52 | |
53 static void RegisterUserPrefs(PrefService* prefs); | 41 static void RegisterUserPrefs(PrefService* prefs); |
54 | 42 |
55 // Entry point for SSLCertificateErrors. This function begins the process | 43 // Entry point for SSLCertificateErrors. This function begins the process |
56 // of resolving a certificate error during an SSL connection. SSLManager | 44 // of resolving a certificate error during an SSL connection. SSLManager |
57 // will adjust the security UI and either call |Cancel| or | 45 // will adjust the security UI and either call |Cancel| or |
58 // |ContinueDespiteLastError| on the URLRequest. | 46 // |ContinueDespiteLastError| on the URLRequest. |
59 // | 47 // |
60 // Called on the IO thread. | 48 // Called on the IO thread. |
61 static void OnSSLCertificateError(ResourceDispatcherHost* resource_dispatcher, | 49 static void OnSSLCertificateError(ResourceDispatcherHost* resource_dispatcher, |
62 URLRequest* request, | 50 URLRequest* request, |
63 int cert_error, | 51 int cert_error, |
64 net::X509Certificate* cert); | 52 net::X509Certificate* cert); |
65 | 53 |
66 // Mixed content entry points. | 54 // Called when SSL state for a host or tab changes. Broadcasts the |
67 void DidDisplayInsecureContent(); | 55 // SSL_INTERNAL_STATE_CHANGED notification. |
68 void DidRunInsecureContent(const std::string& security_origin); | 56 static void NotifySSLInternalStateChanged(); |
69 | |
70 // Entry point for navigation. This function begins the process of updating | |
71 // the security UI when the main frame navigates to a new URL. | |
72 // | |
73 // Called on the UI thread. | |
74 virtual void Observe(NotificationType type, | |
75 const NotificationSource& source, | |
76 const NotificationDetails& details); | |
77 | |
78 // This entry point is called directly (instead of via the notification | |
79 // service) because we need more precise control of the order in which folks | |
80 // are notified of this event. | |
81 void DidCommitProvisionalLoad(const NotificationDetails& details); | |
82 | |
83 // Called to determine if there were any processed SSL errors from request. | |
84 bool ProcessedSSLErrorFromRequest() const; | |
85 | 57 |
86 // Convenience methods for serializing/deserializing the security info. | 58 // Convenience methods for serializing/deserializing the security info. |
87 static std::string SerializeSecurityInfo(int cert_id, | 59 static std::string SerializeSecurityInfo(int cert_id, |
88 int cert_status, | 60 int cert_status, |
89 int security_bits); | 61 int security_bits); |
90 static bool DeserializeSecurityInfo(const std::string& state, | 62 static bool DeserializeSecurityInfo(const std::string& state, |
91 int* cert_id, | 63 int* cert_id, |
92 int* cert_status, | 64 int* cert_status, |
93 int* security_bits); | 65 int* security_bits); |
94 | 66 |
95 // Returns "<organization_name> [<country>]". | 67 // Returns "<organization_name> [<country>]". |
96 static std::wstring GetEVCertName(const net::X509Certificate& cert); | 68 static std::wstring GetEVCertName(const net::X509Certificate& cert); |
97 | 69 |
| 70 // Construct an SSLManager for the specified tab. |
| 71 // If |delegate| is NULL, SSLPolicy::GetDefaultPolicy() is used. |
| 72 explicit SSLManager(NavigationController* controller); |
| 73 ~SSLManager(); |
| 74 |
| 75 SSLPolicy* policy() { return policy_.get(); } |
| 76 SSLPolicyBackend* backend() { return &backend_; } |
| 77 |
| 78 // The navigation controller associated with this SSLManager. The |
| 79 // NavigationController is guaranteed to outlive the SSLManager. |
| 80 NavigationController* controller() { return controller_; } |
| 81 |
| 82 // This entry point is called directly (instead of via the notification |
| 83 // service) because we need more precise control of the order in which folks |
| 84 // are notified of this event. |
| 85 void DidCommitProvisionalLoad(const NotificationDetails& details); |
| 86 |
| 87 // Mixed content entry point. |
| 88 void DidRunInsecureContent(const std::string& security_origin); |
| 89 |
| 90 // Called to determine if there were any processed SSL errors from request. |
| 91 bool ProcessedSSLErrorFromRequest() const; |
| 92 |
| 93 // Entry point for navigation. This function begins the process of updating |
| 94 // the security UI when the main frame navigates to a new URL. |
| 95 // |
| 96 // Called on the UI thread. |
| 97 virtual void Observe(NotificationType type, |
| 98 const NotificationSource& source, |
| 99 const NotificationDetails& details); |
| 100 |
98 private: | 101 private: |
99 // SSLMessageInfo contains the information necessary for displaying a message | 102 // SSLMessageInfo contains the information necessary for displaying a message |
100 // in an info-bar. | 103 // in an info-bar. |
101 struct SSLMessageInfo { | 104 struct SSLMessageInfo { |
102 public: | 105 public: |
103 explicit SSLMessageInfo(const std::wstring& text) | 106 explicit SSLMessageInfo(const std::wstring& text) |
104 : message(text), | 107 : message(text), |
105 action(NULL) { } | 108 action(NULL) { } |
106 | 109 |
107 SSLMessageInfo(const std::wstring& message, | 110 SSLMessageInfo(const std::wstring& message, |
(...skipping 15 matching lines...) Expand all Loading... |
123 // Entry points for notifications to which we subscribe. Note that | 126 // Entry points for notifications to which we subscribe. Note that |
124 // DidCommitProvisionalLoad uses the abstract NotificationDetails type since | 127 // DidCommitProvisionalLoad uses the abstract NotificationDetails type since |
125 // the type we need is in NavigationController which would create a circular | 128 // the type we need is in NavigationController which would create a circular |
126 // header file dependency. | 129 // header file dependency. |
127 void DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details); | 130 void DidLoadFromMemoryCache(LoadFromMemoryCacheDetails* details); |
128 void DidFailProvisionalLoadWithError(ProvisionalLoadDetails* details); | 131 void DidFailProvisionalLoadWithError(ProvisionalLoadDetails* details); |
129 void DidStartResourceResponse(ResourceRequestDetails* details); | 132 void DidStartResourceResponse(ResourceRequestDetails* details); |
130 void DidReceiveResourceRedirect(ResourceRedirectDetails* details); | 133 void DidReceiveResourceRedirect(ResourceRedirectDetails* details); |
131 void DidChangeSSLInternalState(); | 134 void DidChangeSSLInternalState(); |
132 | 135 |
133 // Dispatch NotificationType::SSL_VISIBLE_STATE_CHANGED notification. | |
134 void DispatchSSLVisibleStateChanged(); | |
135 | |
136 // Update the NavigationEntry with our current state. | 136 // Update the NavigationEntry with our current state. |
137 void UpdateEntry(NavigationEntry* entry); | 137 void UpdateEntry(NavigationEntry* entry); |
138 | 138 |
139 // The backend for the SSLPolicy to actuate its decisions. | 139 // The backend for the SSLPolicy to actuate its decisions. |
140 SSLPolicyBackend backend_; | 140 SSLPolicyBackend backend_; |
141 | 141 |
142 // The SSLPolicy instance for this manager. | 142 // The SSLPolicy instance for this manager. |
143 scoped_ptr<SSLPolicy> policy_; | 143 scoped_ptr<SSLPolicy> policy_; |
144 | 144 |
145 // The NavigationController that owns this SSLManager. We are responsible | 145 // The NavigationController that owns this SSLManager. We are responsible |
146 // for the security UI of this tab. | 146 // for the security UI of this tab. |
147 NavigationController* controller_; | 147 NavigationController* controller_; |
148 | 148 |
149 // Handles registering notifications with the NotificationService. | 149 // Handles registering notifications with the NotificationService. |
150 NotificationRegistrar registrar_; | 150 NotificationRegistrar registrar_; |
151 | 151 |
152 DISALLOW_COPY_AND_ASSIGN(SSLManager); | 152 DISALLOW_COPY_AND_ASSIGN(SSLManager); |
153 }; | 153 }; |
154 | 154 |
155 #endif // CHROME_BROWSER_SSL_SSL_MANAGER_H_ | 155 #endif // CHROME_BROWSER_SSL_SSL_MANAGER_H_ |
OLD | NEW |