OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/loader/navigation_resource_throttle.h" | 5 #include "content/browser/loader/navigation_resource_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "content/browser/frame_host/navigation_handle_impl.h" | 14 #include "content/browser/frame_host/navigation_handle_impl.h" |
15 #include "content/browser/frame_host/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 16 #include "content/browser/loader/resource_loader.h" |
16 #include "content/browser/loader/resource_request_info_impl.h" | 17 #include "content/browser/loader/resource_request_info_impl.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/navigation_data.h" | 19 #include "content/public/browser/navigation_data.h" |
19 #include "content/public/browser/resource_context.h" | 20 #include "content/public/browser/resource_context.h" |
20 #include "content/public/browser/resource_controller.h" | 21 #include "content/public/browser/resource_controller.h" |
21 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 22 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
22 #include "content/public/browser/resource_request_info.h" | 23 #include "content/public/browser/resource_request_info.h" |
23 #include "content/public/common/referrer.h" | 24 #include "content/public/common/referrer.h" |
| 25 #include "content/public/common/ssl_status.h" |
24 #include "net/url_request/redirect_info.h" | 26 #include "net/url_request/redirect_info.h" |
25 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
26 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
27 #include "net/url_request/url_request_job_factory.h" | 29 #include "net/url_request/url_request_job_factory.h" |
28 #include "ui/base/page_transition_types.h" | 30 #include "ui/base/page_transition_types.h" |
29 | 31 |
30 namespace content { | 32 namespace content { |
31 | 33 |
32 namespace { | 34 namespace { |
33 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> | 35 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 navigation_handle->WillRedirectRequest( | 106 navigation_handle->WillRedirectRequest( |
105 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, | 107 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, |
106 headers, base::Bind(&SendCheckResultToIOThread, callback)); | 108 headers, base::Bind(&SendCheckResultToIOThread, callback)); |
107 } | 109 } |
108 | 110 |
109 void WillProcessResponseOnUIThread( | 111 void WillProcessResponseOnUIThread( |
110 UIChecksPerformedCallback callback, | 112 UIChecksPerformedCallback callback, |
111 int render_process_id, | 113 int render_process_id, |
112 int render_frame_host_id, | 114 int render_frame_host_id, |
113 scoped_refptr<net::HttpResponseHeaders> headers, | 115 scoped_refptr<net::HttpResponseHeaders> headers, |
| 116 const SSLStatus& ssl_status, |
114 std::unique_ptr<NavigationData> navigation_data) { | 117 std::unique_ptr<NavigationData> navigation_data) { |
115 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
116 RenderFrameHostImpl* render_frame_host = | 119 RenderFrameHostImpl* render_frame_host = |
117 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 120 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
118 if (!render_frame_host) { | 121 if (!render_frame_host) { |
119 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 122 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
120 return; | 123 return; |
121 } | 124 } |
122 | 125 |
123 NavigationHandleImpl* navigation_handle = | 126 NavigationHandleImpl* navigation_handle = |
124 render_frame_host->navigation_handle(); | 127 render_frame_host->navigation_handle(); |
125 if (!navigation_handle) { | 128 if (!navigation_handle) { |
126 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 129 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
127 return; | 130 return; |
128 } | 131 } |
129 | 132 |
130 if (navigation_data) | 133 if (navigation_data) |
131 navigation_handle->set_navigation_data(std::move(navigation_data)); | 134 navigation_handle->set_navigation_data(std::move(navigation_data)); |
132 | 135 |
133 navigation_handle->WillProcessResponse( | 136 navigation_handle->WillProcessResponse( |
134 render_frame_host, headers, | 137 render_frame_host, headers, ssl_status, |
135 base::Bind(&SendCheckResultToIOThread, callback)); | 138 base::Bind(&SendCheckResultToIOThread, callback)); |
136 } | 139 } |
137 | 140 |
138 } // namespace | 141 } // namespace |
139 | 142 |
140 NavigationResourceThrottle::NavigationResourceThrottle( | 143 NavigationResourceThrottle::NavigationResourceThrottle( |
141 net::URLRequest* request, | 144 net::URLRequest* request, |
142 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate, | 145 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate, |
| 146 CertStore* cert_store, |
143 RequestContextType request_context_type) | 147 RequestContextType request_context_type) |
144 : request_(request), | 148 : request_(request), |
145 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), | 149 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), |
| 150 cert_store_(cert_store), |
146 request_context_type_(request_context_type), | 151 request_context_type_(request_context_type), |
147 weak_ptr_factory_(this) {} | 152 weak_ptr_factory_(this) {} |
148 | 153 |
149 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 154 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
150 | 155 |
151 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 156 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
152 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 157 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
153 const ResourceRequestInfoImpl* info = | 158 const ResourceRequestInfoImpl* info = |
154 ResourceRequestInfoImpl::ForRequest(request_); | 159 ResourceRequestInfoImpl::ForRequest(request_); |
155 if (!info) | 160 if (!info) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 251 |
247 // Clone the embedder's NavigationData before moving it to the UI thread. | 252 // Clone the embedder's NavigationData before moving it to the UI thread. |
248 if (navigation_data) | 253 if (navigation_data) |
249 cloned_data = navigation_data->Clone(); | 254 cloned_data = navigation_data->Clone(); |
250 } | 255 } |
251 | 256 |
252 UIChecksPerformedCallback callback = | 257 UIChecksPerformedCallback callback = |
253 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | 258 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, |
254 weak_ptr_factory_.GetWeakPtr()); | 259 weak_ptr_factory_.GetWeakPtr()); |
255 | 260 |
| 261 SSLStatus ssl_status; |
| 262 if (request_->ssl_info().cert.get()) { |
| 263 ResourceLoader::GetSSLStatusForRequest( |
| 264 request_->url(), request_->ssl_info(), info->GetChildID(), |
| 265 cert_store_, &ssl_status); |
| 266 } |
| 267 |
256 BrowserThread::PostTask( | 268 BrowserThread::PostTask( |
257 BrowserThread::UI, FROM_HERE, | 269 BrowserThread::UI, FROM_HERE, |
258 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, | 270 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
259 render_frame_id, response_headers, | 271 render_frame_id, response_headers, ssl_status, |
260 base::Passed(&cloned_data))); | 272 base::Passed(&cloned_data))); |
261 *defer = true; | 273 *defer = true; |
262 } | 274 } |
263 | 275 |
264 const char* NavigationResourceThrottle::GetNameForLogging() const { | 276 const char* NavigationResourceThrottle::GetNameForLogging() const { |
265 return "NavigationResourceThrottle"; | 277 return "NavigationResourceThrottle"; |
266 } | 278 } |
267 | 279 |
268 void NavigationResourceThrottle::OnUIChecksPerformed( | 280 void NavigationResourceThrottle::OnUIChecksPerformed( |
269 NavigationThrottle::ThrottleCheckResult result) { | 281 NavigationThrottle::ThrottleCheckResult result) { |
270 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 282 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
271 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 283 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
272 controller()->CancelAndIgnore(); | 284 controller()->CancelAndIgnore(); |
273 } else if (result == NavigationThrottle::CANCEL) { | 285 } else if (result == NavigationThrottle::CANCEL) { |
274 controller()->Cancel(); | 286 controller()->Cancel(); |
275 } else if (result == NavigationThrottle::BLOCK_REQUEST) { | 287 } else if (result == NavigationThrottle::BLOCK_REQUEST) { |
276 controller()->CancelWithError(net::ERR_BLOCKED_BY_CLIENT); | 288 controller()->CancelWithError(net::ERR_BLOCKED_BY_CLIENT); |
277 } else { | 289 } else { |
278 controller()->Resume(); | 290 controller()->Resume(); |
279 } | 291 } |
280 } | 292 } |
281 | 293 |
282 } // namespace content | 294 } // namespace content |
OLD | NEW |