OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 RenderViewHostDelegate* render_view_delegate, | 54 RenderViewHostDelegate* render_view_delegate, |
55 RenderWidgetHostDelegate* render_widget_delegate, | 55 RenderWidgetHostDelegate* render_widget_delegate, |
56 Delegate* delegate) | 56 Delegate* delegate) |
57 : frame_tree_node_(frame_tree_node), | 57 : frame_tree_node_(frame_tree_node), |
58 delegate_(delegate), | 58 delegate_(delegate), |
59 cross_navigation_pending_(false), | 59 cross_navigation_pending_(false), |
60 render_frame_delegate_(render_frame_delegate), | 60 render_frame_delegate_(render_frame_delegate), |
61 render_view_delegate_(render_view_delegate), | 61 render_view_delegate_(render_view_delegate), |
62 render_widget_delegate_(render_widget_delegate), | 62 render_widget_delegate_(render_widget_delegate), |
63 interstitial_page_(NULL), | 63 interstitial_page_(NULL), |
64 should_reuse_web_ui_(false), | |
64 weak_factory_(this) { | 65 weak_factory_(this) { |
65 DCHECK(frame_tree_node_); | 66 DCHECK(frame_tree_node_); |
66 } | 67 } |
67 | 68 |
68 RenderFrameHostManager::~RenderFrameHostManager() { | 69 RenderFrameHostManager::~RenderFrameHostManager() { |
69 if (pending_render_frame_host_) | 70 if (pending_render_frame_host_) |
70 UnsetPendingRenderFrameHost(); | 71 UnsetPendingRenderFrameHost(); |
71 | 72 |
73 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
74 switches::kEnableBrowserSideNavigation)) { | |
75 UnsetSpeculativeRenderFrameHost(); | |
76 } | |
77 | |
72 // We should always have a current RenderFrameHost except in some tests. | 78 // We should always have a current RenderFrameHost except in some tests. |
73 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); | 79 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); |
74 | 80 |
75 // Delete any swapped out RenderFrameHosts. | 81 // Delete any swapped out RenderFrameHosts. |
76 STLDeleteValues(&proxy_hosts_); | 82 STLDeleteValues(&proxy_hosts_); |
77 } | 83 } |
78 | 84 |
79 void RenderFrameHostManager::Init(BrowserContext* browser_context, | 85 void RenderFrameHostManager::Init(BrowserContext* browser_context, |
80 SiteInstance* site_instance, | 86 SiteInstance* site_instance, |
81 int view_routing_id, | 87 int view_routing_id, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 } | 287 } |
282 } | 288 } |
283 return false; | 289 return false; |
284 } | 290 } |
285 | 291 |
286 void RenderFrameHostManager::OnBeforeUnloadACK( | 292 void RenderFrameHostManager::OnBeforeUnloadACK( |
287 bool for_cross_site_transition, | 293 bool for_cross_site_transition, |
288 bool proceed, | 294 bool proceed, |
289 const base::TimeTicks& proceed_time) { | 295 const base::TimeTicks& proceed_time) { |
290 if (for_cross_site_transition) { | 296 if (for_cross_site_transition) { |
297 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( | |
nasko
2014/12/18 00:22:39
Why not move this check up? Should we ever see OnB
carlosk
2014/12/19 04:27:15
I'm not super sure but it seems it would. My indir
clamy
2014/12/19 13:35:57
We will still see OnBeforeUnloadACK for tab closes
carlosk
2014/12/29 16:40:16
Acknowledged.
| |
298 switches::kEnableBrowserSideNavigation)); | |
291 // Ignore if we're not in a cross-site navigation. | 299 // Ignore if we're not in a cross-site navigation. |
292 if (!cross_navigation_pending_) | 300 if (!cross_navigation_pending_) |
293 return; | 301 return; |
294 | 302 |
295 if (proceed) { | 303 if (proceed) { |
296 // Ok to unload the current page, so proceed with the cross-site | 304 // Ok to unload the current page, so proceed with the cross-site |
297 // navigation. Note that if navigations are not currently suspended, it | 305 // navigation. Note that if navigations are not currently suspended, it |
298 // might be because the renderer was deemed unresponsive and this call was | 306 // might be because the renderer was deemed unresponsive and this call was |
299 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it | 307 // already made by ShouldCloseTabOnUnresponsiveRenderer. In that case, it |
300 // is ok to do nothing here. | 308 // is ok to do nothing here. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 response_started_id_.reset(); | 421 response_started_id_.reset(); |
414 } | 422 } |
415 | 423 |
416 void RenderFrameHostManager::ClearNavigationTransitionData() { | 424 void RenderFrameHostManager::ClearNavigationTransitionData() { |
417 render_frame_host_->ClearPendingTransitionRequestData(); | 425 render_frame_host_->ClearPendingTransitionRequestData(); |
418 } | 426 } |
419 | 427 |
420 void RenderFrameHostManager::DidNavigateFrame( | 428 void RenderFrameHostManager::DidNavigateFrame( |
421 RenderFrameHostImpl* render_frame_host, | 429 RenderFrameHostImpl* render_frame_host, |
422 bool was_caused_by_user_gesture) { | 430 bool was_caused_by_user_gesture) { |
431 DCHECK(render_frame_host); | |
432 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
433 switches::kEnableBrowserSideNavigation)) { | |
434 // TODO(carlosk): we have to figure out what to do with the | |
435 // |render_frame_host| parameter for PlzNavigate. We mus whether eliminate | |
436 // it or fix it's value so we can do similar checks as are currently done | |
437 // below against the current and pending instances. | |
438 // TODO(carlosk): when this method is triggered by the renderer we have to | |
439 // find a way to check if that navigation wasn't canceled in the meantime. | |
440 CommitPending(); | |
clamy
2014/12/16 15:22:48
No we shouldn't eliminate this parameter. Also thi
carlosk
2014/12/19 04:27:15
OK, now I understand. I hadn't realized before tha
clamy
2014/12/19 13:35:57
Yes. I think this CL has enough in it already that
carlosk
2014/12/29 16:40:16
Acknowledged.
| |
441 DCHECK(!speculative_render_frame_host_); | |
442 | |
443 // If the renderer that needs to navigate is not live (it was just created | |
clamy
2014/12/16 15:22:48
Why is that block here? The code in this function
carlosk
2014/12/19 04:27:14
Acknowledged. I didn't realize before that it was
| |
444 // or it crashed), initialize it. | |
445 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { | |
446 // Recreate the opener chain. | |
447 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | |
448 render_frame_host_->GetSiteInstance()); | |
449 InitRenderView(render_frame_host_->render_view_host(), opener_route_id, | |
450 MSG_ROUTING_NONE, frame_tree_node_->IsMainFrame()); | |
451 } | |
452 return; | |
453 } | |
454 | |
423 if (!cross_navigation_pending_) { | 455 if (!cross_navigation_pending_) { |
424 DCHECK(!pending_render_frame_host_); | 456 DCHECK(!pending_render_frame_host_); |
425 | 457 |
426 // We should only hear this from our current renderer. | 458 // We should only hear this from our current renderer. |
427 DCHECK_EQ(render_frame_host_, render_frame_host); | 459 DCHECK_EQ(render_frame_host_, render_frame_host); |
428 | 460 |
429 // Even when there is no pending RVH, there may be a pending Web UI. | 461 // Even when there is no pending RVH, there may be a pending Web UI. |
430 if (pending_web_ui()) | 462 if (pending_web_ui()) |
431 CommitPending(); | 463 CommitPending(); |
432 return; | 464 return; |
433 } | 465 } |
434 | 466 |
435 if (render_frame_host == pending_render_frame_host_) { | 467 if (render_frame_host == pending_render_frame_host_) { |
436 // The pending cross-site navigation completed, so show the renderer. | 468 // The pending cross-site navigation completed, so show the renderer. |
437 CommitPending(); | 469 CommitPending(); |
438 cross_navigation_pending_ = false; | 470 cross_navigation_pending_ = false; |
439 } else if (render_frame_host == render_frame_host_) { | 471 } else if (render_frame_host == render_frame_host_) { |
440 if (was_caused_by_user_gesture) { | 472 if (was_caused_by_user_gesture) { |
441 // A navigation in the original page has taken place. Cancel the pending | 473 // A navigation in the original page has taken place. Cancel the pending |
442 // one. Only do it for user gesture originated navigations to prevent | 474 // one. Only do it for user gesture originated navigations to prevent |
443 // page doing any shenanigans to prevent user from navigating. | 475 // page doing any shenanigans to prevent user from navigating. |
444 // See https://code.google.com/p/chromium/issues/detail?id=75195 | 476 // See https://code.google.com/p/chromium/issues/detail?id=75195 |
nasko
2014/12/18 00:22:40
nit: Use https://crbug.com/75195 for shorter URLs.
carlosk
2014/12/19 04:27:14
Done.
| |
445 CancelPending(); | 477 CancelPending(); |
446 cross_navigation_pending_ = false; | 478 cross_navigation_pending_ = false; |
447 } | 479 } |
448 } else { | 480 } else { |
449 // No one else should be sending us DidNavigate in this state. | 481 // No one else should be sending us DidNavigate in this state. |
450 DCHECK(false); | 482 DCHECK(false); |
451 } | 483 } |
452 } | 484 } |
453 | 485 |
454 void RenderFrameHostManager::DidDisownOpener( | 486 void RenderFrameHostManager::DidDisownOpener( |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
572 // If the SiteInstance for the pending RFH is being used by others don't | 604 // If the SiteInstance for the pending RFH is being used by others don't |
573 // delete the RFH. Just swap it out and it can be reused at a later point. | 605 // delete the RFH. Just swap it out and it can be reused at a later point. |
574 SiteInstanceImpl* site_instance = render_frame_host->GetSiteInstance(); | 606 SiteInstanceImpl* site_instance = render_frame_host->GetSiteInstance(); |
575 if (site_instance->HasSite() && site_instance->active_frame_count() > 1) { | 607 if (site_instance->HasSite() && site_instance->active_frame_count() > 1) { |
576 // Any currently suspended navigations are no longer needed. | 608 // Any currently suspended navigations are no longer needed. |
577 render_frame_host->CancelSuspendedNavigations(); | 609 render_frame_host->CancelSuspendedNavigations(); |
578 | 610 |
579 RenderFrameProxyHost* proxy = | 611 RenderFrameProxyHost* proxy = |
580 new RenderFrameProxyHost(site_instance, frame_tree_node_); | 612 new RenderFrameProxyHost(site_instance, frame_tree_node_); |
581 proxy_hosts_[site_instance->GetId()] = proxy; | 613 proxy_hosts_[site_instance->GetId()] = proxy; |
582 render_frame_host->SwapOut(proxy); | 614 |
615 if (!render_frame_host->is_swapped_out()) | |
616 render_frame_host->SwapOut(proxy); | |
617 | |
583 if (frame_tree_node_->IsMainFrame()) | 618 if (frame_tree_node_->IsMainFrame()) |
584 proxy->TakeFrameHostOwnership(render_frame_host.Pass()); | 619 proxy->TakeFrameHostOwnership(render_frame_host.Pass()); |
585 } else { | 620 } else { |
586 // We won't be coming back, so delete this one. | 621 // We won't be coming back, so delete this one. |
587 render_frame_host.reset(); | 622 render_frame_host.reset(); |
588 } | 623 } |
589 } | 624 } |
590 | 625 |
591 void RenderFrameHostManager::MoveToPendingDeleteHosts( | 626 void RenderFrameHostManager::MoveToPendingDeleteHosts( |
592 scoped_ptr<RenderFrameHostImpl> render_frame_host) { | 627 scoped_ptr<RenderFrameHostImpl> render_frame_host) { |
(...skipping 24 matching lines...) Expand all Loading... | |
617 } | 652 } |
618 } | 653 } |
619 return false; | 654 return false; |
620 } | 655 } |
621 | 656 |
622 void RenderFrameHostManager::ResetProxyHosts() { | 657 void RenderFrameHostManager::ResetProxyHosts() { |
623 STLDeleteValues(&proxy_hosts_); | 658 STLDeleteValues(&proxy_hosts_); |
624 } | 659 } |
625 | 660 |
626 // PlzNavigate | 661 // PlzNavigate |
662 void RenderFrameHostManager::BeginNavigation( | |
663 const FrameHostMsg_BeginNavigation_Params& params, | |
664 const CommonNavigationParams& common_params) { | |
665 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | |
666 switches::kEnableBrowserSideNavigation)); | |
667 // Cleans up any state in case there's an ongoing navigation. | |
668 // TODO(carlosk): remove this cleanup here once we properly cancel ongoing | |
669 // navigations. | |
670 CleanUpNavigation(); | |
671 | |
672 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); | |
673 // TODO(carlosk): Replace the default values with the right ones for | |
674 // dest_instance, dest_is_restore, dest_is_view_source_mode. | |
675 scoped_refptr<SiteInstanceImpl> new_instance = | |
676 static_cast<SiteInstanceImpl*>(GetSiteInstanceForNavigation( | |
677 common_params.url, nullptr, common_params.transition, false, false)); | |
678 | |
679 // Will keep the current RFH if its SiteInstance matches the new one from | |
680 // the navigation or if this is a subframe navigation. If --site-per-process | |
681 // is enabled the RFH is never kept when sites don't match. | |
682 // TODO(carlosk): do not swap processes for renderer initiated navigations | |
683 // (see crbug.com/440266). | |
684 if (current_instance == new_instance.get() || | |
685 (!frame_tree_node_->IsMainFrame() && | |
686 !CommandLine::ForCurrentProcess()->HasSwitch( | |
687 switches::kSitePerProcess))) { | |
688 // Make sure the current RFH is alive. | |
689 if (!render_frame_host_->render_view_host()->IsRenderViewLive()) { | |
690 // Recreate the opener chain. | |
691 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | |
692 render_frame_host_->GetSiteInstance()); | |
693 bool success = InitRenderView(render_frame_host_->render_view_host(), | |
694 opener_route_id, MSG_ROUTING_NONE, | |
695 frame_tree_node_->IsMainFrame()); | |
696 DCHECK(success); | |
697 } | |
698 DCHECK(current_instance->GetProcess()->HasConnection()); | |
699 return; | |
700 } | |
701 | |
702 // Speculatively create a new RFH. | |
703 // TODO(carlosk): enable bindings check below. | |
704 bool success = CreateSpeculativeRenderFrameHost( | |
705 common_params.url, current_instance, new_instance.get(), | |
706 NavigationEntryImpl::kInvalidBindings); | |
707 DCHECK(success); | |
708 DCHECK(new_instance->GetProcess()->HasConnection()); | |
709 } | |
710 | |
711 // PlzNavigate | |
712 bool RenderFrameHostManager::CreateSpeculativeRenderFrameHost( | |
713 const GURL& url, | |
714 SiteInstance* old_instance, | |
715 SiteInstance* new_instance, | |
716 int bindings) { | |
717 CHECK(new_instance); | |
718 CHECK_NE(old_instance, new_instance); | |
719 | |
720 const NavigationEntry* current_navigation_entry = | |
721 delegate_->GetLastCommittedNavigationEntryForRenderManager(); | |
722 scoped_ptr<WebUIImpl> new_web_ui; | |
723 should_reuse_web_ui_ = ShouldReuseWebUI(current_navigation_entry, url); | |
724 if (!should_reuse_web_ui_) | |
725 new_web_ui = CreateWebUI(url, bindings); | |
726 | |
727 int opener_route_id = | |
728 CreateOpenerRenderViewsIfNeeded(old_instance, new_instance); | |
729 | |
730 int create_render_frame_flags = 0; | |
731 if (frame_tree_node_->IsMainFrame()) | |
732 create_render_frame_flags |= CREATE_RF_FOR_MAIN_FRAME_NAVIGATION; | |
733 if (delegate_->IsHidden()) | |
734 create_render_frame_flags |= CREATE_RF_HIDDEN; | |
735 scoped_ptr<RenderFrameHostImpl> new_render_frame_host = | |
736 CreateRenderFrame(new_instance, new_web_ui.get(), opener_route_id, | |
737 create_render_frame_flags, nullptr); | |
738 if (!new_render_frame_host) { | |
739 return false; | |
740 } | |
741 speculative_render_frame_host_.reset(new_render_frame_host.release()); | |
742 speculative_web_ui_.reset(new_web_ui.release()); | |
743 return true; | |
744 } | |
745 | |
746 // PlzNavigate | |
627 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( | 747 RenderFrameHostImpl* RenderFrameHostManager::GetFrameHostForNavigation( |
628 const GURL& url, | 748 const GURL& url, |
629 ui::PageTransition transition) { | 749 ui::PageTransition transition) { |
630 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 750 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
631 switches::kEnableBrowserSideNavigation)); | 751 switches::kEnableBrowserSideNavigation)); |
632 // TODO(clamy): When we handle renderer initiated navigations, make sure not | 752 // Pick the right RenderFrameHost to commit the navigation. |
633 // to use a different process for subframes if --site-per-process is not | |
634 // enabled. | |
635 | 753 |
636 // Pick the right RenderFrameHost to commit the navigation. | 754 SiteInstance* current_instance = render_frame_host_->GetSiteInstance(); |
637 // TODO(clamy): Replace the default values by the right ones. | 755 // TODO(clamy): Replace the default values with the right ones for |
638 RenderFrameHostImpl* render_frame_host = UpdateStateForNavigate( | 756 // dest_instance, dest_is_restore, dest_is_view_source_mode. |
639 url, NULL, transition, false, false, GlobalRequestID(), | 757 scoped_refptr<SiteInstance> new_instance = |
640 NavigationEntryImpl::kInvalidBindings); | 758 GetSiteInstanceForNavigation(url, NULL, transition, false, false); |
641 | 759 |
642 // If the renderer that needs to navigate is not live (it was just created or | 760 // Will keep the current RFH if its SiteInstance matches the new one from |
643 // it crashed), initialize it. | 761 // the navigation or if this is a subframe navigation. If --site-per-process |
644 if (!render_frame_host->render_view_host()->IsRenderViewLive()) { | 762 // is enabled the RFH is never kept when sites don't match. |
645 // Recreate the opener chain. | 763 // TODO(carlosk): do not swap processes for renderer initiated navigations |
646 int opener_route_id = delegate_->CreateOpenerRenderViewsForRenderManager( | 764 // (see crbug.com/440266). |
647 render_frame_host->GetSiteInstance()); | 765 if (current_instance == new_instance.get() || |
648 if (!InitRenderView(render_frame_host->render_view_host(), | 766 (!frame_tree_node_->IsMainFrame() && |
649 opener_route_id, | 767 !CommandLine::ForCurrentProcess()->HasSwitch( |
650 MSG_ROUTING_NONE, | 768 switches::kSitePerProcess))) { |
651 frame_tree_node_->IsMainFrame())) { | 769 CleanUpNavigation(); |
652 return NULL; | 770 return render_frame_host_.get(); |
653 } | |
654 } | 771 } |
655 return render_frame_host; | 772 // If the SiteInstance for the final URL doesn't match the one from the |
773 // speculatively created RenderFrameHost, create a new one using the | |
774 // former. | |
775 if (!speculative_render_frame_host_ || | |
776 speculative_render_frame_host_->GetSiteInstance() != new_instance.get()) { | |
777 CleanUpNavigation(); | |
778 // TODO(clamy): Replace the binding value with the right one. | |
779 bool success = CreateSpeculativeRenderFrameHost( | |
780 url, current_instance, new_instance.get(), | |
781 NavigationEntryImpl::kInvalidBindings); | |
782 CHECK(success); | |
783 } | |
784 DCHECK(speculative_render_frame_host_); | |
785 return speculative_render_frame_host_.get(); | |
786 } | |
787 | |
788 // PlzNavigate | |
789 void RenderFrameHostManager::CleanUpNavigation() { | |
790 scoped_ptr<RenderFrameHostImpl> rfh = UnsetSpeculativeRenderFrameHost(); | |
791 if (rfh) | |
792 DiscardUnusedFrame(rfh.Pass()); | |
793 } | |
794 | |
795 // PlzNavigate | |
796 scoped_ptr<RenderFrameHostImpl> | |
797 RenderFrameHostManager::UnsetSpeculativeRenderFrameHost() { | |
798 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | |
799 switches::kEnableBrowserSideNavigation)); | |
800 if (speculative_web_ui_) | |
801 speculative_web_ui_.reset(); | |
802 should_reuse_web_ui_ = false; | |
803 if (speculative_render_frame_host_) { | |
804 speculative_render_frame_host_->GetProcess()->RemovePendingView(); | |
805 return speculative_render_frame_host_.Pass(); | |
806 } | |
807 return nullptr; | |
656 } | 808 } |
657 | 809 |
658 void RenderFrameHostManager::Observe( | 810 void RenderFrameHostManager::Observe( |
659 int type, | 811 int type, |
660 const NotificationSource& source, | 812 const NotificationSource& source, |
661 const NotificationDetails& details) { | 813 const NotificationDetails& details) { |
662 switch (type) { | 814 switch (type) { |
663 case NOTIFICATION_RENDERER_PROCESS_CLOSED: | 815 case NOTIFICATION_RENDERER_PROCESS_CLOSED: |
664 case NOTIFICATION_RENDERER_PROCESS_CLOSING: | 816 case NOTIFICATION_RENDERER_PROCESS_CLOSING: |
665 RendererProcessClosing( | 817 RendererProcessClosing( |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 // longer relies on swapped out RFH for the top-level frame. | 1260 // longer relies on swapped out RFH for the top-level frame. |
1109 if (!frame_tree_node_->IsMainFrame()) { | 1261 if (!frame_tree_node_->IsMainFrame()) { |
1110 CHECK(!swapped_out); | 1262 CHECK(!swapped_out); |
1111 } | 1263 } |
1112 | 1264 |
1113 scoped_ptr<RenderFrameHostImpl> new_render_frame_host; | 1265 scoped_ptr<RenderFrameHostImpl> new_render_frame_host; |
1114 bool success = true; | 1266 bool success = true; |
1115 if (view_routing_id_ptr) | 1267 if (view_routing_id_ptr) |
1116 *view_routing_id_ptr = MSG_ROUTING_NONE; | 1268 *view_routing_id_ptr = MSG_ROUTING_NONE; |
1117 | 1269 |
1118 // We are creating a pending or swapped out RFH here. We should never create | 1270 // We are creating a pending, speculative or swapped out RFH here. We should |
1119 // it in the same SiteInstance as our current RFH. | 1271 // never create it in the same SiteInstance as our current RFH. |
1120 CHECK_NE(render_frame_host_->GetSiteInstance(), instance); | 1272 CHECK_NE(render_frame_host_->GetSiteInstance(), instance); |
1121 | 1273 |
1122 // Check if we've already created an RFH for this SiteInstance. If so, try | 1274 // Check if we've already created an RFH for this SiteInstance. If so, try |
1123 // to re-use the existing one, which has already been initialized. We'll | 1275 // to re-use the existing one, which has already been initialized. We'll |
1124 // remove it from the list of proxy hosts below if it will be active. | 1276 // remove it from the list of proxy hosts below if it will be active. |
1125 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | 1277 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); |
1126 if (proxy && proxy->render_frame_host()) { | 1278 if (proxy && proxy->render_frame_host()) { |
1127 if (view_routing_id_ptr) | 1279 if (view_routing_id_ptr) |
1128 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID(); | 1280 *view_routing_id_ptr = proxy->GetRenderViewHost()->GetRoutingID(); |
1129 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. | 1281 // Delete the existing RenderFrameProxyHost, but reuse the RenderFrameHost. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1286 proxy_hosts_.find(site_instance->GetId()); | 1438 proxy_hosts_.find(site_instance->GetId()); |
1287 if (iter != proxy_hosts_.end()) | 1439 if (iter != proxy_hosts_.end()) |
1288 return iter->second->GetRoutingID(); | 1440 return iter->second->GetRoutingID(); |
1289 | 1441 |
1290 return MSG_ROUTING_NONE; | 1442 return MSG_ROUTING_NONE; |
1291 } | 1443 } |
1292 | 1444 |
1293 void RenderFrameHostManager::CommitPending() { | 1445 void RenderFrameHostManager::CommitPending() { |
1294 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", | 1446 TRACE_EVENT1("navigation", "RenderFrameHostManager::CommitPending", |
1295 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 1447 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); |
1448 bool browser_side_navigation = CommandLine::ForCurrentProcess()->HasSwitch( | |
1449 switches::kEnableBrowserSideNavigation); | |
1296 // First check whether we're going to want to focus the location bar after | 1450 // First check whether we're going to want to focus the location bar after |
1297 // this commit. We do this now because the navigation hasn't formally | 1451 // this commit. We do this now because the navigation hasn't formally |
1298 // committed yet, so if we've already cleared |pending_web_ui_| the call chain | 1452 // committed yet, so if we've already cleared |pending_web_ui_| the call chain |
1299 // this triggers won't be able to figure out what's going on. | 1453 // this triggers won't be able to figure out what's going on. |
1300 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); | 1454 bool will_focus_location_bar = delegate_->FocusLocationBarByDefault(); |
1301 | 1455 |
1302 // Next commit the Web UI, if any. Either replace |web_ui_| with | 1456 if (!browser_side_navigation) { |
1303 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or | 1457 DCHECK(!speculative_web_ui_); |
1304 // leave |web_ui_| as is if reusing it. | 1458 // Next commit the Web UI, if any. Either replace |web_ui_| with |
1305 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); | 1459 // |pending_web_ui_|, or clear |web_ui_| if there is no pending WebUI, or |
1306 if (pending_web_ui_) { | 1460 // leave |web_ui_| as is if reusing it. |
1307 web_ui_.reset(pending_web_ui_.release()); | 1461 DCHECK(!(pending_web_ui_.get() && pending_and_current_web_ui_.get())); |
1308 } else if (!pending_and_current_web_ui_.get()) { | 1462 if (pending_web_ui_) { |
1309 web_ui_.reset(); | 1463 web_ui_.reset(pending_web_ui_.release()); |
1464 } else if (!pending_and_current_web_ui_.get()) { | |
1465 web_ui_.reset(); | |
1466 } else { | |
1467 DCHECK_EQ(pending_and_current_web_ui_.get(), web_ui_.get()); | |
1468 pending_and_current_web_ui_.reset(); | |
1469 } | |
1310 } else { | 1470 } else { |
1311 DCHECK_EQ(pending_and_current_web_ui_.get(), web_ui_.get()); | 1471 // PlzNavigate |
1312 pending_and_current_web_ui_.reset(); | 1472 if (!should_reuse_web_ui_) |
1473 web_ui_.reset(speculative_web_ui_.release()); | |
1474 DCHECK(!speculative_web_ui_); | |
1313 } | 1475 } |
1314 | 1476 |
1315 // It's possible for the pending_render_frame_host_ to be NULL when we aren't | 1477 // It's possible for the pending_render_frame_host_ to be NULL when we aren't |
1316 // crossing process boundaries. If so, we just needed to handle the Web UI | 1478 // crossing process boundaries. If so, we just needed to handle the Web UI |
1317 // committing above and we're done. | 1479 // committing above and we're done. |
1318 if (!pending_render_frame_host_) { | 1480 if (!pending_render_frame_host_ && !speculative_render_frame_host_) { |
1319 if (will_focus_location_bar) | 1481 if (will_focus_location_bar) |
1320 delegate_->SetFocusToLocationBar(false); | 1482 delegate_->SetFocusToLocationBar(false); |
1321 return; | 1483 return; |
1322 } | 1484 } |
1323 | 1485 |
1324 // Remember if the page was focused so we can focus the new renderer in | 1486 // Remember if the page was focused so we can focus the new renderer in |
1325 // that case. | 1487 // that case. |
1326 bool focus_render_view = !will_focus_location_bar && | 1488 bool focus_render_view = !will_focus_location_bar && |
1327 render_frame_host_->render_view_host()->GetView() && | 1489 render_frame_host_->render_view_host()->GetView() && |
1328 render_frame_host_->render_view_host()->GetView()->HasFocus(); | 1490 render_frame_host_->render_view_host()->GetView()->HasFocus(); |
1329 | 1491 |
1330 bool is_main_frame = frame_tree_node_->IsMainFrame(); | 1492 bool is_main_frame = frame_tree_node_->IsMainFrame(); |
1331 | 1493 |
1332 // Swap in the pending frame and make it active. Also ensure the FrameTree | 1494 scoped_ptr<RenderFrameHostImpl> old_render_frame_host; |
1333 // stays in sync. | 1495 if (!browser_side_navigation) { |
1334 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = | 1496 DCHECK(!speculative_render_frame_host_); |
1335 SetRenderFrameHost(pending_render_frame_host_.Pass()); | 1497 // Swap in the pending frame and make it active. Also ensure the FrameTree |
1498 // stays in sync. | |
1499 old_render_frame_host = | |
1500 SetRenderFrameHost(pending_render_frame_host_.Pass()); | |
1501 } else { | |
1502 // PlzNavigate | |
1503 DCHECK(speculative_render_frame_host_); | |
1504 old_render_frame_host = | |
1505 SetRenderFrameHost(speculative_render_frame_host_.Pass()); | |
1506 } | |
1507 | |
1336 if (is_main_frame) | 1508 if (is_main_frame) |
1337 render_frame_host_->render_view_host()->AttachToFrameTree(); | 1509 render_frame_host_->render_view_host()->AttachToFrameTree(); |
1338 | 1510 |
1339 // The process will no longer try to exit, so we can decrement the count. | 1511 // The process will no longer try to exit, so we can decrement the count. |
1340 render_frame_host_->GetProcess()->RemovePendingView(); | 1512 render_frame_host_->GetProcess()->RemovePendingView(); |
1341 | 1513 |
1342 // Show the new view (or a sad tab) if necessary. | 1514 // Show the new view (or a sad tab) if necessary. |
1343 bool new_rfh_has_view = !!render_frame_host_->render_view_host()->GetView(); | 1515 bool new_rfh_has_view = !!render_frame_host_->render_view_host()->GetView(); |
1344 if (!delegate_->IsHidden() && new_rfh_has_view) { | 1516 if (!delegate_->IsHidden() && new_rfh_has_view) { |
1345 // In most cases, we need to show the new view. | 1517 // In most cases, we need to show the new view. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1684 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 1856 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
1685 SiteInstance* instance) { | 1857 SiteInstance* instance) { |
1686 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 1858 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
1687 if (iter != proxy_hosts_.end()) { | 1859 if (iter != proxy_hosts_.end()) { |
1688 delete iter->second; | 1860 delete iter->second; |
1689 proxy_hosts_.erase(iter); | 1861 proxy_hosts_.erase(iter); |
1690 } | 1862 } |
1691 } | 1863 } |
1692 | 1864 |
1693 } // namespace content | 1865 } // namespace content |
OLD | NEW |