Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "content/browser/frame_host/navigator.h" | 24 #include "content/browser/frame_host/navigator.h" |
| 25 #include "content/browser/frame_host/render_frame_host_factory.h" | 25 #include "content/browser/frame_host/render_frame_host_factory.h" |
| 26 #include "content/browser/frame_host/render_frame_host_impl.h" | 26 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 27 #include "content/browser/frame_host/render_frame_proxy_host.h" | 27 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 28 #include "content/browser/gpu/gpu_surface_tracker.h" | 28 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 29 #include "content/browser/renderer_host/render_process_host_impl.h" | 29 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 30 #include "content/browser/renderer_host/render_view_host_factory.h" | 30 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 31 #include "content/browser/renderer_host/render_view_host_impl.h" | 31 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 32 #include "content/browser/site_instance_impl.h" | 32 #include "content/browser/site_instance_impl.h" |
| 33 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 33 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 34 #include "content/browser/webui/web_ui_impl.h" | 34 // #include "content/browser/webui/web_ui_impl.h" |
| 35 #include "content/common/frame_messages.h" | 35 #include "content/common/frame_messages.h" |
| 36 #include "content/common/site_isolation_policy.h" | 36 #include "content/common/site_isolation_policy.h" |
| 37 #include "content/common/view_messages.h" | 37 #include "content/common/view_messages.h" |
| 38 #include "content/public/browser/content_browser_client.h" | 38 #include "content/public/browser/content_browser_client.h" |
| 39 #include "content/public/browser/render_process_host_observer.h" | 39 #include "content/public/browser/render_process_host_observer.h" |
| 40 #include "content/public/browser/render_widget_host_iterator.h" | 40 #include "content/public/browser/render_widget_host_iterator.h" |
| 41 #include "content/public/browser/render_widget_host_view.h" | 41 #include "content/public/browser/render_widget_host_view.h" |
| 42 #include "content/public/browser/user_metrics.h" | 42 #include "content/public/browser/user_metrics.h" |
| 43 #include "content/public/browser/web_ui_controller.h" | 43 #include "content/public/browser/web_ui_controller.h" |
| 44 #include "content/public/common/browser_plugin_guest_mode.h" | 44 #include "content/public/common/browser_plugin_guest_mode.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 RenderViewHostDelegate* render_view_delegate, | 214 RenderViewHostDelegate* render_view_delegate, |
| 215 RenderWidgetHostDelegate* render_widget_delegate, | 215 RenderWidgetHostDelegate* render_widget_delegate, |
| 216 Delegate* delegate) | 216 Delegate* delegate) |
| 217 : frame_tree_node_(frame_tree_node), | 217 : frame_tree_node_(frame_tree_node), |
| 218 delegate_(delegate), | 218 delegate_(delegate), |
| 219 render_frame_delegate_(render_frame_delegate), | 219 render_frame_delegate_(render_frame_delegate), |
| 220 render_view_delegate_(render_view_delegate), | 220 render_view_delegate_(render_view_delegate), |
| 221 render_widget_delegate_(render_widget_delegate), | 221 render_widget_delegate_(render_widget_delegate), |
| 222 proxy_hosts_(new RenderFrameProxyHostMap(this)), | 222 proxy_hosts_(new RenderFrameProxyHostMap(this)), |
| 223 interstitial_page_(nullptr), | 223 interstitial_page_(nullptr), |
| 224 should_reuse_web_ui_(false), | |
| 225 weak_factory_(this) { | 224 weak_factory_(this) { |
| 226 DCHECK(frame_tree_node_); | 225 DCHECK(frame_tree_node_); |
| 227 } | 226 } |
| 228 | 227 |
| 229 RenderFrameHostManager::~RenderFrameHostManager() { | 228 RenderFrameHostManager::~RenderFrameHostManager() { |
| 230 if (pending_render_frame_host_) { | 229 if (pending_render_frame_host_) { |
| 231 scoped_ptr<RenderFrameHostImpl> relic = UnsetPendingRenderFrameHost(); | 230 scoped_ptr<RenderFrameHostImpl> relic = UnsetPendingRenderFrameHost(); |
| 232 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); | 231 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); |
| 233 } | 232 } |
| 234 | 233 |
| 235 if (speculative_render_frame_host_) { | 234 if (speculative_render_frame_host_) { |
| 236 scoped_ptr<RenderFrameHostImpl> relic = UnsetSpeculativeRenderFrameHost(); | 235 scoped_ptr<RenderFrameHostImpl> relic = UnsetSpeculativeRenderFrameHost(); |
| 237 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); | 236 ShutdownProxiesIfLastActiveFrameInSiteInstance(relic.get()); |
| 238 } | 237 } |
| 239 | 238 |
| 240 ShutdownProxiesIfLastActiveFrameInSiteInstance(render_frame_host_.get()); | 239 ShutdownProxiesIfLastActiveFrameInSiteInstance(render_frame_host_.get()); |
| 241 | 240 |
| 242 // Delete any RenderFrameProxyHosts and swapped out RenderFrameHosts. | 241 // Delete any RenderFrameProxyHosts and swapped out RenderFrameHosts. |
| 243 // It is important to delete those prior to deleting the current | 242 // It is important to delete those prior to deleting the current |
| 244 // RenderFrameHost, since the CrossProcessFrameConnector (owned by | 243 // RenderFrameHost, since the CrossProcessFrameConnector (owned by |
| 245 // RenderFrameProxyHost) points to the RenderWidgetHostView associated with | 244 // RenderFrameProxyHost) points to the RenderWidgetHostView associated with |
| 246 // the current RenderFrameHost and uses it during its destructor. | 245 // the current RenderFrameHost and uses it during its destructor. |
| 247 ResetProxyHosts(); | 246 ResetProxyHosts(); |
| 248 | 247 |
| 249 // Release the WebUI prior to resetting the current RenderFrameHost, as the | |
| 250 // WebUI accesses the RenderFrameHost during cleanup. | |
| 251 web_ui_.reset(); | |
| 252 | |
| 253 // We should always have a current RenderFrameHost except in some tests. | 248 // We should always have a current RenderFrameHost except in some tests. |
| 254 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); | 249 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); |
| 255 } | 250 } |
| 256 | 251 |
| 257 void RenderFrameHostManager::Init(BrowserContext* browser_context, | 252 void RenderFrameHostManager::Init(BrowserContext* browser_context, |
| 258 SiteInstance* site_instance, | 253 SiteInstance* site_instance, |
| 259 int32 view_routing_id, | 254 int32 view_routing_id, |
| 260 int32 frame_routing_id, | 255 int32 frame_routing_id, |
| 261 int32 widget_routing_id, | 256 int32 widget_routing_id, |
| 262 int32 surface_id) { | 257 int32 surface_id) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 | 341 |
| 347 void RenderFrameHostManager::RemoveOuterDelegateFrame() { | 342 void RenderFrameHostManager::RemoveOuterDelegateFrame() { |
| 348 FrameTreeNode* outer_delegate_frame_tree_node = | 343 FrameTreeNode* outer_delegate_frame_tree_node = |
| 349 FrameTreeNode::GloballyFindByID( | 344 FrameTreeNode::GloballyFindByID( |
| 350 delegate_->GetOuterDelegateFrameTreeNodeID()); | 345 delegate_->GetOuterDelegateFrameTreeNodeID()); |
| 351 DCHECK(outer_delegate_frame_tree_node->parent()); | 346 DCHECK(outer_delegate_frame_tree_node->parent()); |
| 352 outer_delegate_frame_tree_node->frame_tree()->RemoveFrame( | 347 outer_delegate_frame_tree_node->frame_tree()->RemoveFrame( |
| 353 outer_delegate_frame_tree_node); | 348 outer_delegate_frame_tree_node); |
| 354 } | 349 } |
| 355 | 350 |
| 356 void RenderFrameHostManager::SetPendingWebUI(const GURL& url, int bindings) { | |
| 357 pending_web_ui_ = CreateWebUI(url, bindings); | |
| 358 pending_and_current_web_ui_.reset(); | |
| 359 } | |
| 360 | |
| 361 scoped_ptr<WebUIImpl> RenderFrameHostManager::CreateWebUI(const GURL& url, | |
| 362 int bindings) { | |
| 363 scoped_ptr<WebUIImpl> new_web_ui(delegate_->CreateWebUIForRenderManager(url)); | |
| 364 | |
| 365 // If we have assigned (zero or more) bindings to this NavigationEntry in the | |
| 366 // past, make sure we're not granting it different bindings than it had | |
| 367 // before. If so, note it and don't give it any bindings, to avoid a | |
| 368 // potential privilege escalation. | |
| 369 if (new_web_ui && bindings != NavigationEntryImpl::kInvalidBindings && | |
| 370 new_web_ui->GetBindings() != bindings) { | |
| 371 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | |
| 372 return nullptr; | |
| 373 } | |
| 374 return new_web_ui.Pass(); | |
| 375 } | |
| 376 | |
| 377 RenderFrameHostImpl* RenderFrameHostManager::Navigate( | 351 RenderFrameHostImpl* RenderFrameHostManager::Navigate( |
| 378 const GURL& dest_url, | 352 const GURL& dest_url, |
| 379 const FrameNavigationEntry& frame_entry, | 353 const FrameNavigationEntry& frame_entry, |
| 380 const NavigationEntryImpl& entry) { | 354 const NavigationEntryImpl& entry) { |
| 381 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate", | 355 TRACE_EVENT1("navigation", "RenderFrameHostManager:Navigate", |
| 382 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 356 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); |
| 383 // Create a pending RenderFrameHost to use for the navigation. | 357 // Create a pending RenderFrameHost to use for the navigation. |
| 384 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate( | 358 RenderFrameHostImpl* dest_render_frame_host = UpdateStateForNavigate( |
| 385 dest_url, | 359 dest_url, |
| 386 // TODO(creis): Move source_site_instance to FNE. | 360 // TODO(creis): Move source_site_instance to FNE. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 | 639 |
| 666 // Make sure any dynamic changes to this frame's sandbox flags that were made | 640 // Make sure any dynamic changes to this frame's sandbox flags that were made |
| 667 // prior to navigation take effect. | 641 // prior to navigation take effect. |
| 668 CommitPendingSandboxFlags(); | 642 CommitPendingSandboxFlags(); |
| 669 } | 643 } |
| 670 | 644 |
| 671 void RenderFrameHostManager::CommitPendingIfNecessary( | 645 void RenderFrameHostManager::CommitPendingIfNecessary( |
| 672 RenderFrameHostImpl* render_frame_host, | 646 RenderFrameHostImpl* render_frame_host, |
| 673 bool was_caused_by_user_gesture) { | 647 bool was_caused_by_user_gesture) { |
| 674 if (!pending_render_frame_host_ && !speculative_render_frame_host_) { | 648 if (!pending_render_frame_host_ && !speculative_render_frame_host_) { |
| 675 DCHECK_IMPLIES(should_reuse_web_ui_, web_ui_); | |
| 676 | 649 |
| 677 // We should only hear this from our current renderer. | 650 // We should only hear this from our current renderer. |
| 678 DCHECK_EQ(render_frame_host_, render_frame_host); | 651 DCHECK_EQ(render_frame_host_, render_frame_host); |
| 679 | 652 |
| 680 // Even when there is no pending RVH, there may be a pending Web UI. | 653 // If current RenderFrameHost has a pending Web UI, commit it. |
| 681 if (pending_web_ui() || speculative_web_ui_) | 654 if (render_frame_host_->pending_web_ui()) |
| 682 CommitPending(); | 655 CommitPending(); |
| 683 return; | 656 return; |
| 684 } | 657 } |
| 685 | 658 |
| 686 if (render_frame_host == pending_render_frame_host_ || | 659 if (render_frame_host == pending_render_frame_host_ || |
| 687 render_frame_host == speculative_render_frame_host_) { | 660 render_frame_host == speculative_render_frame_host_) { |
| 688 // The pending cross-process navigation completed, so show the renderer. | 661 // The pending cross-process navigation completed, so show the renderer. |
| 689 CommitPending(); | 662 CommitPending(); |
| 690 } else if (render_frame_host == render_frame_host_) { | 663 } else if (render_frame_host == render_frame_host_) { |
| 691 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 664 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 if (current_site_instance == dest_site_instance.get() || | 972 if (current_site_instance == dest_site_instance.get() || |
| 1000 (!request.browser_initiated() && is_main_frame) || | 973 (!request.browser_initiated() && is_main_frame) || |
| 1001 (!is_main_frame && !dest_site_instance->RequiresDedicatedProcess() && | 974 (!is_main_frame && !dest_site_instance->RequiresDedicatedProcess() && |
| 1002 !current_site_instance->RequiresDedicatedProcess())) { | 975 !current_site_instance->RequiresDedicatedProcess())) { |
| 1003 // Reuse the current RFH if its SiteInstance matches the the navigation's | 976 // Reuse the current RFH if its SiteInstance matches the the navigation's |
| 1004 // or if this is a subframe navigation. We only swap RFHs for subframes when | 977 // or if this is a subframe navigation. We only swap RFHs for subframes when |
| 1005 // --site-per-process is enabled. | 978 // --site-per-process is enabled. |
| 1006 CleanUpNavigation(); | 979 CleanUpNavigation(); |
| 1007 navigation_rfh = render_frame_host_.get(); | 980 navigation_rfh = render_frame_host_.get(); |
| 1008 | 981 |
| 1009 // As SiteInstances are the same, check if the WebUI should be reused. | 982 // As SiteInstances are the same, make the RFH update its possible pending |
| 1010 const NavigationEntry* current_navigation_entry = | 983 // WebUI. |
| 1011 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | 984 render_frame_host_->UpdatePendingWebUI(request.common_params().url, |
| 1012 should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry, | 985 request.bindings()); |
| 1013 request.common_params().url); | 986 DCHECK(speculative_web_ui() == render_frame_host_->pending_web_ui()); |
|
clamy
2015/09/17 17:04:37
This should be DCHECK(!speculative_render_frame_ho
carlosk
2015/09/30 19:37:27
I added the DCHECK you suggested.
But what I am t
| |
| 1014 if (!should_reuse_web_ui_) { | 987 if (speculative_web_ui() && render_frame_host_->IsRenderFrameLive()) { |
| 1015 speculative_web_ui_ = CreateWebUI(request.common_params().url, | 988 speculative_web_ui()->GetController()->RenderViewReused( |
| 1016 request.bindings()); | 989 render_frame_host_->render_view_host()); |
| 1017 // Make sure the current RenderViewHost has the right bindings. | 990 } |
| 1018 if (speculative_web_ui() && | 991 |
| 1019 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { | 992 // If a speculative WebUI was set, make sure the current RenderViewHost has |
| 1020 render_frame_host_->render_view_host()->AllowBindings( | 993 // the right bindings. |
| 1021 speculative_web_ui()->GetBindings()); | 994 if (speculative_web_ui() && |
| 1022 } | 995 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { |
| 996 render_frame_host_->render_view_host()->AllowBindings( | |
| 997 speculative_web_ui()->GetBindings()); | |
| 1023 } | 998 } |
| 1024 } else { | 999 } else { |
| 1025 // If the SiteInstance for the final URL doesn't match the one from the | 1000 // If the SiteInstance for the final URL doesn't match the one from the |
| 1026 // speculatively created RenderFrameHost, create a new RenderFrameHost using | 1001 // speculatively created RenderFrameHost, create a new RenderFrameHost using |
| 1027 // this new SiteInstance. | 1002 // this new SiteInstance. |
| 1028 if (!speculative_render_frame_host_ || | 1003 if (!speculative_render_frame_host_ || |
| 1029 speculative_render_frame_host_->GetSiteInstance() != | 1004 speculative_render_frame_host_->GetSiteInstance() != |
| 1030 dest_site_instance.get()) { | 1005 dest_site_instance.get()) { |
| 1031 CleanUpNavigation(); | 1006 CleanUpNavigation(); |
| 1032 bool success = CreateSpeculativeRenderFrameHost( | 1007 bool success = CreateSpeculativeRenderFrameHost( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 } | 1047 } |
| 1073 } | 1048 } |
| 1074 | 1049 |
| 1075 return navigation_rfh; | 1050 return navigation_rfh; |
| 1076 } | 1051 } |
| 1077 | 1052 |
| 1078 // PlzNavigate | 1053 // PlzNavigate |
| 1079 void RenderFrameHostManager::CleanUpNavigation() { | 1054 void RenderFrameHostManager::CleanUpNavigation() { |
| 1080 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 1055 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1081 switches::kEnableBrowserSideNavigation)); | 1056 switches::kEnableBrowserSideNavigation)); |
| 1082 speculative_web_ui_.reset(); | 1057 render_frame_host_->DiscardPendingWebUI(); |
|
clamy
2015/09/17 17:04:38
What if you committed a created WebUI at the start
carlosk
2015/09/30 19:37:27
I assume you are referring to the early committing
| |
| 1083 should_reuse_web_ui_ = false; | |
| 1084 if (speculative_render_frame_host_) | 1058 if (speculative_render_frame_host_) |
| 1085 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); | 1059 DiscardUnusedFrame(UnsetSpeculativeRenderFrameHost()); |
| 1086 } | 1060 } |
| 1087 | 1061 |
| 1088 // PlzNavigate | 1062 // PlzNavigate |
| 1089 scoped_ptr<RenderFrameHostImpl> | 1063 scoped_ptr<RenderFrameHostImpl> |
| 1090 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() { | 1064 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() { |
| 1091 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 1065 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1092 switches::kEnableBrowserSideNavigation)); | 1066 switches::kEnableBrowserSideNavigation)); |
| 1093 speculative_render_frame_host_->GetProcess()->RemovePendingView(); | 1067 speculative_render_frame_host_->GetProcess()->RemovePendingView(); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 // We can't switch a RenderView between view source and non-view source mode | 1231 // We can't switch a RenderView between view source and non-view source mode |
| 1258 // without screwing up the session history sometimes (when navigating between | 1232 // without screwing up the session history sometimes (when navigating between |
| 1259 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat | 1233 // "view-source:http://foo.com/" and "http://foo.com/", Blink doesn't treat |
| 1260 // it as a new navigation). So require a BrowsingInstance switch. | 1234 // it as a new navigation). So require a BrowsingInstance switch. |
| 1261 if (current_is_view_source_mode != new_is_view_source_mode) | 1235 if (current_is_view_source_mode != new_is_view_source_mode) |
| 1262 return true; | 1236 return true; |
| 1263 | 1237 |
| 1264 return false; | 1238 return false; |
| 1265 } | 1239 } |
| 1266 | 1240 |
| 1267 bool RenderFrameHostManager::ShouldReuseWebUI( | |
| 1268 const NavigationEntry* current_entry, | |
| 1269 const GURL& new_url) const { | |
| 1270 NavigationControllerImpl& controller = | |
| 1271 delegate_->GetControllerForRenderManager(); | |
| 1272 return current_entry && web_ui_ && | |
| 1273 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | |
| 1274 controller.GetBrowserContext(), current_entry->GetURL()) == | |
| 1275 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | |
| 1276 controller.GetBrowserContext(), new_url)); | |
| 1277 } | |
| 1278 | |
| 1279 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( | 1241 SiteInstance* RenderFrameHostManager::GetSiteInstanceForNavigation( |
| 1280 const GURL& dest_url, | 1242 const GURL& dest_url, |
| 1281 SiteInstance* source_instance, | 1243 SiteInstance* source_instance, |
| 1282 SiteInstance* dest_instance, | 1244 SiteInstance* dest_instance, |
| 1283 SiteInstance* candidate_instance, | 1245 SiteInstance* candidate_instance, |
| 1284 ui::PageTransition transition, | 1246 ui::PageTransition transition, |
| 1285 bool dest_is_restore, | 1247 bool dest_is_restore, |
| 1286 bool dest_is_view_source_mode) { | 1248 bool dest_is_view_source_mode) { |
| 1287 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 1249 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
| 1288 | 1250 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1552 // to open a new tab to an interstitial-inducing URL, and then navigates | 1514 // to open a new tab to an interstitial-inducing URL, and then navigates |
| 1553 // the page to a different same-site URL. (This seems very unlikely in | 1515 // the page to a different same-site URL. (This seems very unlikely in |
| 1554 // practice.) | 1516 // practice.) |
| 1555 if (current_entry) | 1517 if (current_entry) |
| 1556 return current_entry->GetURL(); | 1518 return current_entry->GetURL(); |
| 1557 return current_instance->GetSiteURL(); | 1519 return current_instance->GetSiteURL(); |
| 1558 } | 1520 } |
| 1559 | 1521 |
| 1560 void RenderFrameHostManager::CreatePendingRenderFrameHost( | 1522 void RenderFrameHostManager::CreatePendingRenderFrameHost( |
| 1561 SiteInstance* old_instance, | 1523 SiteInstance* old_instance, |
| 1562 SiteInstance* new_instance) { | 1524 SiteInstance* new_instance, |
| 1525 const GURL& url, | |
| 1526 int bindings) { | |
| 1563 int create_render_frame_flags = 0; | 1527 int create_render_frame_flags = 0; |
| 1564 if (delegate_->IsHidden()) | 1528 if (delegate_->IsHidden()) |
| 1565 create_render_frame_flags |= CREATE_RF_HIDDEN; | 1529 create_render_frame_flags |= CREATE_RF_HIDDEN; |
| 1566 | 1530 |
| 1567 if (pending_render_frame_host_) | 1531 if (pending_render_frame_host_) |
| 1568 CancelPending(); | 1532 CancelPending(); |
| 1569 | 1533 |
| 1570 // The process for the new SiteInstance may (if we're sharing a process with | 1534 // The process for the new SiteInstance may (if we're sharing a process with |
| 1571 // another host that already initialized it) or may not (we have our own | 1535 // another host that already initialized it) or may not (we have our own |
| 1572 // process or the existing process crashed) have been initialized. Calling | 1536 // process or the existing process crashed) have been initialized. Calling |
| 1573 // Init multiple times will be ignored, so this is safe. | 1537 // Init multiple times will be ignored, so this is safe. |
| 1574 if (!new_instance->GetProcess()->Init()) | 1538 if (!new_instance->GetProcess()->Init()) |
| 1575 return; | 1539 return; |
| 1576 | 1540 |
| 1577 CreateProxiesForNewRenderFrameHost(old_instance, new_instance); | 1541 CreateProxiesForNewRenderFrameHost(old_instance, new_instance); |
| 1578 | 1542 |
| 1579 // Create a non-swapped-out RFH with the given opener. | 1543 // Create a non-swapped-out RFH with the given opener. |
| 1580 pending_render_frame_host_ = CreateRenderFrame( | 1544 pending_render_frame_host_ = CreateRenderFrameInternal( |
| 1581 new_instance, pending_web_ui(), create_render_frame_flags, nullptr); | 1545 new_instance, url, bindings, create_render_frame_flags, nullptr); |
| 1582 } | 1546 } |
| 1583 | 1547 |
| 1584 void RenderFrameHostManager::CreateProxiesForNewRenderFrameHost( | 1548 void RenderFrameHostManager::CreateProxiesForNewRenderFrameHost( |
| 1585 SiteInstance* old_instance, | 1549 SiteInstance* old_instance, |
| 1586 SiteInstance* new_instance) { | 1550 SiteInstance* new_instance) { |
| 1587 // Only create opener proxies if they are in the same BrowsingInstance. | 1551 // Only create opener proxies if they are in the same BrowsingInstance. |
| 1588 if (new_instance->IsRelatedSiteInstance(old_instance)) { | 1552 if (new_instance->IsRelatedSiteInstance(old_instance)) { |
| 1589 CreateOpenerProxies(new_instance, frame_tree_node_); | 1553 CreateOpenerProxies(new_instance, frame_tree_node_); |
| 1590 } else if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) { | 1554 } else if (SiteIsolationPolicy::AreCrossProcessFramesPossible()) { |
| 1591 // Ensure that the frame tree has RenderFrameProxyHosts for the | 1555 // Ensure that the frame tree has RenderFrameProxyHosts for the |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1660 } | 1624 } |
| 1661 | 1625 |
| 1662 // PlzNavigate | 1626 // PlzNavigate |
| 1663 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost( | 1627 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost( |
| 1664 const GURL& url, | 1628 const GURL& url, |
| 1665 SiteInstance* old_instance, | 1629 SiteInstance* old_instance, |
| 1666 SiteInstance* new_instance, | 1630 SiteInstance* new_instance, |
| 1667 int bindings) { | 1631 int bindings) { |
| 1668 CHECK(new_instance); | 1632 CHECK(new_instance); |
| 1669 CHECK_NE(old_instance, new_instance); | 1633 CHECK_NE(old_instance, new_instance); |
| 1670 CHECK(!should_reuse_web_ui_); | |
| 1671 | |
| 1672 // Note: |speculative_web_ui_| must be initialized before starting the | |
| 1673 // |speculative_render_frame_host_| creation steps otherwise the WebUI | |
| 1674 // won't be properly initialized. | |
| 1675 speculative_web_ui_ = CreateWebUI(url, bindings); | |
| 1676 | 1634 |
| 1677 // The process for the new SiteInstance may (if we're sharing a process with | 1635 // The process for the new SiteInstance may (if we're sharing a process with |
| 1678 // another host that already initialized it) or may not (we have our own | 1636 // another host that already initialized it) or may not (we have our own |
| 1679 // process or the existing process crashed) have been initialized. Calling | 1637 // process or the existing process crashed) have been initialized. Calling |
| 1680 // Init multiple times will be ignored, so this is safe. | 1638 // Init multiple times will be ignored, so this is safe. |
| 1681 if (!new_instance->GetProcess()->Init()) | 1639 if (!new_instance->GetProcess()->Init()) |
| 1682 return false; | 1640 return false; |
| 1683 | 1641 |
| 1684 CreateProxiesForNewRenderFrameHost(old_instance, new_instance); | 1642 CreateProxiesForNewRenderFrameHost(old_instance, new_instance); |
| 1685 | 1643 |
| 1686 int create_render_frame_flags = 0; | 1644 int create_render_frame_flags = 0; |
| 1687 if (delegate_->IsHidden()) | 1645 if (delegate_->IsHidden()) |
| 1688 create_render_frame_flags |= CREATE_RF_HIDDEN; | 1646 create_render_frame_flags |= CREATE_RF_HIDDEN; |
| 1689 speculative_render_frame_host_ = | 1647 speculative_render_frame_host_ = CreateRenderFrameInternal( |
| 1690 CreateRenderFrame(new_instance, speculative_web_ui_.get(), | 1648 new_instance, url, bindings, create_render_frame_flags, nullptr); |
| 1691 create_render_frame_flags, nullptr); | |
| 1692 | 1649 |
| 1693 if (!speculative_render_frame_host_) { | |
| 1694 speculative_web_ui_.reset(); | |
| 1695 return false; | |
| 1696 } | |
| 1697 return true; | 1650 return true; |
| 1698 } | 1651 } |
| 1699 | 1652 |
| 1700 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame( | 1653 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::CreateRenderFrame( |
| 1701 SiteInstance* instance, | 1654 SiteInstance* instance, |
| 1702 WebUIImpl* web_ui, | |
| 1703 int flags, | 1655 int flags, |
| 1704 int* view_routing_id_ptr) { | 1656 int* view_routing_id_ptr) { |
| 1657 return CreateRenderFrameInternal(instance, GURL(), | |
| 1658 NavigationEntryImpl::kInvalidBindings, flags, | |
| 1659 view_routing_id_ptr); | |
| 1660 } | |
| 1661 | |
| 1662 scoped_ptr<RenderFrameHostImpl> | |
| 1663 RenderFrameHostManager::CreateRenderFrameInternal(SiteInstance* instance, | |
| 1664 const GURL& url, | |
| 1665 int bindings, | |
| 1666 int flags, | |
| 1667 int* view_routing_id_ptr) { | |
| 1705 bool swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | 1668 bool swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); |
| 1706 bool swapped_out_forbidden = | 1669 bool swapped_out_forbidden = |
| 1707 SiteIsolationPolicy::IsSwappedOutStateForbidden(); | 1670 SiteIsolationPolicy::IsSwappedOutStateForbidden(); |
| 1708 | 1671 |
| 1709 CHECK(instance); | 1672 CHECK(instance); |
| 1710 CHECK_IMPLIES(swapped_out_forbidden, !swapped_out); | 1673 CHECK_IMPLIES(swapped_out_forbidden, !swapped_out); |
| 1711 CHECK_IMPLIES(!SiteIsolationPolicy::AreCrossProcessFramesPossible(), | 1674 CHECK_IMPLIES(!SiteIsolationPolicy::AreCrossProcessFramesPossible(), |
| 1712 frame_tree_node_->IsMainFrame()); | 1675 frame_tree_node_->IsMainFrame()); |
| 1713 | 1676 |
| 1714 // Swapped out views should always be hidden. | 1677 // Swapped out views should always be hidden. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1729 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | 1692 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); |
| 1730 if (proxy && proxy->render_frame_host()) { | 1693 if (proxy && proxy->render_frame_host()) { |
| 1731 RenderViewHost* render_view_host = proxy->GetRenderViewHost(); | 1694 RenderViewHost* render_view_host = proxy->GetRenderViewHost(); |
| 1732 CHECK(!swapped_out_forbidden); | 1695 CHECK(!swapped_out_forbidden); |
| 1733 if (view_routing_id_ptr) | 1696 if (view_routing_id_ptr) |
| 1734 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID(); | 1697 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID(); |
| 1735 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. | 1698 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. |
| 1736 // Prevent the process from exiting while we're trying to use it. | 1699 // Prevent the process from exiting while we're trying to use it. |
| 1737 if (!swapped_out) { | 1700 if (!swapped_out) { |
| 1738 new_render_frame_host = proxy->PassFrameHostOwnership(); | 1701 new_render_frame_host = proxy->PassFrameHostOwnership(); |
| 1702 new_render_frame_host->InitializeWebUI(url, bindings); | |
| 1739 new_render_frame_host->GetProcess()->AddPendingView(); | 1703 new_render_frame_host->GetProcess()->AddPendingView(); |
| 1740 | 1704 |
| 1741 proxy_hosts_->Remove(instance->GetId()); | 1705 proxy_hosts_->Remove(instance->GetId()); |
| 1742 // NB |proxy| is deleted at this point. | 1706 // NB |proxy| is deleted at this point. |
| 1743 } | 1707 } |
| 1744 // If we are reusing the RenderViewHost and it doesn't already have a | 1708 // If we are reusing the RenderViewHost and it doesn't already have a |
| 1745 // RenderWidgetHostView, we need to create one if this is the main frame. | 1709 // RenderWidgetHostView, we need to create one if this is the main frame. |
| 1746 if (!render_view_host->GetView() && frame_tree_node_->IsMainFrame()) | 1710 if (!render_view_host->GetView() && frame_tree_node_->IsMainFrame()) |
| 1747 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host); | 1711 delegate_->CreateRenderWidgetHostViewForRenderManager(render_view_host); |
| 1748 } else { | 1712 } else { |
| 1749 // Create a new RenderFrameHost if we don't find an existing one. | 1713 // Create a new RenderFrameHost if we don't find an existing one. |
| 1750 | 1714 |
| 1751 int32 widget_routing_id = MSG_ROUTING_NONE; | 1715 int32 widget_routing_id = MSG_ROUTING_NONE; |
| 1752 int32 surface_id = 0; | 1716 int32 surface_id = 0; |
| 1753 // A RenderFrame in a different process from its parent RenderFrame | 1717 // A RenderFrame in a different process from its parent RenderFrame |
| 1754 // requires a RenderWidget for input/layout/painting. | 1718 // requires a RenderWidget for input/layout/painting. |
| 1755 if (frame_tree_node_->parent() && | 1719 if (frame_tree_node_->parent() && |
| 1756 frame_tree_node_->parent()->current_frame_host()->GetSiteInstance() != | 1720 frame_tree_node_->parent()->current_frame_host()->GetSiteInstance() != |
| 1757 instance) { | 1721 instance) { |
| 1758 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); | 1722 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); |
| 1759 widget_routing_id = instance->GetProcess()->GetNextRoutingID(); | 1723 widget_routing_id = instance->GetProcess()->GetNextRoutingID(); |
| 1760 surface_id = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 1724 surface_id = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 1761 instance->GetProcess()->GetID(), widget_routing_id); | 1725 instance->GetProcess()->GetID(), widget_routing_id); |
| 1762 } | 1726 } |
| 1763 | 1727 |
| 1764 new_render_frame_host = | 1728 new_render_frame_host = |
| 1765 CreateRenderFrameHost(instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, | 1729 CreateRenderFrameHost(instance, MSG_ROUTING_NONE, MSG_ROUTING_NONE, |
| 1766 widget_routing_id, surface_id, flags); | 1730 widget_routing_id, surface_id, flags); |
| 1731 new_render_frame_host->InitializeWebUI(url, bindings); | |
|
clamy
2015/09/17 17:04:37
Why do we need to do that instead of using a RFH c
carlosk
2015/09/30 19:37:27
I did this mainly to avoid having to pump down (ev
| |
| 1767 RenderViewHostImpl* render_view_host = | 1732 RenderViewHostImpl* render_view_host = |
| 1768 new_render_frame_host->render_view_host(); | 1733 new_render_frame_host->render_view_host(); |
| 1769 int proxy_routing_id = MSG_ROUTING_NONE; | 1734 int proxy_routing_id = MSG_ROUTING_NONE; |
| 1770 | 1735 |
| 1771 // Prevent the process from exiting while we're trying to navigate in it. | 1736 // Prevent the process from exiting while we're trying to navigate in it. |
| 1772 // Otherwise, if the new RFH is swapped out already, store it. | 1737 // Otherwise, if the new RFH is swapped out already, store it. |
| 1773 if (!swapped_out) { | 1738 if (!swapped_out) { |
| 1774 new_render_frame_host->GetProcess()->AddPendingView(); | 1739 new_render_frame_host->GetProcess()->AddPendingView(); |
| 1775 } else { | 1740 } else { |
| 1776 proxy = new RenderFrameProxyHost( | 1741 proxy = new RenderFrameProxyHost( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1819 if (view_routing_id_ptr) | 1784 if (view_routing_id_ptr) |
| 1820 *view_routing_id_ptr = render_view_host->GetRoutingID(); | 1785 *view_routing_id_ptr = render_view_host->GetRoutingID(); |
| 1821 } | 1786 } |
| 1822 } | 1787 } |
| 1823 | 1788 |
| 1824 // When a new RenderView is created by the renderer process, the new | 1789 // When a new RenderView is created by the renderer process, the new |
| 1825 // WebContents gets a RenderViewHost in the SiteInstance of its opener | 1790 // WebContents gets a RenderViewHost in the SiteInstance of its opener |
| 1826 // WebContents. If not used in the first navigation, this RVH is swapped out | 1791 // WebContents. If not used in the first navigation, this RVH is swapped out |
| 1827 // and is not granted bindings, so we may need to grant them when swapping it | 1792 // and is not granted bindings, so we may need to grant them when swapping it |
| 1828 // in. | 1793 // in. |
| 1829 if (web_ui && !new_render_frame_host->GetProcess()->IsForGuestsOnly()) { | 1794 // DCHECK_IMPLIES(new_render_frame_host->web_ui(), |
| 1830 int required_bindings = web_ui->GetBindings(); | 1795 // new_render_frame_host->web_ui()->GetBindings() == bindings); |
| 1796 if (new_render_frame_host && new_render_frame_host->web_ui() && | |
| 1797 !new_render_frame_host->GetProcess()->IsForGuestsOnly()) { | |
| 1831 RenderViewHost* render_view_host = | 1798 RenderViewHost* render_view_host = |
| 1832 new_render_frame_host->render_view_host(); | 1799 new_render_frame_host->render_view_host(); |
| 1833 if ((render_view_host->GetEnabledBindings() & required_bindings) != | 1800 if ((render_view_host->GetEnabledBindings() & bindings) != bindings) { |
| 1834 required_bindings) { | 1801 render_view_host->AllowBindings(bindings); |
| 1835 render_view_host->AllowBindings(required_bindings); | |
| 1836 } | 1802 } |
| 1837 } | 1803 } |
| 1838 | 1804 |
| 1839 // Returns the new RFH if it isn't swapped out. | 1805 // Returns the new RFH if it isn't swapped out. |
| 1840 if (success && !swapped_out) { | 1806 if (success && !swapped_out) { |
| 1841 DCHECK(new_render_frame_host->GetSiteInstance() == instance); | 1807 DCHECK(new_render_frame_host->GetSiteInstance() == instance); |
| 1842 return new_render_frame_host.Pass(); | 1808 return new_render_frame_host.Pass(); |
| 1843 } | 1809 } |
| 1844 return nullptr; | 1810 return nullptr; |
| 1845 } | 1811 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1955 // We may have initialized this RenderViewHost for another RenderFrameHost. | 1921 // We may have initialized this RenderViewHost for another RenderFrameHost. |
| 1956 if (render_view_host->IsRenderViewLive()) | 1922 if (render_view_host->IsRenderViewLive()) |
| 1957 return true; | 1923 return true; |
| 1958 | 1924 |
| 1959 // If the ongoing navigation is to a WebUI and the RenderView is not in a | 1925 // If the ongoing navigation is to a WebUI and the RenderView is not in a |
| 1960 // guest process, tell the RenderViewHost about any bindings it will need | 1926 // guest process, tell the RenderViewHost about any bindings it will need |
| 1961 // enabled. | 1927 // enabled. |
| 1962 WebUIImpl* dest_web_ui = nullptr; | 1928 WebUIImpl* dest_web_ui = nullptr; |
| 1963 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1929 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1964 switches::kEnableBrowserSideNavigation)) { | 1930 switches::kEnableBrowserSideNavigation)) { |
| 1965 dest_web_ui = | 1931 dest_web_ui = speculative_web_ui(); |
| 1966 should_reuse_web_ui_ ? web_ui_.get() : speculative_web_ui_.get(); | |
| 1967 } else { | 1932 } else { |
| 1968 dest_web_ui = pending_web_ui(); | 1933 dest_web_ui = pending_web_ui(); |
| 1969 } | 1934 } |
| 1970 if (dest_web_ui && !render_view_host->GetProcess()->IsForGuestsOnly()) { | 1935 if (dest_web_ui && !render_view_host->GetProcess()->IsForGuestsOnly()) { |
| 1971 render_view_host->AllowBindings(dest_web_ui->GetBindings()); | 1936 render_view_host->AllowBindings(dest_web_ui->GetBindings()); |
| 1972 } else { | 1937 } else { |
| 1973 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 1938 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled |
| 1974 // process unless it's swapped out. | 1939 // process unless it's swapped out. |
| 1975 if (render_view_host->is_active()) { | 1940 if (render_view_host->is_active()) { |
| 1976 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1941 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2056 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); | 2021 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); |
| 2057 if (proxy) | 2022 if (proxy) |
| 2058 return proxy->GetRoutingID(); | 2023 return proxy->GetRoutingID(); |
| 2059 | 2024 |
| 2060 return MSG_ROUTING_NONE; | 2025 return MSG_ROUTING_NONE; |
| 2061 } | 2026 } |
| 2062 | 2027 |
| 2063 void RenderFrameHostManager::CommitPending() { | 2028 void RenderFrameHostManager::CommitPending() { |
| 2064 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", | 2029 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", |
| 2065 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 2030 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); |
| 2066 bool browser_side_navigation = | |
| 2067 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 2068 switches::kEnableBrowserSideNavigation); | |
| 2069 | |
| 2070 // First check whether we're going to want to focus the location bar after | 2031 // First check whether we're going to want to focus the location bar after |
| 2071 // this commit. We do this now because the navigation hasn't formally | 2032 // this commit. We do this now because the navigation hasn't formally |
| 2072 // committed yet, so if we've already cleared |pending_web_ui_| the call chain | 2033 // committed yet, so if we've already cleared the pending WebUI the call chain |
| 2073 // this triggers won't be able to figure out what's going on. | 2034 // this triggers won't be able to figure out what's going on. |
| 2074 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 2035 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
| 2075 | 2036 |
| 2076 // Next commit the Web UI, if any. Either replace |web_ui_| with | 2037 // If the current RenderFrameHost has a pending Web UI then commit it. |
| 2077 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or | 2038 if (render_frame_host_->pending_web_ui()) { |
| 2078 // leave |web_ui_| as is if reusing it. | 2039 DCHECK(!pending_render_frame_host_ && !speculative_render_frame_host_); |
| 2079 DCHECK(!(pending_web_ui_ && pending_and_current_web_ui_)); | 2040 render_frame_host_->CommitPendingWebUI(); |
| 2080 if (pending_web_ui_ || speculative_web_ui_) { | |
| 2081 DCHECK(!should_reuse_web_ui_); | |
| 2082 web_ui_.reset(browser_side_navigation ? speculative_web_ui_.release() | |
| 2083 : pending_web_ui_.release()); | |
| 2084 } else if (pending_and_current_web_ui_ || should_reuse_web_ui_) { | |
| 2085 if (browser_side_navigation) { | |
| 2086 DCHECK(web_ui_); | |
| 2087 should_reuse_web_ui_ = false; | |
| 2088 } else { | |
| 2089 DCHECK_EQ(pending_and_current_web_ui_.get(), web_ui_.get()); | |
| 2090 pending_and_current_web_ui_.reset(); | |
| 2091 } | |
| 2092 } else { | |
| 2093 web_ui_.reset(); | |
| 2094 } | |
| 2095 DCHECK(!speculative_web_ui_); | |
| 2096 DCHECK(!should_reuse_web_ui_); | |
| 2097 | |
| 2098 // It's possible for the pending_render_frame_host_ to be nullptr when we | |
| 2099 // aren't crossing process boundaries. If so, we just needed to handle the Web | |
| 2100 // UI committing above and we're done. | |
| 2101 if (!pending_render_frame_host_ && !speculative_render_frame_host_) { | |
| 2102 if (will_focus_location_bar) | 2041 if (will_focus_location_bar) |
| 2103 delegate_->SetFocusToLocationBar(false); | 2042 delegate_->SetFocusToLocationBar(false); |
| 2104 return; | 2043 return; |
| 2105 } | 2044 } |
| 2106 | 2045 |
| 2107 // Remember if the page was focused so we can focus the new renderer in | 2046 // Remember if the page was focused so we can focus the new renderer in |
| 2108 // that case. | 2047 // that case. |
| 2109 bool focus_render_view = !will_focus_location_bar && | 2048 bool focus_render_view = !will_focus_location_bar && |
| 2110 render_frame_host_->GetView() && | 2049 render_frame_host_->GetView() && |
| 2111 render_frame_host_->GetView()->HasFocus(); | 2050 render_frame_host_->GetView()->HasFocus(); |
| 2112 | 2051 |
| 2113 bool is_main_frame = frame_tree_node_->IsMainFrame(); | 2052 bool is_main_frame = frame_tree_node_->IsMainFrame(); |
| 2114 | 2053 |
| 2115 // Swap in the pending or speculative frame and make it active. Also ensure | 2054 // Swap in the pending or speculative frame and make it active. Also ensure |
| 2116 // the FrameTree stays in sync. | 2055 // the FrameTree stays in sync. |
| 2117 scoped_ptr<RenderFrameHostImpl> old_render_frame_host; | 2056 scoped_ptr<RenderFrameHostImpl> old_render_frame_host; |
| 2118 if (!browser_side_navigation) { | 2057 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2058 switches::kEnableBrowserSideNavigation)) { | |
| 2119 DCHECK(!speculative_render_frame_host_); | 2059 DCHECK(!speculative_render_frame_host_); |
| 2120 old_render_frame_host = | 2060 old_render_frame_host = |
| 2121 SetRenderFrameHost(pending_render_frame_host_.Pass()); | 2061 SetRenderFrameHost(pending_render_frame_host_.Pass()); |
| 2122 } else { | 2062 } else { |
| 2123 // PlzNavigate | 2063 // PlzNavigate |
| 2124 DCHECK(speculative_render_frame_host_); | 2064 DCHECK(speculative_render_frame_host_); |
| 2125 old_render_frame_host = | 2065 old_render_frame_host = |
| 2126 SetRenderFrameHost(speculative_render_frame_host_.Pass()); | 2066 SetRenderFrameHost(speculative_render_frame_host_.Pass()); |
| 2127 } | 2067 } |
| 2128 | 2068 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2270 // If we are currently navigating cross-process, we want to get back to normal | 2210 // If we are currently navigating cross-process, we want to get back to normal |
| 2271 // and then navigate as usual. | 2211 // and then navigate as usual. |
| 2272 if (pending_render_frame_host_) | 2212 if (pending_render_frame_host_) |
| 2273 CancelPending(); | 2213 CancelPending(); |
| 2274 | 2214 |
| 2275 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 2215 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
| 2276 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 2216 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
| 2277 dest_url, source_instance, dest_instance, nullptr, transition, | 2217 dest_url, source_instance, dest_instance, nullptr, transition, |
| 2278 dest_is_restore, dest_is_view_source_mode); | 2218 dest_is_restore, dest_is_view_source_mode); |
| 2279 | 2219 |
| 2280 const NavigationEntry* current_entry = | |
| 2281 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | |
| 2282 | |
| 2283 DCHECK(!pending_render_frame_host_); | 2220 DCHECK(!pending_render_frame_host_); |
| 2284 | 2221 |
| 2285 if (new_instance.get() != current_instance) { | 2222 if (new_instance.get() != current_instance) { |
| 2286 TRACE_EVENT_INSTANT2( | 2223 TRACE_EVENT_INSTANT2( |
| 2287 "navigation", | 2224 "navigation", |
| 2288 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", | 2225 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", |
| 2289 TRACE_EVENT_SCOPE_THREAD, | 2226 TRACE_EVENT_SCOPE_THREAD, |
| 2290 "current_instance id", current_instance->GetId(), | 2227 "current_instance id", current_instance->GetId(), |
| 2291 "new_instance id", new_instance->GetId()); | 2228 "new_instance id", new_instance->GetId()); |
| 2292 | 2229 |
| 2293 // New SiteInstance: create a pending RFH to navigate. | 2230 // New SiteInstance: create a pending RFH to navigate. |
| 2294 | 2231 |
| 2295 // This will possibly create (set to nullptr) a Web UI object for the | 2232 CreatePendingRenderFrameHost(current_instance, new_instance.get(), dest_url, |
| 2296 // pending page. We'll use this later to give the page special access. This | 2233 bindings); |
| 2297 // must happen before the new renderer is created below so it will get | |
| 2298 // bindings. It must also happen after the above conditional call to | |
| 2299 // CancelPending(), otherwise CancelPending may clear the pending_web_ui_ | |
| 2300 // and the page will not have its bindings set appropriately. | |
| 2301 SetPendingWebUI(dest_url, bindings); | |
| 2302 CreatePendingRenderFrameHost(current_instance, new_instance.get()); | |
| 2303 if (!pending_render_frame_host_) | 2234 if (!pending_render_frame_host_) |
| 2304 return nullptr; | 2235 return nullptr; |
| 2305 | 2236 |
| 2306 // Check if our current RFH is live before we set up a transition. | 2237 // Check if our current RFH is live before we set up a transition. |
| 2307 if (!render_frame_host_->IsRenderFrameLive()) { | 2238 if (!render_frame_host_->IsRenderFrameLive()) { |
| 2308 // The current RFH is not live. There's no reason to sit around with a | 2239 // The current RFH is not live. There's no reason to sit around with a |
| 2309 // sad tab or a newly created RFH while we wait for the pending RFH to | 2240 // sad tab or a newly created RFH while we wait for the pending RFH to |
| 2310 // navigate. Just switch to the pending RFH now and go back to normal. | 2241 // navigate. Just switch to the pending RFH now and go back to normal. |
| 2311 // (Note that we don't care about on{before}unload handlers if the current | 2242 // (Note that we don't care about on{before}unload handlers if the current |
| 2312 // RFH isn't live.) | 2243 // RFH isn't live.) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2352 | 2283 |
| 2353 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. | 2284 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. |
| 2354 | 2285 |
| 2355 // It's possible to swap out the current RFH and then decide to navigate in it | 2286 // It's possible to swap out the current RFH and then decide to navigate in it |
| 2356 // anyway (e.g., a cross-process navigation that redirects back to the | 2287 // anyway (e.g., a cross-process navigation that redirects back to the |
| 2357 // original site). In that case, we have a proxy for the current RFH but | 2288 // original site). In that case, we have a proxy for the current RFH but |
| 2358 // haven't deleted it yet. The new navigation will swap it back in, so we can | 2289 // haven't deleted it yet. The new navigation will swap it back in, so we can |
| 2359 // delete the proxy. | 2290 // delete the proxy. |
| 2360 proxy_hosts_->Remove(new_instance.get()->GetId()); | 2291 proxy_hosts_->Remove(new_instance.get()->GetId()); |
| 2361 | 2292 |
| 2362 if (ShouldReuseWebUI(current_entry, dest_url)) { | 2293 render_frame_host_->UpdatePendingWebUI(dest_url, bindings); |
| 2363 pending_web_ui_.reset(); | 2294 |
| 2364 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); | 2295 // TODO(carlosk): try moving this into RenderFrameHostImpl::CreateWebUI |
| 2365 } else { | 2296 // Make sure the new RenderViewHost has the right bindings. |
| 2366 SetPendingWebUI(dest_url, bindings); | 2297 if (render_frame_host_->pending_web_ui() && |
| 2367 // Make sure the new RenderViewHost has the right bindings. | 2298 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { |
| 2368 if (pending_web_ui() && | 2299 render_frame_host_->render_view_host()->AllowBindings( |
| 2369 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { | 2300 render_frame_host_->pending_web_ui()->GetBindings()); |
| 2370 render_frame_host_->render_view_host()->AllowBindings( | |
| 2371 pending_web_ui()->GetBindings()); | |
| 2372 } | |
| 2373 } | 2301 } |
| 2374 | 2302 |
| 2375 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) { | 2303 // TODO(carlosk): try moving this into RenderFrameHostImpl::UpdatePendingWebUI |
| 2376 pending_web_ui()->GetController()->RenderViewReused( | 2304 if (render_frame_host_->pending_web_ui() && |
| 2305 render_frame_host_->IsRenderFrameLive()) { | |
| 2306 render_frame_host_->pending_web_ui()->GetController()->RenderViewReused( | |
| 2377 render_frame_host_->render_view_host()); | 2307 render_frame_host_->render_view_host()); |
| 2378 } | 2308 } |
| 2379 | 2309 |
| 2380 // The renderer can exit view source mode when any error or cancellation | 2310 // The renderer can exit view source mode when any error or cancellation |
| 2381 // happen. We must overwrite to recover the mode. | 2311 // happen. We must overwrite to recover the mode. |
| 2382 if (dest_is_view_source_mode) { | 2312 if (dest_is_view_source_mode) { |
| 2383 render_frame_host_->render_view_host()->Send( | 2313 render_frame_host_->render_view_host()->Send( |
| 2384 new ViewMsg_EnableViewSourceMode( | 2314 new ViewMsg_EnableViewSourceMode( |
| 2385 render_frame_host_->render_view_host()->GetRoutingID())); | 2315 render_frame_host_->render_view_host()->GetRoutingID())); |
| 2386 } | 2316 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2399 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host = | 2329 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host = |
| 2400 pending_render_frame_host_.Pass(); | 2330 pending_render_frame_host_.Pass(); |
| 2401 | 2331 |
| 2402 RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( | 2332 RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( |
| 2403 pending_render_frame_host.get(), | 2333 pending_render_frame_host.get(), |
| 2404 render_frame_host_.get()); | 2334 render_frame_host_.get()); |
| 2405 | 2335 |
| 2406 // We no longer need to prevent the process from exiting. | 2336 // We no longer need to prevent the process from exiting. |
| 2407 pending_render_frame_host->GetProcess()->RemovePendingView(); | 2337 pending_render_frame_host->GetProcess()->RemovePendingView(); |
| 2408 | 2338 |
| 2409 pending_web_ui_.reset(); | |
| 2410 pending_and_current_web_ui_.reset(); | |
| 2411 | |
| 2412 return pending_render_frame_host.Pass(); | 2339 return pending_render_frame_host.Pass(); |
| 2413 } | 2340 } |
| 2414 | 2341 |
| 2415 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( | 2342 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( |
| 2416 scoped_ptr<RenderFrameHostImpl> render_frame_host) { | 2343 scoped_ptr<RenderFrameHostImpl> render_frame_host) { |
| 2417 // Swap the two. | 2344 // Swap the two. |
| 2418 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = | 2345 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = |
| 2419 render_frame_host_.Pass(); | 2346 render_frame_host_.Pass(); |
| 2420 render_frame_host_ = render_frame_host.Pass(); | 2347 render_frame_host_ = render_frame_host.Pass(); |
| 2421 | 2348 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2576 if (rvh && !rvh->IsRenderViewLive()) { | 2503 if (rvh && !rvh->IsRenderViewLive()) { |
| 2577 EnsureRenderViewInitialized(rvh, instance); | 2504 EnsureRenderViewInitialized(rvh, instance); |
| 2578 } else { | 2505 } else { |
| 2579 // Create a swapped out RenderView in the given SiteInstance if none | 2506 // Create a swapped out RenderView in the given SiteInstance if none |
| 2580 // exists. Since an opener can point to a subframe, do this on the root | 2507 // exists. Since an opener can point to a subframe, do this on the root |
| 2581 // frame of the current opener's frame tree. | 2508 // frame of the current opener's frame tree. |
| 2582 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | 2509 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
| 2583 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance); | 2510 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance); |
| 2584 } else { | 2511 } else { |
| 2585 frame_tree->root()->render_manager()->CreateRenderFrame( | 2512 frame_tree->root()->render_manager()->CreateRenderFrame( |
| 2586 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, | 2513 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, nullptr); |
| 2587 nullptr); | |
| 2588 } | 2514 } |
| 2589 } | 2515 } |
| 2590 } | 2516 } |
| 2591 } | 2517 } |
| 2592 | 2518 |
| 2593 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { | 2519 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { |
| 2594 if (!frame_tree_node_->opener()) | 2520 if (!frame_tree_node_->opener()) |
| 2595 return MSG_ROUTING_NONE; | 2521 return MSG_ROUTING_NONE; |
| 2596 | 2522 |
| 2597 return frame_tree_node_->opener() | 2523 return frame_tree_node_->opener() |
| 2598 ->render_manager() | 2524 ->render_manager() |
| 2599 ->GetRoutingIdForSiteInstance(instance); | 2525 ->GetRoutingIdForSiteInstance(instance); |
| 2600 } | 2526 } |
| 2601 | 2527 |
| 2602 } // namespace content | 2528 } // namespace content |
| OLD | NEW |