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" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
14 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 14 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
15 #include "content/browser/frame_host/cross_process_frame_connector.h" | 15 #include "content/browser/frame_host/cross_process_frame_connector.h" |
16 #include "content/browser/frame_host/cross_site_transferring_request.h" | 16 #include "content/browser/frame_host/cross_site_transferring_request.h" |
17 #include "content/browser/frame_host/debug_urls.h" | 17 #include "content/browser/frame_host/debug_urls.h" |
18 #include "content/browser/frame_host/interstitial_page_impl.h" | 18 #include "content/browser/frame_host/interstitial_page_impl.h" |
19 #include "content/browser/frame_host/navigation_controller_impl.h" | 19 #include "content/browser/frame_host/navigation_controller_impl.h" |
20 #include "content/browser/frame_host/navigation_entry_impl.h" | 20 #include "content/browser/frame_host/navigation_entry_impl.h" |
21 #include "content/browser/frame_host/navigator.h" | 21 #include "content/browser/frame_host/navigator.h" |
22 #include "content/browser/frame_host/render_frame_host_factory.h" | 22 #include "content/browser/frame_host/render_frame_host_factory.h" |
23 #include "content/browser/frame_host/render_frame_host_impl.h" | 23 #include "content/browser/frame_host/render_frame_host_impl.h" |
24 #include "content/browser/frame_host/render_frame_proxy_host.h" | 24 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 25 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
25 #include "content/browser/renderer_host/render_process_host_impl.h" | 26 #include "content/browser/renderer_host/render_process_host_impl.h" |
26 #include "content/browser/renderer_host/render_view_host_factory.h" | 27 #include "content/browser/renderer_host/render_view_host_factory.h" |
27 #include "content/browser/renderer_host/render_view_host_impl.h" | 28 #include "content/browser/renderer_host/render_view_host_impl.h" |
28 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 29 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
29 #include "content/browser/site_instance_impl.h" | 30 #include "content/browser/site_instance_impl.h" |
30 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 31 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
31 #include "content/browser/webui/web_ui_impl.h" | 32 #include "content/browser/webui/web_ui_impl.h" |
32 #include "content/common/view_messages.h" | 33 #include "content/common/view_messages.h" |
33 #include "content/public/browser/content_browser_client.h" | 34 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
35 #include "content/public/browser/notification_types.h" | 36 #include "content/public/browser/notification_types.h" |
36 #include "content/public/browser/render_widget_host_iterator.h" | 37 #include "content/public/browser/render_widget_host_iterator.h" |
| 38 #include "content/public/browser/render_widget_host_view.h" |
37 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
38 #include "content/public/browser/web_ui_controller.h" | 40 #include "content/public/browser/web_ui_controller.h" |
39 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
40 #include "content/public/common/url_constants.h" | 42 #include "content/public/common/url_constants.h" |
41 | 43 |
42 namespace content { | 44 namespace content { |
43 | 45 |
44 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams( | 46 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams( |
45 const GlobalRequestID& global_request_id, | 47 const GlobalRequestID& global_request_id, |
46 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request, | 48 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 171 |
170 // If the current render_frame_host_ isn't live, we should create it so | 172 // If the current render_frame_host_ isn't live, we should create it so |
171 // that we don't show a sad tab while the dest_render_frame_host fetches | 173 // that we don't show a sad tab while the dest_render_frame_host fetches |
172 // its first page. (Bug 1145340) | 174 // its first page. (Bug 1145340) |
173 if (dest_render_frame_host != render_frame_host_ && | 175 if (dest_render_frame_host != render_frame_host_ && |
174 !render_frame_host_->render_view_host()->IsRenderViewLive()) { | 176 !render_frame_host_->render_view_host()->IsRenderViewLive()) { |
175 // Note: we don't call InitRenderView here because we are navigating away | 177 // Note: we don't call InitRenderView here because we are navigating away |
176 // soon anyway, and we don't have the NavigationEntry for this host. | 178 // soon anyway, and we don't have the NavigationEntry for this host. |
177 delegate_->CreateRenderViewForRenderManager( | 179 delegate_->CreateRenderViewForRenderManager( |
178 render_frame_host_->render_view_host(), MSG_ROUTING_NONE, | 180 render_frame_host_->render_view_host(), MSG_ROUTING_NONE, |
179 MSG_ROUTING_NONE, NULL); | 181 MSG_ROUTING_NONE, frame_tree_node_->IsMainFrame()); |
180 } | 182 } |
181 | 183 |
182 // If the renderer crashed, then try to create a new one to satisfy this | 184 // If the renderer crashed, then try to create a new one to satisfy this |
183 // navigation request. | 185 // navigation request. |
184 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { | 186 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { |
185 // Recreate the opener chain. | 187 // Recreate the opener chain. |
186 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | 188 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( |
187 dest_render_frame_host->GetSiteInstance()); | 189 dest_render_frame_host->GetSiteInstance()); |
188 if (!InitRenderView(dest_render_frame_host->render_view_host(), | 190 if (!InitRenderView(dest_render_frame_host->render_view_host(), |
189 opener_route_id, MSG_ROUTING_NONE)) | 191 opener_route_id, |
| 192 MSG_ROUTING_NONE, |
| 193 frame_tree_node_->IsMainFrame())) |
190 return NULL; | 194 return NULL; |
191 | 195 |
192 // Now that we've created a new renderer, be sure to hide it if it isn't | 196 // Now that we've created a new renderer, be sure to hide it if it isn't |
193 // our primary one. Otherwise, we might crash if we try to call Show() | 197 // our primary one. Otherwise, we might crash if we try to call Show() |
194 // on it later. | 198 // on it later. |
195 if (dest_render_frame_host != render_frame_host_ && | 199 if (dest_render_frame_host != render_frame_host_ && |
196 dest_render_frame_host->render_view_host()->GetView()) { | 200 dest_render_frame_host->render_view_host()->GetView()) { |
197 dest_render_frame_host->render_view_host()->GetView()->Hide(); | 201 dest_render_frame_host->render_view_host()->GetView()->Hide(); |
198 } else if (frame_tree_node_->IsMainFrame()) { | 202 } else if (frame_tree_node_->IsMainFrame()) { |
199 // This is our primary renderer, notify here as we won't be calling | 203 // This is our primary renderer, notify here as we won't be calling |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 498 |
495 if (!frame_tree_node_->IsMainFrame()) { | 499 if (!frame_tree_node_->IsMainFrame()) { |
496 // The RenderFrameHost being swapped out becomes the proxy for this | 500 // The RenderFrameHost being swapped out becomes the proxy for this |
497 // frame in its parent's process. CrossProcessFrameConnector | 501 // frame in its parent's process. CrossProcessFrameConnector |
498 // initialization only needs to happen on an initial cross-process | 502 // initialization only needs to happen on an initial cross-process |
499 // navigation, when the RenderFrame leaves the same process as its parent. | 503 // navigation, when the RenderFrame leaves the same process as its parent. |
500 // The same CrossProcessFrameConnector is used for subsequent cross- | 504 // The same CrossProcessFrameConnector is used for subsequent cross- |
501 // process navigations, but it will be destroyed if the Frame is | 505 // process navigations, but it will be destroyed if the Frame is |
502 // navigated back to the same site instance as its parent. | 506 // navigated back to the same site instance as its parent. |
503 // TODO(kenrb): This will change when RenderFrameProxyHost is created. | 507 // TODO(kenrb): This will change when RenderFrameProxyHost is created. |
| 508 // TODO(nasko): Move CrossProcessFrameConnector to be owned by |
| 509 // RenderFrameProxyHost instead of RenderFrameHostManager once proxy |
| 510 // support lands. |
504 if (!cross_process_frame_connector_) { | 511 if (!cross_process_frame_connector_) { |
505 cross_process_frame_connector_ = | 512 cross_process_frame_connector_ = |
506 new CrossProcessFrameConnector(render_frame_host_.get()); | 513 new CrossProcessFrameConnector(render_frame_host_.get()); |
507 } | 514 } |
508 } | 515 } |
509 | 516 |
510 // Create the RenderFrameProxyHost that will replace the | 517 // Create the RenderFrameProxyHost that will replace the |
511 // RenderFrameHost which is swapping out. If one exists, ensure it is deleted | 518 // RenderFrameHost which is swapping out. If one exists, ensure it is deleted |
512 // from the map and not leaked. | 519 // from the map and not leaked. |
513 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find( | 520 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find( |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 new_render_frame_host->GetProcess()->AddPendingView(); | 965 new_render_frame_host->GetProcess()->AddPendingView(); |
959 } else { | 966 } else { |
960 proxy = new RenderFrameProxyHost( | 967 proxy = new RenderFrameProxyHost( |
961 new_render_frame_host->GetSiteInstance(), frame_tree_node_); | 968 new_render_frame_host->GetSiteInstance(), frame_tree_node_); |
962 proxy_hosts_[instance->GetId()] = proxy; | 969 proxy_hosts_[instance->GetId()] = proxy; |
963 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass()); | 970 proxy->TakeFrameHostOwnership(new_render_frame_host.Pass()); |
964 proxy_routing_id = proxy->GetRoutingID(); | 971 proxy_routing_id = proxy->GetRoutingID(); |
965 } | 972 } |
966 | 973 |
967 bool success = InitRenderView( | 974 bool success = InitRenderView( |
968 render_view_host, opener_route_id, proxy_routing_id); | 975 render_view_host, opener_route_id, proxy_routing_id, |
| 976 frame_tree_node_->IsMainFrame()); |
969 if (success && frame_tree_node_->IsMainFrame()) { | 977 if (success && frame_tree_node_->IsMainFrame()) { |
970 // Don't show the main frame's view until we get a DidNavigate from it. | 978 // Don't show the main frame's view until we get a DidNavigate from it. |
971 render_view_host->GetView()->Hide(); | 979 render_view_host->GetView()->Hide(); |
972 } else if (!swapped_out && pending_render_frame_host_) { | 980 } else if (!swapped_out && pending_render_frame_host_) { |
973 CancelPending(); | 981 CancelPending(); |
974 } | 982 } |
975 routing_id = render_view_host->GetRoutingID(); | 983 routing_id = render_view_host->GetRoutingID(); |
976 } | 984 } |
977 | 985 |
978 // Use this as our new pending RFH if it isn't swapped out. | 986 // Use this as our new pending RFH if it isn't swapped out. |
979 if (!swapped_out) | 987 if (!swapped_out) |
980 pending_render_frame_host_ = new_render_frame_host.Pass(); | 988 pending_render_frame_host_ = new_render_frame_host.Pass(); |
981 | 989 |
982 return routing_id; | 990 return routing_id; |
983 } | 991 } |
984 | 992 |
985 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, | 993 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, |
986 int opener_route_id, | 994 int opener_route_id, |
987 int proxy_routing_id) { | 995 int proxy_routing_id, |
| 996 bool for_main_frame) { |
988 // We may have initialized this RenderViewHost for another RenderFrameHost. | 997 // We may have initialized this RenderViewHost for another RenderFrameHost. |
989 if (render_view_host->IsRenderViewLive()) | 998 if (render_view_host->IsRenderViewLive()) |
990 return true; | 999 return true; |
991 | 1000 |
992 // If the pending navigation is to a WebUI and the RenderView is not in a | 1001 // If the pending navigation is to a WebUI and the RenderView is not in a |
993 // guest process, tell the RenderViewHost about any bindings it will need | 1002 // guest process, tell the RenderViewHost about any bindings it will need |
994 // enabled. | 1003 // enabled. |
995 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { | 1004 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { |
996 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); | 1005 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); |
997 } else { | 1006 } else { |
998 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 1007 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled |
999 // process unless it's swapped out. | 1008 // process unless it's swapped out. |
1000 RenderViewHostImpl* rvh_impl = | 1009 RenderViewHostImpl* rvh_impl = |
1001 static_cast<RenderViewHostImpl*>(render_view_host); | 1010 static_cast<RenderViewHostImpl*>(render_view_host); |
1002 if (!rvh_impl->IsSwappedOut()) { | 1011 if (!rvh_impl->IsSwappedOut()) { |
1003 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1012 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
1004 render_view_host->GetProcess()->GetID())); | 1013 render_view_host->GetProcess()->GetID())); |
1005 } | 1014 } |
1006 } | 1015 } |
1007 | 1016 |
1008 return delegate_->CreateRenderViewForRenderManager( | 1017 return delegate_->CreateRenderViewForRenderManager( |
1009 render_view_host, opener_route_id, proxy_routing_id, | 1018 render_view_host, opener_route_id, proxy_routing_id, for_main_frame); |
1010 cross_process_frame_connector_); | |
1011 } | 1019 } |
1012 | 1020 |
1013 void RenderFrameHostManager::CommitPending() { | 1021 void RenderFrameHostManager::CommitPending() { |
1014 // First check whether we're going to want to focus the location bar after | 1022 // First check whether we're going to want to focus the location bar after |
1015 // this commit. We do this now because the navigation hasn't formally | 1023 // this commit. We do this now because the navigation hasn't formally |
1016 // committed yet, so if we've already cleared |pending_web_ui_| the call chain | 1024 // committed yet, so if we've already cleared |pending_web_ui_| the call chain |
1017 // this triggers won't be able to figure out what's going on. | 1025 // this triggers won't be able to figure out what's going on. |
1018 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 1026 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
1019 | 1027 |
1020 // We expect SwapOutOldPage to have canceled any modal dialogs and told the | 1028 // We expect SwapOutOldPage to have canceled any modal dialogs and told the |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 | 1165 |
1158 RenderFrameProxyHostMap::iterator iter = | 1166 RenderFrameProxyHostMap::iterator iter = |
1159 proxy_hosts_.find(old_site_instance_id); | 1167 proxy_hosts_.find(old_site_instance_id); |
1160 CHECK(iter != proxy_hosts_.end()); | 1168 CHECK(iter != proxy_hosts_.end()); |
1161 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); | 1169 iter->second->TakeFrameHostOwnership(old_render_frame_host.Pass()); |
1162 | 1170 |
1163 // If there are no active views in this SiteInstance, it means that | 1171 // If there are no active views in this SiteInstance, it means that |
1164 // this RFH was the last active one in the SiteInstance. Now that we | 1172 // this RFH was the last active one in the SiteInstance. Now that we |
1165 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs | 1173 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs |
1166 // in this SiteInstance. | 1174 // in this SiteInstance. |
1167 if (!active_view_count) | 1175 if (!active_view_count) { |
1168 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); | 1176 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); |
| 1177 } else { |
| 1178 // If this is a subframe, it should have a CrossProcessFrameConnector |
| 1179 // created already and we just need to link it to the proper view in the |
| 1180 // new process. |
| 1181 if (!is_main_frame) { |
| 1182 RenderWidgetHostView* rwhv = |
| 1183 render_frame_host_->render_view_host()->GetView(); |
| 1184 RenderWidgetHostViewChildFrame* rwhv_child = |
| 1185 static_cast<RenderWidgetHostViewChildFrame*>(rwhv); |
| 1186 cross_process_frame_connector_->set_view(rwhv_child); |
| 1187 } |
| 1188 } |
1169 } | 1189 } |
1170 } | 1190 } |
1171 | 1191 |
1172 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( | 1192 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( |
1173 int32 site_instance_id) { | 1193 int32 site_instance_id) { |
1174 // First remove any swapped out RFH for this SiteInstance from our own list. | 1194 // First remove any swapped out RFH for this SiteInstance from our own list. |
1175 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); | 1195 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); |
1176 | 1196 |
1177 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts | 1197 // Use the safe RenderWidgetHost iterator for now to find all RenderViewHosts |
1178 // in the SiteInstance, then tell their respective FrameTrees to remove all | 1198 // in the SiteInstance, then tell their respective FrameTrees to remove all |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1450 SiteInstance* instance) const { | 1470 SiteInstance* instance) const { |
1451 RenderFrameProxyHostMap::const_iterator iter = | 1471 RenderFrameProxyHostMap::const_iterator iter = |
1452 proxy_hosts_.find(instance->GetId()); | 1472 proxy_hosts_.find(instance->GetId()); |
1453 if (iter != proxy_hosts_.end()) | 1473 if (iter != proxy_hosts_.end()) |
1454 return iter->second; | 1474 return iter->second; |
1455 | 1475 |
1456 return NULL; | 1476 return NULL; |
1457 } | 1477 } |
1458 | 1478 |
1459 } // namespace content | 1479 } // namespace content |
OLD | NEW |