| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "content/browser/frame_host/navigation_handle_impl.h" | 13 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 12 #include "content/browser/frame_host/render_frame_host_impl.h" | 14 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_data.h" |
| 14 #include "content/public/browser/resource_context.h" | 17 #include "content/public/browser/resource_context.h" |
| 15 #include "content/public/browser/resource_controller.h" | 18 #include "content/public/browser/resource_controller.h" |
| 19 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 16 #include "content/public/browser/resource_request_info.h" | 20 #include "content/public/browser/resource_request_info.h" |
| 17 #include "content/public/common/referrer.h" | 21 #include "content/public/common/referrer.h" |
| 18 #include "net/url_request/redirect_info.h" | 22 #include "net/url_request/redirect_info.h" |
| 19 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_job_factory.h" | 25 #include "net/url_request/url_request_job_factory.h" |
| 22 #include "ui/base/page_transition_types.h" | 26 #include "ui/base/page_transition_types.h" |
| 23 | 27 |
| 24 namespace content { | 28 namespace content { |
| 25 | 29 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ->FilterURL(false, &new_validated_url); | 96 ->FilterURL(false, &new_validated_url); |
| 93 navigation_handle->WillRedirectRequest( | 97 navigation_handle->WillRedirectRequest( |
| 94 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, | 98 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, |
| 95 headers, base::Bind(&SendCheckResultToIOThread, callback)); | 99 headers, base::Bind(&SendCheckResultToIOThread, callback)); |
| 96 } | 100 } |
| 97 | 101 |
| 98 void WillProcessResponseOnUIThread( | 102 void WillProcessResponseOnUIThread( |
| 99 UIChecksPerformedCallback callback, | 103 UIChecksPerformedCallback callback, |
| 100 int render_process_id, | 104 int render_process_id, |
| 101 int render_frame_host_id, | 105 int render_frame_host_id, |
| 102 scoped_refptr<net::HttpResponseHeaders> headers) { | 106 scoped_refptr<net::HttpResponseHeaders> headers, |
| 107 std::unique_ptr<NavigationData> navigation_data) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 108 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 104 RenderFrameHostImpl* render_frame_host = | 109 RenderFrameHostImpl* render_frame_host = |
| 105 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 110 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
| 106 if (!render_frame_host) { | 111 if (!render_frame_host) { |
| 107 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 112 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 108 return; | 113 return; |
| 109 } | 114 } |
| 110 | 115 |
| 111 NavigationHandleImpl* navigation_handle = | 116 NavigationHandleImpl* navigation_handle = |
| 112 render_frame_host->navigation_handle(); | 117 render_frame_host->navigation_handle(); |
| 113 if (!navigation_handle) { | 118 if (!navigation_handle) { |
| 114 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 119 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 115 return; | 120 return; |
| 116 } | 121 } |
| 117 | 122 |
| 123 if (navigation_data) |
| 124 navigation_handle->set_navigation_data(std::move(navigation_data)); |
| 125 |
| 118 navigation_handle->WillProcessResponse( | 126 navigation_handle->WillProcessResponse( |
| 119 render_frame_host, headers, | 127 render_frame_host, headers, |
| 120 base::Bind(&SendCheckResultToIOThread, callback)); | 128 base::Bind(&SendCheckResultToIOThread, callback)); |
| 121 } | 129 } |
| 122 | 130 |
| 123 } // namespace | 131 } // namespace |
| 124 | 132 |
| 125 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 133 NavigationResourceThrottle::NavigationResourceThrottle( |
| 126 : request_(request), weak_ptr_factory_(this) {} | 134 net::URLRequest* request, |
| 135 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate) |
| 136 : request_(request), |
| 137 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), |
| 138 weak_ptr_factory_(this) {} |
| 127 | 139 |
| 128 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 140 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
| 129 | 141 |
| 130 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 142 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 132 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 144 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
| 133 if (!info) | 145 if (!info) |
| 134 return; | 146 return; |
| 135 | 147 |
| 136 int render_process_id, render_frame_id; | 148 int render_process_id, render_frame_id; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return; | 218 return; |
| 207 | 219 |
| 208 // Send a copy of the response headers to the NavigationHandle on the UI | 220 // Send a copy of the response headers to the NavigationHandle on the UI |
| 209 // thread. | 221 // thread. |
| 210 scoped_refptr<net::HttpResponseHeaders> response_headers; | 222 scoped_refptr<net::HttpResponseHeaders> response_headers; |
| 211 if (request_->response_headers()) { | 223 if (request_->response_headers()) { |
| 212 response_headers = new net::HttpResponseHeaders( | 224 response_headers = new net::HttpResponseHeaders( |
| 213 request_->response_headers()->raw_headers()); | 225 request_->response_headers()->raw_headers()); |
| 214 } | 226 } |
| 215 | 227 |
| 228 std::unique_ptr<NavigationData> cloned_data; |
| 229 if (resource_dispatcher_host_delegate_) { |
| 230 // Ask the embedder for a NavigationData instance. |
| 231 NavigationData* navigation_data = |
| 232 resource_dispatcher_host_delegate_->GetNavigationData(request_); |
| 233 |
| 234 // Clone the embedder's NavigationData before moving it to the UI thread. |
| 235 if (navigation_data) |
| 236 cloned_data = navigation_data->Clone(); |
| 237 } |
| 238 |
| 216 UIChecksPerformedCallback callback = | 239 UIChecksPerformedCallback callback = |
| 217 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | 240 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, |
| 218 weak_ptr_factory_.GetWeakPtr()); | 241 weak_ptr_factory_.GetWeakPtr()); |
| 219 | 242 |
| 220 BrowserThread::PostTask( | 243 BrowserThread::PostTask( |
| 221 BrowserThread::UI, FROM_HERE, | 244 BrowserThread::UI, FROM_HERE, |
| 222 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, | 245 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
| 223 render_frame_id, response_headers)); | 246 render_frame_id, response_headers, |
| 247 base::Passed(&cloned_data))); |
| 224 *defer = true; | 248 *defer = true; |
| 225 } | 249 } |
| 226 | 250 |
| 227 const char* NavigationResourceThrottle::GetNameForLogging() const { | 251 const char* NavigationResourceThrottle::GetNameForLogging() const { |
| 228 return "NavigationResourceThrottle"; | 252 return "NavigationResourceThrottle"; |
| 229 } | 253 } |
| 230 | 254 |
| 231 void NavigationResourceThrottle::OnUIChecksPerformed( | 255 void NavigationResourceThrottle::OnUIChecksPerformed( |
| 232 NavigationThrottle::ThrottleCheckResult result) { | 256 NavigationThrottle::ThrottleCheckResult result) { |
| 233 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 257 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 244 // block main frame navigations in the future, we'll need to carefully | 268 // block main frame navigations in the future, we'll need to carefully |
| 245 // consider the right thing to do here. | 269 // consider the right thing to do here. |
| 246 DCHECK(!ResourceRequestInfo::ForRequest(request_)->IsMainFrame()); | 270 DCHECK(!ResourceRequestInfo::ForRequest(request_)->IsMainFrame()); |
| 247 controller()->CancelWithError(net::ERR_BLOCKED_BY_RESPONSE); | 271 controller()->CancelWithError(net::ERR_BLOCKED_BY_RESPONSE); |
| 248 } else { | 272 } else { |
| 249 controller()->Resume(); | 273 controller()->Resume(); |
| 250 } | 274 } |
| 251 } | 275 } |
| 252 | 276 |
| 253 } // namespace content | 277 } // namespace content |
| OLD | NEW |