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

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

Issue 2954623003: PlzNavigate: implement REUSE_COMMITTED_OR_PENDING_SITE for redirects (Closed)
Patch Set: Addressed comments Created 3 years, 5 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_manager.h" 5 #include "content/browser/frame_host/render_frame_host_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 dest_rfh == render_frame_host_.get() 694 dest_rfh == render_frame_host_.get()
695 ? NavigationRequest::AssociatedSiteInstanceType::CURRENT 695 ? NavigationRequest::AssociatedSiteInstanceType::CURRENT
696 : NavigationRequest::AssociatedSiteInstanceType::SPECULATIVE); 696 : NavigationRequest::AssociatedSiteInstanceType::SPECULATIVE);
697 } 697 }
698 698
699 // PlzNavigate 699 // PlzNavigate
700 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( 700 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation(
701 const NavigationRequest& request) { 701 const NavigationRequest& request) {
702 CHECK(IsBrowserSideNavigationEnabled()); 702 CHECK(IsBrowserSideNavigationEnabled());
703 703
704 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance();
705
706 SiteInstance* candidate_site_instance =
707 speculative_render_frame_host_
708 ? speculative_render_frame_host_->GetSiteInstance()
709 : nullptr;
710
711 bool was_server_redirect = request.navigation_handle() &&
712 request.navigation_handle()->WasServerRedirect();
713
714 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation(
715 request.common_params().url, request.source_site_instance(),
716 request.dest_site_instance(), candidate_site_instance,
717 request.common_params().transition,
718 request.restore_type() != RestoreType::NONE, request.is_view_source(),
719 was_server_redirect);
720
721 // The appropriate RenderFrameHost to commit the navigation. 704 // The appropriate RenderFrameHost to commit the navigation.
722 RenderFrameHostImpl* navigation_rfh = nullptr; 705 RenderFrameHostImpl* navigation_rfh = nullptr;
723 706
724 // Reuse the current RenderFrameHost if its SiteInstance matches the 707 // First compute the SiteInstance to use for the navigation.
725 // navigation's. 708 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance();
726 bool no_renderer_swap = current_site_instance == dest_site_instance.get(); 709 scoped_refptr<SiteInstance> dest_site_instance =
710 GetSiteInstanceForNavigationRequest(request);
727 711
728 if (frame_tree_node_->IsMainFrame()) { 712 // The SiteInstance determines whether to switch RenderFrameHost or not.
729 // Renderer-initiated main frame navigations that may require a 713 bool use_current_rfh = current_site_instance == dest_site_instance;
730 // SiteInstance swap are sent to the browser via the OpenURL IPC and are
731 // afterwards treated as browser-initiated navigations. NavigationRequests
732 // marked as renderer-initiated are created by receiving a BeginNavigation
733 // IPC, and will then proceed in the same renderer. In site-per-process
734 // mode, it is possible for renderer-intiated navigations to be allowed to
735 // go cross-process. Check it first.
736 bool can_renderer_initiate_transfer =
737 render_frame_host_->IsRenderFrameLive() &&
738 ShouldMakeNetworkRequestForURL(request.common_params().url) &&
739 IsRendererTransferNeededForNavigation(render_frame_host_.get(),
740 request.common_params().url);
741
742 no_renderer_swap |=
743 !request.may_transfer() && !can_renderer_initiate_transfer;
744 } else {
745 // Subframe navigations will use the current renderer, unless specifically
746 // allowed to swap processes.
747 no_renderer_swap |= !CanSubframeSwapProcess(
748 request.common_params().url, request.source_site_instance(),
749 request.dest_site_instance(), was_server_redirect);
750 }
751 714
752 bool notify_webui_of_rf_creation = false; 715 bool notify_webui_of_rf_creation = false;
753 if (no_renderer_swap) { 716 if (use_current_rfh) {
754 // GetFrameHostForNavigation will be called more than once during a 717 // GetFrameHostForNavigation will be called more than once during a
755 // navigation (currently twice, on request and when it's about to commit in 718 // navigation (currently twice, on request and when it's about to commit in
756 // the renderer). In the follow up calls an existing pending WebUI should 719 // the renderer). In the follow up calls an existing pending WebUI should
757 // not be recreated if the URL didn't change. So instead of calling 720 // not be recreated if the URL didn't change. So instead of calling
758 // CleanUpNavigation just discard the speculative RenderFrameHost if one 721 // CleanUpNavigation just discard the speculative RenderFrameHost if one
759 // exists. 722 // exists.
760 if (speculative_render_frame_host_) 723 if (speculative_render_frame_host_)
761 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); 724 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost());
762 725
763 // Short-term solution: avoid creating a WebUI for subframes because 726 // Short-term solution: avoid creating a WebUI for subframes because
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 render_view_host, opener_frame_routing_id, 1929 render_view_host, opener_frame_routing_id,
1967 proxy ? proxy->GetRoutingID() : MSG_ROUTING_NONE, 1930 proxy ? proxy->GetRoutingID() : MSG_ROUTING_NONE,
1968 frame_tree_node_->current_replication_state()); 1931 frame_tree_node_->current_replication_state());
1969 1932
1970 if (created && proxy) 1933 if (created && proxy)
1971 proxy->set_render_frame_proxy_created(true); 1934 proxy->set_render_frame_proxy_created(true);
1972 1935
1973 return created; 1936 return created;
1974 } 1937 }
1975 1938
1939 scoped_refptr<SiteInstance>
1940 RenderFrameHostManager::GetSiteInstanceForNavigationRequest(
1941 const NavigationRequest& request) {
1942 // First, check if the navigation can switch SiteInstances. If not, the
1943 // navigation should use the current SiteInstance.
1944 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance();
1945 bool no_renderer_swap_allowed = false;
1946 bool was_server_redirect = request.navigation_handle() &&
1947 request.navigation_handle()->WasServerRedirect();
1948
1949 if (frame_tree_node_->IsMainFrame()) {
1950 // Renderer-initiated main frame navigations that may require a
1951 // SiteInstance swap are sent to the browser via the OpenURL IPC and are
1952 // afterwards treated as browser-initiated navigations. NavigationRequests
1953 // marked as renderer-initiated are created by receiving a BeginNavigation
1954 // IPC, and will then proceed in the same renderer. In site-per-process
1955 // mode, it is possible for renderer-intiated navigations to be allowed to
1956 // go cross-process. Check it first.
1957 bool can_renderer_initiate_transfer =
1958 render_frame_host_->IsRenderFrameLive() &&
1959 ShouldMakeNetworkRequestForURL(request.common_params().url) &&
1960 IsRendererTransferNeededForNavigation(render_frame_host_.get(),
1961 request.common_params().url);
1962
1963 no_renderer_swap_allowed |=
1964 !request.may_transfer() && !can_renderer_initiate_transfer;
1965 } else {
1966 // Subframe navigations will use the current renderer, unless specifically
1967 // allowed to swap processes.
1968 no_renderer_swap_allowed |= !CanSubframeSwapProcess(
1969 request.common_params().url, request.source_site_instance(),
1970 request.dest_site_instance(), was_server_redirect);
1971 }
Charlie Reis 2017/06/27 18:46:35 Interesting that we're changing the order here and
clamy 2017/06/28 14:08:32 I thought it made more sense to re-order it :). I
Charlie Reis 2017/06/28 17:05:22 Acknowledged.
1972
1973 if (no_renderer_swap_allowed)
1974 return scoped_refptr<SiteInstance>(current_site_instance);
1975
1976 // If the navigation can swap SiteInstances, compute the SiteInstance it
1977 // should use.
1978 SiteInstance* candidate_site_instance =
1979 speculative_render_frame_host_
1980 ? speculative_render_frame_host_->GetSiteInstance()
1981 : nullptr;
1982
1983 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation(
1984 request.common_params().url, request.source_site_instance(),
1985 request.dest_site_instance(), candidate_site_instance,
1986 request.common_params().transition,
1987 request.restore_type() != RestoreType::NONE, request.is_view_source(),
1988 was_server_redirect);
1989
1990 return dest_site_instance;
1991 }
1992
1976 bool RenderFrameHostManager::InitRenderFrame( 1993 bool RenderFrameHostManager::InitRenderFrame(
1977 RenderFrameHostImpl* render_frame_host) { 1994 RenderFrameHostImpl* render_frame_host) {
1978 if (render_frame_host->IsRenderFrameLive()) 1995 if (render_frame_host->IsRenderFrameLive())
1979 return true; 1996 return true;
1980 1997
1981 SiteInstance* site_instance = render_frame_host->GetSiteInstance(); 1998 SiteInstance* site_instance = render_frame_host->GetSiteInstance();
1982 1999
1983 int opener_routing_id = MSG_ROUTING_NONE; 2000 int opener_routing_id = MSG_ROUTING_NONE;
1984 if (frame_tree_node_->opener()) 2001 if (frame_tree_node_->opener())
1985 opener_routing_id = GetOpenerRoutingID(site_instance); 2002 opener_routing_id = GetOpenerRoutingID(site_instance);
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
2829 ->is_hidden() != delegate_->IsHidden()) { 2846 ->is_hidden() != delegate_->IsHidden()) {
2830 if (delegate_->IsHidden()) { 2847 if (delegate_->IsHidden()) {
2831 view->Hide(); 2848 view->Hide();
2832 } else { 2849 } else {
2833 view->Show(); 2850 view->Show();
2834 } 2851 }
2835 } 2852 }
2836 } 2853 }
2837 2854
2838 } // namespace content 2855 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698