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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 // from the map and not leaked. | 531 // from the map and not leaked. |
532 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find( | 532 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find( |
533 render_frame_host_->GetSiteInstance()->GetId()); | 533 render_frame_host_->GetSiteInstance()->GetId()); |
534 if (iter != proxy_hosts_.end()) { | 534 if (iter != proxy_hosts_.end()) { |
535 delete iter->second; | 535 delete iter->second; |
536 proxy_hosts_.erase(iter); | 536 proxy_hosts_.erase(iter); |
537 } | 537 } |
538 | 538 |
539 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( | 539 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( |
540 render_frame_host_->GetSiteInstance(), frame_tree_node_); | 540 render_frame_host_->GetSiteInstance(), frame_tree_node_); |
541 proxy_hosts_[render_frame_host_->GetSiteInstance()->GetId()] = proxy; | 541 std::pair<RenderFrameProxyHostMap::iterator, bool> result = |
542 proxy_hosts_.insert(std::make_pair( | |
543 render_frame_host_->GetSiteInstance()->GetId(), proxy)); | |
544 CHECK(result.second) << "Inserting a duplicate item."; | |
542 | 545 |
543 // Tell the old frame it is being swapped out. This will fire the unload | 546 // Tell the old frame it is being swapped out. This will fire the unload |
544 // handler in the background (without firing the beforeunload handler a second | 547 // handler in the background (without firing the beforeunload handler a second |
545 // time). When the navigation completes, we will send a message to the | 548 // time). When the navigation completes, we will send a message to the |
546 // ResourceDispatcherHost, allowing the pending RVH's response to resume. | 549 // ResourceDispatcherHost, allowing the pending RVH's response to resume. |
547 render_frame_host_->SwapOut(proxy); | 550 render_frame_host_->SwapOut(proxy); |
548 | 551 |
549 // ResourceDispatcherHost has told us to run the onunload handler, which | 552 // ResourceDispatcherHost has told us to run the onunload handler, which |
550 // means it is not a download or unsafe page, and we are going to perform the | 553 // means it is not a download or unsafe page, and we are going to perform the |
551 // navigation. Thus, we no longer need to remember that the RenderFrameHost | 554 // navigation. Thus, we no longer need to remember that the RenderFrameHost |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
902 | 905 |
903 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrameHost( | 906 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrameHost( |
904 SiteInstance* site_instance, | 907 SiteInstance* site_instance, |
905 int view_routing_id, | 908 int view_routing_id, |
906 int frame_routing_id, | 909 int frame_routing_id, |
907 bool swapped_out, | 910 bool swapped_out, |
908 bool hidden) { | 911 bool hidden) { |
909 if (frame_routing_id == MSG_ROUTING_NONE) | 912 if (frame_routing_id == MSG_ROUTING_NONE) |
910 frame_routing_id = site_instance->GetProcess()->GetNextRoutingID(); | 913 frame_routing_id = site_instance->GetProcess()->GetNextRoutingID(); |
911 | 914 |
912 // Create a RVH for main frames, or find the existing one for subframes. | 915 // Create a RVH for the new frame or find an existing one. |
913 FrameTree* frame_tree = frame_tree_node_->frame_tree(); | 916 FrameTree* frame_tree = frame_tree_node_->frame_tree(); |
914 RenderViewHostImpl* render_view_host = NULL; | 917 RenderViewHostImpl* render_view_host = |
915 if (frame_tree_node_->IsMainFrame()) { | 918 frame_tree->GetRenderViewHost(site_instance); |
916 render_view_host = frame_tree->CreateRenderViewHostForMainFrame( | 919 if (!render_view_host) { |
920 render_view_host = frame_tree->CreateRenderViewHost( | |
917 site_instance, view_routing_id, frame_routing_id, swapped_out, hidden); | 921 site_instance, view_routing_id, frame_routing_id, swapped_out, hidden); |
918 } else { | |
919 render_view_host = frame_tree->GetRenderViewHostForSubFrame(site_instance); | |
920 | |
921 // If we haven't found a RVH for a subframe RFH, it's because we currently | |
922 // do not create top-level RFHs for pending subframe navigations. Create | |
923 // the RVH here for now. | |
924 // TODO(creis): Mirror the frame tree so this check isn't necessary. | |
925 if (!render_view_host) { | |
926 render_view_host = frame_tree->CreateRenderViewHostForMainFrame( | |
927 site_instance, view_routing_id, frame_routing_id, swapped_out, | |
928 hidden); | |
929 } | |
930 } | 922 } |
931 | 923 |
932 // TODO(creis): Pass hidden to RFH. | 924 // TODO(creis): Pass hidden to RFH. |
933 scoped_ptr<RenderFrameHostImpl> render_frame_host = | 925 scoped_ptr<RenderFrameHostImpl> render_frame_host = |
934 make_scoped_ptr(RenderFrameHostFactory::Create(render_view_host, | 926 make_scoped_ptr(RenderFrameHostFactory::Create(render_view_host, |
935 render_frame_delegate_, | 927 render_frame_delegate_, |
936 frame_tree, | 928 frame_tree, |
937 frame_tree_node_, | 929 frame_tree_node_, |
938 frame_routing_id, | 930 frame_routing_id, |
939 swapped_out).release()); | 931 swapped_out).release()); |
940 return render_frame_host.Pass(); | 932 return render_frame_host.Pass(); |
941 } | 933 } |
942 | 934 |
943 int RenderFrameHostManager::CreateRenderFrame( | 935 int RenderFrameHostManager::CreateRenderFrame(SiteInstance* instance, |
944 SiteInstance* instance, | 936 int opener_route_id, |
945 int opener_route_id, | 937 bool swapped_out, |
946 bool swapped_out, | 938 bool for_main_frame_navigation, |
947 bool hidden) { | 939 bool hidden) { |
948 CHECK(instance); | 940 CHECK(instance); |
949 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. | 941 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. |
950 | 942 |
943 // TODO(nasko): Remove the following CHECK once cross-site navigation no | |
944 // longer relies on swapped out RFH for the top-level frame. | |
945 if (!frame_tree_node_->IsMainFrame()) { | |
946 CHECK(!swapped_out); | |
947 } | |
948 | |
951 scoped_ptr<RenderFrameHostImpl> new_render_frame_host; | 949 scoped_ptr<RenderFrameHostImpl> new_render_frame_host; |
952 RenderFrameHostImpl* frame_to_announce = NULL; | 950 RenderFrameHostImpl* frame_to_announce = NULL; |
953 int routing_id = MSG_ROUTING_NONE; | 951 int routing_id = MSG_ROUTING_NONE; |
954 | 952 |
955 // We are creating a pending or swapped out RFH here. We should never create | 953 // We are creating a pending or swapped out RFH here. We should never create |
956 // it in the same SiteInstance as our current RFH. | 954 // it in the same SiteInstance as our current RFH. |
957 CHECK_NE(render_frame_host_->GetSiteInstance(), instance); | 955 CHECK_NE(render_frame_host_->GetSiteInstance(), instance); |
958 | 956 |
959 // Check if we've already created an RFH for this SiteInstance. If so, try | 957 // Check if we've already created an RFH for this SiteInstance. If so, try |
960 // to re-use the existing one, which has already been initialized. We'll | 958 // to re-use the existing one, which has already been initialized. We'll |
961 // remove it from the list of swapped out hosts if it commits. | 959 // remove it from the list of swapped out hosts if it commits. |
962 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | 960 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); |
963 | 961 |
964 if (proxy) { | 962 if (proxy) { |
965 routing_id = proxy->GetRenderViewHost()->GetRoutingID(); | 963 routing_id = proxy->GetRoutingID(); |
ncarter (slow)
2014/07/31 17:38:23
This line is the bug. Revert it. This function (su
| |
966 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. | 964 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. |
967 // Prevent the process from exiting while we're trying to use it. | 965 // Prevent the process from exiting while we're trying to use it. |
968 if (!swapped_out) { | 966 if (!swapped_out) { |
969 new_render_frame_host = proxy->PassFrameHostOwnership(); | 967 new_render_frame_host = proxy->PassFrameHostOwnership(); |
970 new_render_frame_host->GetProcess()->AddPendingView(); | 968 new_render_frame_host->GetProcess()->AddPendingView(); |
971 | 969 |
972 proxy_hosts_.erase(instance->GetId()); | 970 proxy_hosts_.erase(instance->GetId()); |
973 delete proxy; | 971 delete proxy; |
974 | 972 |
975 // When a new render view is created by the renderer, the new WebContents | 973 // When a new render view is created by the renderer, the new WebContents |
(...skipping 23 matching lines...) Expand all Loading... | |
999 if (!swapped_out) { | 997 if (!swapped_out) { |
1000 new_render_frame_host->GetProcess()->AddPendingView(); | 998 new_render_frame_host->GetProcess()->AddPendingView(); |
1001 } else { | 999 } else { |
1002 proxy = new RenderFrameProxyHost( | 1000 proxy = new RenderFrameProxyHost( |
1003 new_render_frame_host->GetSiteInstance(), frame_tree_node_); | 1001 new_render_frame_host->GetSiteInstance(), frame_tree_node_); |
1004 proxy_hosts_[instance->GetId()] = proxy; | 1002 proxy_hosts_[instance->GetId()] = proxy; |
1005 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass()); | 1003 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass()); |
1006 proxy_routing_id = proxy->GetRoutingID(); | 1004 proxy_routing_id = proxy->GetRoutingID(); |
1007 } | 1005 } |
1008 | 1006 |
1009 bool success = InitRenderView( | 1007 bool success = InitRenderView(render_view_host, |
1010 render_view_host, opener_route_id, proxy_routing_id, | 1008 opener_route_id, |
1011 frame_tree_node_->IsMainFrame()); | 1009 proxy_routing_id, |
1012 if (success && frame_tree_node_->IsMainFrame()) { | 1010 for_main_frame_navigation); |
1013 // Don't show the main frame's view until we get a DidNavigate from it. | 1011 if (success) { |
1014 render_view_host->GetView()->Hide(); | 1012 if (frame_tree_node_->IsMainFrame()) { |
1013 // Don't show the main frame's view until we get a DidNavigate from it. | |
1014 render_view_host->GetView()->Hide(); | |
1015 } else if (!swapped_out) { | |
1016 // Init the RFH, so a RenderFrame is created in the renderer. | |
1017 DCHECK(new_render_frame_host.get()); | |
1018 success = InitRenderFrame(new_render_frame_host.get()); | |
1019 } | |
1020 if (swapped_out) { | |
1021 proxy_hosts_[instance->GetId()]->InitRenderFrameProxy(); | |
1022 } | |
1015 } else if (!swapped_out && pending_render_frame_host_) { | 1023 } else if (!swapped_out && pending_render_frame_host_) { |
1016 CancelPending(); | 1024 CancelPending(); |
1017 } | 1025 } |
1018 routing_id = render_view_host->GetRoutingID(); | 1026 routing_id = render_view_host->GetRoutingID(); |
1019 frame_to_announce = new_render_frame_host.get(); | 1027 frame_to_announce = new_render_frame_host.get(); |
1020 } | 1028 } |
1021 | 1029 |
1022 // Use this as our new pending RFH if it isn't swapped out. | 1030 // Use this as our new pending RFH if it isn't swapped out. |
1023 if (!swapped_out) | 1031 if (!swapped_out) |
1024 pending_render_frame_host_ = new_render_frame_host.Pass(); | 1032 pending_render_frame_host_ = new_render_frame_host.Pass(); |
1025 | 1033 |
1026 // If a brand new RFH was created, announce it to observers. | 1034 // If a brand new RFH was created, announce it to observers. |
1027 if (frame_to_announce) | 1035 if (frame_to_announce) |
1028 render_frame_delegate_->RenderFrameCreated(frame_to_announce); | 1036 render_frame_delegate_->RenderFrameCreated(frame_to_announce); |
1029 | 1037 |
1030 return routing_id; | 1038 return routing_id; |
1031 } | 1039 } |
1032 | 1040 |
1041 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) { | |
1042 // A RenderFrameProxyHost should never be created in the same SiteInstance as | |
1043 // the current RFH. | |
1044 CHECK(instance); | |
1045 CHECK_NE(instance, render_frame_host_->GetSiteInstance()); | |
1046 | |
1047 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | |
1048 if (proxy) | |
1049 return proxy->GetRoutingID(); | |
1050 | |
1051 proxy = new RenderFrameProxyHost(instance, frame_tree_node_); | |
1052 proxy_hosts_[instance->GetId()] = proxy; | |
1053 proxy->InitRenderFrameProxy(); | |
1054 return proxy->GetRoutingID(); | |
1055 } | |
1056 | |
1033 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, | 1057 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, |
1034 int opener_route_id, | 1058 int opener_route_id, |
1035 int proxy_routing_id, | 1059 int proxy_routing_id, |
1036 bool for_main_frame) { | 1060 bool for_main_frame_navigation) { |
1037 // We may have initialized this RenderViewHost for another RenderFrameHost. | 1061 // We may have initialized this RenderViewHost for another RenderFrameHost. |
1038 if (render_view_host->IsRenderViewLive()) | 1062 if (render_view_host->IsRenderViewLive()) |
1039 return true; | 1063 return true; |
1040 | 1064 |
1041 // If the pending navigation is to a WebUI and the RenderView is not in a | 1065 // If the pending navigation is to a WebUI and the RenderView is not in a |
1042 // guest process, tell the RenderViewHost about any bindings it will need | 1066 // guest process, tell the RenderViewHost about any bindings it will need |
1043 // enabled. | 1067 // enabled. |
1044 if (pending_web_ui() && !render_view_host->GetProcess()->IsIsolatedGuest()) { | 1068 if (pending_web_ui() && !render_view_host->GetProcess()->IsIsolatedGuest()) { |
1045 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); | 1069 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); |
1046 } else { | 1070 } else { |
1047 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 1071 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled |
1048 // process unless it's swapped out. | 1072 // process unless it's swapped out. |
1049 RenderViewHostImpl* rvh_impl = | 1073 RenderViewHostImpl* rvh_impl = |
1050 static_cast<RenderViewHostImpl*>(render_view_host); | 1074 static_cast<RenderViewHostImpl*>(render_view_host); |
1051 if (!rvh_impl->IsSwappedOut()) { | 1075 if (!rvh_impl->IsSwappedOut()) { |
1052 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1076 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
1053 render_view_host->GetProcess()->GetID())); | 1077 render_view_host->GetProcess()->GetID())); |
1054 } | 1078 } |
1055 } | 1079 } |
1056 | 1080 |
1057 return delegate_->CreateRenderViewForRenderManager( | 1081 return delegate_->CreateRenderViewForRenderManager( |
1058 render_view_host, opener_route_id, proxy_routing_id, for_main_frame); | 1082 render_view_host, |
1083 opener_route_id, | |
1084 proxy_routing_id, | |
1085 for_main_frame_navigation); | |
1086 } | |
1087 | |
1088 bool RenderFrameHostManager::InitRenderFrame( | |
1089 RenderFrameHost* render_frame_host) { | |
1090 RenderFrameHostImpl* rfh = | |
1091 static_cast<RenderFrameHostImpl*>(render_frame_host); | |
1092 if (rfh->IsRenderFrameLive()) | |
1093 return true; | |
1094 | |
1095 int parent_routing_id = MSG_ROUTING_NONE; | |
1096 if (frame_tree_node_->parent()) { | |
1097 parent_routing_id = frame_tree_node_->parent()->render_manager()-> | |
1098 GetRoutingIdForSiteInstance(render_frame_host->GetSiteInstance()); | |
1099 CHECK_NE(parent_routing_id, MSG_ROUTING_NONE); | |
1100 } | |
1101 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, | |
1102 parent_routing_id); | |
1103 } | |
1104 | |
1105 int RenderFrameHostManager::GetRoutingIdForSiteInstance( | |
1106 SiteInstance* site_instance) { | |
1107 if (render_frame_host_->GetSiteInstance() == site_instance) | |
1108 return render_frame_host_->GetRoutingID(); | |
1109 | |
1110 RenderFrameProxyHostMap::iterator iter = | |
1111 proxy_hosts_.find(site_instance->GetId()); | |
1112 if (iter != proxy_hosts_.end()) | |
1113 return iter->second->GetRoutingID(); | |
1114 | |
1115 return MSG_ROUTING_NONE; | |
1059 } | 1116 } |
1060 | 1117 |
1061 void RenderFrameHostManager::CommitPending() { | 1118 void RenderFrameHostManager::CommitPending() { |
1062 // First check whether we're going to want to focus the location bar after | 1119 // First check whether we're going to want to focus the location bar after |
1063 // this commit. We do this now because the navigation hasn't formally | 1120 // this commit. We do this now because the navigation hasn't formally |
1064 // committed yet, so if we've already cleared |pending_web_ui_| the call chain | 1121 // committed yet, so if we've already cleared |pending_web_ui_| the call chain |
1065 // this triggers won't be able to figure out what's going on. | 1122 // this triggers won't be able to figure out what's going on. |
1066 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 1123 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
1067 | 1124 |
1068 // We expect SwapOutOldPage to have canceled any modal dialogs and told the | 1125 // We expect SwapOutOldPage to have canceled any modal dialogs and told the |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1168 // TODO(creis): Swap out the subframe in --site-per-process. | 1225 // TODO(creis): Swap out the subframe in --site-per-process. |
1169 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | 1226 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
1170 DCHECK(old_render_frame_host->is_swapped_out() || | 1227 DCHECK(old_render_frame_host->is_swapped_out() || |
1171 !RenderViewHostImpl::IsRVHStateActive( | 1228 !RenderViewHostImpl::IsRVHStateActive( |
1172 old_render_frame_host->render_view_host()->rvh_state())); | 1229 old_render_frame_host->render_view_host()->rvh_state())); |
1173 | 1230 |
1174 // If the RenderViewHost backing the RenderFrameHost is pending shutdown, | 1231 // If the RenderViewHost backing the RenderFrameHost is pending shutdown, |
1175 // the RenderFrameHost should be put in the map of RenderFrameHosts pending | 1232 // the RenderFrameHost should be put in the map of RenderFrameHosts pending |
1176 // shutdown. Otherwise, it is stored in the map of proxy hosts. | 1233 // shutdown. Otherwise, it is stored in the map of proxy hosts. |
1177 if (old_render_frame_host->render_view_host()->rvh_state() == | 1234 if (old_render_frame_host->render_view_host()->rvh_state() == |
1178 RenderViewHostImpl::STATE_PENDING_SHUTDOWN) { | 1235 RenderViewHostImpl::STATE_PENDING_SHUTDOWN) { |
1179 // The proxy for this RenderFrameHost is created when sending the | 1236 // The proxy for this RenderFrameHost is created when sending the |
1180 // SwapOut message, so check if it already exists and delete it. | 1237 // SwapOut message, so check if it already exists and delete it. |
1181 RenderFrameProxyHostMap::iterator iter = | 1238 RenderFrameProxyHostMap::iterator iter = |
1182 proxy_hosts_.find(old_site_instance_id); | 1239 proxy_hosts_.find(old_site_instance_id); |
1183 if (iter != proxy_hosts_.end()) { | 1240 if (iter != proxy_hosts_.end()) { |
1184 delete iter->second; | 1241 delete iter->second; |
1185 proxy_hosts_.erase(iter); | 1242 proxy_hosts_.erase(iter); |
1186 } | 1243 } |
1187 RFHPendingDeleteMap::iterator pending_delete_iter = | 1244 RFHPendingDeleteMap::iterator pending_delete_iter = |
1188 pending_delete_hosts_.find(old_site_instance_id); | 1245 pending_delete_hosts_.find(old_site_instance_id); |
1189 if (pending_delete_iter == pending_delete_hosts_.end() || | 1246 if (pending_delete_iter == pending_delete_hosts_.end() || |
1190 pending_delete_iter->second.get() != old_render_frame_host) { | 1247 pending_delete_iter->second.get() != old_render_frame_host) { |
1191 pending_delete_hosts_[old_site_instance_id] = | 1248 pending_delete_hosts_[old_site_instance_id] = |
1192 linked_ptr<RenderFrameHostImpl>(old_render_frame_host.release()); | 1249 linked_ptr<RenderFrameHostImpl>(old_render_frame_host.release()); |
1193 } | 1250 } |
1194 } else { | 1251 } else { |
1252 CHECK(proxy_hosts_.find(render_frame_host_->GetSiteInstance()->GetId()) == | |
1253 proxy_hosts_.end()); | |
1254 | |
1195 // Capture the active view count on the old RFH SiteInstance, since the | 1255 // Capture the active view count on the old RFH SiteInstance, since the |
1196 // ownership will be passed into the proxy and the pointer will be invalid. | 1256 // ownership might be passed into the proxy and the pointer will be |
1257 // invalid. | |
1197 int active_view_count = | 1258 int active_view_count = |
1198 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance()) | 1259 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance()) |
1199 ->active_view_count(); | 1260 ->active_view_count(); |
1200 | 1261 |
1201 RenderFrameProxyHostMap::iterator iter = | 1262 if (is_main_frame) { |
1202 proxy_hosts_.find(old_site_instance_id); | 1263 RenderFrameProxyHostMap::iterator iter = |
1203 CHECK(iter != proxy_hosts_.end()); | 1264 proxy_hosts_.find(old_site_instance_id); |
1204 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); | 1265 CHECK(iter != proxy_hosts_.end()); |
1266 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); | |
1267 } | |
1205 | 1268 |
1206 // If there are no active views in this SiteInstance, it means that | 1269 // If there are no active views in this SiteInstance, it means that |
1207 // this RFH was the last active one in the SiteInstance. Now that we | 1270 // this RFH was the last active one in the SiteInstance. Now that we |
1208 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs | 1271 // know that all RFHs are swapped out, we can delete all the RFPHs and |
1209 // in this SiteInstance. | 1272 // RVHs in this SiteInstance. |
1210 if (!active_view_count) { | 1273 if (!active_view_count) { |
1211 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); | 1274 ShutdownRenderFrameProxyHostsInSiteInstance(old_site_instance_id); |
1212 } else { | 1275 } else { |
1213 // If this is a subframe, it should have a CrossProcessFrameConnector | 1276 // If this is a subframe, it should have a CrossProcessFrameConnector |
1214 // created already and we just need to link it to the proper view in the | 1277 // created already and we just need to link it to the proper view in the |
1215 // new process. | 1278 // new process. |
1216 if (!is_main_frame) { | 1279 if (!is_main_frame) { |
1217 RenderFrameProxyHost* proxy = GetProxyToParent(); | 1280 RenderFrameProxyHost* proxy = GetProxyToParent(); |
1218 if (proxy) { | 1281 if (proxy) { |
1219 proxy->SetChildRWHView( | 1282 proxy->SetChildRWHView( |
1220 render_frame_host_->render_view_host()->GetView()); | 1283 render_frame_host_->render_view_host()->GetView()); |
1221 } | 1284 } |
1222 } | 1285 } |
1223 } | 1286 } |
1224 } | 1287 } |
1225 } | 1288 } |
1226 | 1289 |
1227 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( | 1290 void RenderFrameHostManager::ShutdownRenderFrameProxyHostsInSiteInstance( |
1228 int32 site_instance_id) { | 1291 int32 site_instance_id) { |
1229 // First remove any swapped out RFH for this SiteInstance from our own list. | 1292 // First remove any swapped out RFH for this SiteInstance from our own list. |
1230 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); | 1293 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); |
1231 | 1294 |
1232 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts | 1295 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts |
1233 // in the SiteInstance, then tell their respective FrameTrees to remove all | 1296 // in the SiteInstance, then tell their respective FrameTrees to remove all |
1234 // RenderFrameProxyHosts corresponding to them. | 1297 // RenderFrameProxyHosts corresponding to them. |
1235 // TODO(creis): Replace this with a RenderFrameHostIterator that protects | 1298 // TODO(creis): Replace this with a RenderFrameHostIterator that protects |
1236 // against use-after-frees if a later element is deleted before getting to it. | 1299 // against use-after-frees if a later element is deleted before getting to it. |
1237 scoped_ptr<RenderWidgetHostIterator> widgets( | 1300 scoped_ptr<RenderWidgetHostIterator> widgets( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1301 // not have its bindings set appropriately. | 1364 // not have its bindings set appropriately. |
1302 SetPendingWebUI(entry); | 1365 SetPendingWebUI(entry); |
1303 | 1366 |
1304 // Ensure that we have created RFHs for the new RFH's opener chain if | 1367 // Ensure that we have created RFHs for the new RFH's opener chain if |
1305 // we are staying in the same BrowsingInstance. This allows the pending RFH | 1368 // we are staying in the same BrowsingInstance. This allows the pending RFH |
1306 // to send cross-process script calls to its opener(s). | 1369 // to send cross-process script calls to its opener(s). |
1307 int opener_route_id = MSG_ROUTING_NONE; | 1370 int opener_route_id = MSG_ROUTING_NONE; |
1308 if (new_instance->IsRelatedSiteInstance(current_instance)) { | 1371 if (new_instance->IsRelatedSiteInstance(current_instance)) { |
1309 opener_route_id = | 1372 opener_route_id = |
1310 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 1373 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
1374 | |
1375 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
1376 switches::kSitePerProcess)) { | |
1377 // Ensure that the frame tree has RenderFrameProxyHosts for the new | |
1378 // SiteInstance in all nodes except the current one. | |
1379 frame_tree_node_->frame_tree()->CreateProxiesForSiteInstance( | |
1380 frame_tree_node_, new_instance); | |
1381 } | |
1311 } | 1382 } |
1312 | 1383 |
1313 // Create a non-swapped-out pending RFH with the given opener and navigate | 1384 // Create a non-swapped-out pending RFH with the given opener and navigate |
1314 // it. | 1385 // it. |
1315 int route_id = CreateRenderFrame(new_instance, opener_route_id, false, | 1386 int route_id = CreateRenderFrame(new_instance, |
1387 opener_route_id, | |
1388 false, | |
1389 frame_tree_node_->IsMainFrame(), | |
1316 delegate_->IsHidden()); | 1390 delegate_->IsHidden()); |
1317 if (route_id == MSG_ROUTING_NONE) | 1391 if (route_id == MSG_ROUTING_NONE) |
1318 return NULL; | 1392 return NULL; |
1319 | 1393 |
1320 // Check if our current RFH is live before we set up a transition. | 1394 // Check if our current RFH is live before we set up a transition. |
1321 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { | 1395 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { |
1322 if (!cross_navigation_pending_) { | 1396 if (!cross_navigation_pending_) { |
1323 // The current RFH is not live. There's no reason to sit around with a | 1397 // The current RFH is not live. There's no reason to sit around with a |
1324 // sad tab or a newly created RFH while we wait for the pending RFH to | 1398 // sad tab or a newly created RFH while we wait for the pending RFH to |
1325 // navigate. Just switch to the pending RFH now and go back to non | 1399 // navigate. Just switch to the pending RFH now and go back to non |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1430 SiteInstanceImpl* site_instance = static_cast<SiteInstanceImpl*>( | 1504 SiteInstanceImpl* site_instance = static_cast<SiteInstanceImpl*>( |
1431 pending_render_frame_host->GetSiteInstance()); | 1505 pending_render_frame_host->GetSiteInstance()); |
1432 if (site_instance->active_view_count() > 1) { | 1506 if (site_instance->active_view_count() > 1) { |
1433 // Any currently suspended navigations are no longer needed. | 1507 // Any currently suspended navigations are no longer needed. |
1434 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); | 1508 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); |
1435 | 1509 |
1436 RenderFrameProxyHost* proxy = | 1510 RenderFrameProxyHost* proxy = |
1437 new RenderFrameProxyHost(site_instance, frame_tree_node_); | 1511 new RenderFrameProxyHost(site_instance, frame_tree_node_); |
1438 proxy_hosts_[site_instance->GetId()] = proxy; | 1512 proxy_hosts_[site_instance->GetId()] = proxy; |
1439 pending_render_frame_host->SwapOut(proxy); | 1513 pending_render_frame_host->SwapOut(proxy); |
1440 proxy->TakeFrameHostOwnership(pending_render_frame_host.Pass()); | 1514 if (frame_tree_node_->IsMainFrame()) |
1515 proxy->TakeFrameHostOwnership(pending_render_frame_host.Pass()); | |
1441 } else { | 1516 } else { |
1442 // We won't be coming back, so delete this one. | 1517 // We won't be coming back, so delete this one. |
1443 pending_render_frame_host.reset(); | 1518 pending_render_frame_host.reset(); |
1444 } | 1519 } |
1445 | 1520 |
1446 pending_web_ui_.reset(); | 1521 pending_web_ui_.reset(); |
1447 pending_and_current_web_ui_.reset(); | 1522 pending_and_current_web_ui_.reset(); |
1448 } | 1523 } |
1449 | 1524 |
1450 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( | 1525 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( |
(...skipping 20 matching lines...) Expand all Loading... | |
1471 | 1546 |
1472 return old_render_frame_host.Pass(); | 1547 return old_render_frame_host.Pass(); |
1473 } | 1548 } |
1474 | 1549 |
1475 bool RenderFrameHostManager::IsRVHOnSwappedOutList( | 1550 bool RenderFrameHostManager::IsRVHOnSwappedOutList( |
1476 RenderViewHostImpl* rvh) const { | 1551 RenderViewHostImpl* rvh) const { |
1477 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( | 1552 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( |
1478 rvh->GetSiteInstance()); | 1553 rvh->GetSiteInstance()); |
1479 if (!proxy) | 1554 if (!proxy) |
1480 return false; | 1555 return false; |
1556 // If there is a proxy without RFH, it is for a subframe in the SiteInstance | |
1557 // of |rvh|. Subframes should be ignored in this case. | |
1558 if (!proxy->render_frame_host()) | |
1559 return false; | |
1481 return IsOnSwappedOutList(proxy->render_frame_host()); | 1560 return IsOnSwappedOutList(proxy->render_frame_host()); |
1482 } | 1561 } |
1483 | 1562 |
1484 bool RenderFrameHostManager::IsOnSwappedOutList( | 1563 bool RenderFrameHostManager::IsOnSwappedOutList( |
1485 RenderFrameHostImpl* rfh) const { | 1564 RenderFrameHostImpl* rfh) const { |
1486 if (!rfh->GetSiteInstance()) | 1565 if (!rfh->GetSiteInstance()) |
1487 return false; | 1566 return false; |
1488 | 1567 |
1489 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find( | 1568 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find( |
1490 rfh->GetSiteInstance()->GetId()); | 1569 rfh->GetSiteInstance()->GetId()); |
(...skipping 15 matching lines...) Expand all Loading... | |
1506 SiteInstance* instance) const { | 1585 SiteInstance* instance) const { |
1507 RenderFrameProxyHostMap::const_iterator iter = | 1586 RenderFrameProxyHostMap::const_iterator iter = |
1508 proxy_hosts_.find(instance->GetId()); | 1587 proxy_hosts_.find(instance->GetId()); |
1509 if (iter != proxy_hosts_.end()) | 1588 if (iter != proxy_hosts_.end()) |
1510 return iter->second; | 1589 return iter->second; |
1511 | 1590 |
1512 return NULL; | 1591 return NULL; |
1513 } | 1592 } |
1514 | 1593 |
1515 } // namespace content | 1594 } // namespace content |
OLD | NEW |