| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "webkit/glue/resource_type.h" | 25 #include "webkit/glue/resource_type.h" |
| 26 | 26 |
| 27 class AutomationProvider; | 27 class AutomationProvider; |
| 28 class NavigationEntry; | 28 class NavigationEntry; |
| 29 class LoadFromMemoryCacheDetails; | 29 class LoadFromMemoryCacheDetails; |
| 30 class LoadNotificationDetails; | 30 class LoadNotificationDetails; |
| 31 class NavigationController; | 31 class NavigationController; |
| 32 class PrefService; | 32 class PrefService; |
| 33 class ResourceRedirectDetails; | 33 class ResourceRedirectDetails; |
| 34 class ResourceRequestDetails; | 34 class ResourceRequestDetails; |
| 35 class SSLCertErrorHandler; |
| 36 class SSLErrorHandler; |
| 35 class SSLErrorInfo; | 37 class SSLErrorInfo; |
| 36 class SSLHostState; | 38 class SSLHostState; |
| 39 class SSLMixedContentHandler; |
| 40 class SSLRequestInfo; |
| 37 class Task; | 41 class Task; |
| 38 class URLRequest; | 42 class URLRequest; |
| 39 class TabContents; | 43 class TabContents; |
| 40 | 44 |
| 41 // The SSLManager SSLManager controls the SSL UI elements in a TabContents. It | 45 // The SSLManager SSLManager controls the SSL UI elements in a TabContents. It |
| 42 // listens for various events that influence when these elements should or | 46 // listens for various events that influence when these elements should or |
| 43 // should not be displayed and adjusts them accordingly. | 47 // should not be displayed and adjusts them accordingly. |
| 44 // | 48 // |
| 45 // There is one SSLManager per tab. | 49 // There is one SSLManager per tab. |
| 46 // The security state (secure/insecure) is stored in the navigation entry. | 50 // The security state (secure/insecure) is stored in the navigation entry. |
| 47 // Along with it are stored any SSL error code and the associated cert. | 51 // Along with it are stored any SSL error code and the associated cert. |
| 48 | 52 |
| 49 class SSLManager : public NotificationObserver { | 53 class SSLManager : public NotificationObserver { |
| 50 public: | 54 public: |
| 51 class CertError; | |
| 52 | |
| 53 // An ErrorHandler carries information from the IO thread to the UI thread | |
| 54 // and is dispatched to the appropriate SSLManager when it arrives on the | |
| 55 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed | |
| 56 // methods to implement the actions that should be taken on the UI thread. | |
| 57 // These methods can call the different convenience methods ContinueRequest/ | |
| 58 // CancelRequest/StartRequest to perform any required action on the URLRequest | |
| 59 // the ErrorHandler was created with. | |
| 60 // IMPORTANT NOTE: if you are not doing anything in | |
| 61 // OnDispatched/OnDispatchFailed, make sure you call TakeNoAction(). This is | |
| 62 // necessary for ensuring the instance is not leaked. | |
| 63 class ErrorHandler : public base::RefCountedThreadSafe<ErrorHandler> { | |
| 64 public: | |
| 65 virtual ~ErrorHandler() { } | |
| 66 | |
| 67 virtual CertError* AsCertError() { return NULL; } | |
| 68 | |
| 69 // Find the appropriate SSLManager for the URLRequest and begin handling | |
| 70 // this error. | |
| 71 // | |
| 72 // Call on UI thread. | |
| 73 void Dispatch(); | |
| 74 | |
| 75 // Available on either thread. | |
| 76 const GURL& request_url() const { return request_url_; } | |
| 77 | |
| 78 // Available on either thread. | |
| 79 ResourceType::Type resource_type() const { return resource_type_; } | |
| 80 | |
| 81 // Available on either thread. | |
| 82 const std::string& frame_origin() const { return frame_origin_; } | |
| 83 | |
| 84 // Available on either thread. | |
| 85 const std::string& main_frame_origin() const { return main_frame_origin_; } | |
| 86 | |
| 87 // Call on the UI thread. | |
| 88 SSLManager* manager() const { return manager_; } | |
| 89 | |
| 90 // Returns the TabContents this object is associated with. Should be | |
| 91 // called from the UI thread. | |
| 92 TabContents* GetTabContents(); | |
| 93 | |
| 94 // Cancels the associated URLRequest. | |
| 95 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 96 void CancelRequest(); | |
| 97 | |
| 98 // Continue the URLRequest ignoring any previous errors. Note that some | |
| 99 // errors cannot be ignored, in which case this will result in the request | |
| 100 // being canceled. | |
| 101 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 102 void ContinueRequest(); | |
| 103 | |
| 104 // Cancels the associated URLRequest and mark it as denied. The renderer | |
| 105 // processes such request in a special manner, optionally replacing them | |
| 106 // with alternate content (typically frames content is replaced with a | |
| 107 // warning message). | |
| 108 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 109 void DenyRequest(); | |
| 110 | |
| 111 // Starts the associated URLRequest. |filter_policy| specifies whether the | |
| 112 // ResourceDispatcher should attempt to filter the loaded content in order | |
| 113 // to make it secure (ex: images are made slightly transparent and are | |
| 114 // stamped). | |
| 115 // Should only be called when the URLRequest has not already been started. | |
| 116 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 117 void StartRequest(FilterPolicy::Type filter_policy); | |
| 118 | |
| 119 // Does nothing on the URLRequest but ensures the current instance ref | |
| 120 // count is decremented appropriately. Subclasses that do not want to | |
| 121 // take any specific actions in their OnDispatched/OnDispatchFailed should | |
| 122 // call this. | |
| 123 void TakeNoAction(); | |
| 124 | |
| 125 protected: | |
| 126 // Construct on the IO thread. | |
| 127 ErrorHandler(ResourceDispatcherHost* resource_dispatcher_host, | |
| 128 URLRequest* request, | |
| 129 ResourceType::Type resource_type, | |
| 130 const std::string& frame_origin, | |
| 131 const std::string& main_frame_origin, | |
| 132 MessageLoop* ui_loop); | |
| 133 | |
| 134 // The following 2 methods are the methods subclasses should implement. | |
| 135 virtual void OnDispatchFailed() { TakeNoAction(); } | |
| 136 | |
| 137 // Can use the manager_ member. | |
| 138 virtual void OnDispatched() { TakeNoAction(); } | |
| 139 | |
| 140 // We cache the message loops to be able to proxy events across the thread | |
| 141 // boundaries. | |
| 142 MessageLoop* ui_loop_; | |
| 143 MessageLoop* io_loop_; | |
| 144 | |
| 145 // Should only be accessed on the UI thread. | |
| 146 SSLManager* manager_; // Our manager. | |
| 147 | |
| 148 // The id of the URLRequest associated with this object. | |
| 149 // Should only be accessed from the IO thread. | |
| 150 ResourceDispatcherHost::GlobalRequestID request_id_; | |
| 151 | |
| 152 // The ResourceDispatcherHost we are associated with. | |
| 153 ResourceDispatcherHost* resource_dispatcher_host_; | |
| 154 | |
| 155 private: | |
| 156 // Completes the CancelRequest operation on the IO thread. | |
| 157 // Call on the IO thread. | |
| 158 void CompleteCancelRequest(int error); | |
| 159 | |
| 160 // Completes the ContinueRequest operation on the IO thread. | |
| 161 // | |
| 162 // Call on the IO thread. | |
| 163 void CompleteContinueRequest(); | |
| 164 | |
| 165 // Completes the StartRequest operation on the IO thread. | |
| 166 // Call on the IO thread. | |
| 167 void CompleteStartRequest(FilterPolicy::Type filter_policy); | |
| 168 | |
| 169 // Derefs this instance. | |
| 170 // Call on the IO thread. | |
| 171 void CompleteTakeNoAction(); | |
| 172 | |
| 173 // We use these members to find the correct SSLManager when we arrive on | |
| 174 // the UI thread. | |
| 175 int render_process_host_id_; | |
| 176 int tab_contents_id_; | |
| 177 | |
| 178 // The URL that we requested. | |
| 179 // This read-only member can be accessed on any thread. | |
| 180 const GURL request_url_; | |
| 181 | |
| 182 // What kind of resource is associated with the requested that generated | |
| 183 // that error. | |
| 184 // This read-only member can be accessed on any thread. | |
| 185 const ResourceType::Type resource_type_; | |
| 186 | |
| 187 // The origin of the frame associated with this request. | |
| 188 // This read-only member can be accessed on any thread. | |
| 189 const std::string frame_origin_; | |
| 190 | |
| 191 // The origin of the main frame associated with this request. | |
| 192 // This read-only member can be accessed on any thread. | |
| 193 const std::string main_frame_origin_; | |
| 194 | |
| 195 // A flag to make sure we notify the URLRequest exactly once. | |
| 196 // Should only be accessed on the IO thread | |
| 197 bool request_has_been_notified_; | |
| 198 | |
| 199 DISALLOW_COPY_AND_ASSIGN(ErrorHandler); | |
| 200 }; | |
| 201 | |
| 202 // A CertError represents an error that occurred with the certificate in an | |
| 203 // SSL session. A CertError object exists both on the IO thread and on the UI | |
| 204 // thread and allows us to cancel/continue a request it is associated with. | |
| 205 class CertError : public ErrorHandler { | |
| 206 public: | |
| 207 | |
| 208 virtual CertError* AsCertError() { return this; } | |
| 209 | |
| 210 // These accessors are available on either thread | |
| 211 const net::SSLInfo& ssl_info() const { return ssl_info_; } | |
| 212 int cert_error() const { return cert_error_; } | |
| 213 | |
| 214 private: | |
| 215 // SSLManager is responsible for creating CertError objects. | |
| 216 friend class SSLManager; | |
| 217 | |
| 218 // Construct on the IO thread. | |
| 219 // We mark this method as private because it is tricky to correctly | |
| 220 // construct a CertError object. | |
| 221 CertError(ResourceDispatcherHost* resource_dispatcher_host, | |
| 222 URLRequest* request, | |
| 223 ResourceType::Type resource_type, | |
| 224 const std::string& frame_origin, | |
| 225 const std::string& main_frame_origin, | |
| 226 int cert_error, | |
| 227 net::X509Certificate* cert, | |
| 228 MessageLoop* ui_loop); | |
| 229 | |
| 230 // ErrorHandler methods | |
| 231 virtual void OnDispatchFailed() { CancelRequest(); } | |
| 232 virtual void OnDispatched() { manager_->OnCertError(this); } | |
| 233 | |
| 234 // These read-only members can be accessed on any thread. | |
| 235 net::SSLInfo ssl_info_; | |
| 236 const int cert_error_; // The error we represent. | |
| 237 | |
| 238 DISALLOW_COPY_AND_ASSIGN(CertError); | |
| 239 }; | |
| 240 | |
| 241 // The MixedContentHandler class is used to query what to do with | |
| 242 // mixed content, from the IO thread to the UI thread. | |
| 243 class MixedContentHandler : public ErrorHandler { | |
| 244 public: | |
| 245 // Created on the IO thread. | |
| 246 MixedContentHandler(ResourceDispatcherHost* rdh, | |
| 247 URLRequest* request, | |
| 248 ResourceType::Type resource_type, | |
| 249 const std::string& frame_origin, | |
| 250 const std::string& main_frame_origin, | |
| 251 int pid, | |
| 252 MessageLoop* ui_loop) | |
| 253 : ErrorHandler(rdh, request, resource_type, frame_origin, | |
| 254 main_frame_origin, ui_loop), | |
| 255 pid_(pid) {} | |
| 256 | |
| 257 int pid() const { return pid_; } | |
| 258 | |
| 259 protected: | |
| 260 virtual void OnDispatchFailed() { TakeNoAction(); } | |
| 261 virtual void OnDispatched() { manager()->OnMixedContent(this); } | |
| 262 | |
| 263 private: | |
| 264 int pid_; | |
| 265 | |
| 266 DISALLOW_COPY_AND_ASSIGN(MixedContentHandler); | |
| 267 }; | |
| 268 | |
| 269 // RequestInfo wraps up the information SSLPolicy needs about a request in | |
| 270 // order to update our security IU. RequestInfo is RefCounted in case we need | |
| 271 // to deal with the request asynchronously. | |
| 272 class RequestInfo : public base::RefCounted<RequestInfo> { | |
| 273 public: | |
| 274 RequestInfo(SSLManager* manager, | |
| 275 const GURL& url, | |
| 276 ResourceType::Type resource_type, | |
| 277 const std::string& frame_origin, | |
| 278 const std::string& main_frame_origin, | |
| 279 FilterPolicy::Type filter_policy, | |
| 280 int pid, | |
| 281 int ssl_cert_id, | |
| 282 int ssl_cert_status) | |
| 283 : manager_(manager), | |
| 284 url_(url), | |
| 285 resource_type_(resource_type), | |
| 286 frame_origin_(frame_origin), | |
| 287 main_frame_origin_(main_frame_origin), | |
| 288 filter_policy_(filter_policy), | |
| 289 pid_(pid), | |
| 290 ssl_cert_id_(ssl_cert_id), | |
| 291 ssl_cert_status_(ssl_cert_status) { | |
| 292 } | |
| 293 | |
| 294 SSLManager* manager() const { return manager_; } | |
| 295 const GURL& url() const { return url_; } | |
| 296 ResourceType::Type resource_type() const { return resource_type_; } | |
| 297 const std::string& frame_origin() const { return frame_origin_; } | |
| 298 const std::string& main_frame_origin() const { return main_frame_origin_; } | |
| 299 FilterPolicy::Type filter_policy() const { return filter_policy_; } | |
| 300 int pid() const { return pid_; } | |
| 301 int ssl_cert_id() const { return ssl_cert_id_; } | |
| 302 int ssl_cert_status() const { return ssl_cert_status_; } | |
| 303 | |
| 304 private: | |
| 305 SSLManager* manager_; | |
| 306 GURL url_; | |
| 307 ResourceType::Type resource_type_; | |
| 308 std::string frame_origin_; | |
| 309 std::string main_frame_origin_; | |
| 310 FilterPolicy::Type filter_policy_; | |
| 311 int pid_; | |
| 312 int ssl_cert_id_; | |
| 313 int ssl_cert_status_; | |
| 314 | |
| 315 DISALLOW_COPY_AND_ASSIGN(RequestInfo); | |
| 316 }; | |
| 317 | |
| 318 // The SSLManager will ask its delegate to decide how to handle events | 55 // The SSLManager will ask its delegate to decide how to handle events |
| 319 // relevant to SSL. Delegates are expected to be stateless and intended to be | 56 // relevant to SSL. Delegates are expected to be stateless and intended to be |
| 320 // easily implementable. | 57 // easily implementable. |
| 321 // | 58 // |
| 322 // Delegates should interact with the rest of the browser only through their | 59 // Delegates should interact with the rest of the browser only through their |
| 323 // parameters and through the delegate API of the SSLManager. | 60 // parameters and through the delegate API of the SSLManager. |
| 324 // | 61 // |
| 325 // If a delegate needs to do something tricky, consider having the SSLManager | 62 // If a delegate needs to do something tricky, consider having the SSLManager |
| 326 // do it instead. | 63 // do it instead. |
| 327 class Delegate { | 64 class Delegate { |
| 328 public: | 65 public: |
| 329 // An error occurred with the certificate in an SSL connection. | 66 // An error occurred with the certificate in an SSL connection. |
| 330 virtual void OnCertError(CertError* error) = 0; | 67 virtual void OnCertError(SSLCertErrorHandler* handler) = 0; |
| 331 | 68 |
| 332 // A request for a mixed-content resource was made. Note that the resource | 69 // A request for a mixed-content resource was made. Note that the resource |
| 333 // request was not started yet and the delegate is responsible for starting | 70 // request was not started yet and the delegate is responsible for starting |
| 334 // it. | 71 // it. |
| 335 virtual void OnMixedContent(MixedContentHandler* handler) = 0; | 72 virtual void OnMixedContent(SSLMixedContentHandler* handler) = 0; |
| 336 | 73 |
| 337 // We have started a resource request with the given info. | 74 // We have started a resource request with the given info. |
| 338 virtual void OnRequestStarted(RequestInfo* info) = 0; | 75 virtual void OnRequestStarted(SSLRequestInfo* info) = 0; |
| 339 | 76 |
| 340 // Update the SSL information in |entry| to match the current state. | 77 // Update the SSL information in |entry| to match the current state. |
| 341 virtual void UpdateEntry(SSLManager* manager, NavigationEntry* entry) = 0; | 78 virtual void UpdateEntry(SSLManager* manager, NavigationEntry* entry) = 0; |
| 342 }; | 79 }; |
| 343 | 80 |
| 344 static void RegisterUserPrefs(PrefService* prefs); | 81 static void RegisterUserPrefs(PrefService* prefs); |
| 345 | 82 |
| 346 // Construct an SSLManager for the specified tab. | 83 // Construct an SSLManager for the specified tab. |
| 347 // If |delegate| is NULL, SSLPolicy::GetDefaultPolicy() is used. | 84 // If |delegate| is NULL, SSLPolicy::GetDefaultPolicy() is used. |
| 348 SSLManager(NavigationController* controller, Delegate* delegate); | 85 SSLManager(NavigationController* controller, Delegate* delegate); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 // not remove from the pending_requests_ of the ResourceDispatcherHost. | 168 // not remove from the pending_requests_ of the ResourceDispatcherHost. |
| 432 // Called on the IO thread. | 169 // Called on the IO thread. |
| 433 static bool ShouldStartRequest(ResourceDispatcherHost* resource_dispatcher, | 170 static bool ShouldStartRequest(ResourceDispatcherHost* resource_dispatcher, |
| 434 URLRequest* request, | 171 URLRequest* request, |
| 435 MessageLoop* ui_loop); | 172 MessageLoop* ui_loop); |
| 436 | 173 |
| 437 // Called by CertError::Dispatch to kick off processing of the cert error by | 174 // Called by CertError::Dispatch to kick off processing of the cert error by |
| 438 // the SSL manager. The error originated from the ResourceDispatcherHost. | 175 // the SSL manager. The error originated from the ResourceDispatcherHost. |
| 439 // | 176 // |
| 440 // Called on the UI thread. | 177 // Called on the UI thread. |
| 441 void OnCertError(CertError* error); | 178 void OnCertError(SSLCertErrorHandler* handler); |
| 442 | 179 |
| 443 // Called by MixedContentHandler::Dispatch to kick off processing of the | 180 // Called by MixedContentHandler::Dispatch to kick off processing of the |
| 444 // mixed-content resource request. The info originated from the | 181 // mixed-content resource request. The info originated from the |
| 445 // ResourceDispatcherHost. | 182 // ResourceDispatcherHost. |
| 446 // | 183 // |
| 447 // Called on the UI thread. | 184 // Called on the UI thread. |
| 448 void OnMixedContent(MixedContentHandler* handler); | 185 void OnMixedContent(SSLMixedContentHandler* handler); |
| 449 | 186 |
| 450 // Entry point for navigation. This function begins the process of updating | 187 // Entry point for navigation. This function begins the process of updating |
| 451 // the security UI when the main frame navigates to a new URL. | 188 // the security UI when the main frame navigates to a new URL. |
| 452 // | 189 // |
| 453 // Called on the UI thread. | 190 // Called on the UI thread. |
| 454 virtual void Observe(NotificationType type, | 191 virtual void Observe(NotificationType type, |
| 455 const NotificationSource& source, | 192 const NotificationSource& source, |
| 456 const NotificationDetails& details); | 193 const NotificationDetails& details); |
| 457 | 194 |
| 458 // This entry point is called directly (instead of via the notification | 195 // This entry point is called directly (instead of via the notification |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 SSLHostState* ssl_host_state_; | 285 SSLHostState* ssl_host_state_; |
| 549 | 286 |
| 550 // The list of messages that should be displayed (in info bars) when the page | 287 // The list of messages that should be displayed (in info bars) when the page |
| 551 // currently loading had loaded. | 288 // currently loading had loaded. |
| 552 std::vector<SSLMessageInfo> pending_messages_; | 289 std::vector<SSLMessageInfo> pending_messages_; |
| 553 | 290 |
| 554 DISALLOW_COPY_AND_ASSIGN(SSLManager); | 291 DISALLOW_COPY_AND_ASSIGN(SSLManager); |
| 555 }; | 292 }; |
| 556 | 293 |
| 557 #endif // CHROME_BROWSER_SSL_SSL_MANAGER_H_ | 294 #endif // CHROME_BROWSER_SSL_SSL_MANAGER_H_ |
| OLD | NEW |