| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/navigator_impl.h" | 5 #include "content/browser/frame_host/navigator_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 error_description, was_ignored_by_handler); | 250 error_description, was_ignored_by_handler); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool NavigatorImpl::NavigateToEntry( | 254 bool NavigatorImpl::NavigateToEntry( |
| 255 FrameTreeNode* frame_tree_node, | 255 FrameTreeNode* frame_tree_node, |
| 256 const FrameNavigationEntry& frame_entry, | 256 const FrameNavigationEntry& frame_entry, |
| 257 const NavigationEntryImpl& entry, | 257 const NavigationEntryImpl& entry, |
| 258 NavigationController::ReloadType reload_type, | 258 NavigationController::ReloadType reload_type, |
| 259 bool is_same_document_history_load, | 259 bool is_same_document_history_load, |
| 260 bool is_pending_entry) { | 260 bool is_pending_entry, |
| 261 const scoped_refptr<ResourceRequestBody>& post_body) { |
| 261 TRACE_EVENT0("browser,navigation", "NavigatorImpl::NavigateToEntry"); | 262 TRACE_EVENT0("browser,navigation", "NavigatorImpl::NavigateToEntry"); |
| 262 | 263 |
| 263 GURL dest_url = frame_entry.url(); | 264 GURL dest_url = frame_entry.url(); |
| 264 Referrer dest_referrer = frame_entry.referrer(); | 265 Referrer dest_referrer = frame_entry.referrer(); |
| 265 if (reload_type == | 266 if (reload_type == |
| 266 NavigationController::ReloadType::RELOAD_ORIGINAL_REQUEST_URL && | 267 NavigationController::ReloadType::RELOAD_ORIGINAL_REQUEST_URL && |
| 267 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) { | 268 entry.GetOriginalRequestURL().is_valid() && !entry.GetHasPostData()) { |
| 268 // We may have been redirected when navigating to the current URL. | 269 // We may have been redirected when navigating to the current URL. |
| 269 // Use the URL the user originally intended to visit, if it's valid and if a | 270 // Use the URL the user originally intended to visit, if it's valid and if a |
| 270 // POST wasn't involved; the latter case avoids issues with sending data to | 271 // POST wasn't involved; the latter case avoids issues with sending data to |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 is_transfer && | 369 is_transfer && |
| 369 entry.transferred_global_request_id().child_id == | 370 entry.transferred_global_request_id().child_id == |
| 370 dest_render_frame_host->GetProcess()->GetID(); | 371 dest_render_frame_host->GetProcess()->GetID(); |
| 371 if (!is_transfer_to_same) { | 372 if (!is_transfer_to_same) { |
| 372 navigation_data_.reset(new NavigationMetricsData( | 373 navigation_data_.reset(new NavigationMetricsData( |
| 373 navigation_start, dest_url, entry.restore_type())); | 374 navigation_start, dest_url, entry.restore_type())); |
| 374 // Create the navigation parameters. | 375 // Create the navigation parameters. |
| 375 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType( | 376 FrameMsg_Navigate_Type::Value navigation_type = GetNavigationType( |
| 376 controller_->GetBrowserContext(), entry, reload_type); | 377 controller_->GetBrowserContext(), entry, reload_type); |
| 377 dest_render_frame_host->Navigate( | 378 dest_render_frame_host->Navigate( |
| 378 entry.ConstructCommonNavigationParams(dest_url, dest_referrer, | 379 entry.ConstructCommonNavigationParams(frame_entry.method(), dest_url, |
| 379 navigation_type, lofi_state, | 380 dest_referrer, navigation_type, |
| 380 navigation_start), | 381 lofi_state, navigation_start), |
| 381 entry.ConstructStartNavigationParams(), | 382 entry.ConstructStartNavigationParams(post_body), |
| 382 entry.ConstructRequestNavigationParams( | 383 entry.ConstructRequestNavigationParams( |
| 383 frame_entry, is_same_document_history_load, | 384 frame_entry, is_same_document_history_load, |
| 384 frame_tree_node->has_committed_real_load(), | 385 frame_tree_node->has_committed_real_load(), |
| 385 controller_->GetPendingEntryIndex() == -1, | 386 controller_->GetPendingEntryIndex() == -1, |
| 386 controller_->GetIndexOfEntry(&entry), | 387 controller_->GetIndexOfEntry(&entry), |
| 387 controller_->GetLastCommittedEntryIndex(), | 388 controller_->GetLastCommittedEntryIndex(), |
| 388 controller_->GetEntryCount())); | 389 controller_->GetEntryCount())); |
| 389 } else { | 390 } else { |
| 390 // No need to navigate again. Just resume the deferred request. | 391 // No need to navigate again. Just resume the deferred request. |
| 391 dest_render_frame_host->GetProcess()->ResumeDeferredNavigation( | 392 dest_render_frame_host->GetProcess()->ResumeDeferredNavigation( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 417 return true; | 418 return true; |
| 418 } | 419 } |
| 419 | 420 |
| 420 bool NavigatorImpl::NavigateToPendingEntry( | 421 bool NavigatorImpl::NavigateToPendingEntry( |
| 421 FrameTreeNode* frame_tree_node, | 422 FrameTreeNode* frame_tree_node, |
| 422 const FrameNavigationEntry& frame_entry, | 423 const FrameNavigationEntry& frame_entry, |
| 423 NavigationController::ReloadType reload_type, | 424 NavigationController::ReloadType reload_type, |
| 424 bool is_same_document_history_load) { | 425 bool is_same_document_history_load) { |
| 425 return NavigateToEntry(frame_tree_node, frame_entry, | 426 return NavigateToEntry(frame_tree_node, frame_entry, |
| 426 *controller_->GetPendingEntry(), reload_type, | 427 *controller_->GetPendingEntry(), reload_type, |
| 427 is_same_document_history_load, true); | 428 is_same_document_history_load, true, nullptr); |
| 428 } | 429 } |
| 429 | 430 |
| 430 bool NavigatorImpl::NavigateNewChildFrame( | 431 bool NavigatorImpl::NavigateNewChildFrame( |
| 431 RenderFrameHostImpl* render_frame_host, | 432 RenderFrameHostImpl* render_frame_host, |
| 432 const std::string& unique_name) { | 433 const std::string& unique_name) { |
| 433 NavigationEntryImpl* entry = | 434 NavigationEntryImpl* entry = |
| 434 controller_->GetEntryWithUniqueID(render_frame_host->nav_entry_id()); | 435 controller_->GetEntryWithUniqueID(render_frame_host->nav_entry_id()); |
| 435 if (!entry) | 436 if (!entry) |
| 436 return false; | 437 return false; |
| 437 | 438 |
| 438 // TODO(creis): Remove unique_name from the IPC, now that we can rely on the | 439 // TODO(creis): Remove unique_name from the IPC, now that we can rely on the |
| 439 // replication state. | 440 // replication state. |
| 440 DCHECK_EQ(render_frame_host->frame_tree_node()->unique_name(), unique_name); | 441 DCHECK_EQ(render_frame_host->frame_tree_node()->unique_name(), unique_name); |
| 441 FrameNavigationEntry* frame_entry = | 442 FrameNavigationEntry* frame_entry = |
| 442 entry->GetFrameEntry(render_frame_host->frame_tree_node()); | 443 entry->GetFrameEntry(render_frame_host->frame_tree_node()); |
| 443 if (!frame_entry) | 444 if (!frame_entry) |
| 444 return false; | 445 return false; |
| 445 | 446 |
| 446 return NavigateToEntry(render_frame_host->frame_tree_node(), *frame_entry, | 447 return NavigateToEntry(render_frame_host->frame_tree_node(), *frame_entry, |
| 447 *entry, NavigationControllerImpl::NO_RELOAD, false, | 448 *entry, NavigationControllerImpl::NO_RELOAD, false, |
| 448 false); | 449 false, nullptr); |
| 449 } | 450 } |
| 450 | 451 |
| 451 void NavigatorImpl::DidNavigate( | 452 void NavigatorImpl::DidNavigate( |
| 452 RenderFrameHostImpl* render_frame_host, | 453 RenderFrameHostImpl* render_frame_host, |
| 453 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { | 454 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 454 FrameTree* frame_tree = render_frame_host->frame_tree_node()->frame_tree(); | 455 FrameTree* frame_tree = render_frame_host->frame_tree_node()->frame_tree(); |
| 455 bool oopifs_possible = SiteIsolationPolicy::AreCrossProcessFramesPossible(); | 456 bool oopifs_possible = SiteIsolationPolicy::AreCrossProcessFramesPossible(); |
| 456 | 457 |
| 457 bool has_embedded_credentials = | 458 bool has_embedded_credentials = |
| 458 params.url.has_username() || params.url.has_password(); | 459 params.url.has_username() || params.url.has_password(); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 } | 701 } |
| 701 | 702 |
| 702 void NavigatorImpl::RequestTransferURL( | 703 void NavigatorImpl::RequestTransferURL( |
| 703 RenderFrameHostImpl* render_frame_host, | 704 RenderFrameHostImpl* render_frame_host, |
| 704 const GURL& url, | 705 const GURL& url, |
| 705 SiteInstance* source_site_instance, | 706 SiteInstance* source_site_instance, |
| 706 const std::vector<GURL>& redirect_chain, | 707 const std::vector<GURL>& redirect_chain, |
| 707 const Referrer& referrer, | 708 const Referrer& referrer, |
| 708 ui::PageTransition page_transition, | 709 ui::PageTransition page_transition, |
| 709 const GlobalRequestID& transferred_global_request_id, | 710 const GlobalRequestID& transferred_global_request_id, |
| 710 bool should_replace_current_entry) { | 711 bool should_replace_current_entry, |
| 712 const scoped_refptr<ResourceRequestBody>& post_body) { |
| 711 // This call only makes sense for subframes if OOPIFs are possible. | 713 // This call only makes sense for subframes if OOPIFs are possible. |
| 712 DCHECK(!render_frame_host->GetParent() || | 714 DCHECK(!render_frame_host->GetParent() || |
| 713 SiteIsolationPolicy::AreCrossProcessFramesPossible()); | 715 SiteIsolationPolicy::AreCrossProcessFramesPossible()); |
| 714 | 716 |
| 715 // Allow the delegate to cancel the transfer. | 717 // Allow the delegate to cancel the transfer. |
| 716 if (!delegate_->ShouldTransferNavigation()) | 718 if (!delegate_->ShouldTransferNavigation()) |
| 717 return; | 719 return; |
| 718 | 720 |
| 719 GURL dest_url(url); | 721 GURL dest_url(url); |
| 720 Referrer referrer_to_use(referrer); | 722 Referrer referrer_to_use(referrer); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 } else { | 766 } else { |
| 765 // If there's no last committed entry, create an entry for about:blank | 767 // If there's no last committed entry, create an entry for about:blank |
| 766 // with a subframe entry for our destination. | 768 // with a subframe entry for our destination. |
| 767 // TODO(creis): Ensure this case can't exist in https://crbug.com/524208. | 769 // TODO(creis): Ensure this case can't exist in https://crbug.com/524208. |
| 768 entry = NavigationEntryImpl::FromNavigationEntry( | 770 entry = NavigationEntryImpl::FromNavigationEntry( |
| 769 controller_->CreateNavigationEntry( | 771 controller_->CreateNavigationEntry( |
| 770 GURL(url::kAboutBlankURL), referrer_to_use, page_transition, | 772 GURL(url::kAboutBlankURL), referrer_to_use, page_transition, |
| 771 is_renderer_initiated, std::string(), | 773 is_renderer_initiated, std::string(), |
| 772 controller_->GetBrowserContext())); | 774 controller_->GetBrowserContext())); |
| 773 } | 775 } |
| 774 // TODO(creis): Handle POST submissions. See https://crbug.com/582211 and | |
| 775 // https://crbug.com/101395. | |
| 776 entry->AddOrUpdateFrameEntry( | 776 entry->AddOrUpdateFrameEntry( |
| 777 node, -1, -1, nullptr, | 777 node, -1, -1, nullptr, |
| 778 static_cast<SiteInstanceImpl*>(source_site_instance), dest_url, | 778 static_cast<SiteInstanceImpl*>(source_site_instance), dest_url, |
| 779 referrer_to_use, PageState(), "GET", -1); | 779 referrer_to_use, PageState(), post_body ? "POST" : "GET", -1); |
| 780 } else { | 780 } else { |
| 781 // Main frame case. | 781 // Main frame case. |
| 782 entry = NavigationEntryImpl::FromNavigationEntry( | 782 entry = NavigationEntryImpl::FromNavigationEntry( |
| 783 controller_->CreateNavigationEntry( | 783 controller_->CreateNavigationEntry( |
| 784 dest_url, referrer_to_use, page_transition, is_renderer_initiated, | 784 dest_url, referrer_to_use, page_transition, is_renderer_initiated, |
| 785 std::string(), controller_->GetBrowserContext())); | 785 std::string(), controller_->GetBrowserContext())); |
| 786 entry->root_node()->frame_entry->set_source_site_instance( | 786 entry->root_node()->frame_entry->set_source_site_instance( |
| 787 static_cast<SiteInstanceImpl*>(source_site_instance)); | 787 static_cast<SiteInstanceImpl*>(source_site_instance)); |
| 788 } | 788 } |
| 789 | 789 |
| 790 entry->SetRedirectChain(redirect_chain); | 790 entry->SetRedirectChain(redirect_chain); |
| 791 // Don't allow an entry replacement if there is no entry to replace. | 791 // Don't allow an entry replacement if there is no entry to replace. |
| 792 // http://crbug.com/457149 | 792 // http://crbug.com/457149 |
| 793 if (should_replace_current_entry && controller_->GetEntryCount() > 0) | 793 if (should_replace_current_entry && controller_->GetEntryCount() > 0) |
| 794 entry->set_should_replace_entry(true); | 794 entry->set_should_replace_entry(true); |
| 795 if (controller_->GetLastCommittedEntry() && | 795 if (controller_->GetLastCommittedEntry() && |
| 796 controller_->GetLastCommittedEntry()->GetIsOverridingUserAgent()) { | 796 controller_->GetLastCommittedEntry()->GetIsOverridingUserAgent()) { |
| 797 entry->SetIsOverridingUserAgent(true); | 797 entry->SetIsOverridingUserAgent(true); |
| 798 } | 798 } |
| 799 entry->set_transferred_global_request_id(transferred_global_request_id); | 799 entry->set_transferred_global_request_id(transferred_global_request_id); |
| 800 // TODO(creis): Set user gesture and intent received timestamp on Android. | 800 // TODO(creis): Set user gesture and intent received timestamp on Android. |
| 801 | 801 |
| 802 // We may not have successfully added the FrameNavigationEntry to |entry| | 802 // We may not have successfully added the FrameNavigationEntry to |entry| |
| 803 // above (per https://crbug.com/608402), in which case we create it from | 803 // above (per https://crbug.com/608402), in which case we create it from |
| 804 // scratch. This works because we do not depend on |frame_entry| being inside | 804 // scratch. This works because we do not depend on |frame_entry| being inside |
| 805 // |entry| during NavigateToEntry. This will go away when we shortcut this | 805 // |entry| during NavigateToEntry. This will go away when we shortcut this |
| 806 // further in https://crbug.com/536906. | 806 // further in https://crbug.com/536906. |
| 807 scoped_refptr<FrameNavigationEntry> frame_entry(entry->GetFrameEntry(node)); | 807 scoped_refptr<FrameNavigationEntry> frame_entry(entry->GetFrameEntry(node)); |
| 808 if (!frame_entry) { | 808 if (!frame_entry) { |
| 809 // TODO(creis): Handle POST submissions here, as above. | |
| 810 frame_entry = new FrameNavigationEntry( | 809 frame_entry = new FrameNavigationEntry( |
| 811 node->unique_name(), -1, -1, nullptr, | 810 node->unique_name(), -1, -1, nullptr, |
| 812 static_cast<SiteInstanceImpl*>(source_site_instance), dest_url, | 811 static_cast<SiteInstanceImpl*>(source_site_instance), dest_url, |
| 813 referrer_to_use, "GET", -1); | 812 referrer_to_use, post_body ? "POST" : "GET", -1); |
| 814 } | 813 } |
| 815 NavigateToEntry(node, *frame_entry, *entry.get(), | 814 NavigateToEntry(node, *frame_entry, *entry.get(), |
| 816 NavigationController::NO_RELOAD, false, false); | 815 NavigationController::NO_RELOAD, false, false, post_body); |
| 817 } | 816 } |
| 818 | 817 |
| 819 // PlzNavigate | 818 // PlzNavigate |
| 820 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, | 819 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, |
| 821 bool proceed) { | 820 bool proceed) { |
| 822 CHECK(IsBrowserSideNavigationEnabled()); | 821 CHECK(IsBrowserSideNavigationEnabled()); |
| 823 DCHECK(frame_tree_node); | 822 DCHECK(frame_tree_node); |
| 824 | 823 |
| 825 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 824 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
| 826 | 825 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 if (pending_entry != controller_->GetVisibleEntry() || | 1146 if (pending_entry != controller_->GetVisibleEntry() || |
| 1148 !should_preserve_entry) { | 1147 !should_preserve_entry) { |
| 1149 controller_->DiscardPendingEntry(true); | 1148 controller_->DiscardPendingEntry(true); |
| 1150 | 1149 |
| 1151 // Also force the UI to refresh. | 1150 // Also force the UI to refresh. |
| 1152 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); | 1151 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 1153 } | 1152 } |
| 1154 } | 1153 } |
| 1155 | 1154 |
| 1156 } // namespace content | 1155 } // namespace content |
| OLD | NEW |