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

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

Issue 444503002: Start using RenderFrameProxyHost objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Create view IFF frame is main frame 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
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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 main frames, or find the existing one for subframes.
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 = NULL;
915 if (frame_tree_node_->IsMainFrame()) { 918 if (frame_tree_node_->IsMainFrame()) {
916 render_view_host = frame_tree->CreateRenderViewHostForMainFrame( 919 render_view_host = frame_tree->CreateRenderViewHost(
917 site_instance, view_routing_id, frame_routing_id, swapped_out, hidden); 920 site_instance, view_routing_id, frame_routing_id, swapped_out, hidden);
918 } else { 921 } else {
919 render_view_host = frame_tree->GetRenderViewHostForSubFrame(site_instance); 922 render_view_host = frame_tree->GetRenderViewHost(site_instance);
920 923
921 // If we haven't found a RVH for a subframe RFH, it's because we currently 924 CHECK(render_view_host);
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 } 925 }
931 926
932 // TODO(creis): Pass hidden to RFH. 927 // TODO(creis): Pass hidden to RFH.
933 scoped_ptr<RenderFrameHostImpl> render_frame_host = 928 scoped_ptr<RenderFrameHostImpl> render_frame_host =
934 make_scoped_ptr(RenderFrameHostFactory::Create(render_view_host, 929 make_scoped_ptr(RenderFrameHostFactory::Create(render_view_host,
935 render_frame_delegate_, 930 render_frame_delegate_,
936 frame_tree, 931 frame_tree,
937 frame_tree_node_, 932 frame_tree_node_,
938 frame_routing_id, 933 frame_routing_id,
939 swapped_out).release()); 934 swapped_out).release());
940 return render_frame_host.Pass(); 935 return render_frame_host.Pass();
941 } 936 }
942 937
943 int RenderFrameHostManager::CreateRenderFrame( 938 int RenderFrameHostManager::CreateRenderFrame(SiteInstance* instance,
944 SiteInstance* instance, 939 int opener_route_id,
945 int opener_route_id, 940 bool swapped_out,
946 bool swapped_out, 941 bool for_main_frame_navigation,
947 bool hidden) { 942 bool hidden) {
948 CHECK(instance); 943 CHECK(instance);
949 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. 944 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden.
950 945
946 // TODO(nasko): Remove the following CHECK once cross-site navigation no
947 // longer relies on swapped out RFH for the top-level frame.
948 if (!frame_tree_node_->IsMainFrame()) {
949 CHECK(!swapped_out);
950 }
951
951 scoped_ptr<RenderFrameHostImpl> new_render_frame_host; 952 scoped_ptr<RenderFrameHostImpl> new_render_frame_host;
952 RenderFrameHostImpl* frame_to_announce = NULL; 953 RenderFrameHostImpl* frame_to_announce = NULL;
953 int routing_id = MSG_ROUTING_NONE; 954 int routing_id = MSG_ROUTING_NONE;
954 955
955 // We are creating a pending or swapped out RFH here. We should never create 956 // We are creating a pending or swapped out RFH here. We should never create
956 // it in the same SiteInstance as our current RFH. 957 // it in the same SiteInstance as our current RFH.
957 CHECK_NE(render_frame_host_->GetSiteInstance(), instance); 958 CHECK_NE(render_frame_host_->GetSiteInstance(), instance);
958 959
959 // Check if we've already created an RFH for this SiteInstance. If so, try 960 // 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 961 // to re-use the existing one, which has already been initialized. We'll
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 if (!swapped_out) { 1000 if (!swapped_out) {
1000 new_render_frame_host->GetProcess()->AddPendingView(); 1001 new_render_frame_host->GetProcess()->AddPendingView();
1001 } else { 1002 } else {
1002 proxy = new RenderFrameProxyHost( 1003 proxy = new RenderFrameProxyHost(
1003 new_render_frame_host->GetSiteInstance(), frame_tree_node_); 1004 new_render_frame_host->GetSiteInstance(), frame_tree_node_);
1004 proxy_hosts_[instance->GetId()] = proxy; 1005 proxy_hosts_[instance->GetId()] = proxy;
1005 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass()); 1006 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass());
1006 proxy_routing_id = proxy->GetRoutingID(); 1007 proxy_routing_id = proxy->GetRoutingID();
1007 } 1008 }
1008 1009
1009 bool success = InitRenderView( 1010 bool success = InitRenderView(render_view_host,
1010 render_view_host, opener_route_id, proxy_routing_id, 1011 opener_route_id,
1011 frame_tree_node_->IsMainFrame()); 1012 proxy_routing_id,
1012 if (success && frame_tree_node_->IsMainFrame()) { 1013 for_main_frame_navigation);
1013 // Don't show the main frame's view until we get a DidNavigate from it. 1014 if (success) {
1014 render_view_host->GetView()->Hide(); 1015 if (frame_tree_node_->IsMainFrame()) {
1016 // Don't show the main frame's view until we get a DidNavigate from it.
1017 render_view_host->GetView()->Hide();
1018 } else if (!swapped_out) {
1019 // Init the RFH, so a RenderFrame is created in the renderer.
1020 DCHECK(new_render_frame_host.get());
1021 success = InitRenderFrame(new_render_frame_host.get());
1022 }
1023 if (swapped_out) {
1024 proxy_hosts_[instance->GetId()]->InitRenderFrameProxy();
1025 }
1015 } else if (!swapped_out && pending_render_frame_host_) { 1026 } else if (!swapped_out && pending_render_frame_host_) {
1016 CancelPending(); 1027 CancelPending();
1017 } 1028 }
1018 routing_id = render_view_host->GetRoutingID(); 1029 routing_id = render_view_host->GetRoutingID();
1019 frame_to_announce = new_render_frame_host.get(); 1030 frame_to_announce = new_render_frame_host.get();
1020 } 1031 }
1021 1032
1022 // Use this as our new pending RFH if it isn't swapped out. 1033 // Use this as our new pending RFH if it isn't swapped out.
1023 if (!swapped_out) 1034 if (!swapped_out)
1024 pending_render_frame_host_ = new_render_frame_host.Pass(); 1035 pending_render_frame_host_ = new_render_frame_host.Pass();
1025 1036
1026 // If a brand new RFH was created, announce it to observers. 1037 // If a brand new RFH was created, announce it to observers.
1027 if (frame_to_announce) 1038 if (frame_to_announce)
1028 render_frame_delegate_->RenderFrameCreated(frame_to_announce); 1039 render_frame_delegate_->RenderFrameCreated(frame_to_announce);
1029 1040
1030 return routing_id; 1041 return routing_id;
1031 } 1042 }
1032 1043
1044 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) {
1045 // A RenderFrameProxyHost should never be created in the same SiteInstance as
1046 // the current RFH.
1047 CHECK(instance);
1048 CHECK_NE(instance, render_frame_host_->GetSiteInstance());
1049
1050 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance);
1051 if (proxy)
1052 return proxy->GetRoutingID();
1053
1054 proxy = new RenderFrameProxyHost(instance, frame_tree_node_);
1055 proxy_hosts_[instance->GetId()] = proxy;
1056 proxy->InitRenderFrameProxy();
1057 return proxy->GetRoutingID();
1058 }
1059
1033 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, 1060 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host,
1034 int opener_route_id, 1061 int opener_route_id,
1035 int proxy_routing_id, 1062 int proxy_routing_id,
1036 bool for_main_frame) { 1063 bool for_main_frame_navigation) {
1037 // We may have initialized this RenderViewHost for another RenderFrameHost. 1064 // We may have initialized this RenderViewHost for another RenderFrameHost.
1038 if (render_view_host->IsRenderViewLive()) 1065 if (render_view_host->IsRenderViewLive())
1039 return true; 1066 return true;
1040 1067
1041 // If the pending navigation is to a WebUI and the RenderView is not in a 1068 // 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 1069 // guest process, tell the RenderViewHost about any bindings it will need
1043 // enabled. 1070 // enabled.
1044 if (pending_web_ui() && !render_view_host->GetProcess()->IsIsolatedGuest()) { 1071 if (pending_web_ui() && !render_view_host->GetProcess()->IsIsolatedGuest()) {
1045 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); 1072 render_view_host->AllowBindings(pending_web_ui()->GetBindings());
1046 } else { 1073 } else {
1047 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled 1074 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled
1048 // process unless it's swapped out. 1075 // process unless it's swapped out.
1049 RenderViewHostImpl* rvh_impl = 1076 RenderViewHostImpl* rvh_impl =
1050 static_cast<RenderViewHostImpl*>(render_view_host); 1077 static_cast<RenderViewHostImpl*>(render_view_host);
1051 if (!rvh_impl->IsSwappedOut()) { 1078 if (!rvh_impl->IsSwappedOut()) {
1052 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( 1079 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
1053 render_view_host->GetProcess()->GetID())); 1080 render_view_host->GetProcess()->GetID()));
1054 } 1081 }
1055 } 1082 }
1056 1083
1057 return delegate_->CreateRenderViewForRenderManager( 1084 return delegate_->CreateRenderViewForRenderManager(
1058 render_view_host, opener_route_id, proxy_routing_id, for_main_frame); 1085 render_view_host,
1086 opener_route_id,
1087 proxy_routing_id,
1088 for_main_frame_navigation);
1089 }
1090
1091 bool RenderFrameHostManager::InitRenderFrame(
1092 RenderFrameHost* render_frame_host) {
1093 RenderFrameHostImpl* rfh =
1094 static_cast<RenderFrameHostImpl*>(render_frame_host);
1095 if (rfh->IsRenderFrameLive())
1096 return true;
1097
1098 int parent_routing_id = MSG_ROUTING_NONE;
1099 if (frame_tree_node_->parent()) {
1100 parent_routing_id = frame_tree_node_->parent()->render_manager()->
1101 GetRoutingIdForSiteInstance(render_frame_host->GetSiteInstance());
1102 CHECK_NE(parent_routing_id, MSG_ROUTING_NONE);
1103 }
1104 return delegate_->CreateRenderFrameForRenderManager(render_frame_host,
1105 parent_routing_id);
1106 }
1107
1108 int RenderFrameHostManager::GetRoutingIdForSiteInstance(
1109 SiteInstance* site_instance) {
1110 if (render_frame_host_->GetSiteInstance() == site_instance)
1111 return render_frame_host_->GetRoutingID();
1112
1113 RenderFrameProxyHostMap::iterator iter =
1114 proxy_hosts_.find(site_instance->GetId());
1115 if (iter != proxy_hosts_.end())
1116 return iter->second->GetRoutingID();
1117
1118 return MSG_ROUTING_NONE;
1059 } 1119 }
1060 1120
1061 void RenderFrameHostManager::CommitPending() { 1121 void RenderFrameHostManager::CommitPending() {
1062 // First check whether we're going to want to focus the location bar after 1122 // 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 1123 // 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 1124 // 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. 1125 // this triggers won't be able to figure out what's going on.
1066 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); 1126 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault();
1067 1127
1068 // We expect SwapOutOldPage to have canceled any modal dialogs and told the 1128 // We expect SwapOutOldPage to have canceled any modal dialogs and told the
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 // TODO(creis): Swap out the subframe in --site-per-process. 1228 // TODO(creis): Swap out the subframe in --site-per-process.
1169 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess)) 1229 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess))
1170 DCHECK(old_render_frame_host->is_swapped_out() || 1230 DCHECK(old_render_frame_host->is_swapped_out() ||
1171 !RenderViewHostImpl::IsRVHStateActive( 1231 !RenderViewHostImpl::IsRVHStateActive(
1172 old_render_frame_host->render_view_host()->rvh_state())); 1232 old_render_frame_host->render_view_host()->rvh_state()));
1173 1233
1174 // If the RenderViewHost backing the RenderFrameHost is pending shutdown, 1234 // If the RenderViewHost backing the RenderFrameHost is pending shutdown,
1175 // the RenderFrameHost should be put in the map of RenderFrameHosts pending 1235 // the RenderFrameHost should be put in the map of RenderFrameHosts pending
1176 // shutdown. Otherwise, it is stored in the map of proxy hosts. 1236 // shutdown. Otherwise, it is stored in the map of proxy hosts.
1177 if (old_render_frame_host->render_view_host()->rvh_state() == 1237 if (old_render_frame_host->render_view_host()->rvh_state() ==
1178 RenderViewHostImpl::STATE_PENDING_SHUTDOWN) { 1238 RenderViewHostImpl::STATE_PENDING_SHUTDOWN) {
1179 // The proxy for this RenderFrameHost is created when sending the 1239 // The proxy for this RenderFrameHost is created when sending the
1180 // SwapOut message, so check if it already exists and delete it. 1240 // SwapOut message, so check if it already exists and delete it.
1181 RenderFrameProxyHostMap::iterator iter = 1241 RenderFrameProxyHostMap::iterator iter =
1182 proxy_hosts_.find(old_site_instance_id); 1242 proxy_hosts_.find(old_site_instance_id);
1183 if (iter != proxy_hosts_.end()) { 1243 if (iter != proxy_hosts_.end()) {
1184 delete iter->second; 1244 delete iter->second;
1185 proxy_hosts_.erase(iter); 1245 proxy_hosts_.erase(iter);
1186 } 1246 }
1187 RFHPendingDeleteMap::iterator pending_delete_iter = 1247 RFHPendingDeleteMap::iterator pending_delete_iter =
1188 pending_delete_hosts_.find(old_site_instance_id); 1248 pending_delete_hosts_.find(old_site_instance_id);
1189 if (pending_delete_iter == pending_delete_hosts_.end() || 1249 if (pending_delete_iter == pending_delete_hosts_.end() ||
1190 pending_delete_iter->second.get() != old_render_frame_host) { 1250 pending_delete_iter->second.get() != old_render_frame_host) {
1191 pending_delete_hosts_[old_site_instance_id] = 1251 pending_delete_hosts_[old_site_instance_id] =
1192 linked_ptr<RenderFrameHostImpl>(old_render_frame_host.release()); 1252 linked_ptr<RenderFrameHostImpl>(old_render_frame_host.release());
1193 } 1253 }
1194 } else { 1254 } else {
1255 CHECK(proxy_hosts_.find(render_frame_host_->GetSiteInstance()->GetId()) ==
1256 proxy_hosts_.end());
1257
1195 // Capture the active view count on the old RFH SiteInstance, since the 1258 // 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. 1259 // ownership might be passed into the proxy and the pointer will be
1260 // invalid.
1197 int active_view_count = 1261 int active_view_count =
1198 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance()) 1262 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance())
1199 ->active_view_count(); 1263 ->active_view_count();
1200 1264
1201 RenderFrameProxyHostMap::iterator iter = 1265 if (is_main_frame) {
1202 proxy_hosts_.find(old_site_instance_id); 1266 RenderFrameProxyHostMap::iterator iter =
1203 CHECK(iter != proxy_hosts_.end()); 1267 proxy_hosts_.find(old_site_instance_id);
1204 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); 1268 CHECK(iter != proxy_hosts_.end());
1269 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass());
1270 }
1205 1271
1206 // If there are no active views in this SiteInstance, it means that 1272 // 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 1273 // 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 1274 // know that all RFHs are swapped out, we can delete all the RFPHs and
1209 // in this SiteInstance. 1275 // RVHs in this SiteInstance.
1210 if (!active_view_count) { 1276 if (!active_view_count) {
1211 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); 1277 ShutdownRenderFrameProxyHostsInSiteInstance(old_site_instance_id);
1212 } else { 1278 } else {
1213 // If this is a subframe, it should have a CrossProcessFrameConnector 1279 // 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 1280 // created already and we just need to link it to the proper view in the
1215 // new process. 1281 // new process.
1216 if (!is_main_frame) { 1282 if (!is_main_frame) {
1217 RenderFrameProxyHost* proxy = GetProxyToParent(); 1283 RenderFrameProxyHost* proxy = GetProxyToParent();
1218 if (proxy) { 1284 if (proxy) {
1219 proxy->SetChildRWHView( 1285 proxy->SetChildRWHView(
1220 render_frame_host_->render_view_host()->GetView()); 1286 render_frame_host_->render_view_host()->GetView());
1221 } 1287 }
1222 } 1288 }
1223 } 1289 }
1224 } 1290 }
1225 } 1291 }
1226 1292
1227 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( 1293 void RenderFrameHostManager::ShutdownRenderFrameProxyHostsInSiteInstance(
1228 int32 site_instance_id) { 1294 int32 site_instance_id) {
1229 // First remove any swapped out RFH for this SiteInstance from our own list. 1295 // First remove any swapped out RFH for this SiteInstance from our own list.
1230 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); 1296 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_);
1231 1297
1232 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts 1298 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts
1233 // in the SiteInstance, then tell their respective FrameTrees to remove all 1299 // in the SiteInstance, then tell their respective FrameTrees to remove all
1234 // RenderFrameProxyHosts corresponding to them. 1300 // RenderFrameProxyHosts corresponding to them.
1235 // TODO(creis): Replace this with a RenderFrameHostIterator that protects 1301 // TODO(creis): Replace this with a RenderFrameHostIterator that protects
1236 // against use-after-frees if a later element is deleted before getting to it. 1302 // against use-after-frees if a later element is deleted before getting to it.
1237 scoped_ptr<RenderWidgetHostIterator> widgets( 1303 scoped_ptr<RenderWidgetHostIterator> widgets(
(...skipping 17 matching lines...) Expand all
1255 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate( 1321 RenderFrameHostImpl* RenderFrameHostManager::UpdateStateForNavigate(
1256 const NavigationEntryImpl& entry) { 1322 const NavigationEntryImpl& entry) {
1257 // If we are currently navigating cross-process, we want to get back to normal 1323 // If we are currently navigating cross-process, we want to get back to normal
1258 // and then navigate as usual. 1324 // and then navigate as usual.
1259 if (cross_navigation_pending_) { 1325 if (cross_navigation_pending_) {
1260 if (pending_render_frame_host_) 1326 if (pending_render_frame_host_)
1261 CancelPending(); 1327 CancelPending();
1262 cross_navigation_pending_ = false; 1328 cross_navigation_pending_ = false;
1263 } 1329 }
1264 1330
1265 // render_frame_host_'s SiteInstance and new_instance will not be deleted
1266 // before the end of this method, so we don't have to worry about their ref
1267 // counts dropping to zero.
1268 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); 1331 SiteInstance* current_instance = render_frame_host_->GetSiteInstance();
1269 SiteInstance* new_instance = current_instance; 1332 scoped_refptr<SiteInstance> new_instance = current_instance;
1270 1333
1271 // We do not currently swap processes for navigations in webview tag guests. 1334 // We do not currently swap processes for navigations in webview tag guests.
1272 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme); 1335 bool is_guest_scheme = current_instance->GetSiteURL().SchemeIs(kGuestScheme);
1273 1336
1274 // Determine if we need a new BrowsingInstance for this entry. If true, this 1337 // 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 1338 // 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. 1339 // 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 1340 // This is used for cases that require a process swap even in the
1278 // process-per-tab model, such as WebUI pages. 1341 // process-per-tab model, such as WebUI pages.
1279 const NavigationEntry* current_entry = 1342 const NavigationEntry* current_entry =
(...skipping 21 matching lines...) Expand all
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
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
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
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
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_manager.h ('k') | content/browser/frame_host/render_frame_proxy_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698