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 // Finally, CancelSSLRequest() or ContinueSSLRequest() will be called after | |
46 // SSLErrorHandler makes a decision on the SSL error. | |
47 class Delegate { | |
48 public: | |
49 // Called when SSLErrorHandler decides to cancel the request because of | |
50 // the SSL error. | |
51 virtual void CancelSSLRequest(const content::GlobalRequestID& id, | |
52 int error, | |
53 const net::SSLInfo* ssl_info) = 0; | |
54 | |
55 // Called when SSLErrorHandler decides to continue the request despite the | |
56 // SSL error. | |
57 virtual void ContinueSSLRequest(const content::GlobalRequestID& id) = 0; | |
58 }; | |
darin (slow to review)
2012/03/09 20:49:03
nit: add a new line at the end of this class.
Takashi Toyoshima
2012/03/10 00:24:44
Done.
| |
42 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); | 59 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); |
43 | 60 |
44 // Find the appropriate SSLManager for the net::URLRequest and begin handling | 61 // Find the appropriate SSLManager for the net::URLRequest and begin handling |
45 // this error. | 62 // this error. |
46 // | 63 // |
47 // Call on UI thread. | 64 // Call on UI thread. |
48 void Dispatch(); | 65 void Dispatch(); |
49 | 66 |
50 // Available on either thread. | 67 // Available on either thread. |
51 const GURL& request_url() const { return request_url_; } | 68 const GURL& request_url() const { return request_url_; } |
(...skipping 24 matching lines...) Expand all Loading... | |
76 // call this. | 93 // call this. |
77 void TakeNoAction(); | 94 void TakeNoAction(); |
78 | 95 |
79 int render_process_id() const { return render_process_id_; } | 96 int render_process_id() const { return render_process_id_; } |
80 int render_view_id() const { return render_view_id_; } | 97 int render_view_id() const { return render_view_id_; } |
81 | 98 |
82 protected: | 99 protected: |
83 friend class base::RefCountedThreadSafe<SSLErrorHandler>; | 100 friend class base::RefCountedThreadSafe<SSLErrorHandler>; |
84 | 101 |
85 // Construct on the IO thread. | 102 // Construct on the IO thread. |
86 SSLErrorHandler(ResourceDispatcherHost* resource_dispatcher_host, | 103 SSLErrorHandler(Delegate* delegate, |
87 net::URLRequest* request, | 104 const content::GlobalRequestID& id, |
darin (slow to review)
2012/03/09 20:49:03
isn't there redundant information being passed her
Takashi Toyoshima
2012/03/10 00:24:44
The contents of GlobalRequestID is different from
| |
88 ResourceType::Type resource_type); | 105 ResourceType::Type resource_type, |
106 const GURL& url, | |
107 int render_process_id, | |
108 int render_view_id); | |
89 | 109 |
90 virtual ~SSLErrorHandler(); | 110 virtual ~SSLErrorHandler(); |
91 | 111 |
92 // The following 2 methods are the methods subclasses should implement. | 112 // The following 2 methods are the methods subclasses should implement. |
93 virtual void OnDispatchFailed(); | 113 virtual void OnDispatchFailed(); |
94 | 114 |
95 // Can use the manager_ member. | 115 // Can use the manager_ member. |
96 virtual void OnDispatched(); | 116 virtual void OnDispatched(); |
97 | 117 |
98 // Should only be accessed on the UI thread. | 118 // Should only be accessed on the UI thread. |
99 SSLManager* manager_; // Our manager. | 119 SSLManager* manager_; // Our manager. |
100 | 120 |
101 // The id of the net::URLRequest associated with this object. | 121 // The id of the request associated with this object. |
102 // Should only be accessed from the IO thread. | 122 // Should only be accessed from the IO thread. |
103 content::GlobalRequestID request_id_; | 123 content::GlobalRequestID request_id_; |
104 | 124 |
105 // The ResourceDispatcherHost we are associated with. | 125 // The delegate we are associated with. |
106 ResourceDispatcherHost* resource_dispatcher_host_; | 126 Delegate* delegate_; |
107 | 127 |
108 private: | 128 private: |
109 // Completes the CancelRequest operation on the IO thread. | 129 // Completes the CancelRequest operation on the IO thread. |
110 // Call on the IO thread. | 130 // Call on the IO thread. |
111 void CompleteCancelRequest(int error); | 131 void CompleteCancelRequest(int error); |
112 | 132 |
113 // Completes the ContinueRequest operation on the IO thread. | 133 // Completes the ContinueRequest operation on the IO thread. |
114 // | 134 // |
115 // Call on the IO thread. | 135 // Call on the IO thread. |
116 void CompleteContinueRequest(); | 136 void CompleteContinueRequest(); |
(...skipping 17 matching lines...) Expand all Loading... | |
134 const ResourceType::Type resource_type_; | 154 const ResourceType::Type resource_type_; |
135 | 155 |
136 // A flag to make sure we notify the net::URLRequest exactly once. | 156 // A flag to make sure we notify the net::URLRequest exactly once. |
137 // Should only be accessed on the IO thread | 157 // Should only be accessed on the IO thread |
138 bool request_has_been_notified_; | 158 bool request_has_been_notified_; |
139 | 159 |
140 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 160 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
141 }; | 161 }; |
142 | 162 |
143 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 163 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
OLD | NEW |