Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/browser/loader/navigation_resource_throttle.cc

Issue 2397893002: Revert the merge of CrossSiteResourceHandler and NavigationResourceThrottle. (Closed)
Patch Set: Add back initialization of started_from_context_menu_. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/navigator.h" 15 #include "content/browser/frame_host/navigator.h"
16 #include "content/browser/frame_host/render_frame_host_impl.h" 16 #include "content/browser/frame_host/render_frame_host_impl.h"
17 #include "content/browser/loader/navigation_resource_handler.h" 17 #include "content/browser/loader/navigation_resource_handler.h"
18 #include "content/browser/loader/resource_dispatcher_host_impl.h"
19 #include "content/browser/loader/resource_loader.h"
20 #include "content/browser/loader/resource_request_info_impl.h" 18 #include "content/browser/loader/resource_request_info_impl.h"
21 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/navigation_data.h" 20 #include "content/public/browser/navigation_data.h"
23 #include "content/public/browser/resource_context.h" 21 #include "content/public/browser/resource_context.h"
24 #include "content/public/browser/resource_controller.h" 22 #include "content/public/browser/resource_controller.h"
25 #include "content/public/browser/resource_dispatcher_host_delegate.h" 23 #include "content/public/browser/resource_dispatcher_host_delegate.h"
26 #include "content/public/browser/resource_request_info.h" 24 #include "content/public/browser/resource_request_info.h"
27 #include "content/public/browser/ssl_status.h" 25 #include "content/public/browser/ssl_status.h"
28 #include "content/public/common/referrer.h" 26 #include "content/public/common/referrer.h"
29 #include "net/url_request/redirect_info.h" 27 #include "net/url_request/redirect_info.h"
30 #include "net/url_request/url_request.h" 28 #include "net/url_request/url_request.h"
31 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
32 #include "net/url_request/url_request_job_factory.h" 30 #include "net/url_request/url_request_job_factory.h"
33 #include "ui/base/page_transition_types.h" 31 #include "ui/base/page_transition_types.h"
34 32
35 namespace content { 33 namespace content {
36 34
37 namespace { 35 namespace {
38 36
39 // Used in unit tests to make UI thread checks succeed even if there is no 37 // Used in unit tests to make UI thread checks succeed even if there is no
40 // NavigationHandle. 38 // NavigationHandle.
41 bool g_ui_checks_always_succeed = false; 39 bool g_ui_checks_always_succeed = false;
42 40
43 // Used in unit tests to transfer all navigations.
44 bool g_force_transfer = false;
45
46 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> 41 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
47 UIChecksPerformedCallback; 42 UIChecksPerformedCallback;
48 43
49 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, 44 void SendCheckResultToIOThread(UIChecksPerformedCallback callback,
50 NavigationThrottle::ThrottleCheckResult result) { 45 NavigationThrottle::ThrottleCheckResult result) {
51 DCHECK_CURRENTLY_ON(BrowserThread::UI); 46 DCHECK_CURRENTLY_ON(BrowserThread::UI);
52 DCHECK_NE(result, NavigationThrottle::DEFER); 47 DCHECK_NE(result, NavigationThrottle::DEFER);
53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 48 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
54 base::Bind(callback, result)); 49 base::Bind(callback, result));
55 } 50 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 new_validated_url, new_method, new_referrer_url, new_is_external_protocol, 132 new_validated_url, new_method, new_referrer_url, new_is_external_protocol,
138 headers, base::Bind(&SendCheckResultToIOThread, callback)); 133 headers, base::Bind(&SendCheckResultToIOThread, callback));
139 } 134 }
140 135
141 void WillProcessResponseOnUIThread( 136 void WillProcessResponseOnUIThread(
142 UIChecksPerformedCallback callback, 137 UIChecksPerformedCallback callback,
143 int render_process_id, 138 int render_process_id,
144 int render_frame_host_id, 139 int render_frame_host_id,
145 scoped_refptr<net::HttpResponseHeaders> headers, 140 scoped_refptr<net::HttpResponseHeaders> headers,
146 const SSLStatus& ssl_status, 141 const SSLStatus& ssl_status,
147 const GlobalRequestID& request_id,
148 bool should_replace_current_entry,
149 bool is_download,
150 bool is_stream,
151 const base::Closure& transfer_callback,
152 std::unique_ptr<NavigationData> navigation_data) { 142 std::unique_ptr<NavigationData> navigation_data) {
153 DCHECK_CURRENTLY_ON(BrowserThread::UI); 143 DCHECK_CURRENTLY_ON(BrowserThread::UI);
154
155 if (g_force_transfer) {
156 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, transfer_callback);
157 }
158
159 NavigationHandleImpl* navigation_handle = 144 NavigationHandleImpl* navigation_handle =
160 FindNavigationHandle(render_process_id, render_frame_host_id, callback); 145 FindNavigationHandle(render_process_id, render_frame_host_id, callback);
161 if (!navigation_handle) 146 if (!navigation_handle)
162 return; 147 return;
163 148
164 if (navigation_data) 149 if (navigation_data)
165 navigation_handle->set_navigation_data(std::move(navigation_data)); 150 navigation_handle->set_navigation_data(std::move(navigation_data));
166 151
167 RenderFrameHostImpl* render_frame_host = 152 RenderFrameHostImpl* render_frame_host =
168 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); 153 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
169 DCHECK(render_frame_host); 154 DCHECK(render_frame_host);
170 navigation_handle->WillProcessResponse( 155 navigation_handle->WillProcessResponse(
171 render_frame_host, headers, ssl_status, request_id, 156 render_frame_host, headers, ssl_status,
172 should_replace_current_entry, is_download, is_stream, transfer_callback,
173 base::Bind(&SendCheckResultToIOThread, callback)); 157 base::Bind(&SendCheckResultToIOThread, callback));
174 } 158 }
175 159
176 } // namespace 160 } // namespace
177 161
178 NavigationResourceThrottle::NavigationResourceThrottle( 162 NavigationResourceThrottle::NavigationResourceThrottle(
179 net::URLRequest* request, 163 net::URLRequest* request,
180 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate, 164 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate,
181 RequestContextType request_context_type) 165 RequestContextType request_context_type)
182 : request_(request), 166 : request_(request),
183 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), 167 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate),
184 request_context_type_(request_context_type), 168 request_context_type_(request_context_type),
185 in_cross_site_transition_(false),
186 on_transfer_done_result_(NavigationThrottle::DEFER),
187 weak_ptr_factory_(this) {} 169 weak_ptr_factory_(this) {}
188 170
189 NavigationResourceThrottle::~NavigationResourceThrottle() {} 171 NavigationResourceThrottle::~NavigationResourceThrottle() {}
190 172
191 void NavigationResourceThrottle::WillStartRequest(bool* defer) { 173 void NavigationResourceThrottle::WillStartRequest(bool* defer) {
192 DCHECK_CURRENTLY_ON(BrowserThread::IO); 174 DCHECK_CURRENTLY_ON(BrowserThread::IO);
193 const ResourceRequestInfoImpl* info = 175 const ResourceRequestInfoImpl* info =
194 ResourceRequestInfoImpl::ForRequest(request_); 176 ResourceRequestInfoImpl::ForRequest(request_);
195 if (!info) 177 if (!info)
196 return; 178 return;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 BrowserThread::UI, FROM_HERE, 237 BrowserThread::UI, FROM_HERE,
256 base::Bind(&CheckWillRedirectRequestOnUIThread, callback, 238 base::Bind(&CheckWillRedirectRequestOnUIThread, callback,
257 render_process_id, render_frame_id, redirect_info.new_url, 239 render_process_id, render_frame_id, redirect_info.new_url,
258 redirect_info.new_method, GURL(redirect_info.new_referrer), 240 redirect_info.new_method, GURL(redirect_info.new_referrer),
259 new_is_external_protocol, response_headers)); 241 new_is_external_protocol, response_headers));
260 *defer = true; 242 *defer = true;
261 } 243 }
262 244
263 void NavigationResourceThrottle::WillProcessResponse(bool* defer) { 245 void NavigationResourceThrottle::WillProcessResponse(bool* defer) {
264 DCHECK_CURRENTLY_ON(BrowserThread::IO); 246 DCHECK_CURRENTLY_ON(BrowserThread::IO);
265 const ResourceRequestInfoImpl* info = 247 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
266 ResourceRequestInfoImpl::ForRequest(request_);
267 if (!info) 248 if (!info)
268 return; 249 return;
269 250
270 int render_process_id, render_frame_id; 251 int render_process_id, render_frame_id;
271 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) 252 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
272 return; 253 return;
273 254
274 // Send a copy of the response headers to the NavigationHandle on the UI 255 // Send a copy of the response headers to the NavigationHandle on the UI
275 // thread. 256 // thread.
276 scoped_refptr<net::HttpResponseHeaders> response_headers; 257 scoped_refptr<net::HttpResponseHeaders> response_headers;
277 if (request_->response_headers()) { 258 if (request_->response_headers()) {
278 response_headers = new net::HttpResponseHeaders( 259 response_headers = new net::HttpResponseHeaders(
279 request_->response_headers()->raw_headers()); 260 request_->response_headers()->raw_headers());
280 } 261 }
281 262
282 std::unique_ptr<NavigationData> cloned_data; 263 std::unique_ptr<NavigationData> cloned_data;
283 if (resource_dispatcher_host_delegate_) { 264 if (resource_dispatcher_host_delegate_) {
284 // Ask the embedder for a NavigationData instance. 265 // Ask the embedder for a NavigationData instance.
285 NavigationData* navigation_data = 266 NavigationData* navigation_data =
286 resource_dispatcher_host_delegate_->GetNavigationData(request_); 267 resource_dispatcher_host_delegate_->GetNavigationData(request_);
287 268
288 // Clone the embedder's NavigationData before moving it to the UI thread. 269 // Clone the embedder's NavigationData before moving it to the UI thread.
289 if (navigation_data) 270 if (navigation_data)
290 cloned_data = navigation_data->Clone(); 271 cloned_data = navigation_data->Clone();
291 } 272 }
292 273
293 UIChecksPerformedCallback callback = 274 UIChecksPerformedCallback callback =
294 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, 275 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
295 weak_ptr_factory_.GetWeakPtr()); 276 weak_ptr_factory_.GetWeakPtr());
296 base::Closure transfer_callback =
297 base::Bind(&NavigationResourceThrottle::InitiateTransfer,
298 weak_ptr_factory_.GetWeakPtr());
299 277
300 SSLStatus ssl_status; 278 SSLStatus ssl_status;
301 if (request_->ssl_info().cert.get()) { 279 if (request_->ssl_info().cert.get()) {
302 NavigationResourceHandler::GetSSLStatusForRequest( 280 NavigationResourceHandler::GetSSLStatusForRequest(
303 request_->url(), request_->ssl_info(), info->GetChildID(), &ssl_status); 281 request_->url(), request_->ssl_info(), info->GetChildID(), &ssl_status);
304 } 282 }
305 283
306 BrowserThread::PostTask( 284 BrowserThread::PostTask(
307 BrowserThread::UI, FROM_HERE, 285 BrowserThread::UI, FROM_HERE,
308 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id, 286 base::Bind(&WillProcessResponseOnUIThread, callback, render_process_id,
309 render_frame_id, response_headers, ssl_status, 287 render_frame_id, response_headers, ssl_status,
310 info->GetGlobalRequestID(),
311 info->should_replace_current_entry(), info->IsDownload(),
312 info->is_stream(), transfer_callback,
313 base::Passed(&cloned_data))); 288 base::Passed(&cloned_data)));
314 *defer = true; 289 *defer = true;
315 } 290 }
316 291
317 const char* NavigationResourceThrottle::GetNameForLogging() const { 292 const char* NavigationResourceThrottle::GetNameForLogging() const {
318 return "NavigationResourceThrottle"; 293 return "NavigationResourceThrottle";
319 } 294 }
320 295
321 void NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing( 296 void NavigationResourceThrottle::set_ui_checks_always_succeed_for_testing(
322 bool ui_checks_always_succeed) { 297 bool ui_checks_always_succeed) {
323 g_ui_checks_always_succeed = ui_checks_always_succeed; 298 g_ui_checks_always_succeed = ui_checks_always_succeed;
324 } 299 }
325 300
326 void NavigationResourceThrottle::set_force_transfer_for_testing(
327 bool force_transfer) {
328 g_force_transfer = force_transfer;
329 }
330
331 void NavigationResourceThrottle::OnUIChecksPerformed( 301 void NavigationResourceThrottle::OnUIChecksPerformed(
332 NavigationThrottle::ThrottleCheckResult result) { 302 NavigationThrottle::ThrottleCheckResult result) {
333 DCHECK_CURRENTLY_ON(BrowserThread::IO); 303 DCHECK_CURRENTLY_ON(BrowserThread::IO);
334 DCHECK_NE(NavigationThrottle::DEFER, result);
335 if (in_cross_site_transition_) {
336 on_transfer_done_result_ = result;
337 return;
338 }
339
340 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { 304 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
341 controller()->CancelAndIgnore(); 305 controller()->CancelAndIgnore();
342 } else if (result == NavigationThrottle::CANCEL) { 306 } else if (result == NavigationThrottle::CANCEL) {
343 controller()->Cancel(); 307 controller()->Cancel();
344 } else if (result == NavigationThrottle::BLOCK_REQUEST) { 308 } else if (result == NavigationThrottle::BLOCK_REQUEST) {
345 controller()->CancelWithError(net::ERR_BLOCKED_BY_CLIENT); 309 controller()->CancelWithError(net::ERR_BLOCKED_BY_CLIENT);
346 } else { 310 } else {
347 controller()->Resume(); 311 controller()->Resume();
348 } 312 }
349 } 313 }
350 314
351 void NavigationResourceThrottle::InitiateTransfer() {
352 DCHECK_CURRENTLY_ON(BrowserThread::IO);
353 in_cross_site_transition_ = true;
354 ResourceRequestInfoImpl* info =
355 ResourceRequestInfoImpl::ForRequest(request_);
356 ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(
357 info->GetGlobalRequestID(),
358 base::Bind(&NavigationResourceThrottle::OnTransferComplete,
359 weak_ptr_factory_.GetWeakPtr()));
360 }
361
362 void NavigationResourceThrottle::OnTransferComplete() {
363 DCHECK_CURRENTLY_ON(BrowserThread::IO);
364 DCHECK(in_cross_site_transition_);
365 in_cross_site_transition_ = false;
366
367 // If the results of the checks on the UI thread are known, unblock the
368 // navigation. Otherwise, wait until the callback has executed.
369 if (on_transfer_done_result_ != NavigationThrottle::DEFER) {
370 OnUIChecksPerformed(on_transfer_done_result_);
371 on_transfer_done_result_ = NavigationThrottle::DEFER;
372 }
373 }
374
375 } // namespace content 315 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/navigation_resource_throttle.h ('k') | content/browser/loader/resource_dispatcher_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698