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

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

Issue 404613005: Start using RenderFrameProxyHost objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile fix Created 6 years, 4 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 | Annotate | Revision Log
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 <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
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
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 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();
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
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/28 19:24:28 Ok, Nick and I looked into this, and I can confirm
kenrb 2014/07/28 21:07:21 As discussed offline, this looks like it is workin
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
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 // not have its bindings set appropriately. 1359 // not have its bindings set appropriately.
1302 SetPendingWebUI(entry); 1360 SetPendingWebUI(entry);
1303 1361
1304 // Ensure that we have created RFHs for the new RFH's opener chain if 1362 // 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 1363 // we are staying in the same BrowsingInstance. This allows the pending RFH
1306 // to send cross-process script calls to its opener(s). 1364 // to send cross-process script calls to its opener(s).
1307 int opener_route_id = MSG_ROUTING_NONE; 1365 int opener_route_id = MSG_ROUTING_NONE;
1308 if (new_instance->IsRelatedSiteInstance(current_instance)) { 1366 if (new_instance->IsRelatedSiteInstance(current_instance)) {
1309 opener_route_id = 1367 opener_route_id =
1310 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); 1368 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance);
1369
1370 if (CommandLine::ForCurrentProcess()->HasSwitch(
1371 switches::kSitePerProcess)) {
1372 // Create the swapped out RVH for the new SiteInstance. This will create
Charlie Reis 2014/07/28 19:24:28 Nick had a good suggestion here. This first block
kenrb 2014/07/28 21:07:20 Done.
1373 // a top-level swapped out RFH as well, which will be wrapped by a
1374 // RenderFrameProxyHost in the subsequent call to create proxies.
1375 if (!frame_tree_node_->IsMainFrame()) {
1376 RenderViewHostImpl* render_view_host =
1377 frame_tree_node_->frame_tree()->GetRenderViewHost(new_instance);
1378 if (!render_view_host) {
1379 frame_tree_node_->frame_tree()->root()->render_manager()
1380 ->CreateRenderFrame(new_instance,
1381 MSG_ROUTING_NONE,
1382 true,
1383 false,
1384 true);
1385 }
1386 }
1387
1388 // Ensure that the frame tree has RenderFrameProxyHosts for the new
1389 // SiteInstance in all nodes except the current one.
1390 frame_tree_node_->frame_tree()->CreateProxiesForSiteInstance(
Charlie Reis 2014/07/28 19:24:28 We should mention that this call creates a scoped_
kenrb 2014/07/28 21:07:21 This is no longer necessary after moving the above
Charlie Reis 2014/07/28 22:32:28 Acknowledged.
1391 frame_tree_node_, new_instance);
1392 }
1311 } 1393 }
1312 1394
1313 // Create a non-swapped-out pending RFH with the given opener and navigate 1395 // Create a non-swapped-out pending RFH with the given opener and navigate
1314 // it. 1396 // it.
1315 int route_id = CreateRenderFrame(new_instance, opener_route_id, false, 1397 int route_id = CreateRenderFrame(new_instance,
1398 opener_route_id,
1399 false,
1400 frame_tree_node_->IsMainFrame(),
1316 delegate_->IsHidden()); 1401 delegate_->IsHidden());
1317 if (route_id == MSG_ROUTING_NONE) 1402 if (route_id == MSG_ROUTING_NONE)
1318 return NULL; 1403 return NULL;
1319 1404
1320 // Check if our current RFH is live before we set up a transition. 1405 // Check if our current RFH is live before we set up a transition.
1321 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { 1406 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) {
1322 if (!cross_navigation_pending_) { 1407 if (!cross_navigation_pending_) {
1323 // The current RFH is not live. There's no reason to sit around with a 1408 // 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 1409 // 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 1410 // 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
1430 SiteInstanceImpl* site_instance = static_cast<SiteInstanceImpl*>( 1515 SiteInstanceImpl* site_instance = static_cast<SiteInstanceImpl*>(
1431 pending_render_frame_host->GetSiteInstance()); 1516 pending_render_frame_host->GetSiteInstance());
1432 if (site_instance->active_view_count() > 1) { 1517 if (site_instance->active_view_count() > 1) {
1433 // Any currently suspended navigations are no longer needed. 1518 // Any currently suspended navigations are no longer needed.
1434 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations(); 1519 pending_render_frame_host->render_view_host()->CancelSuspendedNavigations();
1435 1520
1436 RenderFrameProxyHost* proxy = 1521 RenderFrameProxyHost* proxy =
1437 new RenderFrameProxyHost(site_instance, frame_tree_node_); 1522 new RenderFrameProxyHost(site_instance, frame_tree_node_);
1438 proxy_hosts_[site_instance->GetId()] = proxy; 1523 proxy_hosts_[site_instance->GetId()] = proxy;
1439 pending_render_frame_host->SwapOut(proxy); 1524 pending_render_frame_host->SwapOut(proxy);
1440 proxy->TakeFrameHostOwnership(pending_render_frame_host.Pass()); 1525 if (frame_tree_node_->IsMainFrame())
1526 proxy->TakeFrameHostOwnership(pending_render_frame_host.Pass());
1441 } else { 1527 } else {
1442 // We won't be coming back, so delete this one. 1528 // We won't be coming back, so delete this one.
1443 pending_render_frame_host.reset(); 1529 pending_render_frame_host.reset();
1444 } 1530 }
1445 1531
1446 pending_web_ui_.reset(); 1532 pending_web_ui_.reset();
1447 pending_and_current_web_ui_.reset(); 1533 pending_and_current_web_ui_.reset();
1448 } 1534 }
1449 1535
1450 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( 1536 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost(
(...skipping 20 matching lines...) Expand all
1471 1557
1472 return old_render_frame_host.Pass(); 1558 return old_render_frame_host.Pass();
1473 } 1559 }
1474 1560
1475 bool RenderFrameHostManager::IsRVHOnSwappedOutList( 1561 bool RenderFrameHostManager::IsRVHOnSwappedOutList(
1476 RenderViewHostImpl* rvh) const { 1562 RenderViewHostImpl* rvh) const {
1477 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( 1563 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(
1478 rvh->GetSiteInstance()); 1564 rvh->GetSiteInstance());
1479 if (!proxy) 1565 if (!proxy)
1480 return false; 1566 return false;
1567 // If there is a proxy without RFH, it is for a subframe in the SiteInstance
1568 // of |rvh|. Subframes should be ignored in this case.
1569 if (!proxy->render_frame_host())
1570 return false;
1481 return IsOnSwappedOutList(proxy->render_frame_host()); 1571 return IsOnSwappedOutList(proxy->render_frame_host());
1482 } 1572 }
1483 1573
1484 bool RenderFrameHostManager::IsOnSwappedOutList( 1574 bool RenderFrameHostManager::IsOnSwappedOutList(
1485 RenderFrameHostImpl* rfh) const { 1575 RenderFrameHostImpl* rfh) const {
1486 if (!rfh->GetSiteInstance()) 1576 if (!rfh->GetSiteInstance())
1487 return false; 1577 return false;
1488 1578
1489 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find( 1579 RenderFrameProxyHostMap::const_iterator iter = proxy_hosts_.find(
1490 rfh->GetSiteInstance()->GetId()); 1580 rfh->GetSiteInstance()->GetId());
(...skipping 15 matching lines...) Expand all
1506 SiteInstance* instance) const { 1596 SiteInstance* instance) const {
1507 RenderFrameProxyHostMap::const_iterator iter = 1597 RenderFrameProxyHostMap::const_iterator iter =
1508 proxy_hosts_.find(instance->GetId()); 1598 proxy_hosts_.find(instance->GetId());
1509 if (iter != proxy_hosts_.end()) 1599 if (iter != proxy_hosts_.end())
1510 return iter->second; 1600 return iter->second;
1511 1601
1512 return NULL; 1602 return NULL;
1513 } 1603 }
1514 1604
1515 } // namespace content 1605 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698