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

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

Issue 1785153005: Remove SiteIsolationPolicy::IsSwappedOutStateForbidden(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on ToT. Created 4 years, 9 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 <utility> 10 #include <utility>
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 RenderFrameProxyHost* proxy = 656 RenderFrameProxyHost* proxy =
657 CreateRenderFrameProxyHost(old_render_frame_host->GetSiteInstance(), 657 CreateRenderFrameProxyHost(old_render_frame_host->GetSiteInstance(),
658 old_render_frame_host->render_view_host()); 658 old_render_frame_host->render_view_host());
659 659
660 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. 660 // Tell the old RenderFrameHost to swap out and be replaced by the proxy.
661 old_render_frame_host->SwapOut(proxy, true); 661 old_render_frame_host->SwapOut(proxy, true);
662 662
663 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized. 663 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized.
664 proxy->set_render_frame_proxy_created(true); 664 proxy->set_render_frame_proxy_created(true);
665 665
666 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { 666 MoveToPendingDeleteHosts(std::move(old_render_frame_host));
667 // In --site-per-process, frames delete their RFH rather than storing it
668 // in the proxy. Schedule it for deletion once the SwapOutACK comes in.
669 // TODO(creis): This will be the default when we remove swappedout://.
670 MoveToPendingDeleteHosts(std::move(old_render_frame_host));
671 } else {
672 // We shouldn't get here for subframes, since we only swap subframes when
673 // --site-per-process is used.
674 DCHECK(frame_tree_node_->IsMainFrame());
675
676 // The old RenderFrameHost will stay alive inside the proxy so that existing
677 // JavaScript window references to it stay valid.
678 proxy->TakeFrameHostOwnership(std::move(old_render_frame_host));
679 }
680 } 667 }
681 668
682 void RenderFrameHostManager::DiscardUnusedFrame( 669 void RenderFrameHostManager::DiscardUnusedFrame(
683 scoped_ptr<RenderFrameHostImpl> render_frame_host) { 670 scoped_ptr<RenderFrameHostImpl> render_frame_host) {
684 // TODO(carlosk): this code is very similar to what can be found in 671 // TODO(carlosk): this code is very similar to what can be found in
685 // SwapOutOldFrame and we should see that these are unified at some point. 672 // SwapOutOldFrame and we should see that these are unified at some point.
686 673
687 // If the SiteInstance for the pending RFH is being used by others don't 674 // If the SiteInstance for the pending RFH is being used by others don't
688 // delete the RFH. Just swap it out and it can be reused at a later point. 675 // delete the RFH. Just swap it out and it can be reused at a later point.
689 // In --site-per-process, RenderFrameHosts are not kept around and are 676 // In --site-per-process, RenderFrameHosts are not kept around and are
690 // deleted when not used, replaced by RenderFrameProxyHosts. 677 // deleted when not used, replaced by RenderFrameProxyHosts.
691 SiteInstanceImpl* site_instance = render_frame_host->GetSiteInstance(); 678 SiteInstanceImpl* site_instance = render_frame_host->GetSiteInstance();
692 if (site_instance->HasSite() && site_instance->active_frame_count() > 1) { 679 if (site_instance->HasSite() && site_instance->active_frame_count() > 1) {
693 // Any currently suspended navigations are no longer needed. 680 // Any currently suspended navigations are no longer needed.
694 render_frame_host->CancelSuspendedNavigations(); 681 render_frame_host->CancelSuspendedNavigations();
695 682
696 // If a proxy already exists for the |site_instance|, just reuse it instead 683 // If a proxy already exists for the |site_instance|, just reuse it instead
697 // of creating a new one. There is no need to call SwapOut on the 684 // of creating a new one. There is no need to call SwapOut on the
698 // |render_frame_host|, as this method is only called to discard a pending 685 // |render_frame_host|, as this method is only called to discard a pending
699 // or speculative RenderFrameHost, i.e. one that has never hosted an actual 686 // or speculative RenderFrameHost, i.e. one that has never hosted an actual
700 // document. 687 // document.
701 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); 688 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance);
702 if (!proxy) { 689 if (!proxy) {
703 proxy = CreateRenderFrameProxyHost(site_instance, 690 proxy = CreateRenderFrameProxyHost(site_instance,
704 render_frame_host->render_view_host()); 691 render_frame_host->render_view_host());
705 } 692 }
706
707 if (!SiteIsolationPolicy::IsSwappedOutStateForbidden()) {
708 DCHECK(frame_tree_node_->IsMainFrame());
709
710 // When using swapped out RenderFrameHosts, it is possible for the pending
711 // RenderFrameHost to be an existing one in swapped out state. Since it
712 // has been used to start a navigation, it could have committed a
713 // document. Check if |render_frame_host| is already swapped out, to avoid
714 // swapping it out again.
715 if (!render_frame_host->is_swapped_out())
716 render_frame_host->SwapOut(proxy, false);
717
718 proxy->TakeFrameHostOwnership(std::move(render_frame_host));
719 }
720 } 693 }
721 694
722 render_frame_host.reset(); 695 render_frame_host.reset();
723 } 696 }
724 697
725 void RenderFrameHostManager::MoveToPendingDeleteHosts( 698 void RenderFrameHostManager::MoveToPendingDeleteHosts(
726 scoped_ptr<RenderFrameHostImpl> render_frame_host) { 699 scoped_ptr<RenderFrameHostImpl> render_frame_host) {
727 // If this is the main frame going away and there are no more references to 700 // If this is the main frame going away and there are no more references to
728 // its RenderViewHost, mark it for deletion as well so that we don't try to 701 // its RenderViewHost, mark it for deletion as well so that we don't try to
729 // reuse it. 702 // reuse it.
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 for (const auto& pair : proxy_hosts_) { 942 for (const auto& pair : proxy_hosts_) {
970 pair.second->Send(new FrameMsg_DidStopLoading(pair.second->GetRoutingID())); 943 pair.second->Send(new FrameMsg_DidStopLoading(pair.second->GetRoutingID()));
971 } 944 }
972 } 945 }
973 946
974 void RenderFrameHostManager::OnDidUpdateName(const std::string& name, 947 void RenderFrameHostManager::OnDidUpdateName(const std::string& name,
975 const std::string& unique_name) { 948 const std::string& unique_name) {
976 // The window.name message may be sent outside of --site-per-process when 949 // The window.name message may be sent outside of --site-per-process when
977 // report_frame_name_changes renderer preference is set (used by 950 // report_frame_name_changes renderer preference is set (used by
978 // WebView). Don't send the update to proxies in those cases. 951 // WebView). Don't send the update to proxies in those cases.
979 // TODO(nick,nasko): Should this be IsSwappedOutStateForbidden, to match
980 // OnDidUpdateOrigin?
981 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) 952 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
982 return; 953 return;
983 954
984 for (const auto& pair : proxy_hosts_) { 955 for (const auto& pair : proxy_hosts_) {
985 pair.second->Send(new FrameMsg_DidUpdateName(pair.second->GetRoutingID(), 956 pair.second->Send(new FrameMsg_DidUpdateName(pair.second->GetRoutingID(),
986 name, unique_name)); 957 name, unique_name));
987 } 958 }
988 } 959 }
989 960
990 void RenderFrameHostManager::OnEnforceStrictMixedContentChecking( 961 void RenderFrameHostManager::OnEnforceStrictMixedContentChecking(
991 bool should_enforce) { 962 bool should_enforce) {
992 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) 963 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
993 return; 964 return;
994 965
995 for (const auto& pair : proxy_hosts_) { 966 for (const auto& pair : proxy_hosts_) {
996 pair.second->Send(new FrameMsg_EnforceStrictMixedContentChecking( 967 pair.second->Send(new FrameMsg_EnforceStrictMixedContentChecking(
997 pair.second->GetRoutingID(), should_enforce)); 968 pair.second->GetRoutingID(), should_enforce));
998 } 969 }
999 } 970 }
1000 971
1001 void RenderFrameHostManager::OnDidUpdateOrigin(const url::Origin& origin) { 972 void RenderFrameHostManager::OnDidUpdateOrigin(const url::Origin& origin) {
1002 if (!SiteIsolationPolicy::IsSwappedOutStateForbidden())
1003 return;
1004
1005 for (const auto& pair : proxy_hosts_) { 973 for (const auto& pair : proxy_hosts_) {
1006 pair.second->Send( 974 pair.second->Send(
1007 new FrameMsg_DidUpdateOrigin(pair.second->GetRoutingID(), origin)); 975 new FrameMsg_DidUpdateOrigin(pair.second->GetRoutingID(), origin));
1008 } 976 }
1009 } 977 }
1010 978
1011 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor( 979 RenderFrameHostManager::SiteInstanceDescriptor::SiteInstanceDescriptor(
1012 BrowserContext* browser_context, 980 BrowserContext* browser_context,
1013 GURL dest_url, 981 GURL dest_url,
1014 bool related_to_current) 982 bool related_to_current)
1015 : existing_site_instance(nullptr), 983 : existing_site_instance(nullptr),
1016 new_is_related_to_current(related_to_current) { 984 new_is_related_to_current(related_to_current) {
1017 new_site_url = SiteInstance::GetSiteForURL(browser_context, dest_url); 985 new_site_url = SiteInstance::GetSiteForURL(browser_context, dest_url);
1018 } 986 }
1019 987
1020 void RenderFrameHostManager::RenderProcessGone(SiteInstanceImpl* instance) { 988 void RenderFrameHostManager::RenderProcessGone(SiteInstanceImpl* instance) {
1021 GetRenderFrameProxyHost(instance)->set_render_frame_proxy_created(false); 989 GetRenderFrameProxyHost(instance)->set_render_frame_proxy_created(false);
1022 } 990 }
1023 991
1024 void RenderFrameHostManager::ActiveFrameCountIsZero( 992 void RenderFrameHostManager::ActiveFrameCountIsZero(
1025 SiteInstanceImpl* site_instance) { 993 SiteInstanceImpl* site_instance) {
1026 // |site_instance| no longer contains any active RenderFrameHosts, so we don't 994 // |site_instance| no longer contains any active RenderFrameHosts, so we don't
1027 // need to maintain a proxy there anymore. 995 // need to maintain a proxy there anymore.
1028 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); 996 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance);
1029 CHECK(proxy); 997 CHECK(proxy);
1030 998
1031 // Delete the proxy. If it is for a main frame (and the RFH is stored
1032 // in the proxy) and it was still pending swap out, move the RFH to the
1033 // pending deletion list first.
1034 if (frame_tree_node_->IsMainFrame() && proxy->render_frame_host() &&
1035 proxy->render_frame_host()->rfh_state() ==
1036 RenderFrameHostImpl::STATE_PENDING_SWAP_OUT) {
1037 DCHECK(!SiteIsolationPolicy::IsSwappedOutStateForbidden());
1038 scoped_ptr<RenderFrameHostImpl> swapped_out_rfh =
1039 proxy->PassFrameHostOwnership();
1040 MoveToPendingDeleteHosts(std::move(swapped_out_rfh));
1041 }
1042
1043 DeleteRenderFrameProxyHost(site_instance); 999 DeleteRenderFrameProxyHost(site_instance);
1044 } 1000 }
1045 1001
1046 RenderFrameProxyHost* RenderFrameHostManager::CreateRenderFrameProxyHost( 1002 RenderFrameProxyHost* RenderFrameHostManager::CreateRenderFrameProxyHost(
1047 SiteInstance* site_instance, 1003 SiteInstance* site_instance,
1048 RenderViewHostImpl* rvh) { 1004 RenderViewHostImpl* rvh) {
1049 int site_instance_id = site_instance->GetId(); 1005 int site_instance_id = site_instance->GetId();
1050 CHECK(proxy_hosts_.find(site_instance_id) == proxy_hosts_.end()) 1006 CHECK(proxy_hosts_.find(site_instance_id) == proxy_hosts_.end())
1051 << "A proxy already existed for this SiteInstance."; 1007 << "A proxy already existed for this SiteInstance.";
1052 RenderFrameProxyHost* proxy_host = 1008 RenderFrameProxyHost* proxy_host =
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 CreateRenderFrame(new_instance, create_render_frame_flags, nullptr); 1567 CreateRenderFrame(new_instance, create_render_frame_flags, nullptr);
1612 1568
1613 return !!speculative_render_frame_host_; 1569 return !!speculative_render_frame_host_;
1614 } 1570 }
1615 1571
1616 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame( 1572 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame(
1617 SiteInstance* instance, 1573 SiteInstance* instance,
1618 int flags, 1574 int flags,
1619 int* view_routing_id_ptr) { 1575 int* view_routing_id_ptr) {
1620 bool swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); 1576 bool swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT);
1621 bool swapped_out_forbidden = 1577 int32_t widget_routing_id = MSG_ROUTING_NONE;
1622 SiteIsolationPolicy::IsSwappedOutStateForbidden(); 1578 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
1623 1579
1624 CHECK(instance); 1580 CHECK(instance);
1625 CHECK(!swapped_out_forbidden || !swapped_out); 1581 CHECK(!swapped_out);
1626 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible() || 1582 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible() ||
1627 frame_tree_node_->IsMainFrame()); 1583 frame_tree_node_->IsMainFrame());
1628 1584
1629 // Swapped out views should always be hidden. 1585 // Swapped out views should always be hidden.
1630 DCHECK(!swapped_out || (flags & CREATE_RF_HIDDEN)); 1586 DCHECK(!swapped_out || (flags & CREATE_RF_HIDDEN));
1631 1587
1632 scoped_ptr<RenderFrameHostImpl> new_render_frame_host; 1588 scoped_ptr<RenderFrameHostImpl> new_render_frame_host;
1633 bool success = true; 1589 bool success = true;
1634 if (view_routing_id_ptr) 1590 if (view_routing_id_ptr)
1635 *view_routing_id_ptr = MSG_ROUTING_NONE; 1591 *view_routing_id_ptr = MSG_ROUTING_NONE;
1636 1592
1637 // We are creating a pending, speculative or swapped out RFH here. We should 1593 // We are creating a pending, speculative or swapped out RFH here. We should
1638 // never create it in the same SiteInstance as our current RFH. 1594 // never create it in the same SiteInstance as our current RFH.
1639 CHECK_NE(render_frame_host_->GetSiteInstance(), instance); 1595 CHECK_NE(render_frame_host_->GetSiteInstance(), instance);
1640 1596
1641 // Check if we've already created an RFH for this SiteInstance. If so, try 1597 // A RenderFrame in a different process from its parent RenderFrame
1642 // to re-use the existing one, which has already been initialized. We'll 1598 // requires a RenderWidget for input/layout/painting.
1643 // remove it from the list of proxy hosts below if it will be active. 1599 if (frame_tree_node_->parent() &&
1644 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); 1600 frame_tree_node_->parent()->current_frame_host()->GetSiteInstance() !=
1645 if (proxy && proxy->render_frame_host()) { 1601 instance) {
1646 RenderViewHost* render_view_host = proxy->GetRenderViewHost(); 1602 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible());
1647 CHECK(!swapped_out_forbidden); 1603 widget_routing_id = instance->GetProcess()->GetNextRoutingID();
1648 if (view_routing_id_ptr)
1649 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID();
1650 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost.
1651 // Prevent the process from exiting while we're trying to use it.
1652 if (!swapped_out) {
1653 new_render_frame_host = proxy->PassFrameHostOwnership();
1654 new_render_frame_host->GetProcess()->AddPendingView();
1655
1656 DeleteRenderFrameProxyHost(instance);
1657 // NB |proxy| is deleted at this point.
1658
1659 // If we are reusing the RenderViewHost and it doesn't already have a
1660 // RenderWidgetHostView, we need to create one if this is the main frame.
1661 if (render_view_host->IsRenderViewLive() &&
1662 !render_view_host->GetWidget()->GetView() &&
1663 frame_tree_node_->IsMainFrame()) {
1664 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host);
1665 }
1666 }
1667 } else {
1668 // Create a new RenderFrameHost if we don't find an existing one.
1669
1670 int32_t widget_routing_id = MSG_ROUTING_NONE;
1671
1672 // A RenderFrame in a different process from its parent RenderFrame
1673 // requires a RenderWidget for input/layout/painting.
1674 if (frame_tree_node_->parent() &&
1675 frame_tree_node_->parent()->current_frame_host()->GetSiteInstance() !=
1676 instance) {
1677 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible());
1678 widget_routing_id = instance->GetProcess()->GetNextRoutingID();
1679 }
1680
1681 new_render_frame_host = CreateRenderFrameHost(
1682 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, widget_routing_id, flags);
1683 RenderViewHostImpl* render_view_host =
1684 new_render_frame_host->render_view_host();
1685
1686 // Prevent the process from exiting while we're trying to navigate in it.
1687 // Otherwise, if the new RFH is swapped out already, store it.
1688 if (!swapped_out) {
1689 new_render_frame_host->GetProcess()->AddPendingView();
1690 } else {
1691 proxy =
1692 CreateRenderFrameProxyHost(new_render_frame_host->GetSiteInstance(),
1693 new_render_frame_host->render_view_host());
1694 proxy->TakeFrameHostOwnership(std::move(new_render_frame_host));
1695 }
1696
1697 if (frame_tree_node_->IsMainFrame()) {
1698 success = InitRenderView(render_view_host, proxy);
1699
1700 // If we are reusing the RenderViewHost and it doesn't already have a
1701 // RenderWidgetHostView, we need to create one if this is the main frame.
1702 if (!swapped_out && !render_view_host->GetWidget()->GetView())
1703 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host);
1704 } else {
1705 DCHECK(render_view_host->IsRenderViewLive());
1706 }
1707
1708 if (success) {
1709 if (frame_tree_node_->IsMainFrame()) {
1710 // Don't show the main frame's view until we get a DidNavigate from it.
1711 // Only the RenderViewHost for the top-level RenderFrameHost has a
1712 // RenderWidgetHostView; RenderWidgetHosts for out-of-process iframes
1713 // will be created later and hidden.
1714 if (render_view_host->GetWidget()->GetView())
1715 render_view_host->GetWidget()->GetView()->Hide();
1716 }
1717 // RenderViewHost for |instance| might exist prior to calling
1718 // CreateRenderFrame. In such a case, InitRenderView will not create the
1719 // RenderFrame in the renderer process and it needs to be done
1720 // explicitly.
1721 if (swapped_out_forbidden) {
1722 // Init the RFH, so a RenderFrame is created in the renderer.
1723 DCHECK(new_render_frame_host);
1724 success = InitRenderFrame(new_render_frame_host.get());
1725 }
1726 }
1727
1728 if (success) {
1729 if (view_routing_id_ptr)
1730 *view_routing_id_ptr = render_view_host->GetRoutingID();
1731 }
1732 } 1604 }
1733 1605
1734 // Returns the new RFH if it isn't swapped out. 1606 new_render_frame_host = CreateRenderFrameHost(
1735 if (success && !swapped_out) { 1607 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, widget_routing_id, flags);
1608 RenderViewHostImpl* render_view_host =
1609 new_render_frame_host->render_view_host();
1610
1611 // Prevent the process from exiting while we're trying to navigate in it.
1612 new_render_frame_host->GetProcess()->AddPendingView();
1613
1614 if (frame_tree_node_->IsMainFrame()) {
1615 success = InitRenderView(render_view_host, proxy);
1616
1617 // If we are reusing the RenderViewHost and it doesn't already have a
1618 // RenderWidgetHostView, we need to create one if this is the main frame.
1619 if (!render_view_host->GetWidget()->GetView())
1620 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host);
1621 } else {
1622 DCHECK(render_view_host->IsRenderViewLive());
1623 }
1624
1625 if (success) {
1626 if (frame_tree_node_->IsMainFrame()) {
1627 // Don't show the main frame's view until we get a DidNavigate from it.
1628 // Only the RenderViewHost for the top-level RenderFrameHost has a
1629 // RenderWidgetHostView; RenderWidgetHosts for out-of-process iframes
1630 // will be created later and hidden.
1631 if (render_view_host->GetWidget()->GetView())
1632 render_view_host->GetWidget()->GetView()->Hide();
1633 }
1634 // RenderViewHost for |instance| might exist prior to calling
1635 // CreateRenderFrame. In such a case, InitRenderView will not create the
1636 // RenderFrame in the renderer process and it needs to be done
1637 // explicitly.
1638 DCHECK(new_render_frame_host);
1639 success = InitRenderFrame(new_render_frame_host.get());
1640 }
1641
1642 if (success) {
1643 if (view_routing_id_ptr)
1644 *view_routing_id_ptr = render_view_host->GetRoutingID();
1645 }
1646
1647 // Return the new RenderFrameHost on successful creation.
1648 if (success) {
1736 DCHECK(new_render_frame_host->GetSiteInstance() == instance); 1649 DCHECK(new_render_frame_host->GetSiteInstance() == instance);
1737 return new_render_frame_host; 1650 return new_render_frame_host;
1738 } 1651 }
1739 return nullptr; 1652 return nullptr;
1740 } 1653 }
1741 1654
1742 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) { 1655 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) {
1743 // A RenderFrameProxyHost should never be created in the same SiteInstance as 1656 // A RenderFrameProxyHost should never be created in the same SiteInstance as
1744 // the current RFH. 1657 // the current RFH.
1745 CHECK(instance); 1658 CHECK(instance);
1746 CHECK_NE(instance, render_frame_host_->GetSiteInstance()); 1659 CHECK_NE(instance, render_frame_host_->GetSiteInstance());
1747 1660
1748 RenderViewHostImpl* render_view_host = nullptr; 1661 RenderViewHostImpl* render_view_host = nullptr;
1749 1662
1750 // Ensure a RenderViewHost exists for |instance|, as it creates the page 1663 // Ensure a RenderViewHost exists for |instance|, as it creates the page
1751 // level structure in Blink. 1664 // level structure in Blink.
1752 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { 1665 render_view_host =
1753 render_view_host = 1666 frame_tree_node_->frame_tree()->GetRenderViewHost(instance);
1754 frame_tree_node_->frame_tree()->GetRenderViewHost(instance); 1667 if (!render_view_host) {
1755 if (!render_view_host) { 1668 CHECK(frame_tree_node_->IsMainFrame());
1756 CHECK(frame_tree_node_->IsMainFrame()); 1669 render_view_host = frame_tree_node_->frame_tree()->CreateRenderViewHost(
1757 render_view_host = frame_tree_node_->frame_tree()->CreateRenderViewHost( 1670 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, true, true);
1758 instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, true, true);
1759 }
1760 } 1671 }
1761 1672
1762 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); 1673 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
1763 if (proxy && proxy->is_render_frame_proxy_live()) 1674 if (proxy && proxy->is_render_frame_proxy_live())
1764 return proxy->GetRoutingID(); 1675 return proxy->GetRoutingID();
1765 1676
1766 if (!proxy) 1677 if (!proxy)
1767 proxy = CreateRenderFrameProxyHost(instance, render_view_host); 1678 proxy = CreateRenderFrameProxyHost(instance, render_view_host);
1768 1679
1769 if (SiteIsolationPolicy::IsSwappedOutStateForbidden() && 1680 if (frame_tree_node_->IsMainFrame()) {
1770 frame_tree_node_->IsMainFrame()) {
1771 InitRenderView(render_view_host, proxy); 1681 InitRenderView(render_view_host, proxy);
1772 } else { 1682 } else {
1773 proxy->InitRenderFrameProxy(); 1683 proxy->InitRenderFrameProxy();
1774 } 1684 }
1775 1685
1776 return proxy->GetRoutingID(); 1686 return proxy->GetRoutingID();
1777 } 1687 }
1778 1688
1779 void RenderFrameHostManager::CreateProxiesForChildFrame(FrameTreeNode* child) { 1689 void RenderFrameHostManager::CreateProxiesForChildFrame(FrameTreeNode* child) {
1780 RenderFrameProxyHost* outer_delegate_proxy = 1690 RenderFrameProxyHost* outer_delegate_proxy =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 // RenderFrameProxyHost. 1813 // RenderFrameProxyHost.
1904 int proxy_routing_id = MSG_ROUTING_NONE; 1814 int proxy_routing_id = MSG_ROUTING_NONE;
1905 RenderFrameProxyHost* existing_proxy = GetRenderFrameProxyHost(site_instance); 1815 RenderFrameProxyHost* existing_proxy = GetRenderFrameProxyHost(site_instance);
1906 if (existing_proxy) { 1816 if (existing_proxy) {
1907 proxy_routing_id = existing_proxy->GetRoutingID(); 1817 proxy_routing_id = existing_proxy->GetRoutingID();
1908 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE); 1818 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE);
1909 if (!existing_proxy->is_render_frame_proxy_live()) { 1819 if (!existing_proxy->is_render_frame_proxy_live()) {
1910 // Calling InitRenderFrameProxy on main frames seems to be causing 1820 // Calling InitRenderFrameProxy on main frames seems to be causing
1911 // https://crbug.com/575245, so track down how this can happen. 1821 // https://crbug.com/575245, so track down how this can happen.
1912 // TODO(creis): Remove this once we've found the cause. 1822 // TODO(creis): Remove this once we've found the cause.
1913 if (SiteIsolationPolicy::IsSwappedOutStateForbidden() && 1823 if (!frame_tree_node_->parent()) {
1914 !frame_tree_node_->parent()) {
1915 base::debug::SetCrashKeyValue( 1824 base::debug::SetCrashKeyValue(
1916 "initrf_frame_id", 1825 "initrf_frame_id",
1917 base::IntToString(render_frame_host->GetRoutingID())); 1826 base::IntToString(render_frame_host->GetRoutingID()));
1918 base::debug::SetCrashKeyValue("initrf_proxy_id", 1827 base::debug::SetCrashKeyValue("initrf_proxy_id",
1919 base::IntToString(proxy_routing_id)); 1828 base::IntToString(proxy_routing_id));
1920 base::debug::SetCrashKeyValue( 1829 base::debug::SetCrashKeyValue(
1921 "initrf_view_id", 1830 "initrf_view_id",
1922 base::IntToString( 1831 base::IntToString(
1923 render_frame_host->render_view_host()->GetRoutingID())); 1832 render_frame_host->render_view_host()->GetRoutingID()));
1924 base::debug::SetCrashKeyValue( 1833 base::debug::SetCrashKeyValue(
(...skipping 14 matching lines...) Expand all
1939 return delegate_->CreateRenderFrameForRenderManager( 1848 return delegate_->CreateRenderFrameForRenderManager(
1940 render_frame_host, proxy_routing_id, opener_routing_id, parent_routing_id, 1849 render_frame_host, proxy_routing_id, opener_routing_id, parent_routing_id,
1941 previous_sibling_routing_id); 1850 previous_sibling_routing_id);
1942 } 1851 }
1943 1852
1944 int RenderFrameHostManager::GetRoutingIdForSiteInstance( 1853 int RenderFrameHostManager::GetRoutingIdForSiteInstance(
1945 SiteInstance* site_instance) { 1854 SiteInstance* site_instance) {
1946 if (render_frame_host_->GetSiteInstance() == site_instance) 1855 if (render_frame_host_->GetSiteInstance() == site_instance)
1947 return render_frame_host_->GetRoutingID(); 1856 return render_frame_host_->GetRoutingID();
1948 1857
1949 // If there is a matching pending RFH, only return it if swapped out is
1950 // allowed, since otherwise there should be a proxy that should be used
1951 // instead.
1952 if (pending_render_frame_host_ &&
1953 pending_render_frame_host_->GetSiteInstance() == site_instance &&
1954 !SiteIsolationPolicy::IsSwappedOutStateForbidden())
1955 return pending_render_frame_host_->GetRoutingID();
1956
1957 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); 1858 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance);
1958 if (proxy) 1859 if (proxy)
1959 return proxy->GetRoutingID(); 1860 return proxy->GetRoutingID();
1960 1861
1961 return MSG_ROUTING_NONE; 1862 return MSG_ROUTING_NONE;
1962 } 1863 }
1963 1864
1964 void RenderFrameHostManager::CommitPendingWebUI() { 1865 void RenderFrameHostManager::CommitPendingWebUI() {
1965 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPendingWebUI", 1866 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPendingWebUI",
1966 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); 1867 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id());
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 1961
2061 // Notify that we've swapped RenderFrameHosts. We do this before shutting down 1962 // Notify that we've swapped RenderFrameHosts. We do this before shutting down
2062 // the RFH so that we can clean up RendererResources related to the RFH first. 1963 // the RFH so that we can clean up RendererResources related to the RFH first.
2063 delegate_->NotifySwappedFromRenderManager( 1964 delegate_->NotifySwappedFromRenderManager(
2064 old_render_frame_host.get(), render_frame_host_.get(), is_main_frame); 1965 old_render_frame_host.get(), render_frame_host_.get(), is_main_frame);
2065 1966
2066 // The RenderViewHost keeps track of the main RenderFrameHost routing id. 1967 // The RenderViewHost keeps track of the main RenderFrameHost routing id.
2067 // If this is committing a main frame navigation, update it and set the 1968 // If this is committing a main frame navigation, update it and set the
2068 // routing id in the RenderViewHost associated with the old RenderFrameHost 1969 // routing id in the RenderViewHost associated with the old RenderFrameHost
2069 // to MSG_ROUTING_NONE. 1970 // to MSG_ROUTING_NONE.
2070 if (is_main_frame && SiteIsolationPolicy::IsSwappedOutStateForbidden()) { 1971 if (is_main_frame) {
2071 render_frame_host_->render_view_host()->set_main_frame_routing_id( 1972 render_frame_host_->render_view_host()->set_main_frame_routing_id(
2072 render_frame_host_->routing_id()); 1973 render_frame_host_->routing_id());
2073 old_render_frame_host->render_view_host()->set_main_frame_routing_id( 1974 old_render_frame_host->render_view_host()->set_main_frame_routing_id(
2074 MSG_ROUTING_NONE); 1975 MSG_ROUTING_NONE);
2075 } 1976 }
2076 1977
2077 // Swap out the old frame now that the new one is visible. 1978 // Swap out the old frame now that the new one is visible.
2078 // This will swap it out and then put it on the proxy list (if there are other 1979 // This will swap it out and then put it on the proxy list (if there are other
2079 // active views in its SiteInstance) or schedule it for deletion when the swap 1980 // active views in its SiteInstance) or schedule it for deletion when the swap
2080 // out ack arrives (or immediately if the process isn't live). 1981 // out ack arrives (or immediately if the process isn't live).
2081 // In the --site-per-process case, old subframe RFHs are not kept alive inside 1982 // In the --site-per-process case, old subframe RFHs are not kept alive inside
2082 // the proxy. 1983 // the proxy.
2083 SwapOutOldFrame(std::move(old_render_frame_host)); 1984 SwapOutOldFrame(std::move(old_render_frame_host));
2084 1985
2085 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { 1986 // Since the new RenderFrameHost is now committed, there must be no proxies
2086 // Since the new RenderFrameHost is now committed, there must be no proxies 1987 // for its SiteInstance. Delete any existing ones.
2087 // for its SiteInstance. Delete any existing ones. 1988 DeleteRenderFrameProxyHost(render_frame_host_->GetSiteInstance());
2088 DeleteRenderFrameProxyHost(render_frame_host_->GetSiteInstance());
2089 }
2090 1989
2091 // If this is a subframe, it should have a CrossProcessFrameConnector 1990 // If this is a subframe, it should have a CrossProcessFrameConnector
2092 // created already. Use it to link the new RFH's view to the proxy that 1991 // created already. Use it to link the new RFH's view to the proxy that
2093 // belongs to the parent frame's SiteInstance. If this navigation causes 1992 // belongs to the parent frame's SiteInstance. If this navigation causes
2094 // an out-of-process frame to return to the same process as its parent, the 1993 // an out-of-process frame to return to the same process as its parent, the
2095 // proxy would have been removed from proxy_hosts_ above. 1994 // proxy would have been removed from proxy_hosts_ above.
2096 // Note: We do this after swapping out the old RFH because that may create 1995 // Note: We do this after swapping out the old RFH because that may create
2097 // the proxy we're looking for. 1996 // the proxy we're looking for.
2098 RenderFrameProxyHost* proxy_to_parent = GetProxyToParent(); 1997 RenderFrameProxyHost* proxy_to_parent = GetProxyToParent();
2099 if (proxy_to_parent) { 1998 if (proxy_to_parent) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) { 2370 if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) {
2472 // Ensure that all the nodes in the opener's FrameTree have 2371 // Ensure that all the nodes in the opener's FrameTree have
2473 // RenderFrameProxyHosts for the new SiteInstance. Only pass the node to 2372 // RenderFrameProxyHosts for the new SiteInstance. Only pass the node to
2474 // be skipped if it's in the same FrameTree. 2373 // be skipped if it's in the same FrameTree.
2475 if (skip_this_node && skip_this_node->frame_tree() != frame_tree) 2374 if (skip_this_node && skip_this_node->frame_tree() != frame_tree)
2476 skip_this_node = nullptr; 2375 skip_this_node = nullptr;
2477 frame_tree->CreateProxiesForSiteInstance(skip_this_node, instance); 2376 frame_tree->CreateProxiesForSiteInstance(skip_this_node, instance);
2478 } else { 2377 } else {
2479 // If any of the RenderViewHosts (current, pending, or swapped out) for this 2378 // If any of the RenderViewHosts (current, pending, or swapped out) for this
2480 // FrameTree has the same SiteInstance, then we can return early and reuse 2379 // FrameTree has the same SiteInstance, then we can return early and reuse
2481 // them. An exception is if we are in IsSwappedOutStateForbidden mode and 2380 // them. An exception is if we find a pending RenderViewHost: in this case,
2482 // find a pending RenderViewHost: in this case, we should still create a 2381 // we should still create a proxy, which will allow communicating with the
2483 // proxy, which will allow communicating with the opener until the pending 2382 // opener until the pending RenderView commits, or if the pending navigation
2484 // RenderView commits, or if the pending navigation is canceled. 2383 // is canceled.
2485 RenderViewHostImpl* rvh = frame_tree->GetRenderViewHost(instance); 2384 RenderViewHostImpl* rvh = frame_tree->GetRenderViewHost(instance);
2486 bool need_proxy_for_pending_rvh = 2385 bool need_proxy_for_pending_rvh = (rvh == pending_render_view_host());
2487 SiteIsolationPolicy::IsSwappedOutStateForbidden() &&
2488 (rvh == pending_render_view_host());
2489 if (rvh && rvh->IsRenderViewLive() && !need_proxy_for_pending_rvh) 2386 if (rvh && rvh->IsRenderViewLive() && !need_proxy_for_pending_rvh)
2490 return; 2387 return;
2491 2388
2492 if (rvh && !rvh->IsRenderViewLive()) { 2389 if (rvh && !rvh->IsRenderViewLive()) {
2493 EnsureRenderViewInitialized(rvh, instance); 2390 EnsureRenderViewInitialized(rvh, instance);
2494 } else { 2391 } else {
2495 // Create a swapped out RenderView in the given SiteInstance if none 2392 // Create a RenderFrameProxyHost in the given SiteInstance if none
2496 // exists. Since an opener can point to a subframe, do this on the root 2393 // exists. Since an opener can point to a subframe, do this on the root
2497 // frame of the current opener's frame tree. 2394 // frame of the current opener's frame tree.
2498 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { 2395 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance);
2499 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance);
2500 } else {
2501 frame_tree->root()->render_manager()->CreateRenderFrame(
2502 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, nullptr);
2503 }
2504 } 2396 }
2505 } 2397 }
2506 } 2398 }
2507 2399
2508 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { 2400 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) {
2509 if (!frame_tree_node_->opener()) 2401 if (!frame_tree_node_->opener())
2510 return MSG_ROUTING_NONE; 2402 return MSG_ROUTING_NONE;
2511 2403
2512 return frame_tree_node_->opener() 2404 return frame_tree_node_->opener()
2513 ->render_manager() 2405 ->render_manager()
(...skipping 26 matching lines...) Expand all
2540 } else if (pending_render_frame_host_) { 2432 } else if (pending_render_frame_host_) {
2541 send_msg(pending_render_frame_host_.get(), 2433 send_msg(pending_render_frame_host_.get(),
2542 pending_render_frame_host_->GetRoutingID(), msg); 2434 pending_render_frame_host_->GetRoutingID(), msg);
2543 } 2435 }
2544 2436
2545 msg->set_routing_id(render_frame_host_->GetRoutingID()); 2437 msg->set_routing_id(render_frame_host_->GetRoutingID());
2546 render_frame_host_->Send(msg); 2438 render_frame_host_->Send(msg);
2547 } 2439 }
2548 2440
2549 } // namespace content 2441 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698