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

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

Issue 2810583006: PlzNavigate: Avoid creating WebUI for subframes. (Closed)
Patch Set: @dbeam suggestion Created 3 years, 8 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation( 712 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation(
713 request.common_params().url, request.source_site_instance(), 713 request.common_params().url, request.source_site_instance(),
714 request.dest_site_instance(), candidate_site_instance, 714 request.dest_site_instance(), candidate_site_instance,
715 request.common_params().transition, 715 request.common_params().transition,
716 request.restore_type() != RestoreType::NONE, request.is_view_source(), 716 request.restore_type() != RestoreType::NONE, request.is_view_source(),
717 was_server_redirect); 717 was_server_redirect);
718 718
719 // The appropriate RenderFrameHost to commit the navigation. 719 // The appropriate RenderFrameHost to commit the navigation.
720 RenderFrameHostImpl* navigation_rfh = nullptr; 720 RenderFrameHostImpl* navigation_rfh = nullptr;
721 721
722 bool notify_webui_of_rf_creation = false;
723
724 // Reuse the current RenderFrameHost if its SiteInstance matches the 722 // Reuse the current RenderFrameHost if its SiteInstance matches the
725 // navigation's. 723 // navigation's.
726 bool no_renderer_swap = current_site_instance == dest_site_instance.get(); 724 bool no_renderer_swap = current_site_instance == dest_site_instance.get();
727 725
728 if (frame_tree_node_->IsMainFrame()) { 726 if (frame_tree_node_->IsMainFrame()) {
729 // Renderer-initiated main frame navigations that may require a 727 // Renderer-initiated main frame navigations that may require a
730 // SiteInstance swap are sent to the browser via the OpenURL IPC and are 728 // SiteInstance swap are sent to the browser via the OpenURL IPC and are
731 // afterwards treated as browser-initiated navigations. NavigationRequests 729 // afterwards treated as browser-initiated navigations. NavigationRequests
732 // marked as renderer-initiated are created by receiving a BeginNavigation 730 // marked as renderer-initiated are created by receiving a BeginNavigation
733 // IPC, and will then proceed in the same renderer. In site-per-process 731 // 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 732 // mode, it is possible for renderer-intiated navigations to be allowed to
735 // go cross-process. Check it first. 733 // go cross-process. Check it first.
736 bool can_renderer_initiate_transfer = 734 bool can_renderer_initiate_transfer =
737 render_frame_host_->IsRenderFrameLive() && 735 render_frame_host_->IsRenderFrameLive() &&
738 ShouldMakeNetworkRequestForURL(request.common_params().url) && 736 ShouldMakeNetworkRequestForURL(request.common_params().url) &&
739 IsRendererTransferNeededForNavigation(render_frame_host_.get(), 737 IsRendererTransferNeededForNavigation(render_frame_host_.get(),
740 request.common_params().url); 738 request.common_params().url);
741 739
742 no_renderer_swap |= 740 no_renderer_swap |=
743 !request.may_transfer() && !can_renderer_initiate_transfer; 741 !request.may_transfer() && !can_renderer_initiate_transfer;
744 } else { 742 } else {
745 // Subframe navigations will use the current renderer, unless specifically 743 // Subframe navigations will use the current renderer, unless specifically
746 // allowed to swap processes. 744 // allowed to swap processes.
747 no_renderer_swap |= !CanSubframeSwapProcess( 745 no_renderer_swap |= !CanSubframeSwapProcess(
748 request.common_params().url, request.source_site_instance(), 746 request.common_params().url, request.source_site_instance(),
749 request.dest_site_instance(), was_server_redirect); 747 request.dest_site_instance(), was_server_redirect);
750 } 748 }
751 749
750 bool notify_webui_of_rf_creation = false;
752 if (no_renderer_swap) { 751 if (no_renderer_swap) {
753 // GetFrameHostForNavigation will be called more than once during a 752 // GetFrameHostForNavigation will be called more than once during a
754 // navigation (currently twice, on request and when it's about to commit in 753 // navigation (currently twice, on request and when it's about to commit in
755 // the renderer). In the follow up calls an existing pending WebUI should 754 // the renderer). In the follow up calls an existing pending WebUI should
756 // not be recreated if the URL didn't change. So instead of calling 755 // not be recreated if the URL didn't change. So instead of calling
757 // CleanUpNavigation just discard the speculative RenderFrameHost if one 756 // CleanUpNavigation just discard the speculative RenderFrameHost if one
758 // exists. 757 // exists.
759 if (speculative_render_frame_host_) 758 if (speculative_render_frame_host_)
760 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); 759 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost());
761 760
762 UpdatePendingWebUIOnCurrentFrameHost(request.common_params().url, 761 if (frame_tree_node_->IsMainFrame()) {
763 request.bindings()); 762 UpdatePendingWebUIOnCurrentFrameHost(request.common_params().url,
763 request.bindings());
764 }
764 765
765 navigation_rfh = render_frame_host_.get(); 766 navigation_rfh = render_frame_host_.get();
766 767
767 DCHECK(!speculative_render_frame_host_); 768 DCHECK(!speculative_render_frame_host_);
768 } else { 769 } else {
769 // If the current RenderFrameHost cannot be used a speculative one is 770 // If the current RenderFrameHost cannot be used a speculative one is
770 // created with the SiteInstance for the current URL. If a speculative 771 // created with the SiteInstance for the current URL. If a speculative
771 // RenderFrameHost already exists we try as much as possible to reuse it and 772 // RenderFrameHost already exists we try as much as possible to reuse it and
772 // its associated WebUI. 773 // its associated WebUI.
773 774
774 // Check if an existing speculative RenderFrameHost can be reused. 775 // Check if an existing speculative RenderFrameHost can be reused.
775 if (!speculative_render_frame_host_ || 776 if (!speculative_render_frame_host_ ||
776 speculative_render_frame_host_->GetSiteInstance() != 777 speculative_render_frame_host_->GetSiteInstance() !=
777 dest_site_instance.get()) { 778 dest_site_instance.get()) {
778 // If a previous speculative RenderFrameHost didn't exist or if its 779 // If a previous speculative RenderFrameHost didn't exist or if its
779 // SiteInstance differs from the one for the current URL, a new one needs 780 // SiteInstance differs from the one for the current URL, a new one needs
780 // to be created. 781 // to be created.
781 CleanUpNavigation(); 782 CleanUpNavigation();
782 bool success = CreateSpeculativeRenderFrameHost(current_site_instance, 783 bool success = CreateSpeculativeRenderFrameHost(current_site_instance,
783 dest_site_instance.get()); 784 dest_site_instance.get());
784 DCHECK(success); 785 DCHECK(success);
785 } 786 }
786 DCHECK(speculative_render_frame_host_); 787 DCHECK(speculative_render_frame_host_);
787 788
788 bool changed_web_ui = speculative_render_frame_host_->UpdatePendingWebUI( 789 if (frame_tree_node_->IsMainFrame()) {
789 request.common_params().url, request.bindings()); 790 bool changed_web_ui = speculative_render_frame_host_->UpdatePendingWebUI(
790 speculative_render_frame_host_->CommitPendingWebUI(); 791 request.common_params().url, request.bindings());
791 DCHECK_EQ(GetNavigatingWebUI(), speculative_render_frame_host_->web_ui()); 792 speculative_render_frame_host_->CommitPendingWebUI();
792 notify_webui_of_rf_creation = 793 DCHECK_EQ(GetNavigatingWebUI(), speculative_render_frame_host_->web_ui());
793 changed_web_ui && speculative_render_frame_host_->web_ui(); 794 notify_webui_of_rf_creation =
794 795 changed_web_ui && speculative_render_frame_host_->web_ui();
796 }
795 navigation_rfh = speculative_render_frame_host_.get(); 797 navigation_rfh = speculative_render_frame_host_.get();
796 798
797 // Check if our current RFH is live. 799 // Check if our current RFH is live.
798 if (!render_frame_host_->IsRenderFrameLive()) { 800 if (!render_frame_host_->IsRenderFrameLive()) {
799 // The current RFH is not live. There's no reason to sit around with a 801 // The current RFH is not live. There's no reason to sit around with a
800 // sad tab or a newly created RFH while we wait for the navigation to 802 // sad tab or a newly created RFH while we wait for the navigation to
801 // complete. Just switch to the speculative RFH now and go back to normal. 803 // complete. Just switch to the speculative RFH now and go back to normal.
802 // (Note that we don't care about on{before}unload handlers if the current 804 // (Note that we don't care about on{before}unload handlers if the current
803 // RFH isn't live.) 805 // RFH isn't live.)
804 // 806 //
(...skipping 23 matching lines...) Expand all
828 DCHECK(navigation_rfh && 830 DCHECK(navigation_rfh &&
829 (navigation_rfh == render_frame_host_.get() || 831 (navigation_rfh == render_frame_host_.get() ||
830 navigation_rfh == speculative_render_frame_host_.get())); 832 navigation_rfh == speculative_render_frame_host_.get()));
831 833
832 // If the RenderFrame that needs to navigate is not live (its process was just 834 // If the RenderFrame that needs to navigate is not live (its process was just
833 // created or has crashed), initialize it. 835 // created or has crashed), initialize it.
834 if (!navigation_rfh->IsRenderFrameLive()) { 836 if (!navigation_rfh->IsRenderFrameLive()) {
835 if (!ReinitializeRenderFrame(navigation_rfh)) 837 if (!ReinitializeRenderFrame(navigation_rfh))
836 return nullptr; 838 return nullptr;
837 839
838 notify_webui_of_rf_creation = true; 840 if (frame_tree_node_->IsMainFrame())
841 notify_webui_of_rf_creation = true;
839 842
840 if (navigation_rfh == render_frame_host_.get()) { 843 if (navigation_rfh == render_frame_host_.get()) {
841 // TODO(nasko): This is a very ugly hack. The Chrome extensions process 844 // TODO(nasko): This is a very ugly hack. The Chrome extensions process
842 // manager still uses NotificationService and expects to see a 845 // manager still uses NotificationService and expects to see a
843 // RenderViewHost changed notification after WebContents and 846 // RenderViewHost changed notification after WebContents and
844 // RenderFrameHostManager are completely initialized. This should be 847 // RenderFrameHostManager are completely initialized. This should be
845 // removed once the process manager moves away from NotificationService. 848 // removed once the process manager moves away from NotificationService.
846 // See https://crbug.com/462682. 849 // See https://crbug.com/462682.
847 delegate_->NotifyMainFrameSwappedFromRenderManager( 850 delegate_->NotifyMainFrameSwappedFromRenderManager(
848 nullptr, render_frame_host_->render_view_host()); 851 nullptr, render_frame_host_->render_view_host());
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 delegate_->IsHidden()) { 2811 delegate_->IsHidden()) {
2809 if (delegate_->IsHidden()) { 2812 if (delegate_->IsHidden()) {
2810 render_frame_host_->GetView()->Hide(); 2813 render_frame_host_->GetView()->Hide();
2811 } else { 2814 } else {
2812 render_frame_host_->GetView()->Show(); 2815 render_frame_host_->GetView()->Show();
2813 } 2816 }
2814 } 2817 }
2815 } 2818 }
2816 2819
2817 } // namespace content 2820 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698