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

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

Issue 2901833002: Create NavigationHandle after beforeunload with PlzNavigate. (Closed)
Patch Set: small fix from jam 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
« 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 "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 }
362 } 366 }
363 367
364 net::HttpRequestHeaders headers; 368 net::HttpRequestHeaders headers;
365 headers.AddHeadersFromString(begin_params_.headers); 369 headers.AddHeadersFromString(begin_params_.headers);
366 AddAdditionalRequestHeaders( 370 AddAdditionalRequestHeaders(
367 &headers, common_params_.url, common_params_.navigation_type, 371 &headers, common_params_.url, common_params_.navigation_type,
368 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), 372 frame_tree_node_->navigator()->GetController()->GetBrowserContext(),
369 common_params.method, user_agent_override, frame_tree_node); 373 common_params.method, user_agent_override, frame_tree_node);
370 begin_params_.headers = headers.ToString(); 374 begin_params_.headers = headers.ToString();
371 } 375 }
372 376
373 NavigationRequest::~NavigationRequest() { 377 NavigationRequest::~NavigationRequest() {
374 TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this); 378 TRACE_EVENT_ASYNC_END0("navigation", "NavigationRequest", this);
375 } 379 }
376 380
377 void NavigationRequest::BeginNavigation() { 381 void NavigationRequest::BeginNavigation() {
378 DCHECK(!loader_); 382 DCHECK(!loader_);
379 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); 383 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE);
380 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, 384 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
381 "BeginNavigation"); 385 "BeginNavigation");
382 state_ = STARTED; 386 state_ = STARTED;
387 CreateNavigationHandle();
388
389 if (nav_entry_id_) {
390 NavigationEntryImpl* nav_entry =
391 static_cast<NavigationControllerImpl*>(
392 frame_tree_node_->navigator()->GetController())
393 ->GetEntryWithUniqueID(nav_entry_id_);
394 if (nav_entry) {
395 navigation_handle_->set_base_url_for_data_url(
396 nav_entry->GetBaseURLForDataURL());
397 }
398 }
399
383 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); 400 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get());
384 401
385 if (ShouldMakeNetworkRequestForURL(common_params_.url) && 402 if (ShouldMakeNetworkRequestForURL(common_params_.url) &&
386 !navigation_handle_->IsSameDocument()) { 403 !navigation_handle_->IsSameDocument()) {
387 // It's safe to use base::Unretained because this NavigationRequest owns 404 // It's safe to use base::Unretained because this NavigationRequest owns
388 // the NavigationHandle where the callback will be stored. 405 // the NavigationHandle where the callback will be stored.
389 // TODO(clamy): pass the method to the NavigationHandle instead of a 406 // TODO(clamy): pass the method to the NavigationHandle instead of a
390 // boolean. 407 // boolean.
391 bool is_external_protocol = 408 bool is_external_protocol =
392 !GetContentClient()->browser()->IsHandledURL(common_params_.url); 409 !GetContentClient()->browser()->IsHandledURL(common_params_.url);
(...skipping 27 matching lines...) Expand all
420 CommitNavigation(); 437 CommitNavigation();
421 } 438 }
422 439
423 void NavigationRequest::SetWaitingForRendererResponse() { 440 void NavigationRequest::SetWaitingForRendererResponse() {
424 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this, 441 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationRequest", this,
425 "WaitingForRendererResponse"); 442 "WaitingForRendererResponse");
426 DCHECK(state_ == NOT_STARTED); 443 DCHECK(state_ == NOT_STARTED);
427 state_ = WAITING_FOR_RENDERER_RESPONSE; 444 state_ = WAITING_FOR_RENDERER_RESPONSE;
428 } 445 }
429 446
430 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { 447 void NavigationRequest::CreateNavigationHandle() {
431 DCHECK_EQ(frame_tree_node_->navigation_request(), this); 448 DCHECK_EQ(frame_tree_node_->navigation_request(), this);
432 FrameTreeNode* frame_tree_node = frame_tree_node_; 449 FrameTreeNode* frame_tree_node = frame_tree_node_;
433 450
434 std::vector<GURL> redirect_chain; 451 std::vector<GURL> redirect_chain;
435 if (!begin_params_.client_side_redirect_url.is_empty()) 452 if (!begin_params_.client_side_redirect_url.is_empty())
436 redirect_chain.push_back(begin_params_.client_side_redirect_url); 453 redirect_chain.push_back(begin_params_.client_side_redirect_url);
437 redirect_chain.push_back(common_params_.url); 454 redirect_chain.push_back(common_params_.url);
438 455
439 std::unique_ptr<NavigationHandleImpl> navigation_handle = 456 std::unique_ptr<NavigationHandleImpl> navigation_handle =
440 NavigationHandleImpl::Create(common_params_.url, redirect_chain, 457 NavigationHandleImpl::Create(common_params_.url, redirect_chain,
441 frame_tree_node_, !browser_initiated_, 458 frame_tree_node_, !browser_initiated_,
442 FrameMsg_Navigate_Type::IsSameDocument( 459 FrameMsg_Navigate_Type::IsSameDocument(
443 common_params_.navigation_type), 460 common_params_.navigation_type),
444 common_params_.navigation_start, 461 common_params_.navigation_start,
445 pending_nav_entry_id, 462 nav_entry_id_,
446 false, // started_in_context_menu 463 false, // started_in_context_menu
447 common_params_.should_check_main_world_csp, 464 common_params_.should_check_main_world_csp,
448 begin_params_.is_form_submission); 465 begin_params_.is_form_submission);
449 466
450 if (!frame_tree_node->navigation_request()) { 467 if (!frame_tree_node->navigation_request()) {
451 // A callback could have cancelled this request synchronously in which case 468 // A callback could have cancelled this request synchronously in which case
452 // |this| is deleted. 469 // |this| is deleted.
453 return; 470 return;
454 } 471 }
455 472
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationRequest", this, 643 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationRequest", this,
627 "OnRequestFailed", "error", net_error); 644 "OnRequestFailed", "error", net_error);
628 state_ = FAILED; 645 state_ = FAILED;
629 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 646 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
630 647
631 // With PlzNavigate, debug URLs will give a failed navigation because the 648 // 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 649 // 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 650 // renderer, however do not discard the pending entry so that the URL bar
634 // shows them correctly. 651 // shows them correctly.
635 if (!IsRendererDebugURL(common_params_.url)) { 652 if (!IsRendererDebugURL(common_params_.url)) {
653 int expected_pending_entry_id =
654 navigation_handle_.get() ? navigation_handle_->pending_nav_entry_id()
655 : nav_entry_id_;
636 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( 656 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded(
637 navigation_handle_.get()); 657 expected_pending_entry_id);
638 } 658 }
639 659
640 // If the request was canceled by the user do not show an error page. 660 // If the request was canceled by the user do not show an error page.
641 if (net_error == net::ERR_ABORTED) { 661 if (net_error == net::ERR_ABORTED) {
642 frame_tree_node_->ResetNavigationRequest(false, true); 662 frame_tree_node_->ResetNavigationRequest(false, true);
643 return; 663 return;
644 } 664 }
645 665
646 // Decide whether to leave the error page in the original process. 666 // Decide whether to leave the error page in the original process.
647 // * If this was a renderer-initiated navigation, and the request is blocked 667 // * If this was a renderer-initiated navigation, and the request is blocked
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 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);
879 899
880 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 900 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
881 std::move(handle_), common_params_, 901 std::move(handle_), common_params_,
882 request_params_, is_view_source_); 902 request_params_, is_view_source_);
883 903
884 frame_tree_node_->ResetNavigationRequest(true, true); 904 frame_tree_node_->ResetNavigationRequest(true, true);
885 } 905 }
886 906
887 } // namespace content 907 } // 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