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

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 1811913003: PlzNavigate: support NavigationThrottle::WillProcessResponse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on top of 1832803002 Created 4 years, 9 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
« no previous file with comments | « content/browser/frame_host/navigation_request.h ('k') | content/browser/frame_host/navigator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/frame_host/navigation_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/devtools/render_frame_devtools_agent_host.h" 9 #include "content/browser/devtools/render_frame_devtools_agent_host.h"
10 #include "content/browser/frame_host/frame_tree.h" 10 #include "content/browser/frame_host/frame_tree.h"
11 #include "content/browser/frame_host/frame_tree_node.h" 11 #include "content/browser/frame_host/frame_tree_node.h"
12 #include "content/browser/frame_host/navigation_controller_impl.h" 12 #include "content/browser/frame_host/navigation_controller_impl.h"
13 #include "content/browser/frame_host/navigation_handle_impl.h" 13 #include "content/browser/frame_host/navigation_handle_impl.h"
14 #include "content/browser/frame_host/navigation_request_info.h" 14 #include "content/browser/frame_host/navigation_request_info.h"
15 #include "content/browser/frame_host/navigator.h" 15 #include "content/browser/frame_host/navigator.h"
16 #include "content/browser/frame_host/navigator_impl.h"
16 #include "content/browser/loader/navigation_url_loader.h" 17 #include "content/browser/loader/navigation_url_loader.h"
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" 18 #include "content/browser/service_worker/service_worker_context_wrapper.h"
18 #include "content/browser/service_worker/service_worker_navigation_handle.h" 19 #include "content/browser/service_worker/service_worker_navigation_handle.h"
19 #include "content/browser/site_instance_impl.h" 20 #include "content/browser/site_instance_impl.h"
20 #include "content/common/resource_request_body.h" 21 #include "content/common/resource_request_body.h"
21 #include "content/public/browser/browser_context.h" 22 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
23 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
24 #include "content/public/browser/stream_handle.h" 25 #include "content/public/browser/stream_handle.h"
25 #include "content/public/common/content_client.h" 26 #include "content/public/common/content_client.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 common_params_.referrer), 218 common_params_.referrer),
218 begin_params_.has_user_gesture, common_params_.transition, false, 219 begin_params_.has_user_gesture, common_params_.transition, false,
219 base::Bind(&NavigationRequest::OnStartChecksComplete, 220 base::Bind(&NavigationRequest::OnStartChecksComplete,
220 base::Unretained(this))); 221 base::Unretained(this)));
221 return; 222 return;
222 } 223 }
223 224
224 // There is no need to make a network request for this navigation, so commit 225 // There is no need to make a network request for this navigation, so commit
225 // it immediately. 226 // it immediately.
226 state_ = RESPONSE_STARTED; 227 state_ = RESPONSE_STARTED;
227 frame_tree_node_->navigator()->CommitNavigation( 228
228 this, nullptr, scoped_ptr<StreamHandle>()); 229 // Select an appropriate RenderFrameHost.
230 RenderFrameHostImpl* render_frame_host =
231 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this);
232 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
233 common_params_.url);
234
235 // Inform the NavigationHandle that the navigation will commit.
236 navigation_handle_->ReadyToCommitNavigation(render_frame_host);
237
238 CommitNavigation();
229 } 239 }
230 240
231 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 241 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) {
232 // TODO(nasko): Update the NavigationHandle creation to ensure that the 242 // TODO(nasko): Update the NavigationHandle creation to ensure that the
233 // proper values are specified for is_synchronous and is_srcdoc. 243 // proper values are specified for is_synchronous and is_srcdoc.
234 navigation_handle_ = NavigationHandleImpl::Create( 244 navigation_handle_ = NavigationHandleImpl::Create(
235 common_params_.url, frame_tree_node_, 245 common_params_.url, frame_tree_node_,
236 false, // is_synchronous 246 false, // is_synchronous
237 false, // is_srcdoc 247 false, // is_srcdoc
238 common_params_.navigation_start, pending_nav_entry_id); 248 common_params_.navigation_start, pending_nav_entry_id);
(...skipping 23 matching lines...) Expand all
262 base::Bind(&NavigationRequest::OnRedirectChecksComplete, 272 base::Bind(&NavigationRequest::OnRedirectChecksComplete,
263 base::Unretained(this))); 273 base::Unretained(this)));
264 } 274 }
265 275
266 void NavigationRequest::OnResponseStarted( 276 void NavigationRequest::OnResponseStarted(
267 const scoped_refptr<ResourceResponse>& response, 277 const scoped_refptr<ResourceResponse>& response,
268 scoped_ptr<StreamHandle> body) { 278 scoped_ptr<StreamHandle> body) {
269 DCHECK(state_ == STARTED); 279 DCHECK(state_ == STARTED);
270 state_ = RESPONSE_STARTED; 280 state_ = RESPONSE_STARTED;
271 281
282 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not
283 // commit; they leave the frame showing the previous page.
284 DCHECK(response);
285 if (response->head.headers.get() &&
286 (response->head.headers->response_code() == 204 ||
287 response->head.headers->response_code() == 205)) {
288 frame_tree_node_->ResetNavigationRequest(false);
289 return;
290 }
291
272 // Update the service worker params of the request params. 292 // Update the service worker params of the request params.
273 request_params_.should_create_service_worker = 293 request_params_.should_create_service_worker =
274 (frame_tree_node_->pending_sandbox_flags() & 294 (frame_tree_node_->pending_sandbox_flags() &
275 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; 295 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
276 if (navigation_handle_->service_worker_handle()) { 296 if (navigation_handle_->service_worker_handle()) {
277 request_params_.service_worker_provider_id = 297 request_params_.service_worker_provider_id =
278 navigation_handle_->service_worker_handle() 298 navigation_handle_->service_worker_handle()
279 ->service_worker_provider_host_id(); 299 ->service_worker_provider_host_id();
280 } 300 }
281 301
282 // Update the lofi state of the request. 302 // Update the lofi state of the request.
283 if (response->head.is_using_lofi) 303 if (response->head.is_using_lofi)
284 common_params_.lofi_state = LOFI_ON; 304 common_params_.lofi_state = LOFI_ON;
285 else 305 else
286 common_params_.lofi_state = LOFI_OFF; 306 common_params_.lofi_state = LOFI_OFF;
287 307
288 frame_tree_node_->navigator()->CommitNavigation( 308 // Select an appropriate renderer to commit the navigation.
289 this, response.get(), std::move(body)); 309 RenderFrameHostImpl* render_frame_host =
310 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this);
311 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host,
312 common_params_.url);
313
314 // Store the response and the StreamHandle until checks have been processed.
315 response_ = response;
316 body_ = std::move(body);
317
318 // Check if the navigation should be allowed to proceed.
319 navigation_handle_->WillProcessResponse(
320 render_frame_host, response->head.headers.get(),
321 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete,
322 base::Unretained(this)));
290 } 323 }
291 324
292 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, 325 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache,
293 int net_error) { 326 int net_error) {
294 DCHECK(state_ == STARTED); 327 DCHECK(state_ == STARTED);
295 state_ = FAILED; 328 state_ = FAILED;
296 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 329 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
297 frame_tree_node_->navigator()->FailedNavigation( 330 frame_tree_node_->navigator()->FailedNavigation(
298 frame_tree_node_, has_stale_copy_in_cache, net_error); 331 frame_tree_node_, has_stale_copy_in_cache, net_error);
299 } 332 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 368 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
336 result == NavigationThrottle::CANCEL) { 369 result == NavigationThrottle::CANCEL) {
337 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 370 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
338 frame_tree_node_->ResetNavigationRequest(false); 371 frame_tree_node_->ResetNavigationRequest(false);
339 return; 372 return;
340 } 373 }
341 374
342 loader_->FollowRedirect(); 375 loader_->FollowRedirect();
343 } 376 }
344 377
378 void NavigationRequest::OnWillProcessResponseChecksComplete(
379 NavigationThrottle::ThrottleCheckResult result) {
380 CHECK(result != NavigationThrottle::DEFER);
381
382 // Abort the request if needed. This will destroy the NavigationRequest.
383 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
384 result == NavigationThrottle::CANCEL) {
385 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
386 frame_tree_node_->ResetNavigationRequest(false);
387 return;
388 }
389
390 // Have the processing of the response resume in the network stack.
391 loader_->ProceedWithResponse();
392
393 CommitNavigation();
394
395 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused
396 // the destruction of the NavigationRequest.
397 }
398
399 void NavigationRequest::CommitNavigation() {
400 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url));
401
402 // Retrieve the RenderFrameHost that needs to commit the navigation.
403 RenderFrameHostImpl* render_frame_host =
404 navigation_handle_->GetRenderFrameHost();
405 DCHECK(render_frame_host ==
406 frame_tree_node_->render_manager()->current_frame_host() ||
407 render_frame_host ==
408 frame_tree_node_->render_manager()->speculative_frame_host());
409
410 TransferNavigationHandleOwnership(render_frame_host);
411 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
412 common_params_, request_params_,
413 is_view_source_);
414
415 // When navigating to a Javascript url, the NavigationRequest is not stored
416 // in the FrameTreeNode. Therefore do not reset it, as this could cancel an
417 // existing pending navigation.
418 if (!common_params_.url.SchemeIs(url::kJavaScriptScheme))
419 frame_tree_node_->ResetNavigationRequest(true);
420 }
421
345 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() { 422 void NavigationRequest::InitializeServiceWorkerHandleIfNeeded() {
346 // Only initialize the ServiceWorkerNavigationHandle if it can be created for 423 // Only initialize the ServiceWorkerNavigationHandle if it can be created for
347 // this frame. 424 // this frame.
348 bool can_create_service_worker = 425 bool can_create_service_worker =
349 (frame_tree_node_->pending_sandbox_flags() & 426 (frame_tree_node_->pending_sandbox_flags() &
350 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; 427 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin;
351 if (!can_create_service_worker) 428 if (!can_create_service_worker)
352 return; 429 return;
353 430
354 // Use the SiteInstance of the navigating RenderFrameHost to get access to 431 // Use the SiteInstance of the navigating RenderFrameHost to get access to
(...skipping 11 matching lines...) Expand all
366 browser_context, navigating_frame_host->GetSiteInstance()); 443 browser_context, navigating_frame_host->GetSiteInstance());
367 DCHECK(partition); 444 DCHECK(partition);
368 445
369 ServiceWorkerContextWrapper* service_worker_context = 446 ServiceWorkerContextWrapper* service_worker_context =
370 static_cast<ServiceWorkerContextWrapper*>( 447 static_cast<ServiceWorkerContextWrapper*>(
371 partition->GetServiceWorkerContext()); 448 partition->GetServiceWorkerContext());
372 navigation_handle_->InitServiceWorkerHandle(service_worker_context); 449 navigation_handle_->InitServiceWorkerHandle(service_worker_context);
373 } 450 }
374 451
375 } // namespace content 452 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.h ('k') | content/browser/frame_host/navigator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698