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

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

Issue 2901833002: Create NavigationHandle after beforeunload with PlzNavigate. (Closed)
Patch Set: Rewrote BeforeUnload test Created 3 years, 7 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 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 "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "content/browser/appcache/appcache_navigation_handle.h" 10 #include "content/browser/appcache/appcache_navigation_handle.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 controller->GetEntryCount()), 250 controller->GetEntryCount()),
251 browser_initiated, 251 browser_initiated,
252 true, // may_transfer 252 true, // may_transfer
253 &frame_entry, &entry)); 253 &frame_entry, &entry));
254 return navigation_request; 254 return navigation_request;
255 } 255 }
256 256
257 // static 257 // static
258 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( 258 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated(
259 FrameTreeNode* frame_tree_node, 259 FrameTreeNode* frame_tree_node,
260 NavigationEntryImpl* entry,
260 const CommonNavigationParams& common_params, 261 const CommonNavigationParams& common_params,
261 const BeginNavigationParams& begin_params, 262 const BeginNavigationParams& begin_params,
262 int current_history_list_offset, 263 int current_history_list_offset,
263 int current_history_list_length) { 264 int current_history_list_length) {
264 // Only normal navigations to a different document or reloads are expected. 265 // Only normal navigations to a different document or reloads are expected.
265 // - Renderer-initiated fragment-navigations never take place in the browser, 266 // - Renderer-initiated fragment-navigations never take place in the browser,
266 // even with PlzNavigate. 267 // even with PlzNavigate.
267 // - Restore-navigations are always browser-initiated. 268 // - Restore-navigations are always browser-initiated.
268 // - History-navigations use the browser-initiated path, event the ones that 269 // - History-navigations use the browser-initiated path, event the ones that
269 // are initiated by a javascript script, please see the IPC message 270 // are initiated by a javascript script, please see the IPC message
(...skipping 20 matching lines...) Expand all
290 false, // intended_as_new_entry 291 false, // intended_as_new_entry
291 -1, // pending_history_list_offset 292 -1, // pending_history_list_offset
292 current_history_list_offset, current_history_list_length, 293 current_history_list_offset, current_history_list_length,
293 false, // is_view_source 294 false, // is_view_source
294 false, // should_clear_history_list 295 false, // should_clear_history_list
295 begin_params.has_user_gesture); 296 begin_params.has_user_gesture);
296 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( 297 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest(
297 frame_tree_node, common_params, begin_params, request_params, 298 frame_tree_node, common_params, begin_params, request_params,
298 false, // browser_initiated 299 false, // browser_initiated
299 false, // may_transfer 300 false, // may_transfer
300 nullptr, nullptr)); 301 nullptr, entry));
301 return navigation_request; 302 return navigation_request;
302 } 303 }
303 304
304 NavigationRequest::NavigationRequest( 305 NavigationRequest::NavigationRequest(
305 FrameTreeNode* frame_tree_node, 306 FrameTreeNode* frame_tree_node,
306 const CommonNavigationParams& common_params, 307 const CommonNavigationParams& common_params,
307 const BeginNavigationParams& begin_params, 308 const BeginNavigationParams& begin_params,
308 const RequestNavigationParams& request_params, 309 const RequestNavigationParams& request_params,
309 bool browser_initiated, 310 bool browser_initiated,
310 bool may_transfer, 311 bool may_transfer,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 frame_tree_node->current_frame_host()->GetSiteInstance(); 350 frame_tree_node->current_frame_host()->GetSiteInstance();
350 } 351 }
351 352
352 // Update the load flags with cache information. 353 // Update the load flags with cache information.
353 UpdateLoadFlagsWithCacheFlags(&begin_params_.load_flags, 354 UpdateLoadFlagsWithCacheFlags(&begin_params_.load_flags,
354 common_params_.navigation_type, 355 common_params_.navigation_type,
355 common_params_.method == "POST"); 356 common_params_.method == "POST");
356 357
357 // Add necessary headers that may not be present in the BeginNavigationParams. 358 // Add necessary headers that may not be present in the BeginNavigationParams.
358 std::string user_agent_override; 359 std::string user_agent_override;
359 if (entry && entry->GetIsOverridingUserAgent()) { 360 if (entry) {
360 user_agent_override = 361 nav_entry_id_ = entry->GetUniqueID();
361 frame_tree_node_->navigator()->GetDelegate()->GetUserAgentOverride(); 362 if (entry->GetIsOverridingUserAgent()) {
363 user_agent_override =
364 frame_tree_node_->navigator()->GetDelegate()->GetUserAgentOverride();
365 }
366 } else {
367 nav_entry_id_ = 0;
nasko 2017/05/24 14:20:03 nit: This is already initialized to 0 in the heade
clamy 2017/05/24 18:34:38 Ah I missed the header file initialization (not us
362 } 368 }
363 369
364 net::HttpRequestHeaders headers; 370 net::HttpRequestHeaders headers;
365 headers.AddHeadersFromString(begin_params_.headers); 371 headers.AddHeadersFromString(begin_params_.headers);
366 AddAdditionalRequestHeaders( 372 AddAdditionalRequestHeaders(
367 &headers, common_params_.url, common_params_.navigation_type, 373 &headers, common_params_.url, common_params_.navigation_type,
368 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 374 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
369 common_params.method, user_agent_override, frame_tree_node); 375 common_params.method, user_agent_override, frame_tree_node);
370 begin_params_.headers = headers.ToString(); 376 begin_params_.headers = headers.ToString();
371 } 377 }
372 378
373 NavigationRequest::~NavigationRequest() { 379 NavigationRequest::~NavigationRequest() {
374 TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this); 380 TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this);
375 } 381 }
376 382
377 void NavigationRequest::BeginNavigation() { 383 void NavigationRequest::BeginNavigation() {
378 DCHECK(!loader_); 384 DCHECK(!loader_);
379 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 385 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
380 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, 386 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
381 "BeginNavigation"); 387 "BeginNavigation");
382 state_ = STARTED; 388 state_ = STARTED;
389 CreateNavigationHandle();
390
391 if (nav_entry_id_) {
392 NavigationEntryImpl* nav_entry =
393 static_cast<NavigationControllerImpl*>(
394 frame_tree_node_->navigator()->GetController())
395 ->GetEntryWithUniqueID(nav_entry_id_);
396 if (nav_entry) {
397 navigation_handle_->set_base_url_for_data_url(
398 nav_entry->GetBaseURLForDataURL());
399 }
400 }
401
383 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 402 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
384 403
385 if (ShouldMakeNetworkRequestForURL(common_params_.url) && 404 if (ShouldMakeNetworkRequestForURL(common_params_.url) &&
386 !navigation_handle_->IsSameDocument()) { 405 !navigation_handle_->IsSameDocument()) {
387 // It's safe to use base::Unretained because this NavigationRequest owns 406 // It's safe to use base::Unretained because this NavigationRequest owns
388 // the NavigationHandle where the callback will be stored. 407 // the NavigationHandle where the callback will be stored.
389 // TODO(clamy): pass the method to the NavigationHandle instead of a 408 // TODO(clamy): pass the method to the NavigationHandle instead of a
390 // boolean. 409 // boolean.
391 bool is_external_protocol = 410 bool is_external_protocol =
392 !GetContentClient()->browser()->IsHandledURL(common_params_.url); 411 !GetContentClient()->browser()->IsHandledURL(common_params_.url);
(...skipping 27 matching lines...) Expand all
420 CommitNavigation(); 439 CommitNavigation();
421 } 440 }
422 441
423 void NavigationRequest::SetWaitingForRendererResponse() { 442 void NavigationRequest::SetWaitingForRendererResponse() {
424 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, 443 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
425 "WaitingForRendererResponse"); 444 "WaitingForRendererResponse");
426 DCHECK(state_ == NOT_STARTED); 445 DCHECK(state_ == NOT_STARTED);
427 state_ = WAITING_FOR_RENDERER_RESPONSE; 446 state_ = WAITING_FOR_RENDERER_RESPONSE;
428 } 447 }
429 448
430 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 449 void NavigationRequest::CreateNavigationHandle() {
431 DCHECK_EQ(frame_tree_node_->navigation_request(), this); 450 DCHECK_EQ(frame_tree_node_->navigation_request(), this);
432 FrameTreeNode* frame_tree_node = frame_tree_node_; 451 FrameTreeNode* frame_tree_node = frame_tree_node_;
433 452
434 std::vector<GURL> redirect_chain; 453 std::vector<GURL> redirect_chain;
435 if (!begin_params_.client_side_redirect_url.is_empty()) 454 if (!begin_params_.client_side_redirect_url.is_empty())
436 redirect_chain.push_back(begin_params_.client_side_redirect_url); 455 redirect_chain.push_back(begin_params_.client_side_redirect_url);
437 redirect_chain.push_back(common_params_.url); 456 redirect_chain.push_back(common_params_.url);
438 457
439 std::unique_ptr<NavigationHandleImpl> navigation_handle = 458 std::unique_ptr<NavigationHandleImpl> navigation_handle =
440 NavigationHandleImpl::Create(common_params_.url, redirect_chain, 459 NavigationHandleImpl::Create(common_params_.url, redirect_chain,
441 frame_tree_node_, !browser_initiated_, 460 frame_tree_node_, !browser_initiated_,
442 FrameMsg_Navigate_Type::IsSameDocument( 461 FrameMsg_Navigate_Type::IsSameDocument(
443 common_params_.navigation_type), 462 common_params_.navigation_type),
444 common_params_.navigation_start, 463 common_params_.navigation_start,
445 pending_nav_entry_id, 464 nav_entry_id_,
446 false, // started_in_context_menu 465 false, // started_in_context_menu
447 common_params_.should_check_main_world_csp, 466 common_params_.should_check_main_world_csp,
448 begin_params_.is_form_submission); 467 begin_params_.is_form_submission);
449 468
450 if (!frame_tree_node->navigation_request()) { 469 if (!frame_tree_node->navigation_request()) {
451 // A callback could have cancelled this request synchronously in which case 470 // A callback could have cancelled this request synchronously in which case
452 // |this| is deleted. 471 // |this| is deleted.
453 return; 472 return;
454 } 473 }
455 474
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationRequest", this, 645 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationRequest", this,
627 "OnRequestFailed", "error", net_error); 646 "OnRequestFailed", "error", net_error);
628 state_ = FAILED; 647 state_ = FAILED;
629 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 648 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
630 649
631 // With PlzNavigate, debug URLs will give a failed navigation because the 650 // With PlzNavigate, debug URLs will give a failed navigation because the
632 // WebUI backend won't find a handler for them. They will be processed in the 651 // WebUI backend won't find a handler for them. They will be processed in the
633 // renderer, however do not discard the pending entry so that the URL bar 652 // renderer, however do not discard the pending entry so that the URL bar
634 // shows them correctly. 653 // shows them correctly.
635 if (!IsRendererDebugURL(common_params_.url)) { 654 if (!IsRendererDebugURL(common_params_.url)) {
655 int expected_pending_entry_id =
656 navigation_handle_.get() ? navigation_handle_->pending_nav_entry_id()
657 : nav_entry_id_;
636 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( 658 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded(
637 navigation_handle_.get()); 659 expected_pending_entry_id);
638 } 660 }
639 661
640 // If the request was canceled by the user do not show an error page. 662 // If the request was canceled by the user do not show an error page.
641 if (net_error == net::ERR_ABORTED) { 663 if (net_error == net::ERR_ABORTED) {
642 frame_tree_node_->ResetNavigationRequest(false, true); 664 frame_tree_node_->ResetNavigationRequest(false, true);
643 return; 665 return;
644 } 666 }
645 667
646 // Decide whether to leave the error page in the original process. 668 // Decide whether to leave the error page in the original process.
647 // * If this was a renderer-initiated navigation, and the request is blocked 669 // * If this was a renderer-initiated navigation, and the request is blocked
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 898 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
877 899
878 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 900 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
879 std::move(handle_), common_params_, 901 std::move(handle_), common_params_,
880 request_params_, is_view_source_); 902 request_params_, is_view_source_);
881 903
882 frame_tree_node_->ResetNavigationRequest(true, true); 904 frame_tree_node_->ResetNavigationRequest(true, true);
883 } 905 }
884 906
885 } // namespace content 907 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698