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()); |
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. | |
1018 if (speculative_web_ui() && | |
1019 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { | |
1020 render_frame_host_->render_view_host()->AllowBindings( | |
1021 speculative_web_ui()->GetBindings()); | |
1022 } | |
1023 } | 990 } |
| 991 |
| 992 // // If a speculative WebUI was set, make sure the current RenderViewHost h
as |
| 993 // // the right bindings. |
| 994 // if (speculative_web_ui() && |
| 995 // !render_frame_host_->GetProcess()->IsForGuestsOnly()) { |
| 996 // render_frame_host_->render_view_host()->AllowBindings( |
| 997 // speculative_web_ui()->GetBindings()); |
| 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( |
1033 request.common_params().url, current_site_instance, | 1008 request.common_params().url, current_site_instance, |
(...skipping 38 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(); |
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 past_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, past_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, past_bindings); |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 success = InitRenderFrame(new_render_frame_host.get()); | 1779 success = InitRenderFrame(new_render_frame_host.get()); |
1815 } | 1780 } |
1816 } | 1781 } |
1817 | 1782 |
1818 if (success) { | 1783 if (success) { |
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 ou
t |
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 // if (new_render_frame_host && new_render_frame_host->web_ui() && |
1830 int required_bindings = web_ui->GetBindings(); | 1795 // !new_render_frame_host->GetProcess()->IsForGuestsOnly()) { |
1831 RenderViewHost* render_view_host = | 1796 // RenderViewHost* render_view_host = |
1832 new_render_frame_host->render_view_host(); | 1797 // new_render_frame_host->render_view_host(); |
1833 if ((render_view_host->GetEnabledBindings() & required_bindings) != | 1798 // int bindings = new_render_frame_host->web_ui()->GetBindings(); |
1834 required_bindings) { | 1799 // if ((render_view_host->GetEnabledBindings() & bindings) != bindings) { |
1835 render_view_host->AllowBindings(required_bindings); | 1800 // render_view_host->AllowBindings(bindings); |
1836 } | 1801 // } |
1837 } | 1802 // } |
1838 | 1803 |
1839 // Returns the new RFH if it isn't swapped out. | 1804 // Returns the new RFH if it isn't swapped out. |
1840 if (success && !swapped_out) { | 1805 if (success && !swapped_out) { |
1841 DCHECK(new_render_frame_host->GetSiteInstance() == instance); | 1806 DCHECK(new_render_frame_host->GetSiteInstance() == instance); |
1842 return new_render_frame_host.Pass(); | 1807 return new_render_frame_host.Pass(); |
1843 } | 1808 } |
1844 return nullptr; | 1809 return nullptr; |
1845 } | 1810 } |
1846 | 1811 |
1847 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) { | 1812 int RenderFrameHostManager::CreateRenderFrameProxy(SiteInstance* instance) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1949 int proxy_routing_id) { | 1914 int proxy_routing_id) { |
1950 // Ensure the renderer process is initialized before creating the | 1915 // Ensure the renderer process is initialized before creating the |
1951 // RenderView. | 1916 // RenderView. |
1952 if (!render_view_host->GetProcess()->Init()) | 1917 if (!render_view_host->GetProcess()->Init()) |
1953 return false; | 1918 return false; |
1954 | 1919 |
1955 // We may have initialized this RenderViewHost for another RenderFrameHost. | 1920 // We may have initialized this RenderViewHost for another RenderFrameHost. |
1956 if (render_view_host->IsRenderViewLive()) | 1921 if (render_view_host->IsRenderViewLive()) |
1957 return true; | 1922 return true; |
1958 | 1923 |
1959 // If the ongoing navigation is to a WebUI and the RenderView is not in a | 1924 // // 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 | 1925 // // guest process, tell the RenderViewHost about any bindings it will need |
1961 // enabled. | 1926 // // enabled. |
1962 WebUIImpl* dest_web_ui = nullptr; | 1927 // WebUIImpl* dest_web_ui = nullptr; |
1963 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 1928 // if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
1964 switches::kEnableBrowserSideNavigation)) { | 1929 // switches::kEnableBrowserSideNavigation)) { |
1965 dest_web_ui = | 1930 // dest_web_ui = speculative_web_ui(); |
1966 should_reuse_web_ui_ ? web_ui_.get() : speculative_web_ui_.get(); | 1931 // } else { |
1967 } else { | 1932 // dest_web_ui = pending_web_ui(); |
1968 dest_web_ui = pending_web_ui(); | 1933 // } |
1969 } | 1934 // if (dest_web_ui && !render_view_host->GetProcess()->IsForGuestsOnly()) { |
1970 if (dest_web_ui && !render_view_host->GetProcess()->IsForGuestsOnly()) { | 1935 // render_view_host->AllowBindings(dest_web_ui->GetBindings()); |
1971 render_view_host->AllowBindings(dest_web_ui->GetBindings()); | 1936 // } else { |
1972 } else { | 1937 // // Ensure that we don't create an unprivileged RenderView in a WebUI-enab
led |
1973 // Ensure that we don't create an unprivileged RenderView in a WebUI-enabled | 1938 // // process unless it's swapped out. |
1974 // process unless it's swapped out. | 1939 // if (render_view_host->is_active()) { |
1975 if (render_view_host->is_active()) { | 1940 // CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
1976 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 1941 // render_view_host->GetProcess()->GetID())); |
1977 render_view_host->GetProcess()->GetID())); | 1942 // } |
1978 } | 1943 // } |
1979 } | |
1980 | 1944 |
1981 int opener_frame_routing_id = | 1945 int opener_frame_routing_id = |
1982 GetOpenerRoutingID(render_view_host->GetSiteInstance()); | 1946 GetOpenerRoutingID(render_view_host->GetSiteInstance()); |
1983 | 1947 |
1984 return delegate_->CreateRenderViewForRenderManager( | 1948 return delegate_->CreateRenderViewForRenderManager( |
1985 render_view_host, opener_frame_routing_id, proxy_routing_id, | 1949 render_view_host, opener_frame_routing_id, proxy_routing_id, |
1986 frame_tree_node_->current_replication_state()); | 1950 frame_tree_node_->current_replication_state()); |
1987 } | 1951 } |
1988 | 1952 |
1989 bool RenderFrameHostManager::InitRenderFrame( | 1953 bool RenderFrameHostManager::InitRenderFrame( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); | 2020 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(site_instance); |
2057 if (proxy) | 2021 if (proxy) |
2058 return proxy->GetRoutingID(); | 2022 return proxy->GetRoutingID(); |
2059 | 2023 |
2060 return MSG_ROUTING_NONE; | 2024 return MSG_ROUTING_NONE; |
2061 } | 2025 } |
2062 | 2026 |
2063 void RenderFrameHostManager::CommitPending() { | 2027 void RenderFrameHostManager::CommitPending() { |
2064 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", | 2028 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", |
2065 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 2029 "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 | 2030 // 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 | 2031 // 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 | 2032 // 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. | 2033 // this triggers won't be able to figure out what's going on. |
2074 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 2034 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
2075 | 2035 |
2076 // Next commit the Web UI, if any. Either replace |web_ui_| with | 2036 // 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 | 2037 if (render_frame_host_->pending_web_ui()) { |
2078 // leave |web_ui_| as is if reusing it. | 2038 DCHECK(!pending_render_frame_host_ && !speculative_render_frame_host_); |
2079 DCHECK(!(pending_web_ui_ && pending_and_current_web_ui_)); | 2039 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) | 2040 if (will_focus_location_bar) |
2103 delegate_->SetFocusToLocationBar(false); | 2041 delegate_->SetFocusToLocationBar(false); |
2104 return; | 2042 return; |
2105 } | 2043 } |
2106 | 2044 |
2107 // Remember if the page was focused so we can focus the new renderer in | 2045 // Remember if the page was focused so we can focus the new renderer in |
2108 // that case. | 2046 // that case. |
2109 bool focus_render_view = !will_focus_location_bar && | 2047 bool focus_render_view = !will_focus_location_bar && |
2110 render_frame_host_->GetView() && | 2048 render_frame_host_->GetView() && |
2111 render_frame_host_->GetView()->HasFocus(); | 2049 render_frame_host_->GetView()->HasFocus(); |
2112 | 2050 |
2113 bool is_main_frame = frame_tree_node_->IsMainFrame(); | 2051 bool is_main_frame = frame_tree_node_->IsMainFrame(); |
2114 | 2052 |
2115 // Swap in the pending or speculative frame and make it active. Also ensure | 2053 // Swap in the pending or speculative frame and make it active. Also ensure |
2116 // the FrameTree stays in sync. | 2054 // the FrameTree stays in sync. |
2117 scoped_ptr<RenderFrameHostImpl> old_render_frame_host; | 2055 scoped_ptr<RenderFrameHostImpl> old_render_frame_host; |
2118 if (!browser_side_navigation) { | 2056 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2057 switches::kEnableBrowserSideNavigation)) { |
2119 DCHECK(!speculative_render_frame_host_); | 2058 DCHECK(!speculative_render_frame_host_); |
2120 old_render_frame_host = | 2059 old_render_frame_host = |
2121 SetRenderFrameHost(pending_render_frame_host_.Pass()); | 2060 SetRenderFrameHost(pending_render_frame_host_.Pass()); |
2122 } else { | 2061 } else { |
2123 // PlzNavigate | 2062 // PlzNavigate |
2124 DCHECK(speculative_render_frame_host_); | 2063 DCHECK(speculative_render_frame_host_); |
2125 old_render_frame_host = | 2064 old_render_frame_host = |
2126 SetRenderFrameHost(speculative_render_frame_host_.Pass()); | 2065 SetRenderFrameHost(speculative_render_frame_host_.Pass()); |
2127 } | 2066 } |
2128 | 2067 |
(...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 | 2209 // If we are currently navigating cross-process, we want to get back to normal |
2271 // and then navigate as usual. | 2210 // and then navigate as usual. |
2272 if (pending_render_frame_host_) | 2211 if (pending_render_frame_host_) |
2273 CancelPending(); | 2212 CancelPending(); |
2274 | 2213 |
2275 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | 2214 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
2276 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( | 2215 scoped_refptr<SiteInstance> new_instance = GetSiteInstanceForNavigation( |
2277 dest_url, source_instance, dest_instance, nullptr, transition, | 2216 dest_url, source_instance, dest_instance, nullptr, transition, |
2278 dest_is_restore, dest_is_view_source_mode); | 2217 dest_is_restore, dest_is_view_source_mode); |
2279 | 2218 |
2280 const NavigationEntry* current_entry = | |
2281 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | |
2282 | |
2283 DCHECK(!pending_render_frame_host_); | 2219 DCHECK(!pending_render_frame_host_); |
2284 | 2220 |
2285 if (new_instance.get() != current_instance) { | 2221 if (new_instance.get() != current_instance) { |
2286 TRACE_EVENT_INSTANT2( | 2222 TRACE_EVENT_INSTANT2( |
2287 "navigation", | 2223 "navigation", |
2288 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", | 2224 "RenderFrameHostManager::UpdateStateForNavigate:New SiteInstance", |
2289 TRACE_EVENT_SCOPE_THREAD, | 2225 TRACE_EVENT_SCOPE_THREAD, |
2290 "current_instance id", current_instance->GetId(), | 2226 "current_instance id", current_instance->GetId(), |
2291 "new_instance id", new_instance->GetId()); | 2227 "new_instance id", new_instance->GetId()); |
2292 | 2228 |
2293 // New SiteInstance: create a pending RFH to navigate. | 2229 // New SiteInstance: create a pending RFH to navigate. |
2294 | 2230 |
2295 // This will possibly create (set to nullptr) a Web UI object for the | 2231 CreatePendingRenderFrameHost(current_instance, new_instance.get(), dest_url, |
2296 // pending page. We'll use this later to give the page special access. This | 2232 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_) | 2233 if (!pending_render_frame_host_) |
2304 return nullptr; | 2234 return nullptr; |
2305 | 2235 |
2306 // Check if our current RFH is live before we set up a transition. | 2236 // Check if our current RFH is live before we set up a transition. |
2307 if (!render_frame_host_->IsRenderFrameLive()) { | 2237 if (!render_frame_host_->IsRenderFrameLive()) { |
2308 // The current RFH is not live. There's no reason to sit around with a | 2238 // 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 | 2239 // 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. | 2240 // 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 | 2241 // (Note that we don't care about on{before}unload handlers if the current |
2312 // RFH isn't live.) | 2242 // RFH isn't live.) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 | 2282 |
2353 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. | 2283 // Otherwise the same SiteInstance can be used. Navigate render_frame_host_. |
2354 | 2284 |
2355 // It's possible to swap out the current RFH and then decide to navigate in it | 2285 // 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 | 2286 // 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 | 2287 // 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 | 2288 // haven't deleted it yet. The new navigation will swap it back in, so we can |
2359 // delete the proxy. | 2289 // delete the proxy. |
2360 proxy_hosts_->Remove(new_instance.get()->GetId()); | 2290 proxy_hosts_->Remove(new_instance.get()->GetId()); |
2361 | 2291 |
2362 if (ShouldReuseWebUI(current_entry, dest_url)) { | 2292 render_frame_host_->UpdatePendingWebUI(dest_url, bindings); |
2363 pending_web_ui_.reset(); | |
2364 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); | |
2365 } else { | |
2366 SetPendingWebUI(dest_url, bindings); | |
2367 // Make sure the new RenderViewHost has the right bindings. | |
2368 if (pending_web_ui() && | |
2369 !render_frame_host_->GetProcess()->IsForGuestsOnly()) { | |
2370 render_frame_host_->render_view_host()->AllowBindings( | |
2371 pending_web_ui()->GetBindings()); | |
2372 } | |
2373 } | |
2374 | 2293 |
2375 if (pending_web_ui() && render_frame_host_->IsRenderFrameLive()) { | 2294 // TODO(carlosk): try moving this into RenderFrameHostImpl::CreateWebUI |
2376 pending_web_ui()->GetController()->RenderViewReused( | 2295 // // Make sure the new RenderViewHost has the right bindings. |
| 2296 // if (render_frame_host_->pending_web_ui() && |
| 2297 // !render_frame_host_->GetProcess()->IsForGuestsOnly()) { |
| 2298 // render_frame_host_->render_view_host()->AllowBindings( |
| 2299 // render_frame_host_->pending_web_ui()->GetBindings()); |
| 2300 // } |
| 2301 |
| 2302 // TODO(carlosk): try moving this into RenderFrameHostImpl::UpdatePendingWebUI |
| 2303 if (render_frame_host_->pending_web_ui() && |
| 2304 render_frame_host_->IsRenderFrameLive()) { |
| 2305 render_frame_host_->pending_web_ui()->GetController()->RenderViewReused( |
2377 render_frame_host_->render_view_host()); | 2306 render_frame_host_->render_view_host()); |
2378 } | 2307 } |
2379 | 2308 |
2380 // The renderer can exit view source mode when any error or cancellation | 2309 // The renderer can exit view source mode when any error or cancellation |
2381 // happen. We must overwrite to recover the mode. | 2310 // happen. We must overwrite to recover the mode. |
2382 if (dest_is_view_source_mode) { | 2311 if (dest_is_view_source_mode) { |
2383 render_frame_host_->render_view_host()->Send( | 2312 render_frame_host_->render_view_host()->Send( |
2384 new ViewMsg_EnableViewSourceMode( | 2313 new ViewMsg_EnableViewSourceMode( |
2385 render_frame_host_->render_view_host()->GetRoutingID())); | 2314 render_frame_host_->render_view_host()->GetRoutingID())); |
2386 } | 2315 } |
2387 | 2316 |
2388 return render_frame_host_.get(); | 2317 return render_frame_host_.get(); |
2389 } | 2318 } |
2390 | 2319 |
2391 void RenderFrameHostManager::CancelPending() { | 2320 void RenderFrameHostManager::CancelPending() { |
2392 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending", | 2321 TRACE_EVENT1("navigation", "RenderFrameHostManager::CancelPending", |
2393 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 2322 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); |
2394 DiscardUnusedFrame(UnsetPendingRenderFrameHost()); | 2323 DiscardUnusedFrame(UnsetPendingRenderFrameHost()); |
| 2324 // TODO(carlosk): not sure yet this is the right place for this call... |
| 2325 render_frame_host_->DiscardPendingWebUI(); |
2395 } | 2326 } |
2396 | 2327 |
2397 scoped_ptr<RenderFrameHostImpl> | 2328 scoped_ptr<RenderFrameHostImpl> |
2398 RenderFrameHostManager::UnsetPendingRenderFrameHost() { | 2329 RenderFrameHostManager::UnsetPendingRenderFrameHost() { |
2399 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host = | 2330 scoped_ptr<RenderFrameHostImpl> pending_render_frame_host = |
2400 pending_render_frame_host_.Pass(); | 2331 pending_render_frame_host_.Pass(); |
2401 | 2332 |
2402 RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( | 2333 RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( |
2403 pending_render_frame_host.get(), | 2334 pending_render_frame_host.get(), |
2404 render_frame_host_.get()); | 2335 render_frame_host_.get()); |
2405 | 2336 |
2406 // We no longer need to prevent the process from exiting. | 2337 // We no longer need to prevent the process from exiting. |
2407 pending_render_frame_host->GetProcess()->RemovePendingView(); | 2338 pending_render_frame_host->GetProcess()->RemovePendingView(); |
2408 | 2339 |
2409 pending_web_ui_.reset(); | |
2410 pending_and_current_web_ui_.reset(); | |
2411 | |
2412 return pending_render_frame_host.Pass(); | 2340 return pending_render_frame_host.Pass(); |
2413 } | 2341 } |
2414 | 2342 |
2415 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( | 2343 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( |
2416 scoped_ptr<RenderFrameHostImpl> render_frame_host) { | 2344 scoped_ptr<RenderFrameHostImpl> render_frame_host) { |
2417 // Swap the two. | 2345 // Swap the two. |
2418 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = | 2346 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = |
2419 render_frame_host_.Pass(); | 2347 render_frame_host_.Pass(); |
2420 render_frame_host_ = render_frame_host.Pass(); | 2348 render_frame_host_ = render_frame_host.Pass(); |
2421 | 2349 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2576 if (rvh && !rvh->IsRenderViewLive()) { | 2504 if (rvh && !rvh->IsRenderViewLive()) { |
2577 EnsureRenderViewInitialized(rvh, instance); | 2505 EnsureRenderViewInitialized(rvh, instance); |
2578 } else { | 2506 } else { |
2579 // Create a swapped out RenderView in the given SiteInstance if none | 2507 // 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 | 2508 // exists. Since an opener can point to a subframe, do this on the root |
2581 // frame of the current opener's frame tree. | 2509 // frame of the current opener's frame tree. |
2582 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { | 2510 if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
2583 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance); | 2511 frame_tree->root()->render_manager()->CreateRenderFrameProxy(instance); |
2584 } else { | 2512 } else { |
2585 frame_tree->root()->render_manager()->CreateRenderFrame( | 2513 frame_tree->root()->render_manager()->CreateRenderFrame( |
2586 instance, nullptr, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, | 2514 instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, nullptr); |
2587 nullptr); | |
2588 } | 2515 } |
2589 } | 2516 } |
2590 } | 2517 } |
2591 } | 2518 } |
2592 | 2519 |
2593 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { | 2520 int RenderFrameHostManager::GetOpenerRoutingID(SiteInstance* instance) { |
2594 if (!frame_tree_node_->opener()) | 2521 if (!frame_tree_node_->opener()) |
2595 return MSG_ROUTING_NONE; | 2522 return MSG_ROUTING_NONE; |
2596 | 2523 |
2597 return frame_tree_node_->opener() | 2524 return frame_tree_node_->opener() |
2598 ->render_manager() | 2525 ->render_manager() |
2599 ->GetRoutingIdForSiteInstance(instance); | 2526 ->GetRoutingIdForSiteInstance(instance); |
2600 } | 2527 } |
2601 | 2528 |
2602 } // namespace content | 2529 } // namespace content |
OLD | NEW |