OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_ERROR_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
6 #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 6 #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/public/browser/global_request_id.h" | 14 #include "content/public/browser/global_request_id.h" |
15 #include "content/public/common/resource_type.h" | 15 #include "content/public/common/resource_type.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class SSLInfo; | 19 class SSLInfo; |
20 class URLRequest; | 20 class URLRequest; |
21 } // namespace net | 21 } // namespace net |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 | 24 |
25 class ResourceDispatcherHostImpl; | 25 class ResourceDispatcherHostImpl; |
26 class SSLCertErrorHandler; | 26 class SSLCertErrorHandler; |
27 class SSLManager; | 27 class SSLManager; |
| 28 class WebContents; |
28 | 29 |
29 // An SSLErrorHandler carries information from the IO thread to the UI thread | 30 // An SSLErrorHandler carries information from the IO thread to the UI thread |
30 // and is dispatched to the appropriate SSLManager when it arrives on the | 31 // and is dispatched to the appropriate SSLManager when it arrives on the |
31 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed | 32 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed |
32 // methods to implement the actions that should be taken on the UI thread. | 33 // methods to implement the actions that should be taken on the UI thread. |
33 // These methods can call the different convenience methods ContinueRequest/ | 34 // These methods can call the different convenience methods ContinueRequest/ |
34 // CancelRequest to perform any required action on the net::URLRequest the | 35 // CancelRequest to perform any required action on the net::URLRequest the |
35 // ErrorHandler was created with. | 36 // ErrorHandler was created with. |
36 // | 37 // |
37 // IMPORTANT NOTE: | 38 // IMPORTANT NOTE: |
(...skipping 20 matching lines...) Expand all Loading... |
58 protected: | 59 protected: |
59 virtual ~Delegate() {} | 60 virtual ~Delegate() {} |
60 }; | 61 }; |
61 | 62 |
62 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); | 63 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); |
63 | 64 |
64 // Find the appropriate SSLManager for the net::URLRequest and begin handling | 65 // Find the appropriate SSLManager for the net::URLRequest and begin handling |
65 // this error. | 66 // this error. |
66 // | 67 // |
67 // Call on UI thread. | 68 // Call on UI thread. |
68 void Dispatch(); | 69 void Dispatch(const base::Callback<WebContents*(void)>& web_contents_getter); |
69 | 70 |
70 // Available on either thread. | 71 // Available on either thread. |
71 const GURL& request_url() const { return request_url_; } | 72 const GURL& request_url() const { return request_url_; } |
72 | 73 |
73 // Available on either thread. | 74 // Available on either thread. |
74 ResourceType resource_type() const { return resource_type_; } | 75 ResourceType resource_type() const { return resource_type_; } |
75 | 76 |
76 // Cancels the associated net::URLRequest. | 77 // Cancels the associated net::URLRequest. |
77 // This method can be called from OnDispatchFailed and OnDispatched. | 78 // This method can be called from OnDispatchFailed and OnDispatched. |
78 CONTENT_EXPORT void CancelRequest(); | 79 CONTENT_EXPORT void CancelRequest(); |
(...skipping 10 matching lines...) Expand all Loading... |
89 // warning message). | 90 // warning message). |
90 // This method can be called from OnDispatchFailed and OnDispatched. | 91 // This method can be called from OnDispatchFailed and OnDispatched. |
91 void DenyRequest(); | 92 void DenyRequest(); |
92 | 93 |
93 // Does nothing on the net::URLRequest but ensures the current instance ref | 94 // Does nothing on the net::URLRequest but ensures the current instance ref |
94 // count is decremented appropriately. Subclasses that do not want to | 95 // count is decremented appropriately. Subclasses that do not want to |
95 // take any specific actions in their OnDispatched/OnDispatchFailed should | 96 // take any specific actions in their OnDispatched/OnDispatchFailed should |
96 // call this. | 97 // call this. |
97 void TakeNoAction(); | 98 void TakeNoAction(); |
98 | 99 |
99 int render_process_id() const { return render_process_id_; } | 100 // Returns the manager associated with this SSLErrorHandler. |
100 int render_frame_id() const { return render_frame_id_; } | 101 // Should only be accessed on the UI thread. |
| 102 SSLManager* GetManager() const; |
101 | 103 |
102 protected: | 104 protected: |
103 friend class base::RefCountedThreadSafe<SSLErrorHandler>; | 105 friend class base::RefCountedThreadSafe<SSLErrorHandler>; |
104 | 106 |
105 // Construct on the IO thread. | 107 // Construct on the IO thread. |
106 SSLErrorHandler(const base::WeakPtr<Delegate>& delegate, | 108 SSLErrorHandler(const base::WeakPtr<Delegate>& delegate, |
107 ResourceType resource_type, | 109 ResourceType resource_type, |
108 const GURL& url, | 110 const GURL& url); |
109 int render_process_id, | |
110 int render_frame_id); | |
111 | 111 |
112 virtual ~SSLErrorHandler(); | 112 virtual ~SSLErrorHandler(); |
113 | 113 |
114 // The following 2 methods are the methods subclasses should implement. | 114 // The following 2 methods are the methods subclasses should implement. |
115 virtual void OnDispatchFailed(); | 115 virtual void OnDispatchFailed(); |
116 | 116 |
117 // Can use the manager_ member. | 117 // Can use the manager_ member. |
118 virtual void OnDispatched(); | 118 virtual void OnDispatched(); |
119 | 119 |
120 // Should only be accessed on the UI thread. | 120 // Should only be accessed on the UI thread. |
121 SSLManager* manager_; // Our manager. | 121 SSLManager* manager_; // Our manager. |
122 | 122 |
123 // The delegate we are associated with. | 123 // The delegate we are associated with. |
124 base::WeakPtr<Delegate> delegate_; | 124 base::WeakPtr<Delegate> delegate_; |
125 | 125 |
126 private: | 126 private: |
127 // Completes the CancelRequest operation on the IO thread. | 127 // Completes the CancelRequest operation on the IO thread. |
128 // Call on the IO thread. | 128 // Call on the IO thread. |
129 void CompleteCancelRequest(int error); | 129 void CompleteCancelRequest(int error); |
130 | 130 |
131 // Completes the ContinueRequest operation on the IO thread. | 131 // Completes the ContinueRequest operation on the IO thread. |
132 // | 132 // |
133 // Call on the IO thread. | 133 // Call on the IO thread. |
134 void CompleteContinueRequest(); | 134 void CompleteContinueRequest(); |
135 | 135 |
136 // Derefs this instance. | 136 // Derefs this instance. |
137 // Call on the IO thread. | 137 // Call on the IO thread. |
138 void CompleteTakeNoAction(); | 138 void CompleteTakeNoAction(); |
139 | 139 |
140 // We use these members to find the correct SSLManager when we arrive on | |
141 // the UI thread. | |
142 int render_process_id_; | |
143 int render_frame_id_; | |
144 | |
145 // The URL that we requested. | 140 // The URL that we requested. |
146 // This read-only member can be accessed on any thread. | 141 // This read-only member can be accessed on any thread. |
147 const GURL request_url_; | 142 const GURL request_url_; |
148 | 143 |
149 // What kind of resource is associated with the requested that generated | 144 // What kind of resource is associated with the requested that generated |
150 // that error. | 145 // that error. |
151 // This read-only member can be accessed on any thread. | 146 // This read-only member can be accessed on any thread. |
152 const ResourceType resource_type_; | 147 const ResourceType resource_type_; |
153 | 148 |
154 // A flag to make sure we notify the net::URLRequest exactly once. | 149 // A flag to make sure we notify the net::URLRequest exactly once. |
155 // Should only be accessed on the IO thread | 150 // Should only be accessed on the IO thread |
156 bool request_has_been_notified_; | 151 bool request_has_been_notified_; |
157 | 152 |
158 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 153 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
159 }; | 154 }; |
160 | 155 |
161 } // namespace content | 156 } // namespace content |
162 | 157 |
163 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 158 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
OLD | NEW |