[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | ||||
6 | #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 8 | |
9 | #include <string> | ||||
10 | |||||
11 | #include "base/basictypes.h" | ||||
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 5edce1e | 2009-05-14 08:47:30 | [diff] [blame] | 13 | #include "chrome/browser/ssl/ssl_manager.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 14 | #include "content/browser/renderer_host/global_request_id.h" |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 15 | #include "googleurl/src/gurl.h" |
16 | #include "webkit/glue/resource_type.h" | ||||
17 | |||||
[email protected] | 92b24c1 | 2009-12-10 20:04:35 | [diff] [blame] | 18 | class ResourceDispatcherHost; |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 19 | class SSLCertErrorHandler; |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 20 | class TabContents; |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 21 | |
22 | namespace net { | ||||
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 23 | class URLRequest; |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 24 | } // namespace net |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 25 | |
26 | // An SSLErrorHandler carries information from the IO thread to the UI thread | ||||
27 | // and is dispatched to the appropriate SSLManager when it arrives on the | ||||
28 | // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed | ||||
29 | // methods to implement the actions that should be taken on the UI thread. | ||||
30 | // These methods can call the different convenience methods ContinueRequest/ | ||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 31 | // CancelRequest to perform any required action on the net::URLRequest the |
[email protected] | 8a58f9a | 2010-05-18 18:38:09 | [diff] [blame] | 32 | // ErrorHandler was created with. |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 33 | // |
34 | // IMPORTANT NOTE: | ||||
35 | // | ||||
36 | // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure | ||||
37 | // you call TakeNoAction(). This is necessary for ensuring the instance is | ||||
38 | // not leaked. | ||||
39 | // | ||||
40 | class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { | ||||
41 | public: | ||||
[email protected] | e4be2dd | 2010-12-14 00:44:39 | [diff] [blame] | 42 | virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 43 | |
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 44 | // Find the appropriate SSLManager for the net::URLRequest and begin handling |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 45 | // this error. |
46 | // | ||||
47 | // Call on UI thread. | ||||
48 | void Dispatch(); | ||||
49 | |||||
50 | // Available on either thread. | ||||
51 | const GURL& request_url() const { return request_url_; } | ||||
52 | |||||
53 | // Available on either thread. | ||||
54 | ResourceType::Type resource_type() const { return resource_type_; } | ||||
55 | |||||
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 56 | // Returns the TabContents this object is associated with. Should be |
57 | // called from the UI thread. | ||||
58 | TabContents* GetTabContents(); | ||||
59 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 60 | // Cancels the associated net::URLRequest. |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 61 | // This method can be called from OnDispatchFailed and OnDispatched. |
62 | void CancelRequest(); | ||||
63 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 64 | // Continue the net::URLRequest ignoring any previous errors. Note that some |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 65 | // errors cannot be ignored, in which case this will result in the request |
66 | // being canceled. | ||||
67 | // This method can be called from OnDispatchFailed and OnDispatched. | ||||
68 | void ContinueRequest(); | ||||
69 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 70 | // Cancels the associated net::URLRequest and mark it as denied. The renderer |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 71 | // processes such request in a special manner, optionally replacing them |
72 | // with alternate content (typically frames content is replaced with a | ||||
73 | // warning message). | ||||
74 | // This method can be called from OnDispatchFailed and OnDispatched. | ||||
75 | void DenyRequest(); | ||||
76 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 77 | // Does nothing on the net::URLRequest but ensures the current instance ref |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 78 | // count is decremented appropriately. Subclasses that do not want to |
79 | // take any specific actions in their OnDispatched/OnDispatchFailed should | ||||
80 | // call this. | ||||
81 | void TakeNoAction(); | ||||
82 | |||||
83 | protected: | ||||
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 84 | friend class base::RefCountedThreadSafe<SSLErrorHandler>; |
85 | |||||
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 86 | // Construct on the IO thread. |
87 | SSLErrorHandler(ResourceDispatcherHost* resource_dispatcher_host, | ||||
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 88 | net::URLRequest* request, |
[email protected] | 7a8c55e | 2011-02-15 08:21:16 | [diff] [blame] | 89 | ResourceType::Type resource_type); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 90 | |
[email protected] | 02d08e0 | 2010-10-08 17:50:46 | [diff] [blame] | 91 | virtual ~SSLErrorHandler(); |
[email protected] | e6e6ba4 | 2009-11-07 01:56:19 | [diff] [blame] | 92 | |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 93 | // The following 2 methods are the methods subclasses should implement. |
[email protected] | 02d08e0 | 2010-10-08 17:50:46 | [diff] [blame] | 94 | virtual void OnDispatchFailed(); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 95 | |
96 | // Can use the manager_ member. | ||||
[email protected] | 02d08e0 | 2010-10-08 17:50:46 | [diff] [blame] | 97 | virtual void OnDispatched(); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 98 | |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 99 | // Should only be accessed on the UI thread. |
100 | SSLManager* manager_; // Our manager. | ||||
101 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 102 | // The id of the net::URLRequest associated with this object. |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 103 | // Should only be accessed from the IO thread. |
[email protected] | 92b24c1 | 2009-12-10 20:04:35 | [diff] [blame] | 104 | GlobalRequestID request_id_; |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 105 | |
106 | // The ResourceDispatcherHost we are associated with. | ||||
107 | ResourceDispatcherHost* resource_dispatcher_host_; | ||||
108 | |||||
109 | private: | ||||
110 | // Completes the CancelRequest operation on the IO thread. | ||||
111 | // Call on the IO thread. | ||||
112 | void CompleteCancelRequest(int error); | ||||
113 | |||||
114 | // Completes the ContinueRequest operation on the IO thread. | ||||
115 | // | ||||
116 | // Call on the IO thread. | ||||
117 | void CompleteContinueRequest(); | ||||
118 | |||||
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 119 | // Derefs this instance. |
120 | // Call on the IO thread. | ||||
121 | void CompleteTakeNoAction(); | ||||
122 | |||||
123 | // We use these members to find the correct SSLManager when we arrive on | ||||
124 | // the UI thread. | ||||
125 | int render_process_host_id_; | ||||
126 | int tab_contents_id_; | ||||
127 | |||||
128 | // The URL that we requested. | ||||
129 | // This read-only member can be accessed on any thread. | ||||
130 | const GURL request_url_; | ||||
131 | |||||
132 | // What kind of resource is associated with the requested that generated | ||||
133 | // that error. | ||||
134 | // This read-only member can be accessed on any thread. | ||||
135 | const ResourceType::Type resource_type_; | ||||
136 | |||||
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 137 | // A flag to make sure we notify the net::URLRequest exactly once. |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 138 | // Should only be accessed on the IO thread |
139 | bool request_has_been_notified_; | ||||
140 | |||||
141 | DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | ||||
142 | }; | ||||
143 | |||||
144 | #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |