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

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

Issue 270883003: Decouple RVH creation from CrossProcessFrameConnector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some more cleanup and fixes. Created 6 years, 7 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "content/browser/child_process_security_policy_impl.h" 12 #include "content/browser/child_process_security_policy_impl.h"
13 #include "content/browser/devtools/render_view_devtools_agent_host.h" 13 #include "content/browser/devtools/render_view_devtools_agent_host.h"
14 #include "content/browser/frame_host/cross_process_frame_connector.h" 14 #include "content/browser/frame_host/cross_process_frame_connector.h"
15 #include "content/browser/frame_host/cross_site_transferring_request.h" 15 #include "content/browser/frame_host/cross_site_transferring_request.h"
16 #include "content/browser/frame_host/debug_urls.h" 16 #include "content/browser/frame_host/debug_urls.h"
17 #include "content/browser/frame_host/interstitial_page_impl.h" 17 #include "content/browser/frame_host/interstitial_page_impl.h"
18 #include "content/browser/frame_host/navigation_controller_impl.h" 18 #include "content/browser/frame_host/navigation_controller_impl.h"
19 #include "content/browser/frame_host/navigation_entry_impl.h" 19 #include "content/browser/frame_host/navigation_entry_impl.h"
20 #include "content/browser/frame_host/navigator.h" 20 #include "content/browser/frame_host/navigator.h"
21 #include "content/browser/frame_host/render_frame_host_factory.h" 21 #include "content/browser/frame_host/render_frame_host_factory.h"
22 #include "content/browser/frame_host/render_frame_host_impl.h" 22 #include "content/browser/frame_host/render_frame_host_impl.h"
23 #include "content/browser/frame_host/render_frame_proxy_host.h" 23 #include "content/browser/frame_host/render_frame_proxy_host.h"
24 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
24 #include "content/browser/renderer_host/render_process_host_impl.h" 25 #include "content/browser/renderer_host/render_process_host_impl.h"
25 #include "content/browser/renderer_host/render_view_host_factory.h" 26 #include "content/browser/renderer_host/render_view_host_factory.h"
26 #include "content/browser/renderer_host/render_view_host_impl.h" 27 #include "content/browser/renderer_host/render_view_host_impl.h"
27 #include "content/browser/renderer_host/render_widget_host_view_base.h" 28 #include "content/browser/renderer_host/render_widget_host_view_base.h"
28 #include "content/browser/site_instance_impl.h" 29 #include "content/browser/site_instance_impl.h"
29 #include "content/browser/webui/web_ui_controller_factory_registry.h" 30 #include "content/browser/webui/web_ui_controller_factory_registry.h"
30 #include "content/browser/webui/web_ui_impl.h" 31 #include "content/browser/webui/web_ui_impl.h"
31 #include "content/common/view_messages.h" 32 #include "content/common/view_messages.h"
32 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
33 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/notification_types.h" 35 #include "content/public/browser/notification_types.h"
35 #include "content/public/browser/render_widget_host_iterator.h" 36 #include "content/public/browser/render_widget_host_iterator.h"
37 #include "content/public/browser/render_widget_host_view.h"
36 #include "content/public/browser/user_metrics.h" 38 #include "content/public/browser/user_metrics.h"
37 #include "content/public/browser/web_ui_controller.h" 39 #include "content/public/browser/web_ui_controller.h"
38 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
39 #include "content/public/common/url_constants.h" 41 #include "content/public/common/url_constants.h"
40 42
41 namespace content { 43 namespace content {
42 44
43 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams( 45 RenderFrameHostManager::PendingNavigationParams::PendingNavigationParams(
44 const GlobalRequestID& global_request_id, 46 const GlobalRequestID& global_request_id,
45 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request, 47 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return NULL; // We weren't able to create a pending render frame host. 173 return NULL; // We weren't able to create a pending render frame host.
172 174
173 // If the current render_frame_host_ isn't live, we should create it so 175 // If the current render_frame_host_ isn't live, we should create it so
174 // that we don't show a sad tab while the dest_render_frame_host fetches 176 // that we don't show a sad tab while the dest_render_frame_host fetches
175 // its first page. (Bug 1145340) 177 // its first page. (Bug 1145340)
176 if (dest_render_frame_host != render_frame_host_ && 178 if (dest_render_frame_host != render_frame_host_ &&
177 !render_frame_host_->render_view_host()->IsRenderViewLive()) { 179 !render_frame_host_->render_view_host()->IsRenderViewLive()) {
178 // Note: we don't call InitRenderView here because we are navigating away 180 // Note: we don't call InitRenderView here because we are navigating away
179 // soon anyway, and we don't have the NavigationEntry for this host. 181 // soon anyway, and we don't have the NavigationEntry for this host.
180 delegate_->CreateRenderViewForRenderManager( 182 delegate_->CreateRenderViewForRenderManager(
181 render_frame_host_->render_view_host(), MSG_ROUTING_NONE, NULL); 183 render_frame_host_->render_view_host(), MSG_ROUTING_NONE,
184 frame_tree_node_->IsMainFrame());
182 } 185 }
183 186
184 // If the renderer crashed, then try to create a new one to satisfy this 187 // If the renderer crashed, then try to create a new one to satisfy this
185 // navigation request. 188 // navigation request.
186 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) { 189 if (!dest_render_frame_host->render_view_host()->IsRenderViewLive()) {
187 // Recreate the opener chain. 190 // Recreate the opener chain.
188 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( 191 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager(
189 dest_render_frame_host->GetSiteInstance()); 192 dest_render_frame_host->GetSiteInstance());
190 if (!InitRenderView(dest_render_frame_host->render_view_host(), 193 if (!InitRenderView(dest_render_frame_host->render_view_host(),
191 opener_route_id)) 194 opener_route_id, frame_tree_node_->IsMainFrame()))
192 return NULL; 195 return NULL;
193 196
194 // Now that we've created a new renderer, be sure to hide it if it isn't 197 // Now that we've created a new renderer, be sure to hide it if it isn't
195 // our primary one. Otherwise, we might crash if we try to call Show() 198 // our primary one. Otherwise, we might crash if we try to call Show()
196 // on it later. 199 // on it later.
197 if (dest_render_frame_host != render_frame_host_ && 200 if (dest_render_frame_host != render_frame_host_ &&
198 dest_render_frame_host->render_view_host()->GetView()) { 201 dest_render_frame_host->render_view_host()->GetView()) {
199 dest_render_frame_host->render_view_host()->GetView()->Hide(); 202 dest_render_frame_host->render_view_host()->GetView()->Hide();
200 } else if (frame_tree_node_->IsMainFrame()) { 203 } else if (frame_tree_node_->IsMainFrame()) {
201 // This is our primary renderer, notify here as we won't be calling 204 // This is our primary renderer, notify here as we won't be calling
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 931
929 // Prevent the process from exiting while we're trying to navigate in it. 932 // Prevent the process from exiting while we're trying to navigate in it.
930 // Otherwise, if the new RFH is swapped out already, store it. 933 // Otherwise, if the new RFH is swapped out already, store it.
931 if (!swapped_out) { 934 if (!swapped_out) {
932 new_render_frame_host->GetProcess()->AddPendingView(); 935 new_render_frame_host->GetProcess()->AddPendingView();
933 } else { 936 } else {
934 proxy_hosts_[instance->GetId()] = new RenderFrameProxyHost( 937 proxy_hosts_[instance->GetId()] = new RenderFrameProxyHost(
935 new_render_frame_host.Pass()); 938 new_render_frame_host.Pass());
936 } 939 }
937 940
938 bool success = InitRenderView(render_view_host, opener_route_id); 941 bool success = InitRenderView(
942 render_view_host, opener_route_id, frame_tree_node_->IsMainFrame());
939 if (success && frame_tree_node_->IsMainFrame()) { 943 if (success && frame_tree_node_->IsMainFrame()) {
940 // Don't show the main frame's view until we get a DidNavigate from it. 944 // Don't show the main frame's view until we get a DidNavigate from it.
941 render_view_host->GetView()->Hide(); 945 render_view_host->GetView()->Hide();
942 } else if (!swapped_out && pending_render_frame_host_) { 946 } else if (!swapped_out && pending_render_frame_host_) {
943 CancelPending(); 947 CancelPending();
944 } 948 }
945 routing_id = render_view_host->GetRoutingID(); 949 routing_id = render_view_host->GetRoutingID();
946 } 950 }
947 951
948 // Use this as our new pending RFH if it isn't swapped out. 952 // Use this as our new pending RFH if it isn't swapped out.
949 if (!swapped_out) 953 if (!swapped_out)
950 pending_render_frame_host_ = new_render_frame_host.Pass(); 954 pending_render_frame_host_ = new_render_frame_host.Pass();
951 955
952 return routing_id; 956 return routing_id;
953 } 957 }
954 958
955 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host, 959 bool RenderFrameHostManager::InitRenderView(RenderViewHost* render_view_host,
956 int opener_route_id) { 960 int opener_route_id,
961 bool main_frame) {
957 // We may have initialized this RenderViewHost for another RenderFrameHost. 962 // We may have initialized this RenderViewHost for another RenderFrameHost.
958 if (render_view_host->IsRenderViewLive()) 963 if (render_view_host->IsRenderViewLive())
959 return true; 964 return true;
960 965
961 // If the pending navigation is to a WebUI and the RenderView is not in a 966 // If the pending navigation is to a WebUI and the RenderView is not in a
962 // guest process, tell the RenderViewHost about any bindings it will need 967 // guest process, tell the RenderViewHost about any bindings it will need
963 // enabled. 968 // enabled.
964 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) { 969 if (pending_web_ui() && !render_view_host->GetProcess()->IsGuest()) {
965 render_view_host->AllowBindings(pending_web_ui()->GetBindings()); 970 render_view_host->AllowBindings(pending_web_ui()->GetBindings());
966 } else { 971 } else {
967 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled 972 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled
968 // process unless it's swapped out. 973 // process unless it's swapped out.
969 RenderViewHostImpl* rvh_impl = 974 RenderViewHostImpl* rvh_impl =
970 static_cast<RenderViewHostImpl*>(render_view_host); 975 static_cast<RenderViewHostImpl*>(render_view_host);
971 if (!rvh_impl->IsSwappedOut()) { 976 if (!rvh_impl->IsSwappedOut()) {
972 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( 977 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
973 render_view_host->GetProcess()->GetID())); 978 render_view_host->GetProcess()->GetID()));
974 } 979 }
975 } 980 }
976 981
977 return delegate_->CreateRenderViewForRenderManager( 982 return delegate_->CreateRenderViewForRenderManager(
978 render_view_host, opener_route_id, cross_process_frame_connector_); 983 render_view_host, opener_route_id, main_frame);
979 } 984 }
980 985
981 void RenderFrameHostManager::CommitPending() { 986 void RenderFrameHostManager::CommitPending() {
982 // First check whether we're going to want to focus the location bar after 987 // First check whether we're going to want to focus the location bar after
983 // this commit. We do this now because the navigation hasn't formally 988 // this commit. We do this now because the navigation hasn't formally
984 // committed yet, so if we've already cleared |pending_web_ui_| the call chain 989 // committed yet, so if we've already cleared |pending_web_ui_| the call chain
985 // this triggers won't be able to figure out what's going on. 990 // this triggers won't be able to figure out what's going on.
986 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); 991 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault();
987 992
988 // We expect SwapOutOldPage to have canceled any modal dialogs and told the 993 // We expect SwapOutOldPage to have canceled any modal dialogs and told the
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 // If there are no active views in this SiteInstance, it means that 1130 // If there are no active views in this SiteInstance, it means that
1126 // this RFH was the last active one in the SiteInstance. Now that we 1131 // this RFH was the last active one in the SiteInstance. Now that we
1127 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs 1132 // know that all RFHs are swapped out, we can delete all the RFHs and RVHs
1128 // in this SiteInstance. We do this after ensuring the RFH is on the 1133 // in this SiteInstance. We do this after ensuring the RFH is on the
1129 // swapped out list to simplify the deletion. 1134 // swapped out list to simplify the deletion.
1130 if (!static_cast<SiteInstanceImpl*>( 1135 if (!static_cast<SiteInstanceImpl*>(
1131 old_render_frame_host->GetSiteInstance())->active_view_count()) { 1136 old_render_frame_host->GetSiteInstance())->active_view_count()) {
1132 old_render_frame_host.reset(); 1137 old_render_frame_host.reset();
1133 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id); 1138 ShutdownRenderFrameHostsInSiteInstance(old_site_instance_id);
1134 } else { 1139 } else {
1140 // If this is a subframe, it should have a CrossProcessFrameConnector
1141 // created already and we just need to link it to the proper view in the
1142 // new process.
1143 if (!is_main_frame) {
1144 RenderWidgetHostView* rwhv =
1145 render_frame_host_->render_view_host()->GetView();
1146 RenderWidgetHostViewChildFrame* rwhv_child =
1147 static_cast<RenderWidgetHostViewChildFrame*>(rwhv);
1148 cross_process_frame_connector_->set_view(rwhv_child);
1149 }
1135 proxy_hosts_[old_site_instance_id] = new RenderFrameProxyHost( 1150 proxy_hosts_[old_site_instance_id] = new RenderFrameProxyHost(
1136 old_render_frame_host.Pass()); 1151 old_render_frame_host.Pass());
1137 } 1152 }
1138 } 1153 }
1139 } 1154 }
1140 1155
1141 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance( 1156 void RenderFrameHostManager::ShutdownRenderFrameHostsInSiteInstance(
1142 int32 site_instance_id) { 1157 int32 site_instance_id) {
1143 // First remove any swapped out RFH for this SiteInstance from our own list. 1158 // First remove any swapped out RFH for this SiteInstance from our own list.
1144 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_); 1159 ClearProxiesInSiteInstance(site_instance_id, frame_tree_node_);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 SiteInstance* instance) const { 1438 SiteInstance* instance) const {
1424 RenderFrameProxyHostMap::const_iterator iter = 1439 RenderFrameProxyHostMap::const_iterator iter =
1425 proxy_hosts_.find(instance->GetId()); 1440 proxy_hosts_.find(instance->GetId());
1426 if (iter != proxy_hosts_.end()) 1441 if (iter != proxy_hosts_.end())
1427 return iter->second; 1442 return iter->second;
1428 1443
1429 return NULL; 1444 return NULL;
1430 } 1445 }
1431 1446
1432 } // namespace content 1447 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698