OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/browser/ssl/ssl_manager.h" | |
14 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
15 #include "content/public/browser/global_request_id.h" | 14 #include "content/public/browser/global_request_id.h" |
16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
17 #include "webkit/glue/resource_type.h" | 16 #include "webkit/glue/resource_type.h" |
18 | 17 |
19 class ResourceDispatcherHost; | |
20 class SSLCertErrorHandler; | 18 class SSLCertErrorHandler; |
19 class SSLManager; | |
21 | 20 |
22 namespace net { | 21 namespace net { |
22 class SSLInfo; | |
23 class URLRequest; | 23 class URLRequest; |
24 } // namespace net | 24 } // namespace net |
25 | 25 |
26 // An SSLErrorHandler carries information from the IO thread to the UI thread | 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 | 27 // and is dispatched to the appropriate SSLManager when it arrives on the |
28 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed | 28 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed |
29 // methods to implement the actions that should be taken on the UI thread. | 29 // methods to implement the actions that should be taken on the UI thread. |
30 // These methods can call the different convenience methods ContinueRequest/ | 30 // These methods can call the different convenience methods ContinueRequest/ |
31 // CancelRequest to perform any required action on the net::URLRequest the | 31 // CancelRequest to perform any required action on the net::URLRequest the |
32 // ErrorHandler was created with. | 32 // ErrorHandler was created with. |
33 // | 33 // |
34 // IMPORTANT NOTE: | 34 // IMPORTANT NOTE: |
35 // | 35 // |
36 // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure | 36 // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure |
37 // you call TakeNoAction(). This is necessary for ensuring the instance is | 37 // you call TakeNoAction(). This is necessary for ensuring the instance is |
38 // not leaked. | 38 // not leaked. |
39 // | 39 // |
40 class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { | 40 class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> { |
41 public: | 41 public: |
42 // Delegate functions must be called from IO thread. All functions accept | |
43 // |id| as the first argument. |id| is a copy of the second argument of | |
44 // SSLManager::OnSSLCertificateError() and represents the request. | |
45 // Query functions are used to retrieve the request related information. | |
46 // Finally, CancelSSLRequest() or ContinueSSLRequest() will be called after | |
47 // SSLErrorHandler makes a decision on the SSL error. | |
48 class Delegate { | |
49 public: | |
50 // Queries what kind of resource is associated with a request that | |
51 // generated the error. | |
52 virtual ResourceType::Type ResourceTypeForSSLRequest( | |
darin (slow to review)
2012/02/28 23:36:44
hmm... the ResourceType is not a property that eve
Takashi Toyoshima
2012/02/29 00:15:24
ResourceTypeForSSLRequest() and URLForSSLRequest w
| |
53 const content::GlobalRequestID& id) = 0; | |
54 | |
55 // Queries the requested URL which generated the error. | |
56 virtual const GURL& URLForSSLRequest( | |
57 const content::GlobalRequestID& id) = 0; | |
58 | |
59 // Queries the render process and view ids which represent RenderViewHost | |
60 // to which the request belong. | |
61 virtual bool RenderViewForSSLRequest(const content::GlobalRequestID& id, | |
62 int* render_process_host_id, | |
63 int* render_view_host_id) = 0; | |
64 | |
65 // Called when SSLErrorHandler decides to cancel the request because of | |
66 // the SSL error. | |
67 virtual void CancelSSLRequest(const content::GlobalRequestID& id, | |
68 int error, | |
69 const net::SSLInfo* ssl_info) = 0; | |
70 | |
71 // Called when SSLErrorHandler decides to continue the request despite the | |
72 // SSL error. | |
73 virtual void ContinueSSLRequest(const content::GlobalRequestID& id) = 0; | |
74 }; | |
42 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); | 75 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); |
43 | 76 |
44 // Find the appropriate SSLManager for the net::URLRequest and begin handling | 77 // Find the appropriate SSLManager for the net::URLRequest and begin handling |
45 // this error. | 78 // this error. |
46 // | 79 // |
47 // Call on UI thread. | 80 // Call on UI thread. |
48 void Dispatch(); | 81 void Dispatch(); |
49 | 82 |
50 // Available on either thread. | 83 // Available on either thread. |
51 const GURL& request_url() const { return request_url_; } | 84 const GURL& request_url() const { return request_url_; } |
(...skipping 24 matching lines...) Expand all Loading... | |
76 // call this. | 109 // call this. |
77 void TakeNoAction(); | 110 void TakeNoAction(); |
78 | 111 |
79 int render_process_id() const { return render_process_id_; } | 112 int render_process_id() const { return render_process_id_; } |
80 int render_view_id() const { return render_view_id_; } | 113 int render_view_id() const { return render_view_id_; } |
81 | 114 |
82 protected: | 115 protected: |
83 friend class base::RefCountedThreadSafe<SSLErrorHandler>; | 116 friend class base::RefCountedThreadSafe<SSLErrorHandler>; |
84 | 117 |
85 // Construct on the IO thread. | 118 // Construct on the IO thread. |
86 SSLErrorHandler(ResourceDispatcherHost* resource_dispatcher_host, | 119 SSLErrorHandler(Delegate* delegate, const content::GlobalRequestID& id); |
87 net::URLRequest* request, | |
88 ResourceType::Type resource_type); | |
89 | 120 |
90 virtual ~SSLErrorHandler(); | 121 virtual ~SSLErrorHandler(); |
91 | 122 |
92 // The following 2 methods are the methods subclasses should implement. | 123 // The following 2 methods are the methods subclasses should implement. |
93 virtual void OnDispatchFailed(); | 124 virtual void OnDispatchFailed(); |
94 | 125 |
95 // Can use the manager_ member. | 126 // Can use the manager_ member. |
96 virtual void OnDispatched(); | 127 virtual void OnDispatched(); |
97 | 128 |
98 // Should only be accessed on the UI thread. | 129 // Should only be accessed on the UI thread. |
99 SSLManager* manager_; // Our manager. | 130 SSLManager* manager_; // Our manager. |
100 | 131 |
101 // The id of the net::URLRequest associated with this object. | 132 // The id of the request associated with this object. |
102 // Should only be accessed from the IO thread. | 133 // Should only be accessed from the IO thread. |
103 content::GlobalRequestID request_id_; | 134 content::GlobalRequestID request_id_; |
104 | 135 |
105 // The ResourceDispatcherHost we are associated with. | 136 // The delegate we are associated with. |
106 ResourceDispatcherHost* resource_dispatcher_host_; | 137 Delegate* delegate_; |
107 | 138 |
108 private: | 139 private: |
109 // Completes the CancelRequest operation on the IO thread. | 140 // Completes the CancelRequest operation on the IO thread. |
110 // Call on the IO thread. | 141 // Call on the IO thread. |
111 void CompleteCancelRequest(int error); | 142 void CompleteCancelRequest(int error); |
112 | 143 |
113 // Completes the ContinueRequest operation on the IO thread. | 144 // Completes the ContinueRequest operation on the IO thread. |
114 // | 145 // |
115 // Call on the IO thread. | 146 // Call on the IO thread. |
116 void CompleteContinueRequest(); | 147 void CompleteContinueRequest(); |
(...skipping 17 matching lines...) Expand all Loading... | |
134 const ResourceType::Type resource_type_; | 165 const ResourceType::Type resource_type_; |
135 | 166 |
136 // A flag to make sure we notify the net::URLRequest exactly once. | 167 // A flag to make sure we notify the net::URLRequest exactly once. |
137 // Should only be accessed on the IO thread | 168 // Should only be accessed on the IO thread |
138 bool request_has_been_notified_; | 169 bool request_has_been_notified_; |
139 | 170 |
140 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 171 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
141 }; | 172 }; |
142 | 173 |
143 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 174 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
OLD | NEW |