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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 return NULL; // We weren't able to create a pending render frame host. | 170 return NULL; // We weren't able to create a pending render frame host. |
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, NULL); | 180 render_frame_host_->render_view_host(), MSG_ROUTING_NONE, |
181 frame_tree_node_->IsMainFrame()); | |
179 } | 182 } |
180 | 183 |
181 // 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 |
182 // navigation request. | 185 // navigation request. |
183 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { | 186 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { |
184 // Recreate the opener chain. | 187 // Recreate the opener chain. |
185 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | 188 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( |
186 dest_render_frame_host->GetSiteInstance()); | 189 dest_render_frame_host->GetSiteInstance()); |
187 if (!InitRenderView(dest_render_frame_host->render_view_host(), | 190 if (!InitRenderView(dest_render_frame_host->render_view_host(), |
188 opener_route_id)) | 191 opener_route_id, frame_tree_node_->IsMainFrame())) |
189 return NULL; | 192 return NULL; |
190 | 193 |
191 // Now that we've created a new renderer, be sure to hide it if it isn't | 194 // Now that we've created a new renderer, be sure to hide it if it isn't |
192 // our primary one. Otherwise, we might crash if we try to call Show() | 195 // our primary one. Otherwise, we might crash if we try to call Show() |
193 // on it later. | 196 // on it later. |
194 if (dest_render_frame_host != render_frame_host_ && | 197 if (dest_render_frame_host != render_frame_host_ && |
195 dest_render_frame_host->render_view_host()->GetView()) { | 198 dest_render_frame_host->render_view_host()->GetView()) { |
196 dest_render_frame_host->render_view_host()->GetView()->Hide(); | 199 dest_render_frame_host->render_view_host()->GetView()->Hide(); |
197 } else if (frame_tree_node_->IsMainFrame()) { | 200 } else if (frame_tree_node_->IsMainFrame()) { |
198 // This is our primary renderer, notify here as we won't be calling | 201 // This is our primary renderer, notify here as we won't be calling |
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 | 941 |
939 // Prevent the process from exiting while we're trying to navigate in it. | 942 // Prevent the process from exiting while we're trying to navigate in it. |
940 // Otherwise, if the new RFH is swapped out already, store it. | 943 // Otherwise, if the new RFH is swapped out already, store it. |
941 if (!swapped_out) { | 944 if (!swapped_out) { |
942 new_render_frame_host->GetProcess()->AddPendingView(); | 945 new_render_frame_host->GetProcess()->AddPendingView(); |
943 } else { | 946 } else { |
944 proxy_hosts_[instance->GetId()] = new RenderFrameProxyHost( | 947 proxy_hosts_[instance->GetId()] = new RenderFrameProxyHost( |
945 new_render_frame_host.Pass()); | 948 new_render_frame_host.Pass()); |
946 } | 949 } |
947 | 950 |
948 bool success = InitRenderView(render_view_host, opener_route_id); | 951 bool success = InitRenderView( |
952 render_view_host, opener_route_id, frame_tree_node_->IsMainFrame()); | |
949 if (success && frame_tree_node_->IsMainFrame()) { | 953 if (success && frame_tree_node_->IsMainFrame()) { |
950 // Don't show the main frame's view until we get a DidNavigate from it. | 954 // Don't show the main frame's view until we get a DidNavigate from it. |
951 render_view_host->GetView()->Hide(); | 955 render_view_host->GetView()->Hide(); |
952 } else if (!swapped_out && pending_render_frame_host_) { | 956 } else if (!swapped_out && pending_render_frame_host_) { |
953 CancelPending(); | 957 CancelPending(); |
954 } | 958 } |
955 routing_id = render_view_host->GetRoutingID(); | 959 routing_id = render_view_host->GetRoutingID(); |
956 } | 960 } |
957 | 961 |
958 // Use this as our new pending RFH if it isn't swapped out. | 962 // Use this as our new pending RFH if it isn't swapped out. |
959 if (!swapped_out) | 963 if (!swapped_out) |
960 pending_render_frame_host_ = new_render_frame_host.Pass(); | 964 pending_render_frame_host_ = new_render_frame_host.Pass(); |
961 | 965 |
962 return routing_id; | 966 return routing_id; |
963 } | 967 } |
964 | 968 |
965 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, | 969 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, |
966 int opener_route_id) { | 970 int opener_route_id, |
971 bool for_main_frame) { | |
967 // We may have initialized this RenderViewHost for another RenderFrameHost. | 972 // We may have initialized this RenderViewHost for another RenderFrameHost. |
968 if (render_view_host->IsRenderViewLive()) | 973 if (render_view_host->IsRenderViewLive()) |
969 return true; | 974 return true; |
970 | 975 |
971 // If the pending navigation is to a WebUI and the RenderView is not in a | 976 // If the pending navigation is to a WebUI and the RenderView is not in a |
972 // guest process, tell the RenderViewHost about any bindings it will need | 977 // guest process, tell the RenderViewHost about any bindings it will need |
973 // enabled. | 978 // enabled. |
974 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { | 979 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { |
975 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); | 980 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); |
976 } else { | 981 } else { |
977 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 982 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled |
978 // process unless it's swapped out. | 983 // process unless it's swapped out. |
979 RenderViewHostImpl* rvh_impl = | 984 RenderViewHostImpl* rvh_impl = |
980 static_cast<RenderViewHostImpl*>(render_view_host); | 985 static_cast<RenderViewHostImpl*>(render_view_host); |
981 if (!rvh_impl->IsSwappedOut()) { | 986 if (!rvh_impl->IsSwappedOut()) { |
982 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 987 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
983 render_view_host->GetProcess()->GetID())); | 988 render_view_host->GetProcess()->GetID())); |
984 } | 989 } |
985 } | 990 } |
986 | 991 |
987 return delegate_->CreateRenderViewForRenderManager( | 992 return delegate_->CreateRenderViewForRenderManager( |
988 render_view_host, opener_route_id, cross_process_frame_connector_); | 993 render_view_host, opener_route_id, for_main_frame); |
989 } | 994 } |
990 | 995 |
991 void RenderFrameHostManager::CommitPending() { | 996 void RenderFrameHostManager::CommitPending() { |
992 // First check whether we're going to want to focus the location bar after | 997 // First check whether we're going to want to focus the location bar after |
993 // this commit. We do this now because the navigation hasn't formally | 998 // this commit. We do this now because the navigation hasn't formally |
994 // committed yet, so if we've already cleared |pending_web_ui_| the call chain | 999 // committed yet, so if we've already cleared |pending_web_ui_| the call chain |
995 // this triggers won't be able to figure out what's going on. | 1000 // this triggers won't be able to figure out what's going on. |
996 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 1001 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
997 | 1002 |
998 // We expect SwapOutOldPage to have canceled any modal dialogs and told the | 1003 // We expect SwapOutOldPage to have canceled any modal dialogs and told the |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 // If there are no active views in this SiteInstance, it means that | 1139 // If there are no active views in this SiteInstance, it means that |
1135 // this RFH was the last active one in the SiteInstance. Now that we | 1140 // this RFH was the last active one in the SiteInstance. Now that we |
1136 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs | 1141 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs |
1137 // in this SiteInstance. We do this after ensuring the RFH is on the | 1142 // in this SiteInstance. We do this after ensuring the RFH is on the |
1138 // swapped out list to simplify the deletion. | 1143 // swapped out list to simplify the deletion. |
1139 if (!static_cast<SiteInstanceImpl*>( | 1144 if (!static_cast<SiteInstanceImpl*>( |
1140 old_render_frame_host->GetSiteInstance())->active_view_count()) { | 1145 old_render_frame_host->GetSiteInstance())->active_view_count()) { |
1141 old_render_frame_host.reset(); | 1146 old_render_frame_host.reset(); |
1142 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); | 1147 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); |
1143 } else { | 1148 } else { |
1149 // If this is a subframe, it should have a CrossProcessFrameConnector | |
kenrb
2014/05/16 17:44:54
Would it make sense to make CrossProcessFrameConne
nasko
2014/05/16 18:24:17
I think it might make sense. It will require some
| |
1150 // created already and we just need to link it to the proper view in the | |
1151 // new process. | |
1152 if (!is_main_frame) { | |
1153 RenderWidgetHostView* rwhv = | |
1154 render_frame_host_->render_view_host()->GetView(); | |
1155 RenderWidgetHostViewChildFrame* rwhv_child = | |
1156 static_cast<RenderWidgetHostViewChildFrame*>(rwhv); | |
1157 cross_process_frame_connector_->set_view(rwhv_child); | |
1158 } | |
1144 proxy_hosts_[old_site_instance_id] = new RenderFrameProxyHost( | 1159 proxy_hosts_[old_site_instance_id] = new RenderFrameProxyHost( |
1145 old_render_frame_host.Pass()); | 1160 old_render_frame_host.Pass()); |
1146 } | 1161 } |
1147 } | 1162 } |
1148 } | 1163 } |
1149 | 1164 |
1150 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( | 1165 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( |
1151 int32 site_instance_id) { | 1166 int32 site_instance_id) { |
1152 // First remove any swapped out RFH for this SiteInstance from our own list. | 1167 // First remove any swapped out RFH for this SiteInstance from our own list. |
1153 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); | 1168 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1427 SiteInstance* instance) const { | 1442 SiteInstance* instance) const { |
1428 RenderFrameProxyHostMap::const_iterator iter = | 1443 RenderFrameProxyHostMap::const_iterator iter = |
1429 proxy_hosts_.find(instance->GetId()); | 1444 proxy_hosts_.find(instance->GetId()); |
1430 if (iter != proxy_hosts_.end()) | 1445 if (iter != proxy_hosts_.end()) |
1431 return iter->second; | 1446 return iter->second; |
1432 | 1447 |
1433 return NULL; | 1448 return NULL; |
1434 } | 1449 } |
1435 | 1450 |
1436 } // namespace content | 1451 } // namespace content |
OLD | NEW |