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, |
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 this check once cross-site navigation no longer | |
Charlie Reis
2014/07/24 22:36:29
"this check" is ambiguous. Do this mean we want t
nasko
2014/07/25 07:13:20
Remove the whole block, as I expect the "swapped_o
kenrb
2014/07/25 23:42:05
I capitalized CHECK to remove the ambiguity.
| |
944 // 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(); |
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 24 matching lines...) Expand all Loading... | |
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( |
1010 render_view_host, opener_route_id, proxy_routing_id, | 1008 render_view_host, opener_route_id, proxy_routing_id, for_main_frame); |
Charlie Reis
2014/07/24 22:36:30
When do for_main_frame and frame_tree_node_->IsMai
kenrb
2014/07/25 23:42:05
Can you follow up on this with Nasko? I am not cle
Charlie Reis
2014/07/28 19:24:28
I think we've worked it out (mostly). See my late
ncarter (slow)
2014/07/28 22:30:49
In the code there are two competing notions of "ma
ncarter (slow)
2014/07/28 22:31:26
Stale comment -- ignore.
| |
1011 frame_tree_node_->IsMainFrame()); | 1009 if (success) { |
1012 if (success && frame_tree_node_->IsMainFrame()) { | 1010 if (frame_tree_node_->IsMainFrame()) { |
1013 // Don't show the main frame's view until we get a DidNavigate from it. | 1011 // Don't show the main frame's view until we get a DidNavigate from it. |
1014 render_view_host->GetView()->Hide(); | 1012 render_view_host->GetView()->Hide(); |
1013 } else if (!swapped_out) { | |
1014 // Init the RFH, so a RenderFrame is created in the renderer. | |
1015 DCHECK(new_render_frame_host.get()); | |
1016 success = InitRenderFrame(new_render_frame_host.get()); | |
1017 } | |
1018 if (swapped_out) { | |
1019 proxy_hosts_[instance->GetId()]->InitRenderFrameProxy(); | |
1020 } | |
1015 } else if (!swapped_out && pending_render_frame_host_) { | 1021 } else if (!swapped_out && pending_render_frame_host_) { |
1016 CancelPending(); | 1022 CancelPending(); |
1017 } | 1023 } |
1018 routing_id = render_view_host->GetRoutingID(); | 1024 routing_id = render_view_host->GetRoutingID(); |
1019 frame_to_announce = new_render_frame_host.get(); | 1025 frame_to_announce = new_render_frame_host.get(); |
1020 } | 1026 } |
1021 | 1027 |
1022 // Use this as our new pending RFH if it isn't swapped out. | 1028 // Use this as our new pending RFH if it isn't swapped out. |
1023 if (!swapped_out) | 1029 if (!swapped_out) |
1024 pending_render_frame_host_ = new_render_frame_host.Pass(); | 1030 pending_render_frame_host_ = new_render_frame_host.Pass(); |
1025 | 1031 |
1026 // If a brand new RFH was created, announce it to observers. | 1032 // If a brand new RFH was created, announce it to observers. |
1027 if (frame_to_announce) | 1033 if (frame_to_announce) |
1028 render_frame_delegate_->RenderFrameCreated(frame_to_announce); | 1034 render_frame_delegate_->RenderFrameCreated(frame_to_announce); |
1029 | 1035 |
1030 return routing_id; | 1036 return routing_id; |
1031 } | 1037 } |
1032 | 1038 |
1039 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) { | |
1040 // A RenderFrameProxyHost should never be created in the same SiteInstance as | |
1041 // the current RFH. | |
1042 CHECK(instance); | |
1043 CHECK_NE(instance, render_frame_host_->GetSiteInstance()); | |
1044 | |
1045 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | |
1046 if (proxy) | |
1047 return proxy->GetRoutingID(); | |
1048 | |
1049 proxy = new RenderFrameProxyHost(instance, frame_tree_node_); | |
1050 proxy_hosts_[instance->GetId()] = proxy; | |
1051 proxy->InitRenderFrameProxy(); | |
1052 return proxy->GetRoutingID(); | |
1053 } | |
1054 | |
1033 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, | 1055 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, |
1034 int opener_route_id, | 1056 int opener_route_id, |
1035 int proxy_routing_id, | 1057 int proxy_routing_id, |
1036 bool for_main_frame) { | 1058 bool for_main_frame) { |
1037 // We may have initialized this RenderViewHost for another RenderFrameHost. | 1059 // We may have initialized this RenderViewHost for another RenderFrameHost. |
1038 if (render_view_host->IsRenderViewLive()) | 1060 if (render_view_host->IsRenderViewLive()) |
1039 return true; | 1061 return true; |
1040 | 1062 |
1041 // If the pending navigation is to a WebUI and the RenderView is not in a | 1063 // 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 | 1064 // guest process, tell the RenderViewHost about any bindings it will need |
1043 // enabled. | 1065 // enabled. |
1044 if (pending_web_ui() && !render_view_host->GetProcess()->IsIsolatedGuest()) { | 1066 if (pending_web_ui() && !render_view_host->GetProcess()->IsIsolatedGuest()) { |
1045 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); | 1067 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); |
1046 } else { | 1068 } else { |
1047 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 1069 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled |
1048 // process unless it's swapped out. | 1070 // process unless it's swapped out. |
1049 RenderViewHostImpl* rvh_impl = | 1071 RenderViewHostImpl* rvh_impl = |
1050 static_cast<RenderViewHostImpl*>(render_view_host); | 1072 static_cast<RenderViewHostImpl*>(render_view_host); |
1051 if (!rvh_impl->IsSwappedOut()) { | 1073 if (!rvh_impl->IsSwappedOut()) { |
1052 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1074 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
1053 render_view_host->GetProcess()->GetID())); | 1075 render_view_host->GetProcess()->GetID())); |
1054 } | 1076 } |
1055 } | 1077 } |
1056 | 1078 |
1057 return delegate_->CreateRenderViewForRenderManager( | 1079 return delegate_->CreateRenderViewForRenderManager( |
1058 render_view_host, opener_route_id, proxy_routing_id, for_main_frame); | 1080 render_view_host, opener_route_id, proxy_routing_id, for_main_frame); |
1059 } | 1081 } |
1060 | 1082 |
1083 bool RenderFrameHostManager::InitRenderFrame( | |
1084 RenderFrameHost* render_frame_host) { | |
1085 RenderFrameHostImpl* rfh = | |
1086 static_cast<RenderFrameHostImpl*>(render_frame_host); | |
1087 if (rfh->IsRenderFrameLive()) | |
1088 return true; | |
1089 | |
1090 int parent_routing_id = MSG_ROUTING_NONE; | |
1091 if (frame_tree_node_->parent()) { | |
1092 parent_routing_id = frame_tree_node_->parent()->render_manager()-> | |
1093 GetRoutingIdForSiteInstance(render_frame_host->GetSiteInstance()); | |
1094 CHECK_NE(parent_routing_id, MSG_ROUTING_NONE); | |
1095 } | |
1096 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, | |
1097 parent_routing_id); | |
1098 } | |
1099 | |
1100 int RenderFrameHostManager::GetRoutingIdForSiteInstance( | |
1101 SiteInstance* site_instance) { | |
1102 if (render_frame_host_->GetSiteInstance() == site_instance) | |
1103 return render_frame_host_->GetRoutingID(); | |
1104 | |
1105 RenderFrameProxyHostMap::iterator iter = | |
1106 proxy_hosts_.find(site_instance->GetId()); | |
1107 if (iter != proxy_hosts_.end()) | |
1108 return iter->second->GetRoutingID(); | |
1109 | |
1110 return MSG_ROUTING_NONE; | |
1111 } | |
1112 | |
1061 void RenderFrameHostManager::CommitPending() { | 1113 void RenderFrameHostManager::CommitPending() { |
1062 // First check whether we're going to want to focus the location bar after | 1114 // 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 | 1115 // 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 | 1116 // 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. | 1117 // this triggers won't be able to figure out what's going on. |
1066 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 1118 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
1067 | 1119 |
1068 // We expect SwapOutOldPage to have canceled any modal dialogs and told the | 1120 // We expect SwapOutOldPage to have canceled any modal dialogs and told the |
1069 // renderer to suppress any further dialogs until it is swapped out. However, | 1121 // renderer to suppress any further dialogs until it is swapped out. However, |
1070 // crash reports indicate that it's still possible for modal dialogs to exist | 1122 // crash reports indicate that it's still possible for modal dialogs to exist |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1168 // TODO(creis): Swap out the subframe in --site-per-process. | 1220 // TODO(creis): Swap out the subframe in --site-per-process. |
1169 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) | 1221 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) |
1170 DCHECK(old_render_frame_host->is_swapped_out() || | 1222 DCHECK(old_render_frame_host->is_swapped_out() || |
1171 !RenderViewHostImpl::IsRVHStateActive( | 1223 !RenderViewHostImpl::IsRVHStateActive( |
1172 old_render_frame_host->render_view_host()->rvh_state())); | 1224 old_render_frame_host->render_view_host()->rvh_state())); |
1173 | 1225 |
1174 // If the RenderViewHost backing the RenderFrameHost is pending shutdown, | 1226 // If the RenderViewHost backing the RenderFrameHost is pending shutdown, |
1175 // the RenderFrameHost should be put in the map of RenderFrameHosts pending | 1227 // the RenderFrameHost should be put in the map of RenderFrameHosts pending |
1176 // shutdown. Otherwise, it is stored in the map of proxy hosts. | 1228 // shutdown. Otherwise, it is stored in the map of proxy hosts. |
1177 if (old_render_frame_host->render_view_host()->rvh_state() == | 1229 if (old_render_frame_host->render_view_host()->rvh_state() == |
1178 RenderViewHostImpl::STATE_PENDING_SHUTDOWN) { | 1230 RenderViewHostImpl::STATE_PENDING_SHUTDOWN) { |
1179 // The proxy for this RenderFrameHost is created when sending the | 1231 // The proxy for this RenderFrameHost is created when sending the |
1180 // SwapOut message, so check if it already exists and delete it. | 1232 // SwapOut message, so check if it already exists and delete it. |
1181 RenderFrameProxyHostMap::iterator iter = | 1233 RenderFrameProxyHostMap::iterator iter = |
1182 proxy_hosts_.find(old_site_instance_id); | 1234 proxy_hosts_.find(old_site_instance_id); |
1183 if (iter != proxy_hosts_.end()) { | 1235 if (iter != proxy_hosts_.end()) { |
1184 delete iter->second; | 1236 delete iter->second; |
1185 proxy_hosts_.erase(iter); | 1237 proxy_hosts_.erase(iter); |
1186 } | 1238 } |
1187 RFHPendingDeleteMap::iterator pending_delete_iter = | 1239 RFHPendingDeleteMap::iterator pending_delete_iter = |
1188 pending_delete_hosts_.find(old_site_instance_id); | 1240 pending_delete_hosts_.find(old_site_instance_id); |
1189 if (pending_delete_iter == pending_delete_hosts_.end() || | 1241 if (pending_delete_iter == pending_delete_hosts_.end() || |
1190 pending_delete_iter->second.get() != old_render_frame_host) { | 1242 pending_delete_iter->second.get() != old_render_frame_host) { |
1191 pending_delete_hosts_[old_site_instance_id] = | 1243 pending_delete_hosts_[old_site_instance_id] = |
1192 linked_ptr<RenderFrameHostImpl>(old_render_frame_host.release()); | 1244 linked_ptr<RenderFrameHostImpl>(old_render_frame_host.release()); |
1193 } | 1245 } |
1194 } else { | 1246 } else { |
1247 CHECK(proxy_hosts_.find(render_frame_host_->GetSiteInstance()->GetId()) == | |
1248 proxy_hosts_.end()); | |
1249 | |
1195 // Capture the active view count on the old RFH SiteInstance, since the | 1250 // 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. | 1251 // ownership might be passed into the proxy and the pointer will be |
1252 // invalid. | |
1197 int active_view_count = | 1253 int active_view_count = |
1198 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance()) | 1254 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance()) |
1199 ->active_view_count(); | 1255 ->active_view_count(); |
1200 | 1256 |
1201 RenderFrameProxyHostMap::iterator iter = | 1257 if (is_main_frame) { |
1202 proxy_hosts_.find(old_site_instance_id); | 1258 RenderFrameProxyHostMap::iterator iter = |
1203 CHECK(iter != proxy_hosts_.end()); | 1259 proxy_hosts_.find(old_site_instance_id); |
1204 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); | 1260 CHECK(iter != proxy_hosts_.end()); |
1261 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); | |
1262 } | |
1205 | 1263 |
1206 // If there are no active views in this SiteInstance, it means that | 1264 // 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 | 1265 // 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 | 1266 // know that all RFHs are swapped out, we can delete all the RFPHs and |
1209 // in this SiteInstance. | 1267 // RVHs in this SiteInstance. |
1210 if (!active_view_count) { | 1268 if (!active_view_count) { |
1211 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); | 1269 ShutdownRenderFrameProxyHostsInSiteInstance(old_site_instance_id); |
1212 } else { | 1270 } else { |
1213 // If this is a subframe, it should have a CrossProcessFrameConnector | 1271 // 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 | 1272 // created already and we just need to link it to the proper view in the |
1215 // new process. | 1273 // new process. |
1216 if (!is_main_frame) { | 1274 if (!is_main_frame) { |
1217 RenderFrameProxyHost* proxy = GetProxyToParent(); | 1275 RenderFrameProxyHost* proxy = GetProxyToParent(); |
1218 if (proxy) { | 1276 if (proxy) { |
1219 proxy->SetChildRWHView( | 1277 proxy->SetChildRWHView( |
1220 render_frame_host_->render_view_host()->GetView()); | 1278 render_frame_host_->render_view_host()->GetView()); |
1221 } | 1279 } |
1222 } | 1280 } |
1223 } | 1281 } |
1224 } | 1282 } |
1225 } | 1283 } |
1226 | 1284 |
1227 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( | 1285 void RenderFrameHostManager::ShutdownRenderFrameProxyHostsInSiteInstance( |
1228 int32 site_instance_id) { | 1286 int32 site_instance_id) { |
1229 // First remove any swapped out RFH for this SiteInstance from our own list. | 1287 // First remove any swapped out RFH for this SiteInstance from our own list. |
1230 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); | 1288 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); |
1231 | 1289 |
1232 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts | 1290 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts |
1233 // in the SiteInstance, then tell their respective FrameTrees to remove all | 1291 // in the SiteInstance, then tell their respective FrameTrees to remove all |
1234 // RenderFrameProxyHosts corresponding to them. | 1292 // RenderFrameProxyHosts corresponding to them. |
1235 // TODO(creis): Replace this with a RenderFrameHostIterator that protects | 1293 // TODO(creis): Replace this with a RenderFrameHostIterator that protects |
1236 // against use-after-frees if a later element is deleted before getting to it. | 1294 // against use-after-frees if a later element is deleted before getting to it. |
1237 scoped_ptr<RenderWidgetHostIterator> widgets( | 1295 scoped_ptr<RenderWidgetHostIterator> widgets( |
(...skipping 17 matching lines...) Expand all Loading... | |
1255 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate( | 1313 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate( |
1256 const NavigationEntryImpl& entry) { | 1314 const NavigationEntryImpl& entry) { |
1257 // If we are currently navigating cross-process, we want to get back to normal | 1315 // If we are currently navigating cross-process, we want to get back to normal |
1258 // and then navigate as usual. | 1316 // and then navigate as usual. |
1259 if (cross_navigation_pending_) { | 1317 if (cross_navigation_pending_) { |
1260 if (pending_render_frame_host_) | 1318 if (pending_render_frame_host_) |
1261 CancelPending(); | 1319 CancelPending(); |
1262 cross_navigation_pending_ = false; | 1320 cross_navigation_pending_ = false; |
1263 } | 1321 } |
1264 | 1322 |
1265 // render_frame_host_'s SiteInstance and new_instance will not be deleted | 1323 // render_frame_host_'s SiteInstance will not be deleted before the end of |
1266 // before the end of this method, so we don't have to worry about their ref | 1324 // this method, so we don't have to worry about the ref count dropping to |
1267 // counts dropping to zero. | 1325 // zero. The new_instance is possibly passed to CreateProxiesForSiteInstance, |
1326 // which expects properly ref-counted object, so use a scoped_refptr for it. | |
Charlie Reis
2014/07/24 22:36:29
Why does it expect that? As mentioned earlier, it
nasko
2014/07/25 07:13:20
I think I wrote the initial code for CreateProxies
kenrb
2014/07/25 23:42:05
Changed to SiteInstance*.
| |
1268 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1327 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
1269 SiteInstance* new_instance = current_instance; | 1328 scoped_refptr<SiteInstance> new_instance(current_instance); |
1270 | 1329 |
1271 // We do not currently swap processes for navigations in webview tag guests. | 1330 // We do not currently swap processes for navigations in webview tag guests. |
1272 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme); | 1331 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme); |
1273 | 1332 |
1274 // Determine if we need a new BrowsingInstance for this entry. If true, this | 1333 // Determine if we need a new BrowsingInstance for this entry. If true, this |
1275 // implies that it will get a new SiteInstance (and likely process), and that | 1334 // implies that it will get a new SiteInstance (and likely process), and that |
1276 // other tabs in the current BrowsingInstance will be unable to script it. | 1335 // other tabs in the current BrowsingInstance will be unable to script it. |
1277 // This is used for cases that require a process swap even in the | 1336 // This is used for cases that require a process swap even in the |
1278 // process-per-tab model, such as WebUI pages. | 1337 // process-per-tab model, such as WebUI pages. |
1279 const NavigationEntry* current_entry = | 1338 const NavigationEntry* current_entry = |
(...skipping 21 matching lines...) Expand all Loading... | |
1301 // not have its bindings set appropriately. | 1360 // not have its bindings set appropriately. |
1302 SetPendingWebUI(entry); | 1361 SetPendingWebUI(entry); |
1303 | 1362 |
1304 // Ensure that we have created RFHs for the new RFH's opener chain if | 1363 // 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 | 1364 // we are staying in the same BrowsingInstance. This allows the pending RFH |
1306 // to send cross-process script calls to its opener(s). | 1365 // to send cross-process script calls to its opener(s). |
1307 int opener_route_id = MSG_ROUTING_NONE; | 1366 int opener_route_id = MSG_ROUTING_NONE; |
1308 if (new_instance->IsRelatedSiteInstance(current_instance)) { | 1367 if (new_instance->IsRelatedSiteInstance(current_instance)) { |
1309 opener_route_id = | 1368 opener_route_id = |
1310 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 1369 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
1370 | |
1371 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
1372 switches::kSitePerProcess)) { | |
1373 // Create the swapped out RVH for the new SiteInstance. This will create | |
1374 // a top-level swapped out RFH as well, which will be wrapped by a | |
1375 // RenderFrameProxyHost in the subsequent call to create proxies. | |
1376 if (!frame_tree_node_->IsMainFrame()) { | |
1377 RenderViewHostImpl* render_view_host = | |
1378 frame_tree_node_->frame_tree()->GetRenderViewHost(new_instance); | |
1379 if (!render_view_host) { | |
1380 frame_tree_node_->frame_tree()->root()->render_manager() | |
1381 ->CreateRenderFrame(new_instance, | |
1382 MSG_ROUTING_NONE, | |
1383 true, | |
1384 false, | |
1385 true); | |
1386 } | |
1387 } | |
1388 | |
1389 // Ensure that the frame tree has RenderFrameProxyHosts for the new | |
1390 // SiteInstance in all nodes except the current one. | |
1391 frame_tree_node_->frame_tree()->CreateProxiesForSiteInstance( | |
1392 frame_tree_node_, new_instance); | |
1393 } | |
1311 } | 1394 } |
1312 | 1395 |
1313 // Create a non-swapped-out pending RFH with the given opener and navigate | 1396 // Create a non-swapped-out pending RFH with the given opener and navigate |
1314 // it. | 1397 // it. |
1315 int route_id = CreateRenderFrame(new_instance, opener_route_id, false, | 1398 int route_id = CreateRenderFrame(new_instance, |
1399 opener_route_id, | |
1400 false, | |
1401 frame_tree_node_->IsMainFrame(), | |
1316 delegate_->IsHidden()); | 1402 delegate_->IsHidden()); |
1317 if (route_id == MSG_ROUTING_NONE) | 1403 if (route_id == MSG_ROUTING_NONE) |
1318 return NULL; | 1404 return NULL; |
1319 | 1405 |
1320 // Check if our current RFH is live before we set up a transition. | 1406 // Check if our current RFH is live before we set up a transition. |
1321 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { | 1407 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { |
1322 if (!cross_navigation_pending_) { | 1408 if (!cross_navigation_pending_) { |
1323 // The current RFH is not live. There's no reason to sit around with a | 1409 // 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 | 1410 // 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 | 1411 // 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*>( | 1516 SiteInstanceImpl* site_instance = static_cast<SiteInstanceImpl*>( |
1431 pending_render_frame_host->GetSiteInstance()); | 1517 pending_render_frame_host->GetSiteInstance()); |
1432 if (site_instance->active_view_count() > 1) { | 1518 if (site_instance->active_view_count() > 1) { |
1433 // Any currently suspended navigations are no longer needed. | 1519 // Any currently suspended navigations are no longer needed. |
1434 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); | 1520 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); |
1435 | 1521 |
1436 RenderFrameProxyHost* proxy = | 1522 RenderFrameProxyHost* proxy = |
1437 new RenderFrameProxyHost(site_instance, frame_tree_node_); | 1523 new RenderFrameProxyHost(site_instance, frame_tree_node_); |
1438 proxy_hosts_[site_instance->GetId()] = proxy; | 1524 proxy_hosts_[site_instance->GetId()] = proxy; |
1439 pending_render_frame_host->SwapOut(proxy); | 1525 pending_render_frame_host->SwapOut(proxy); |
1440 proxy->TakeFrameHostOwnership(pending_render_frame_host.Pass()); | 1526 if (frame_tree_node_->IsMainFrame()) |
1527 proxy->TakeFrameHostOwnership(pending_render_frame_host.Pass()); | |
1441 } else { | 1528 } else { |
1442 // We won't be coming back, so delete this one. | 1529 // We won't be coming back, so delete this one. |
1443 pending_render_frame_host.reset(); | 1530 pending_render_frame_host.reset(); |
1444 } | 1531 } |
1445 | 1532 |
1446 pending_web_ui_.reset(); | 1533 pending_web_ui_.reset(); |
1447 pending_and_current_web_ui_.reset(); | 1534 pending_and_current_web_ui_.reset(); |
1448 } | 1535 } |
1449 | 1536 |
1450 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( | 1537 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( |
(...skipping 20 matching lines...) Expand all Loading... | |
1471 | 1558 |
1472 return old_render_frame_host.Pass(); | 1559 return old_render_frame_host.Pass(); |
1473 } | 1560 } |
1474 | 1561 |
1475 bool RenderFrameHostManager::IsRVHOnSwappedOutList( | 1562 bool RenderFrameHostManager::IsRVHOnSwappedOutList( |
1476 RenderViewHostImpl* rvh) const { | 1563 RenderViewHostImpl* rvh) const { |
1477 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( | 1564 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( |
1478 rvh->GetSiteInstance()); | 1565 rvh->GetSiteInstance()); |
1479 if (!proxy) | 1566 if (!proxy) |
1480 return false; | 1567 return false; |
1568 // If there is a proxy without RFH, it is for a subframe in the SiteInstance | |
1569 // of |rvh|. Subframes should be ignored in this case. | |
1570 if (!proxy->render_frame_host()) | |
1571 return false; | |
1481 return IsOnSwappedOutList(proxy->render_frame_host()); | 1572 return IsOnSwappedOutList(proxy->render_frame_host()); |
1482 } | 1573 } |
1483 | 1574 |
1484 bool RenderFrameHostManager::IsOnSwappedOutList( | 1575 bool RenderFrameHostManager::IsOnSwappedOutList( |
1485 RenderFrameHostImpl* rfh) const { | 1576 RenderFrameHostImpl* rfh) const { |
1486 if (!rfh->GetSiteInstance()) | 1577 if (!rfh->GetSiteInstance()) |
1487 return false; | 1578 return false; |
1488 | 1579 |
1489 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find( | 1580 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find( |
1490 rfh->GetSiteInstance()->GetId()); | 1581 rfh->GetSiteInstance()->GetId()); |
(...skipping 15 matching lines...) Expand all Loading... | |
1506 SiteInstance* instance) const { | 1597 SiteInstance* instance) const { |
1507 RenderFrameProxyHostMap::const_iterator iter = | 1598 RenderFrameProxyHostMap::const_iterator iter = |
1508 proxy_hosts_.find(instance->GetId()); | 1599 proxy_hosts_.find(instance->GetId()); |
1509 if (iter != proxy_hosts_.end()) | 1600 if (iter != proxy_hosts_.end()) |
1510 return iter->second; | 1601 return iter->second; |
1511 | 1602 |
1512 return NULL; | 1603 return NULL; |
1513 } | 1604 } |
1514 | 1605 |
1515 } // namespace content | 1606 } // namespace content |
OLD | NEW |