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 #include "content/browser/ssl/ssl_error_handler.h" | 5 #include "content/browser/ssl/ssl_error_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/browser/renderer_host/render_view_host.h" | 8 #include "content/browser/renderer_host/render_view_host.h" |
9 #include "content/browser/renderer_host/resource_dispatcher_host.h" | |
10 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 9 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
Takashi Toyoshima
2012/02/28 21:28:16
Oops, I notice that this inclusion at line 9 also
| |
11 #include "content/browser/ssl/ssl_cert_error_handler.h" | 10 #include "content/browser/ssl/ssl_cert_error_handler.h" |
12 #include "content/browser/tab_contents/navigation_controller_impl.h" | 11 #include "content/browser/tab_contents/navigation_controller_impl.h" |
13 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
15 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
16 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
17 | 16 |
18 using content::BrowserThread; | 17 using content::BrowserThread; |
19 using content::WebContents; | 18 using content::WebContents; |
19 using net::SSLInfo; | |
20 | 20 |
21 SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, | 21 SSLErrorHandler::SSLErrorHandler(Delegate* delegate, |
22 net::URLRequest* request, | 22 const content::GlobalRequestID& id) |
23 ResourceType::Type resource_type) | |
24 : manager_(NULL), | 23 : manager_(NULL), |
25 request_id_(0, 0), | 24 request_id_(id), |
26 resource_dispatcher_host_(rdh), | 25 delegate_(delegate), |
27 request_url_(request->url()), | 26 request_url_(delegate->URLForSSLRequest(id)), |
28 resource_type_(resource_type), | 27 resource_type_(delegate->ResourceTypeForSSLRequest(id)), |
29 request_has_been_notified_(false) { | 28 request_has_been_notified_(false) { |
30 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
30 DCHECK(delegate); | |
31 | 31 |
32 ResourceDispatcherHostRequestInfo* info = | 32 if (!delegate->RenderViewForSSLRequest( |
33 ResourceDispatcherHost::InfoForRequest(request); | 33 id, &render_process_id_, &render_view_id_)) |
34 request_id_.child_id = info->child_id(); | |
35 request_id_.request_id = info->request_id(); | |
36 | |
37 if (!ResourceDispatcherHost::RenderViewForRequest(request, | |
38 &render_process_id_, | |
39 &render_view_id_)) | |
40 NOTREACHED(); | 34 NOTREACHED(); |
41 | 35 |
42 // This makes sure we don't disappear on the IO thread until we've given an | 36 // This makes sure we don't disappear on the IO thread until we've given an |
43 // answer to the net::URLRequest. | 37 // answer to the net::URLRequest. |
44 // | 38 // |
45 // Release in CompleteCancelRequest, CompleteContinueRequest, or | 39 // Release in CompleteCancelRequest, CompleteContinueRequest, or |
46 // CompleteTakeNoAction. | 40 // CompleteTakeNoAction. |
47 AddRef(); | 41 AddRef(); |
48 } | 42 } |
49 | 43 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 void SSLErrorHandler::CompleteCancelRequest(int error) { | 120 void SSLErrorHandler::CompleteCancelRequest(int error) { |
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
128 | 122 |
129 // It is important that we notify the net::URLRequest only once. If we try | 123 // It is important that we notify the net::URLRequest only once. If we try |
130 // to notify the request twice, it may no longer exist and |this| might have | 124 // to notify the request twice, it may no longer exist and |this| might have |
131 // already have been deleted. | 125 // already have been deleted. |
132 DCHECK(!request_has_been_notified_); | 126 DCHECK(!request_has_been_notified_); |
133 if (request_has_been_notified_) | 127 if (request_has_been_notified_) |
134 return; | 128 return; |
135 | 129 |
136 net::URLRequest* request = | 130 SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler(); |
137 resource_dispatcher_host_->GetURLRequest(request_id_); | 131 const SSLInfo* ssl_info = NULL; |
138 if (request && request->is_pending()) { | 132 if (cert_error) |
139 // The request can be NULL if it was cancelled by the renderer (as the | 133 ssl_info = &cert_error->ssl_info(); |
140 // result of the user navigating to a new page from the location bar). | 134 delegate_->CancelSSLRequest(request_id_, error, ssl_info); |
141 DVLOG(1) << "CompleteCancelRequest() url: " << request->url().spec(); | |
142 SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler(); | |
143 if (cert_error) | |
144 request->SimulateSSLError(error, cert_error->ssl_info()); | |
145 else | |
146 request->SimulateError(error); | |
147 } | |
148 request_has_been_notified_ = true; | 135 request_has_been_notified_ = true; |
149 | 136 |
150 // We're done with this object on the IO thread. | 137 // We're done with this object on the IO thread. |
151 Release(); | 138 Release(); |
152 } | 139 } |
153 | 140 |
154 void SSLErrorHandler::CompleteContinueRequest() { | 141 void SSLErrorHandler::CompleteContinueRequest() { |
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
156 | 143 |
157 // It is important that we notify the net::URLRequest only once. If we try to | 144 // It is important that we notify the net::URLRequest only once. If we try to |
158 // notify the request twice, it may no longer exist and |this| might have | 145 // notify the request twice, it may no longer exist and |this| might have |
159 // already have been deleted. | 146 // already have been deleted. |
160 DCHECK(!request_has_been_notified_); | 147 DCHECK(!request_has_been_notified_); |
161 if (request_has_been_notified_) | 148 if (request_has_been_notified_) |
162 return; | 149 return; |
163 | 150 |
164 net::URLRequest* request = | 151 delegate_->ContinueSSLRequest(request_id_); |
165 resource_dispatcher_host_->GetURLRequest(request_id_); | |
166 if (request) { | |
167 // The request can be NULL if it was cancelled by the renderer (as the | |
168 // result of the user navigating to a new page from the location bar). | |
169 DVLOG(1) << "CompleteContinueRequest() url: " << request->url().spec(); | |
170 request->ContinueDespiteLastError(); | |
171 } | |
172 request_has_been_notified_ = true; | 152 request_has_been_notified_ = true; |
173 | 153 |
174 // We're done with this object on the IO thread. | 154 // We're done with this object on the IO thread. |
175 Release(); | 155 Release(); |
176 } | 156 } |
177 | 157 |
178 void SSLErrorHandler::CompleteTakeNoAction() { | 158 void SSLErrorHandler::CompleteTakeNoAction() { |
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
180 | 160 |
181 // It is important that we notify the net::URLRequest only once. If we try to | 161 // It is important that we notify the net::URLRequest only once. If we try to |
182 // notify the request twice, it may no longer exist and |this| might have | 162 // notify the request twice, it may no longer exist and |this| might have |
183 // already have been deleted. | 163 // already have been deleted. |
184 DCHECK(!request_has_been_notified_); | 164 DCHECK(!request_has_been_notified_); |
185 if (request_has_been_notified_) | 165 if (request_has_been_notified_) |
186 return; | 166 return; |
187 | 167 |
188 request_has_been_notified_ = true; | 168 request_has_been_notified_ = true; |
189 | 169 |
190 // We're done with this object on the IO thread. | 170 // We're done with this object on the IO thread. |
191 Release(); | 171 Release(); |
192 } | 172 } |
OLD | NEW |