OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
6 | 6 |
7 #include "chrome/browser/browser_thread.h" | 7 #include "chrome/browser/browser_thread.h" |
8 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 8 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
9 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" | 9 #include "chrome/browser/renderer_host/resource_dispatcher_host_request_info.h" |
10 #include "chrome/browser/ssl/ssl_cert_error_handler.h" | 10 #include "chrome/browser/ssl/ssl_cert_error_handler.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "chrome/browser/tab_contents/tab_util.h" | 12 #include "chrome/browser/tab_contents/tab_util.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
15 | 15 |
16 SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, | 16 SSLErrorHandler::SSLErrorHandler(ResourceDispatcherHost* rdh, |
17 URLRequest* request, | 17 net::URLRequest* request, |
18 ResourceType::Type resource_type, | 18 ResourceType::Type resource_type, |
19 const std::string& frame_origin, | 19 const std::string& frame_origin, |
20 const std::string& main_frame_origin) | 20 const std::string& main_frame_origin) |
21 : manager_(NULL), | 21 : manager_(NULL), |
22 request_id_(0, 0), | 22 request_id_(0, 0), |
23 resource_dispatcher_host_(rdh), | 23 resource_dispatcher_host_(rdh), |
24 request_url_(request->url()), | 24 request_url_(request->url()), |
25 resource_type_(resource_type), | 25 resource_type_(resource_type), |
26 frame_origin_(frame_origin), | 26 frame_origin_(frame_origin), |
27 main_frame_origin_(main_frame_origin), | 27 main_frame_origin_(main_frame_origin), |
28 request_has_been_notified_(false) { | 28 request_has_been_notified_(false) { |
29 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
30 | 30 |
31 ResourceDispatcherHostRequestInfo* info = | 31 ResourceDispatcherHostRequestInfo* info = |
32 ResourceDispatcherHost::InfoForRequest(request); | 32 ResourceDispatcherHost::InfoForRequest(request); |
33 request_id_.child_id = info->child_id(); | 33 request_id_.child_id = info->child_id(); |
34 request_id_.request_id = info->request_id(); | 34 request_id_.request_id = info->request_id(); |
35 | 35 |
36 if (!ResourceDispatcherHost::RenderViewForRequest(request, | 36 if (!ResourceDispatcherHost::RenderViewForRequest(request, |
37 &render_process_host_id_, | 37 &render_process_host_id_, |
38 &tab_contents_id_)) | 38 &tab_contents_id_)) |
39 NOTREACHED(); | 39 NOTREACHED(); |
40 | 40 |
41 // This makes sure we don't disappear on the IO thread until we've given an | 41 // This makes sure we don't disappear on the IO thread until we've given an |
42 // answer to the URLRequest. | 42 // answer to the net::URLRequest. |
43 // | 43 // |
44 // Release in CompleteCancelRequest, CompleteContinueRequest, or | 44 // Release in CompleteCancelRequest, CompleteContinueRequest, or |
45 // CompleteTakeNoAction. | 45 // CompleteTakeNoAction. |
46 AddRef(); | 46 AddRef(); |
47 } | 47 } |
48 | 48 |
49 SSLErrorHandler::~SSLErrorHandler() {} | 49 SSLErrorHandler::~SSLErrorHandler() {} |
50 | 50 |
51 void SSLErrorHandler::OnDispatchFailed() { | 51 void SSLErrorHandler::OnDispatchFailed() { |
52 TakeNoAction(); | 52 TakeNoAction(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 // We need to complete this task on the IO thread. | 113 // We need to complete this task on the IO thread. |
114 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
115 BrowserThread::IO, FROM_HERE, | 115 BrowserThread::IO, FROM_HERE, |
116 NewRunnableMethod(this, &SSLErrorHandler::CompleteTakeNoAction)); | 116 NewRunnableMethod(this, &SSLErrorHandler::CompleteTakeNoAction)); |
117 } | 117 } |
118 | 118 |
119 void SSLErrorHandler::CompleteCancelRequest(int error) { | 119 void SSLErrorHandler::CompleteCancelRequest(int error) { |
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
121 | 121 |
122 // It is important that we notify the URLRequest only once. If we try to | 122 // It is important that we notify the net::URLRequest only once. If we try |
123 // notify the request twice, it may no longer exist and |this| might have | 123 // to notify the request twice, it may no longer exist and |this| might have |
124 // already have been deleted. | 124 // already have been deleted. |
125 DCHECK(!request_has_been_notified_); | 125 DCHECK(!request_has_been_notified_); |
126 if (request_has_been_notified_) | 126 if (request_has_been_notified_) |
127 return; | 127 return; |
128 | 128 |
129 URLRequest* request = resource_dispatcher_host_->GetURLRequest(request_id_); | 129 net::URLRequest* request = |
| 130 resource_dispatcher_host_->GetURLRequest(request_id_); |
130 if (request) { | 131 if (request) { |
131 // The request can be NULL if it was cancelled by the renderer (as the | 132 // The request can be NULL if it was cancelled by the renderer (as the |
132 // result of the user navigating to a new page from the location bar). | 133 // result of the user navigating to a new page from the location bar). |
133 DVLOG(1) << "CompleteCancelRequest() url: " << request->url().spec(); | 134 DVLOG(1) << "CompleteCancelRequest() url: " << request->url().spec(); |
134 SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler(); | 135 SSLCertErrorHandler* cert_error = AsSSLCertErrorHandler(); |
135 if (cert_error) | 136 if (cert_error) |
136 request->SimulateSSLError(error, cert_error->ssl_info()); | 137 request->SimulateSSLError(error, cert_error->ssl_info()); |
137 else | 138 else |
138 request->SimulateError(error); | 139 request->SimulateError(error); |
139 } | 140 } |
140 request_has_been_notified_ = true; | 141 request_has_been_notified_ = true; |
141 | 142 |
142 // We're done with this object on the IO thread. | 143 // We're done with this object on the IO thread. |
143 Release(); | 144 Release(); |
144 } | 145 } |
145 | 146 |
146 void SSLErrorHandler::CompleteContinueRequest() { | 147 void SSLErrorHandler::CompleteContinueRequest() { |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
148 | 149 |
149 // It is important that we notify the URLRequest only once. If we try to | 150 // It is important that we notify the net::URLRequest only once. If we try to |
150 // notify the request twice, it may no longer exist and |this| might have | 151 // notify the request twice, it may no longer exist and |this| might have |
151 // already have been deleted. | 152 // already have been deleted. |
152 DCHECK(!request_has_been_notified_); | 153 DCHECK(!request_has_been_notified_); |
153 if (request_has_been_notified_) | 154 if (request_has_been_notified_) |
154 return; | 155 return; |
155 | 156 |
156 URLRequest* request = resource_dispatcher_host_->GetURLRequest(request_id_); | 157 net::URLRequest* request = |
| 158 resource_dispatcher_host_->GetURLRequest(request_id_); |
157 if (request) { | 159 if (request) { |
158 // The request can be NULL if it was cancelled by the renderer (as the | 160 // The request can be NULL if it was cancelled by the renderer (as the |
159 // result of the user navigating to a new page from the location bar). | 161 // result of the user navigating to a new page from the location bar). |
160 DVLOG(1) << "CompleteContinueRequest() url: " << request->url().spec(); | 162 DVLOG(1) << "CompleteContinueRequest() url: " << request->url().spec(); |
161 request->ContinueDespiteLastError(); | 163 request->ContinueDespiteLastError(); |
162 } | 164 } |
163 request_has_been_notified_ = true; | 165 request_has_been_notified_ = true; |
164 | 166 |
165 // We're done with this object on the IO thread. | 167 // We're done with this object on the IO thread. |
166 Release(); | 168 Release(); |
167 } | 169 } |
168 | 170 |
169 void SSLErrorHandler::CompleteTakeNoAction() { | 171 void SSLErrorHandler::CompleteTakeNoAction() { |
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
171 | 173 |
172 // It is important that we notify the URLRequest only once. If we try to | 174 // It is important that we notify the net::URLRequest only once. If we try to |
173 // notify the request twice, it may no longer exist and |this| might have | 175 // notify the request twice, it may no longer exist and |this| might have |
174 // already have been deleted. | 176 // already have been deleted. |
175 DCHECK(!request_has_been_notified_); | 177 DCHECK(!request_has_been_notified_); |
176 if (request_has_been_notified_) | 178 if (request_has_been_notified_) |
177 return; | 179 return; |
178 | 180 |
179 request_has_been_notified_ = true; | 181 request_has_been_notified_ = true; |
180 | 182 |
181 // We're done with this object on the IO thread. | 183 // We're done with this object on the IO thread. |
182 Release(); | 184 Release(); |
183 } | 185 } |
OLD | NEW |