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