Chromium Code Reviews| 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 <utility> | 10 #include <utility> |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 pending_render_frame_host_->ClearAllWebUI(); | 728 pending_render_frame_host_->ClearAllWebUI(); |
| 729 // PlzNavigate | 729 // PlzNavigate |
| 730 if (speculative_render_frame_host_) | 730 if (speculative_render_frame_host_) |
| 731 speculative_render_frame_host_->ClearAllWebUI(); | 731 speculative_render_frame_host_->ClearAllWebUI(); |
| 732 } | 732 } |
| 733 | 733 |
| 734 // PlzNavigate | 734 // PlzNavigate |
| 735 void RenderFrameHostManager::DidCreateNavigationRequest( | 735 void RenderFrameHostManager::DidCreateNavigationRequest( |
| 736 NavigationRequest* request) { | 736 NavigationRequest* request) { |
| 737 CHECK(IsBrowserSideNavigationEnabled()); | 737 CHECK(IsBrowserSideNavigationEnabled()); |
| 738 RenderFrameHostImpl* dest_rfh = GetFrameHostForNavigation(*request); | 738 RenderFrameHostImpl* dest_rfh = GetFrameHostForNavigation(request); |
| 739 DCHECK(dest_rfh); | 739 DCHECK(dest_rfh); |
| 740 request->set_associated_site_instance_type( | |
| 741 dest_rfh == render_frame_host_.get() | |
| 742 ? NavigationRequest::AssociatedSiteInstanceType::CURRENT | |
| 743 : NavigationRequest::AssociatedSiteInstanceType::SPECULATIVE); | |
|
Charlie Reis
2016/05/23 17:26:40
Just curious, what was the reason this needed to b
clamy
2016/05/24 11:18:32
Yes this was a TODO to move it to GetFrameHostForN
| |
| 744 } | 740 } |
| 745 | 741 |
| 746 // PlzNavigate | 742 // PlzNavigate |
| 747 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( | 743 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( |
| 748 const NavigationRequest& request) { | 744 NavigationRequest* request) { |
| 749 CHECK(IsBrowserSideNavigationEnabled()); | 745 CHECK(IsBrowserSideNavigationEnabled()); |
| 750 | 746 |
| 751 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance(); | 747 SiteInstance* current_site_instance = render_frame_host_->GetSiteInstance(); |
| 752 | 748 |
| 753 SiteInstance* candidate_site_instance = | 749 SiteInstance* candidate_site_instance = |
| 754 speculative_render_frame_host_ | 750 speculative_render_frame_host_ |
| 755 ? speculative_render_frame_host_->GetSiteInstance() | 751 ? speculative_render_frame_host_->GetSiteInstance() |
| 756 : nullptr; | 752 : nullptr; |
| 757 | 753 |
| 758 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation( | 754 scoped_refptr<SiteInstance> dest_site_instance = GetSiteInstanceForNavigation( |
| 759 request.common_params().url, request.source_site_instance(), | 755 request->common_params().url, request->source_site_instance(), |
| 760 request.dest_site_instance(), candidate_site_instance, | 756 request->dest_site_instance(), candidate_site_instance, |
| 761 request.common_params().transition, | 757 request->common_params().transition, |
| 762 request.restore_type() != NavigationEntryImpl::RESTORE_NONE, | 758 request->restore_type() != NavigationEntryImpl::RESTORE_NONE, |
| 763 request.is_view_source()); | 759 request->is_view_source()); |
| 764 | 760 |
| 765 // The appropriate RenderFrameHost to commit the navigation. | 761 // The appropriate RenderFrameHost to commit the navigation. |
| 766 RenderFrameHostImpl* navigation_rfh = nullptr; | 762 RenderFrameHostImpl* navigation_rfh = nullptr; |
| 767 | 763 |
| 768 bool notify_webui_of_rv_creation = false; | 764 bool notify_webui_of_rv_creation = false; |
| 769 | 765 |
| 770 // Reuse the current RenderFrameHost if its SiteInstance matches the | 766 // Reuse the current RenderFrameHost if its SiteInstance matches the |
| 771 // navigation's. | 767 // navigation's. |
| 772 bool no_renderer_swap = current_site_instance == dest_site_instance.get(); | 768 bool no_renderer_swap = current_site_instance == dest_site_instance.get(); |
| 773 | 769 |
| 774 if (frame_tree_node_->IsMainFrame()) { | 770 if (frame_tree_node_->IsMainFrame()) { |
| 775 // Renderer-initiated main frame navigations that may require a | 771 // Renderer-initiated main frame navigations that may require a |
| 776 // SiteInstance swap are sent to the browser via the OpenURL IPC and are | 772 // SiteInstance swap are sent to the browser via the OpenURL IPC and are |
| 777 // afterwards treated as browser-initiated navigations. NavigationRequests | 773 // afterwards treated as browser-initiated navigations. NavigationRequests |
| 778 // marked as renderer-initiated are created by receiving a BeginNavigation | 774 // marked as renderer-initiated are created by receiving a BeginNavigation |
| 779 // IPC, and will then proceed in the same renderer. In site-per-process | 775 // IPC, and will then proceed in the same renderer. In site-per-process |
| 780 // mode, it is possible for renderer-intiated navigations to be allowed to | 776 // mode, it is possible for renderer-intiated navigations to be allowed to |
| 781 // go cross-process. Check it first. | 777 // go cross-process. Check it first. |
| 782 bool can_renderer_initiate_transfer = | 778 bool can_renderer_initiate_transfer = |
| 783 render_frame_host_->IsRenderFrameLive() && | 779 render_frame_host_->IsRenderFrameLive() && |
| 784 ShouldMakeNetworkRequestForURL(request.common_params().url) && | 780 ShouldMakeNetworkRequestForURL(request->common_params().url) && |
| 785 IsRendererTransferNeededForNavigation(render_frame_host_.get(), | 781 IsRendererTransferNeededForNavigation(render_frame_host_.get(), |
| 786 request.common_params().url); | 782 request->common_params().url); |
| 787 | 783 |
| 788 no_renderer_swap |= | 784 no_renderer_swap |= |
| 789 !request.browser_initiated() && !can_renderer_initiate_transfer; | 785 !request->browser_initiated() && !can_renderer_initiate_transfer; |
| 790 } else { | 786 } else { |
| 791 // Subframe navigations will use the current renderer, unless specifically | 787 // Subframe navigations will use the current renderer, unless specifically |
| 792 // allowed to swap processes. | 788 // allowed to swap processes. |
| 793 no_renderer_swap |= !CanSubframeSwapProcess(request.common_params().url, | 789 no_renderer_swap |= !CanSubframeSwapProcess(request->common_params().url, |
| 794 request.source_site_instance(), | 790 request->source_site_instance(), |
| 795 request.dest_site_instance()); | 791 request->dest_site_instance()); |
| 796 } | 792 } |
| 797 | 793 |
| 798 if (no_renderer_swap) { | 794 if (no_renderer_swap) { |
| 799 // GetFrameHostForNavigation will be called more than once during a | 795 // GetFrameHostForNavigation will be called more than once during a |
| 800 // navigation (currently twice, on request and when it's about to commit in | 796 // navigation (currently twice, on request and when it's about to commit in |
| 801 // the renderer). In the follow up calls an existing pending WebUI should | 797 // the renderer). In the follow up calls an existing pending WebUI should |
| 802 // not be recreated if the URL didn't change. So instead of calling | 798 // not be recreated if the URL didn't change. So instead of calling |
| 803 // CleanUpNavigation just discard the speculative RenderFrameHost if one | 799 // CleanUpNavigation just discard the speculative RenderFrameHost if one |
| 804 // exists. | 800 // exists. |
| 805 if (speculative_render_frame_host_) | 801 if (speculative_render_frame_host_) |
| 806 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); | 802 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); |
| 807 | 803 |
| 808 UpdatePendingWebUIOnCurrentFrameHost(request.common_params().url, | 804 UpdatePendingWebUIOnCurrentFrameHost(request->common_params().url, |
| 809 request.bindings()); | 805 request->bindings()); |
| 810 | 806 |
| 811 navigation_rfh = render_frame_host_.get(); | 807 navigation_rfh = render_frame_host_.get(); |
| 812 | 808 |
| 813 DCHECK(!speculative_render_frame_host_); | 809 DCHECK(!speculative_render_frame_host_); |
| 814 } else { | 810 } else { |
| 815 // If the current RenderFrameHost cannot be used a speculative one is | 811 // If the current RenderFrameHost cannot be used a speculative one is |
| 816 // created with the SiteInstance for the current URL. If a speculative | 812 // created with the SiteInstance for the current URL. If a speculative |
| 817 // RenderFrameHost already exists we try as much as possible to reuse it and | 813 // RenderFrameHost already exists we try as much as possible to reuse it and |
| 818 // its associated WebUI. | 814 // its associated WebUI. |
| 819 | 815 |
| 820 // Check if an existing speculative RenderFrameHost can be reused. | 816 // Check if an existing speculative RenderFrameHost can be reused. |
| 821 if (!speculative_render_frame_host_ || | 817 if (!speculative_render_frame_host_ || |
| 822 speculative_render_frame_host_->GetSiteInstance() != | 818 speculative_render_frame_host_->GetSiteInstance() != |
| 823 dest_site_instance.get()) { | 819 dest_site_instance.get()) { |
| 824 // If a previous speculative RenderFrameHost didn't exist or if its | 820 // If a previous speculative RenderFrameHost didn't exist or if its |
| 825 // SiteInstance differs from the one for the current URL, a new one needs | 821 // SiteInstance differs from the one for the current URL, a new one needs |
| 826 // to be created. | 822 // to be created. |
| 827 CleanUpNavigation(); | 823 CleanUpNavigation(); |
| 828 bool success = CreateSpeculativeRenderFrameHost(current_site_instance, | 824 bool success = CreateSpeculativeRenderFrameHost(current_site_instance, |
| 829 dest_site_instance.get()); | 825 dest_site_instance.get()); |
| 830 DCHECK(success); | 826 DCHECK(success); |
| 831 } | 827 } |
| 832 DCHECK(speculative_render_frame_host_); | 828 DCHECK(speculative_render_frame_host_); |
| 833 | 829 |
| 834 bool changed_web_ui = speculative_render_frame_host_->UpdatePendingWebUI( | 830 bool changed_web_ui = speculative_render_frame_host_->UpdatePendingWebUI( |
| 835 request.common_params().url, request.bindings()); | 831 request->common_params().url, request->bindings()); |
| 836 speculative_render_frame_host_->CommitPendingWebUI(); | 832 speculative_render_frame_host_->CommitPendingWebUI(); |
| 837 DCHECK_EQ(GetNavigatingWebUI(), speculative_render_frame_host_->web_ui()); | 833 DCHECK_EQ(GetNavigatingWebUI(), speculative_render_frame_host_->web_ui()); |
| 838 notify_webui_of_rv_creation = | 834 notify_webui_of_rv_creation = |
| 839 changed_web_ui && speculative_render_frame_host_->web_ui(); | 835 changed_web_ui && speculative_render_frame_host_->web_ui(); |
| 840 | 836 |
| 841 navigation_rfh = speculative_render_frame_host_.get(); | 837 navigation_rfh = speculative_render_frame_host_.get(); |
| 842 | 838 |
| 843 // Check if our current RFH is live. | 839 // Check if our current RFH is live. |
| 844 if (!render_frame_host_->IsRenderFrameLive()) { | 840 if (!render_frame_host_->IsRenderFrameLive()) { |
| 845 // The current RFH is not live. There's no reason to sit around with a | 841 // The current RFH is not live. There's no reason to sit around with a |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 } | 880 } |
| 885 DCHECK(navigation_rfh->IsRenderFrameLive()); | 881 DCHECK(navigation_rfh->IsRenderFrameLive()); |
| 886 } | 882 } |
| 887 | 883 |
| 888 // If a WebUI was created in a speculative RenderFrameHost or a new RenderView | 884 // If a WebUI was created in a speculative RenderFrameHost or a new RenderView |
| 889 // was created then the WebUI never interacted with the RenderView. Notify | 885 // was created then the WebUI never interacted with the RenderView. Notify |
| 890 // using RenderViewCreated. | 886 // using RenderViewCreated. |
| 891 if (notify_webui_of_rv_creation && GetNavigatingWebUI()) | 887 if (notify_webui_of_rv_creation && GetNavigatingWebUI()) |
| 892 GetNavigatingWebUI()->RenderViewCreated(navigation_rfh->render_view_host()); | 888 GetNavigatingWebUI()->RenderViewCreated(navigation_rfh->render_view_host()); |
| 893 | 889 |
| 890 request->set_associated_site_instance_type( | |
| 891 navigation_rfh == render_frame_host_.get() | |
| 892 ? NavigationRequest::AssociatedSiteInstanceType::CURRENT | |
| 893 : NavigationRequest::AssociatedSiteInstanceType::SPECULATIVE); | |
| 894 | |
| 894 return navigation_rfh; | 895 return navigation_rfh; |
| 895 } | 896 } |
| 896 | 897 |
| 897 // PlzNavigate | 898 // PlzNavigate |
| 898 void RenderFrameHostManager::CleanUpNavigation() { | 899 void RenderFrameHostManager::CleanUpNavigation() { |
| 899 CHECK(IsBrowserSideNavigationEnabled()); | 900 CHECK(IsBrowserSideNavigationEnabled()); |
| 900 if (speculative_render_frame_host_) { | 901 if (speculative_render_frame_host_) { |
| 901 bool was_loading = speculative_render_frame_host_->is_loading(); | 902 bool was_loading = speculative_render_frame_host_->is_loading(); |
| 902 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); | 903 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); |
| 903 if (was_loading) | 904 if (was_loading) |
| (...skipping 1663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2567 resolved_url)) { | 2568 resolved_url)) { |
| 2568 DCHECK(!dest_instance || | 2569 DCHECK(!dest_instance || |
| 2569 dest_instance == render_frame_host_->GetSiteInstance()); | 2570 dest_instance == render_frame_host_->GetSiteInstance()); |
| 2570 return false; | 2571 return false; |
| 2571 } | 2572 } |
| 2572 | 2573 |
| 2573 return true; | 2574 return true; |
| 2574 } | 2575 } |
| 2575 | 2576 |
| 2576 } // namespace content | 2577 } // namespace content |
| OLD | NEW |