Chromium Code Reviews| 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" |
| 15 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
| 13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/navigation_data.h" | |
| 14 #include "content/public/browser/resource_context.h" | 18 #include "content/public/browser/resource_context.h" |
| 15 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_dispatcher_host_delegate.h" | |
| 16 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 17 #include "content/public/common/referrer.h" | 22 #include "content/public/common/referrer.h" |
| 18 #include "net/url_request/redirect_info.h" | 23 #include "net/url_request/redirect_info.h" |
| 19 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
| 20 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
| 21 #include "net/url_request/url_request_job_factory.h" | 26 #include "net/url_request/url_request_job_factory.h" |
| 22 #include "ui/base/page_transition_types.h" | 27 #include "ui/base/page_transition_types.h" |
| 23 | 28 |
| 24 namespace content { | 29 namespace content { |
| 25 | 30 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 ->FilterURL(false, &new_validated_url); | 97 ->FilterURL(false, &new_validated_url); |
| 93 navigation_handle->WillRedirectRequest( | 98 navigation_handle->WillRedirectRequest( |
| 94 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, | 99 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, |
| 95 headers, base::Bind(&SendCheckResultToIOThread, callback)); | 100 headers, base::Bind(&SendCheckResultToIOThread, callback)); |
| 96 } | 101 } |
| 97 | 102 |
| 98 void WillProcessResponseOnUIThread( | 103 void WillProcessResponseOnUIThread( |
| 99 UIChecksPerformedCallback callback, | 104 UIChecksPerformedCallback callback, |
| 100 int render_process_id, | 105 int render_process_id, |
| 101 int render_frame_host_id, | 106 int render_frame_host_id, |
| 102 scoped_refptr<net::HttpResponseHeaders> headers) { | 107 scoped_refptr<net::HttpResponseHeaders> headers, |
| 108 std::unique_ptr<NavigationData> navigation_data) { | |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 109 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 104 RenderFrameHostImpl* render_frame_host = | 110 RenderFrameHostImpl* render_frame_host = |
| 105 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 111 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
| 106 if (!render_frame_host) { | 112 if (!render_frame_host) { |
| 107 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 113 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 108 return; | 114 return; |
| 109 } | 115 } |
| 110 | 116 |
| 111 NavigationHandleImpl* navigation_handle = | 117 NavigationHandleImpl* navigation_handle = |
| 112 render_frame_host->navigation_handle(); | 118 render_frame_host->navigation_handle(); |
| 113 if (!navigation_handle) { | 119 if (!navigation_handle) { |
| 114 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 120 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 115 return; | 121 return; |
| 116 } | 122 } |
| 117 | 123 |
| 124 if (navigation_data) | |
| 125 navigation_handle->SetNavigationData(std::move(navigation_data)); | |
| 126 | |
| 118 navigation_handle->WillProcessResponse( | 127 navigation_handle->WillProcessResponse( |
| 119 render_frame_host, headers, | 128 render_frame_host, headers, |
| 120 base::Bind(&SendCheckResultToIOThread, callback)); | 129 base::Bind(&SendCheckResultToIOThread, callback)); |
| 121 } | 130 } |
| 122 | 131 |
| 123 } // namespace | 132 } // namespace |
| 124 | 133 |
| 125 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 134 NavigationResourceThrottle::NavigationResourceThrottle( |
| 126 : request_(request), weak_ptr_factory_(this) {} | 135 net::URLRequest* request, |
| 136 ResourceDispatcherHostImpl* resource_dispatcher_host) | |
| 137 : request_(request), | |
| 138 resource_dispatcher_host_(resource_dispatcher_host), | |
| 139 weak_ptr_factory_(this) {} | |
| 127 | 140 |
| 128 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 141 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
| 129 | 142 |
| 130 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 143 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 144 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 132 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 145 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
| 133 if (!info) | 146 if (!info) |
| 134 return; | 147 return; |
| 135 | 148 |
| 136 int render_process_id, render_frame_id; | 149 int render_process_id, render_frame_id; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 return; | 219 return; |
| 207 | 220 |
| 208 // Send a copy of the response headers to the NavigationHandle on the UI | 221 // Send a copy of the response headers to the NavigationHandle on the UI |
| 209 // thread. | 222 // thread. |
| 210 scoped_refptr<net::HttpResponseHeaders> response_headers; | 223 scoped_refptr<net::HttpResponseHeaders> response_headers; |
| 211 if (request_->response_headers()) { | 224 if (request_->response_headers()) { |
| 212 response_headers = new net::HttpResponseHeaders( | 225 response_headers = new net::HttpResponseHeaders( |
| 213 request_->response_headers()->raw_headers()); | 226 request_->response_headers()->raw_headers()); |
| 214 } | 227 } |
| 215 | 228 |
| 229 // Ask the embedder for a NavigationData instance. | |
| 230 std::unique_ptr<NavigationData> navigation_data; | |
| 231 std::unique_ptr<NavigationData> clone; | |
|
nasko
2016/05/02 22:02:49
nit: Keep instances of the same code as identical
RyanSturm
2016/05/02 23:02:56
Done.
| |
| 232 if (resource_dispatcher_host_ && resource_dispatcher_host_->delegate()) { | |
| 233 navigation_data = | |
| 234 resource_dispatcher_host_->delegate()->GetNavigationData(request_); | |
| 235 | |
| 236 // Clone the embedder NavigationData before moving it to the UI thread. | |
| 237 if (navigation_data) | |
| 238 clone = navigation_data->Clone(); | |
| 239 } | |
| 240 | |
| 216 UIChecksPerformedCallback callback = | 241 UIChecksPerformedCallback callback = |
| 217 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | 242 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, |
| 218 weak_ptr_factory_.GetWeakPtr()); | 243 weak_ptr_factory_.GetWeakPtr()); |
| 219 | 244 |
| 220 BrowserThread::PostTask( | 245 BrowserThread::PostTask( |
| 221 BrowserThread::UI, FROM_HERE, | 246 BrowserThread::UI, FROM_HERE, |
| 222 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, | 247 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
| 223 render_frame_id, response_headers)); | 248 render_frame_id, response_headers, base::Passed(&clone))); |
| 224 *defer = true; | 249 *defer = true; |
| 225 } | 250 } |
| 226 | 251 |
| 227 const char* NavigationResourceThrottle::GetNameForLogging() const { | 252 const char* NavigationResourceThrottle::GetNameForLogging() const { |
| 228 return "NavigationResourceThrottle"; | 253 return "NavigationResourceThrottle"; |
| 229 } | 254 } |
| 230 | 255 |
| 231 void NavigationResourceThrottle::OnUIChecksPerformed( | 256 void NavigationResourceThrottle::OnUIChecksPerformed( |
| 232 NavigationThrottle::ThrottleCheckResult result) { | 257 NavigationThrottle::ThrottleCheckResult result) { |
| 233 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 258 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 234 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 259 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
| 235 controller()->CancelAndIgnore(); | 260 controller()->CancelAndIgnore(); |
| 236 } else if (result == NavigationThrottle::CANCEL) { | 261 } else if (result == NavigationThrottle::CANCEL) { |
| 237 controller()->Cancel(); | 262 controller()->Cancel(); |
| 238 } else { | 263 } else { |
| 239 controller()->Resume(); | 264 controller()->Resume(); |
| 240 } | 265 } |
| 241 } | 266 } |
| 242 | 267 |
| 243 } // namespace content | 268 } // namespace content |
| OLD | NEW |