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