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

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

Issue 2584513003: PlzNavigate: identify same-page browser-initiated navigation. (Closed)
Patch Set: Addressed comment (@nasko) #2. Created 3 years, 10 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/render_frame_host_impl.h" 5 #include "content/browser/frame_host/render_frame_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 2440 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 // Blink doesn't send throb notifications for JavaScript URLs, so it is not 2451 // Blink doesn't send throb notifications for JavaScript URLs, so it is not
2452 // done here either. 2452 // done here either.
2453 if (!common_params.url.SchemeIs(url::kJavaScriptScheme)) 2453 if (!common_params.url.SchemeIs(url::kJavaScriptScheme))
2454 OnDidStartLoading(true); 2454 OnDidStartLoading(true);
2455 } 2455 }
2456 2456
2457 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) { 2457 void RenderFrameHostImpl::NavigateToInterstitialURL(const GURL& data_url) {
2458 DCHECK(data_url.SchemeIs(url::kDataScheme)); 2458 DCHECK(data_url.SchemeIs(url::kDataScheme));
2459 CommonNavigationParams common_params( 2459 CommonNavigationParams common_params(
2460 data_url, Referrer(), ui::PAGE_TRANSITION_LINK, 2460 data_url, Referrer(), ui::PAGE_TRANSITION_LINK,
2461 FrameMsg_Navigate_Type::NORMAL, false, false, base::TimeTicks::Now(), 2461 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, false, false,
2462 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL(), PREVIEWS_OFF, 2462 base::TimeTicks::Now(), FrameMsg_UILoadMetricsReportType::NO_REPORT,
2463 base::TimeTicks::Now(), "GET", nullptr); 2463 GURL(), GURL(), PREVIEWS_OFF, base::TimeTicks::Now(), "GET", nullptr);
2464 if (IsBrowserSideNavigationEnabled()) { 2464 if (IsBrowserSideNavigationEnabled()) {
2465 CommitNavigation(nullptr, nullptr, common_params, RequestNavigationParams(), 2465 CommitNavigation(nullptr, nullptr, common_params, RequestNavigationParams(),
2466 false); 2466 false);
2467 } else { 2467 } else {
2468 Navigate(common_params, StartNavigationParams(), RequestNavigationParams()); 2468 Navigate(common_params, StartNavigationParams(), RequestNavigationParams());
2469 } 2469 }
2470 } 2470 }
2471 2471
2472 void RenderFrameHostImpl::Stop() { 2472 void RenderFrameHostImpl::Stop() {
2473 Send(new FrameMsg_Stop(routing_id_)); 2473 Send(new FrameMsg_Stop(routing_id_));
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 } 2623 }
2624 } 2624 }
2625 2625
2626 // PlzNavigate 2626 // PlzNavigate
2627 void RenderFrameHostImpl::CommitNavigation( 2627 void RenderFrameHostImpl::CommitNavigation(
2628 ResourceResponse* response, 2628 ResourceResponse* response,
2629 std::unique_ptr<StreamHandle> body, 2629 std::unique_ptr<StreamHandle> body,
2630 const CommonNavigationParams& common_params, 2630 const CommonNavigationParams& common_params,
2631 const RequestNavigationParams& request_params, 2631 const RequestNavigationParams& request_params,
2632 bool is_view_source) { 2632 bool is_view_source) {
2633 DCHECK((response && body.get()) || 2633 DCHECK(
2634 common_params.url.SchemeIs(url::kDataScheme) || 2634 (response && body.get()) ||
2635 !ShouldMakeNetworkRequestForURL(common_params.url) || 2635 common_params.url.SchemeIs(url::kDataScheme) ||
2636 IsRendererDebugURL(common_params.url)); 2636 !ShouldMakeNetworkRequestForURL(common_params.url) ||
2637 FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type) ||
2638 IsRendererDebugURL(common_params.url));
2637 UpdatePermissionsForNavigation(common_params, request_params); 2639 UpdatePermissionsForNavigation(common_params, request_params);
2638 2640
2639 // Get back to a clean state, in case we start a new navigation without 2641 // Get back to a clean state, in case we start a new navigation without
2640 // completing an unload handler. 2642 // completing an unload handler.
2641 ResetWaitingState(); 2643 ResetWaitingState();
2642 2644
2643 // The renderer can exit view source mode when any error or cancellation 2645 // The renderer can exit view source mode when any error or cancellation
2644 // happen. When reusing the same renderer, overwrite to recover the mode. 2646 // happen. When reusing the same renderer, overwrite to recover the mode.
2645 if (is_view_source && 2647 if (is_view_source &&
2646 this == frame_tree_node_->render_manager()->current_frame_host()) { 2648 this == frame_tree_node_->render_manager()->current_frame_host()) {
2647 DCHECK(!GetParent()); 2649 DCHECK(!GetParent());
2648 render_view_host()->Send(new FrameMsg_EnableViewSourceMode(routing_id_)); 2650 render_view_host()->Send(new FrameMsg_EnableViewSourceMode(routing_id_));
2649 } 2651 }
2650 2652
2651 const GURL body_url = body.get() ? body->GetURL() : GURL(); 2653 const GURL body_url = body.get() ? body->GetURL() : GURL();
2652 const ResourceResponseHead head = response ? 2654 const ResourceResponseHead head = response ?
2653 response->head : ResourceResponseHead(); 2655 response->head : ResourceResponseHead();
2654 Send(new FrameMsg_CommitNavigation(routing_id_, head, body_url, common_params, 2656 Send(new FrameMsg_CommitNavigation(routing_id_, head, body_url, common_params,
2655 request_params)); 2657 request_params));
2656 2658
2657 // If a network request was made, update the Previews state. 2659 // If a network request was made, update the Previews state.
2658 if (ShouldMakeNetworkRequestForURL(common_params.url)) 2660 if (ShouldMakeNetworkRequestForURL(common_params.url) &&
2661 !FrameMsg_Navigate_Type::IsSameDocument(common_params.navigation_type)) {
2659 last_navigation_previews_state_ = common_params.previews_state; 2662 last_navigation_previews_state_ = common_params.previews_state;
2663 }
2660 2664
2661 // TODO(clamy): Release the stream handle once the renderer has finished 2665 // TODO(clamy): Release the stream handle once the renderer has finished
2662 // reading it. 2666 // reading it.
2663 stream_handle_ = std::move(body); 2667 stream_handle_ = std::move(body);
2664 2668
2665 // When navigating to a debug url, no commit is expected from the 2669 // When navigating to a debug url, no commit is expected from the
2666 // RenderFrameHost, nor should the throbber start. The NavigationRequest is 2670 // RenderFrameHost, nor should the throbber start. The NavigationRequest is
2667 // also not stored in the FrameTreeNode. Therefore do not reset it, as this 2671 // also not stored in the FrameTreeNode. Therefore do not reset it, as this
2668 // could cancel an existing pending navigation. 2672 // could cancel an existing pending navigation.
2669 if (!IsRendererDebugURL(common_params.url)) { 2673 if (!IsRendererDebugURL(common_params.url)) {
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
3324 } 3328 }
3325 3329
3326 void RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError() { 3330 void RenderFrameHostImpl::OnMediaInterfaceFactoryConnectionError() {
3327 DCHECK(media_interface_proxy_); 3331 DCHECK(media_interface_proxy_);
3328 media_interface_proxy_.reset(); 3332 media_interface_proxy_.reset();
3329 } 3333 }
3330 3334
3331 std::unique_ptr<NavigationHandleImpl> 3335 std::unique_ptr<NavigationHandleImpl>
3332 RenderFrameHostImpl::TakeNavigationHandleForCommit( 3336 RenderFrameHostImpl::TakeNavigationHandleForCommit(
3333 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { 3337 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3334 // If this is a same-page navigation, there isn't an existing NavigationHandle 3338 bool is_browser_initiated = (params.nav_entry_id != 0);
3335 // to use for the navigation. Create one, but don't reset any NavigationHandle 3339
3336 // tracking an ongoing navigation, since this may lead to the cancellation of
3337 // the navigation.
3338 if (params.was_within_same_page) { 3340 if (params.was_within_same_page) {
3339 // We don't ever expect navigation_handle_ to match, because handles are not 3341 if (IsBrowserSideNavigationEnabled()) {
3340 // created for same-page navigations. 3342 // When browser-side navigation is enabled, a NavigationHandle is created
3341 DCHECK(!navigation_handle_ || !navigation_handle_->IsSamePage()); 3343 // for browser-initiated same-page navigation. Try to take it if it's
3342 3344 // still available and matches the current navigation.
3345 if (is_browser_initiated && navigation_handle_ &&
3346 navigation_handle_->IsSamePage() &&
3347 navigation_handle_->GetURL() == params.url) {
3348 return std::move(navigation_handle_);
3349 }
3350 } else {
3351 // When browser-side navigation is disabled, there is never any existing
3352 // NavigationHandle to use for the navigation. We don't ever expect
3353 // navigation_handle_ to match.
3354 DCHECK(!navigation_handle_ || !navigation_handle_->IsSamePage());
3355 }
3356 // No existing NavigationHandle has been found. Create a new one, but don't
3357 // reset any NavigationHandle tracking an ongoing navigation, since this may
3358 // lead to the cancellation of the navigation.
3343 // First, determine if the navigation corresponds to the pending navigation 3359 // First, determine if the navigation corresponds to the pending navigation
3344 // entry. This is the case for a browser-initiated same-page navigation, 3360 // entry. This is the case for a browser-initiated same-page navigation,
3345 // which does not cause a NavigationHandle to be created because it does not 3361 // which does not cause a NavigationHandle to be created because it does not
3346 // go through DidStartProvisionalLoad. 3362 // go through DidStartProvisionalLoad.
3347 bool is_renderer_initiated = true; 3363 bool is_renderer_initiated = true;
3348 int pending_nav_entry_id = 0; 3364 int pending_nav_entry_id = 0;
3349 NavigationEntryImpl* pending_entry = 3365 NavigationEntryImpl* pending_entry =
3350 NavigationEntryImpl::FromNavigationEntry( 3366 NavigationEntryImpl::FromNavigationEntry(
3351 frame_tree_node()->navigator()->GetController()->GetPendingEntry()); 3367 frame_tree_node()->navigator()->GetController()->GetPendingEntry());
3352 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) { 3368 if (pending_entry && pending_entry->GetUniqueID() == params.nav_entry_id) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3406 // There is no pending NavigationEntry in these cases, so pass 0 as the 3422 // There is no pending NavigationEntry in these cases, so pass 0 as the
3407 // pending_nav_entry_id. If the previous handle was a prematurely aborted 3423 // pending_nav_entry_id. If the previous handle was a prematurely aborted
3408 // navigation loaded via LoadDataWithBaseURL, propagate the entry id. 3424 // navigation loaded via LoadDataWithBaseURL, propagate the entry id.
3409 return NavigationHandleImpl::Create( 3425 return NavigationHandleImpl::Create(
3410 params.url, frame_tree_node_, is_renderer_initiated, 3426 params.url, frame_tree_node_, is_renderer_initiated,
3411 params.was_within_same_page, base::TimeTicks::Now(), 3427 params.was_within_same_page, base::TimeTicks::Now(),
3412 entry_id_for_data_nav, false); // started_from_context_menu 3428 entry_id_for_data_nav, false); // started_from_context_menu
3413 } 3429 }
3414 3430
3415 } // namespace content 3431 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698