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/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 Loading... | |
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 // Short-term solution: avoid creating a WebUI for subframes because |
763 request.bindings()); | 762 // non-PlzNavigate code path doesn't do it and some WebUI pages don't |
763 // support it. See http://crrev.com/2810583006/. | |
Charlie Reis
2017/04/19 19:34:04
Thanks, that helps. Let's change the last line of
arthursonzogni
2017/04/20 09:46:22
Done.
| |
764 if (frame_tree_node_->IsMainFrame()) { | |
765 UpdatePendingWebUIOnCurrentFrameHost(request.common_params().url, | |
766 request.bindings()); | |
767 } | |
764 | 768 |
765 navigation_rfh = render_frame_host_.get(); | 769 navigation_rfh = render_frame_host_.get(); |
766 | 770 |
767 DCHECK(!speculative_render_frame_host_); | 771 DCHECK(!speculative_render_frame_host_); |
768 } else { | 772 } else { |
769 // If the current RenderFrameHost cannot be used a speculative one is | 773 // If the current RenderFrameHost cannot be used a speculative one is |
770 // created with the SiteInstance for the current URL. If a speculative | 774 // 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 | 775 // RenderFrameHost already exists we try as much as possible to reuse it and |
772 // its associated WebUI. | 776 // its associated WebUI. |
773 | 777 |
774 // Check if an existing speculative RenderFrameHost can be reused. | 778 // Check if an existing speculative RenderFrameHost can be reused. |
775 if (!speculative_render_frame_host_ || | 779 if (!speculative_render_frame_host_ || |
776 speculative_render_frame_host_->GetSiteInstance() != | 780 speculative_render_frame_host_->GetSiteInstance() != |
777 dest_site_instance.get()) { | 781 dest_site_instance.get()) { |
778 // If a previous speculative RenderFrameHost didn't exist or if its | 782 // 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 | 783 // SiteInstance differs from the one for the current URL, a new one needs |
780 // to be created. | 784 // to be created. |
781 CleanUpNavigation(); | 785 CleanUpNavigation(); |
782 bool success = CreateSpeculativeRenderFrameHost(current_site_instance, | 786 bool success = CreateSpeculativeRenderFrameHost(current_site_instance, |
783 dest_site_instance.get()); | 787 dest_site_instance.get()); |
784 DCHECK(success); | 788 DCHECK(success); |
785 } | 789 } |
786 DCHECK(speculative_render_frame_host_); | 790 DCHECK(speculative_render_frame_host_); |
787 | 791 |
788 bool changed_web_ui = speculative_render_frame_host_->UpdatePendingWebUI( | 792 // Short-term solution: avoid creating a WebUI for subframes because |
789 request.common_params().url, request.bindings()); | 793 // non-PlzNavigate code path doesn't do it and some WebUI pages don't |
790 speculative_render_frame_host_->CommitPendingWebUI(); | 794 // support it. See http://crrev.com/2810583006/. |
791 DCHECK_EQ(GetNavigatingWebUI(), speculative_render_frame_host_->web_ui()); | 795 if (frame_tree_node_->IsMainFrame()) { |
792 notify_webui_of_rf_creation = | 796 bool changed_web_ui = speculative_render_frame_host_->UpdatePendingWebUI( |
793 changed_web_ui && speculative_render_frame_host_->web_ui(); | 797 request.common_params().url, request.bindings()); |
794 | 798 speculative_render_frame_host_->CommitPendingWebUI(); |
799 DCHECK_EQ(GetNavigatingWebUI(), speculative_render_frame_host_->web_ui()); | |
800 notify_webui_of_rf_creation = | |
801 changed_web_ui && speculative_render_frame_host_->web_ui(); | |
802 } | |
795 navigation_rfh = speculative_render_frame_host_.get(); | 803 navigation_rfh = speculative_render_frame_host_.get(); |
796 | 804 |
797 // Check if our current RFH is live. | 805 // Check if our current RFH is live. |
798 if (!render_frame_host_->IsRenderFrameLive()) { | 806 if (!render_frame_host_->IsRenderFrameLive()) { |
799 // The current RFH is not live. There's no reason to sit around with a | 807 // 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 | 808 // 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. | 809 // 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 | 810 // (Note that we don't care about on{before}unload handlers if the current |
803 // RFH isn't live.) | 811 // RFH isn't live.) |
804 // | 812 // |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
845 // removed once the process manager moves away from NotificationService. | 853 // removed once the process manager moves away from NotificationService. |
846 // See https://crbug.com/462682. | 854 // See https://crbug.com/462682. |
847 delegate_->NotifyMainFrameSwappedFromRenderManager( | 855 delegate_->NotifyMainFrameSwappedFromRenderManager( |
848 nullptr, render_frame_host_->render_view_host()); | 856 nullptr, render_frame_host_->render_view_host()); |
849 } | 857 } |
850 } | 858 } |
851 | 859 |
852 // If a WebUI was created in a speculative RenderFrameHost or a new | 860 // If a WebUI was created in a speculative RenderFrameHost or a new |
853 // RenderFrame was created then the WebUI never interacted with the | 861 // RenderFrame was created then the WebUI never interacted with the |
854 // RenderFrame or its RenderView. Notify using RenderFrameCreated. | 862 // RenderFrame or its RenderView. Notify using RenderFrameCreated. |
855 if (notify_webui_of_rf_creation && GetNavigatingWebUI()) | 863 if (notify_webui_of_rf_creation && GetNavigatingWebUI() && |
864 // Short-term solution: avoid creating a WebUI for subframes because | |
865 // non-PlzNavigate code path doesn't do it and some WebUI pages don't | |
866 // support it. See http://crrev.com/2810583006/. | |
Charlie Reis
2017/04/19 19:34:04
nit: Let's move this comment above line 863, since
arthursonzogni
2017/04/20 09:46:22
Done.
| |
867 frame_tree_node_->IsMainFrame()) { | |
856 GetNavigatingWebUI()->RenderFrameCreated(navigation_rfh); | 868 GetNavigatingWebUI()->RenderFrameCreated(navigation_rfh); |
869 } | |
857 | 870 |
858 return navigation_rfh; | 871 return navigation_rfh; |
859 } | 872 } |
860 | 873 |
861 // PlzNavigate | 874 // PlzNavigate |
862 void RenderFrameHostManager::CleanUpNavigation() { | 875 void RenderFrameHostManager::CleanUpNavigation() { |
863 CHECK(IsBrowserSideNavigationEnabled()); | 876 CHECK(IsBrowserSideNavigationEnabled()); |
864 if (speculative_render_frame_host_) { | 877 if (speculative_render_frame_host_) { |
865 bool was_loading = speculative_render_frame_host_->is_loading(); | 878 bool was_loading = speculative_render_frame_host_->is_loading(); |
866 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); | 879 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); |
(...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2808 delegate_->IsHidden()) { | 2821 delegate_->IsHidden()) { |
2809 if (delegate_->IsHidden()) { | 2822 if (delegate_->IsHidden()) { |
2810 render_frame_host_->GetView()->Hide(); | 2823 render_frame_host_->GetView()->Hide(); |
2811 } else { | 2824 } else { |
2812 render_frame_host_->GetView()->Show(); | 2825 render_frame_host_->GetView()->Show(); |
2813 } | 2826 } |
2814 } | 2827 } |
2815 } | 2828 } |
2816 | 2829 |
2817 } // namespace content | 2830 } // namespace content |
OLD | NEW |