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

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

Issue 1167693007: PlzNavigate: renderer-initiated navigations create a pending NavigationEntry (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/frame_host/frame_tree.h" 10 #include "content/browser/frame_host/frame_tree.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void NavigatorImpl::DidStartProvisionalLoad( 118 void NavigatorImpl::DidStartProvisionalLoad(
119 RenderFrameHostImpl* render_frame_host, 119 RenderFrameHostImpl* render_frame_host,
120 const GURL& url) { 120 const GURL& url) {
121 bool is_error_page = (url.spec() == kUnreachableWebDataURL); 121 bool is_error_page = (url.spec() == kUnreachableWebDataURL);
122 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL); 122 bool is_iframe_srcdoc = (url.spec() == kAboutSrcDocURL);
123 GURL validated_url(url); 123 GURL validated_url(url);
124 RenderProcessHost* render_process_host = render_frame_host->GetProcess(); 124 RenderProcessHost* render_process_host = render_frame_host->GetProcess();
125 render_process_host->FilterURL(false, &validated_url); 125 render_process_host->FilterURL(false, &validated_url);
126 126
127 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame(); 127 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
128 NavigationEntryImpl* pending_entry = controller_->GetPendingEntry(); 128 if (is_main_frame && !is_error_page)
129 if (is_main_frame) { 129 MainFrameNavigationStarted(validated_url,
130 // If there is no browser-initiated pending entry for this navigation and it 130 render_frame_host->GetSiteInstance());
131 // is not for the error URL, create a pending entry using the current
132 // SiteInstance, and ensure the address bar updates accordingly. We don't
133 // know the referrer or extra headers at this point, but the referrer will
134 // be set properly upon commit.
135 bool has_browser_initiated_pending_entry = pending_entry &&
136 !pending_entry->is_renderer_initiated();
137 if (!has_browser_initiated_pending_entry && !is_error_page) {
138 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
139 controller_->CreateNavigationEntry(validated_url,
140 content::Referrer(),
141 ui::PAGE_TRANSITION_LINK,
142 true /* is_renderer_initiated */,
143 std::string(),
144 controller_->GetBrowserContext()));
145 entry->set_site_instance(render_frame_host->GetSiteInstance());
146 // TODO(creis): If there's a pending entry already, find a safe way to
147 // update it instead of replacing it and copying over things like this.
148 if (pending_entry) {
149 entry->set_transferred_global_request_id(
150 pending_entry->transferred_global_request_id());
151 entry->set_should_replace_entry(pending_entry->should_replace_entry());
152 entry->SetRedirectChain(pending_entry->GetRedirectChain());
153 }
154 controller_->SetPendingEntry(entry);
155 if (delegate_)
156 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
157 }
158 }
159 131
160 if (delegate_) { 132 if (delegate_) {
161 // Notify the observer about the start of the provisional load. 133 // Notify the observer about the start of the provisional load.
162 delegate_->DidStartProvisionalLoad( 134 delegate_->DidStartProvisionalLoad(
163 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc); 135 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc);
164 } 136 }
165 } 137 }
166 138
167 139
168 void NavigatorImpl::DidFailProvisionalLoadWithError( 140 void NavigatorImpl::DidFailProvisionalLoadWithError(
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 632
661 // In all other cases the current navigation, if any, is canceled and a new 633 // In all other cases the current navigation, if any, is canceled and a new
662 // NavigationRequest is created for the node. 634 // NavigationRequest is created for the node.
663 scoped_ptr<NavigationRequest> navigation_request = 635 scoped_ptr<NavigationRequest> navigation_request =
664 NavigationRequest::CreateRendererInitiated( 636 NavigationRequest::CreateRendererInitiated(
665 frame_tree_node, common_params, begin_params, body, 637 frame_tree_node, common_params, begin_params, body,
666 controller_->GetLastCommittedEntryIndex(), 638 controller_->GetLastCommittedEntryIndex(),
667 controller_->GetEntryCount()); 639 controller_->GetEntryCount());
668 frame_tree_node->SetNavigationRequest(navigation_request.Pass()); 640 frame_tree_node->SetNavigationRequest(navigation_request.Pass());
669 641
670 if (frame_tree_node->IsMainFrame()) 642 if (frame_tree_node->IsMainFrame()) {
Charlie Reis 2015/06/02 17:36:18 Do we not get here for error pages?
clamy 2015/06/03 09:11:10 No this is the beginning of a normal navigation.
643 // In the case of a renderer-initiated main frame navigation, the
644 // RenderFrameHost will not be swapped. Therefore it is safe to call
Charlie Reis 2015/06/02 17:36:18 This first sentence isn't true in general. Render
clamy 2015/06/03 09:11:10 No they don't, edited the comment to precise that.
Charlie Reis 2015/06/03 20:26:04 Acknowledged.
645 // MainFrameNavigationStarted with the SiteInstance from the current
646 // RenderFrameHost.
647 MainFrameNavigationStarted(
648 common_params.url,
Charlie Reis 2015/06/02 17:36:18 I just noticed that we're not validating the URL w
clamy 2015/06/03 09:11:10 Acknowledged. Added a TODO at the beginning of the
649 frame_tree_node->current_frame_host()->GetSiteInstance());
671 navigation_data_.reset(); 650 navigation_data_.reset();
651 }
672 652
673 BeginNavigation(frame_tree_node); 653 BeginNavigation(frame_tree_node);
674 } 654 }
675 655
676 // PlzNavigate 656 // PlzNavigate
677 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, 657 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node,
678 ResourceResponse* response, 658 ResourceResponse* response,
679 scoped_ptr<StreamHandle> body) { 659 scoped_ptr<StreamHandle> body) {
680 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( 660 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
681 switches::kEnableBrowserSideNavigation)); 661 switches::kEnableBrowserSideNavigation));
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 UMA_HISTOGRAM_TIMES( 884 UMA_HISTOGRAM_TIMES(
905 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", 885 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted",
906 time_to_commit); 886 time_to_commit);
907 UMA_HISTOGRAM_TIMES( 887 UMA_HISTOGRAM_TIMES(
908 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", 888 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted",
909 time_to_network); 889 time_to_network);
910 } 890 }
911 navigation_data_.reset(); 891 navigation_data_.reset();
912 } 892 }
913 893
894 void NavigatorImpl::MainFrameNavigationStarted(
895 const GURL& url,
896 SiteInstanceImpl* site_instance) {
897 // If there is no browser-initiated pending entry for this navigation and it
898 // is not for the error URL, create a pending entry using the current
899 // SiteInstance, and ensure the address bar updates accordingly. We don't
900 // know the referrer or extra headers at this point, but the referrer will
901 // be set properly upon commit.
902 NavigationEntryImpl* pending_entry = controller_->GetPendingEntry();
903 bool has_browser_initiated_pending_entry =
904 pending_entry && !pending_entry->is_renderer_initiated();
905 if (!has_browser_initiated_pending_entry) {
906 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
907 controller_->CreateNavigationEntry(
908 url, content::Referrer(), ui::PAGE_TRANSITION_LINK,
909 true /* is_renderer_initiated */, std::string(),
910 controller_->GetBrowserContext()));
911 entry->set_site_instance(site_instance);
912 // TODO(creis): If there's a pending entry already, find a safe way to
913 // update it instead of replacing it and copying over things like this.
914 if (pending_entry) {
915 entry->set_transferred_global_request_id(
916 pending_entry->transferred_global_request_id());
917 entry->set_should_replace_entry(pending_entry->should_replace_entry());
918 entry->SetRedirectChain(pending_entry->GetRedirectChain());
919 }
920 controller_->SetPendingEntry(entry);
921 if (delegate_)
922 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
923 }
924 }
925
914 } // namespace content 926 } // namespace content
OLDNEW
« content/browser/frame_host/navigator_impl.h ('K') | « content/browser/frame_host/navigator_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698