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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 navigation_handle->WillRedirectRequest( | 98 navigation_handle->WillRedirectRequest( |
| 94 new_validated_url, new_method_is_post, new_referrer_url, | 99 new_validated_url, new_method_is_post, new_referrer_url, |
| 95 new_is_external_protocol, headers, | 100 new_is_external_protocol, headers, |
| 96 base::Bind(&SendCheckResultToIOThread, callback)); | 101 base::Bind(&SendCheckResultToIOThread, callback)); |
| 97 } | 102 } |
| 98 | 103 |
| 99 void WillProcessResponseOnUIThread( | 104 void WillProcessResponseOnUIThread( |
| 100 UIChecksPerformedCallback callback, | 105 UIChecksPerformedCallback callback, |
| 101 int render_process_id, | 106 int render_process_id, |
| 102 int render_frame_host_id, | 107 int render_frame_host_id, |
| 103 scoped_refptr<net::HttpResponseHeaders> headers) { | 108 scoped_refptr<net::HttpResponseHeaders> headers, |
| 109 std::unique_ptr<NavigationData> navigation_data) { | |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 110 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 105 RenderFrameHostImpl* render_frame_host = | 111 RenderFrameHostImpl* render_frame_host = |
| 106 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 112 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
| 107 if (!render_frame_host) { | 113 if (!render_frame_host) { |
| 108 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 114 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 109 return; | 115 return; |
| 110 } | 116 } |
| 111 | 117 |
| 112 NavigationHandleImpl* navigation_handle = | 118 NavigationHandleImpl* navigation_handle = |
| 113 render_frame_host->navigation_handle(); | 119 render_frame_host->navigation_handle(); |
| 114 if (!navigation_handle) { | 120 if (!navigation_handle) { |
| 115 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 121 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 116 return; | 122 return; |
| 117 } | 123 } |
| 118 | 124 |
| 125 if (navigation_data.get()) { | |
|
nasko
2016/04/26 20:18:40
nit: No need for {} on one line if statements.
RyanSturm
2016/04/27 23:27:47
Done.
| |
| 126 navigation_handle->SetNavigationData(std::move(navigation_data)); | |
| 127 } | |
| 128 | |
| 119 navigation_handle->WillProcessResponse( | 129 navigation_handle->WillProcessResponse( |
| 120 render_frame_host, headers, | 130 render_frame_host, headers, |
| 121 base::Bind(&SendCheckResultToIOThread, callback)); | 131 base::Bind(&SendCheckResultToIOThread, callback)); |
| 122 } | 132 } |
| 123 | 133 |
| 124 } // namespace | 134 } // namespace |
| 125 | 135 |
| 126 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) | 136 NavigationResourceThrottle::NavigationResourceThrottle( |
| 127 : request_(request), weak_ptr_factory_(this) {} | 137 net::URLRequest* request, |
| 138 ResourceDispatcherHostImpl* rdh) | |
| 139 : request_(request), rdh_(rdh), weak_ptr_factory_(this) {} | |
| 128 | 140 |
| 129 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 141 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
| 130 | 142 |
| 131 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 143 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 144 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 133 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 145 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
| 134 if (!info) | 146 if (!info) |
| 135 return; | 147 return; |
| 136 | 148 |
| 137 int render_process_id, render_frame_id; | 149 int render_process_id, render_frame_id; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 return; | 220 return; |
| 209 | 221 |
| 210 // Send a copy of the response headers to the NavigationHandle on the UI | 222 // Send a copy of the response headers to the NavigationHandle on the UI |
| 211 // thread. | 223 // thread. |
| 212 scoped_refptr<net::HttpResponseHeaders> response_headers; | 224 scoped_refptr<net::HttpResponseHeaders> response_headers; |
| 213 if (request_->response_headers()) { | 225 if (request_->response_headers()) { |
| 214 response_headers = new net::HttpResponseHeaders( | 226 response_headers = new net::HttpResponseHeaders( |
| 215 request_->response_headers()->raw_headers()); | 227 request_->response_headers()->raw_headers()); |
| 216 } | 228 } |
| 217 | 229 |
| 230 // Ask the embedder for a NavigationData instance. | |
| 231 std::unique_ptr<NavigationData> navigation_data(nullptr); | |
| 232 if (rdh_ && rdh_->delegate()) | |
| 233 navigation_data = rdh_->delegate()->GetNavigationData(request_); | |
| 234 | |
| 235 // Clone the embedder NavigationData before moving it to the UI thread. | |
| 236 std::unique_ptr<NavigationData> clone(nullptr); | |
| 237 if (navigation_data.get()) | |
| 238 clone = navigation_data->Clone(); | |
| 239 | |
| 218 UIChecksPerformedCallback callback = | 240 UIChecksPerformedCallback callback = |
| 219 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | 241 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, |
| 220 weak_ptr_factory_.GetWeakPtr()); | 242 weak_ptr_factory_.GetWeakPtr()); |
| 221 | 243 |
| 222 BrowserThread::PostTask( | 244 BrowserThread::PostTask( |
| 223 BrowserThread::UI, FROM_HERE, | 245 BrowserThread::UI, FROM_HERE, |
| 224 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, | 246 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, |
| 225 render_frame_id, response_headers)); | 247 render_frame_id, response_headers, base::Passed(&clone))); |
| 226 *defer = true; | 248 *defer = true; |
| 227 } | 249 } |
| 228 | 250 |
| 229 const char* NavigationResourceThrottle::GetNameForLogging() const { | 251 const char* NavigationResourceThrottle::GetNameForLogging() const { |
| 230 return "NavigationResourceThrottle"; | 252 return "NavigationResourceThrottle"; |
| 231 } | 253 } |
| 232 | 254 |
| 233 void NavigationResourceThrottle::OnUIChecksPerformed( | 255 void NavigationResourceThrottle::OnUIChecksPerformed( |
| 234 NavigationThrottle::ThrottleCheckResult result) { | 256 NavigationThrottle::ThrottleCheckResult result) { |
| 235 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 257 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 236 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 258 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
| 237 controller()->CancelAndIgnore(); | 259 controller()->CancelAndIgnore(); |
| 238 } else if (result == NavigationThrottle::CANCEL) { | 260 } else if (result == NavigationThrottle::CANCEL) { |
| 239 controller()->Cancel(); | 261 controller()->Cancel(); |
| 240 } else { | 262 } else { |
| 241 controller()->Resume(); | 263 controller()->Resume(); |
| 242 } | 264 } |
| 243 } | 265 } |
| 244 | 266 |
| 245 } // namespace content | 267 } // namespace content |
| OLD | NEW |