OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/render_view_host_manager.h" | 5 #include "content/browser/web_contents/render_view_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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 67 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); |
68 iter != swapped_out_hosts_.end(); | 68 iter != swapped_out_hosts_.end(); |
69 ++iter) { | 69 ++iter) { |
70 iter->second->Shutdown(); | 70 iter->second->Shutdown(); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 void RenderViewHostManager::Init(BrowserContext* browser_context, | 74 void RenderViewHostManager::Init(BrowserContext* browser_context, |
75 SiteInstance* site_instance, | 75 SiteInstance* site_instance, |
76 int routing_id, | 76 int routing_id, |
77 int main_frame_routing_id) { | 77 int main_frame_routing_id, |
78 bool hidden) { | |
78 // Create a RenderViewHost, once we have an instance. It is important to | 79 // Create a RenderViewHost, once we have an instance. It is important to |
79 // immediately give this SiteInstance to a RenderViewHost so that it is | 80 // immediately give this SiteInstance to a RenderViewHost so that it is |
80 // ref counted. | 81 // ref counted. |
81 if (!site_instance) | 82 if (!site_instance) |
82 site_instance = SiteInstance::Create(browser_context); | 83 site_instance = SiteInstance::Create(browser_context); |
83 render_view_host_ = static_cast<RenderViewHostImpl*>( | 84 render_view_host_ = static_cast<RenderViewHostImpl*>( |
84 RenderViewHostFactory::Create( | 85 RenderViewHostFactory::Create( |
85 site_instance, render_view_delegate_, render_widget_delegate_, | 86 site_instance, render_view_delegate_, render_widget_delegate_, |
86 routing_id, main_frame_routing_id, false)); | 87 routing_id, main_frame_routing_id, false, hidden)); |
87 | 88 |
88 // Keep track of renderer processes as they start to shut down or are | 89 // Keep track of renderer processes as they start to shut down or are |
89 // crashed/killed. | 90 // crashed/killed. |
90 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | 91 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
91 NotificationService::AllSources()); | 92 NotificationService::AllSources()); |
92 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, | 93 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, |
93 NotificationService::AllSources()); | 94 NotificationService::AllSources()); |
94 } | 95 } |
95 | 96 |
96 RenderViewHostImpl* RenderViewHostManager::current_host() const { | 97 RenderViewHostImpl* RenderViewHostManager::current_host() const { |
(...skipping 23 matching lines...) Expand all Loading... | |
120 // potential privilege escalation. | 121 // potential privilege escalation. |
121 if (pending_web_ui_.get() && | 122 if (pending_web_ui_.get() && |
122 entry.bindings() != NavigationEntryImpl::kInvalidBindings && | 123 entry.bindings() != NavigationEntryImpl::kInvalidBindings && |
123 pending_web_ui_->GetBindings() != entry.bindings()) { | 124 pending_web_ui_->GetBindings() != entry.bindings()) { |
124 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); | 125 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
125 pending_web_ui_.reset(); | 126 pending_web_ui_.reset(); |
126 } | 127 } |
127 } | 128 } |
128 | 129 |
129 RenderViewHostImpl* RenderViewHostManager::Navigate( | 130 RenderViewHostImpl* RenderViewHostManager::Navigate( |
130 const NavigationEntryImpl& entry) { | 131 const NavigationEntryImpl& entry, bool hidden) { |
131 TRACE_EVENT0("browser", "RenderViewHostManager:Navigate"); | 132 TRACE_EVENT0("browser", "RenderViewHostManager:Navigate"); |
132 // Create a pending RenderViewHost. It will give us the one we should use | 133 // Create a pending RenderViewHost. It will give us the one we should use |
133 RenderViewHostImpl* dest_render_view_host = | 134 RenderViewHostImpl* dest_render_view_host = |
134 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry)); | 135 static_cast<RenderViewHostImpl*>( |
136 UpdateRendererStateForNavigate(entry, hidden)); | |
135 if (!dest_render_view_host) | 137 if (!dest_render_view_host) |
136 return NULL; // We weren't able to create a pending render view host. | 138 return NULL; // We weren't able to create a pending render view host. |
137 | 139 |
138 // If the current render_view_host_ isn't live, we should create it so | 140 // If the current render_view_host_ isn't live, we should create it so |
139 // that we don't show a sad tab while the dest_render_view_host fetches | 141 // that we don't show a sad tab while the dest_render_view_host fetches |
140 // its first page. (Bug 1145340) | 142 // its first page. (Bug 1145340) |
141 if (dest_render_view_host != render_view_host_ && | 143 if (dest_render_view_host != render_view_host_ && |
142 !render_view_host_->IsRenderViewLive()) { | 144 !render_view_host_->IsRenderViewLive()) { |
143 // Note: we don't call InitRenderView here because we are navigating away | 145 // Note: we don't call InitRenderView here because we are navigating away |
144 // soon anyway, and we don't have the NavigationEntry for this host. | 146 // soon anyway, and we don't have the NavigationEntry for this host. |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 // SiteInstance to a RenderViewHost (if it is different than our current | 637 // SiteInstance to a RenderViewHost (if it is different than our current |
636 // SiteInstance), so that it is ref counted. This will happen in | 638 // SiteInstance), so that it is ref counted. This will happen in |
637 // CreateRenderView. | 639 // CreateRenderView. |
638 return curr_instance->GetRelatedSiteInstance(dest_url); | 640 return curr_instance->GetRelatedSiteInstance(dest_url); |
639 } | 641 } |
640 } | 642 } |
641 | 643 |
642 int RenderViewHostManager::CreateRenderView( | 644 int RenderViewHostManager::CreateRenderView( |
643 SiteInstance* instance, | 645 SiteInstance* instance, |
644 int opener_route_id, | 646 int opener_route_id, |
645 bool swapped_out) { | 647 bool swapped_out, |
648 bool hidden) { | |
Charlie Reis
2013/08/19 22:18:02
Can we add a DCHECK that swapped_out implies hidde
jamesr
2013/08/19 23:50:39
Done.
| |
646 CHECK(instance); | 649 CHECK(instance); |
647 | 650 |
648 // Check if we've already created an RVH for this SiteInstance. If so, try | 651 // Check if we've already created an RVH for this SiteInstance. If so, try |
649 // to re-use the existing one, which has already been initialized. We'll | 652 // to re-use the existing one, which has already been initialized. We'll |
650 // remove it from the list of swapped out hosts if it commits. | 653 // remove it from the list of swapped out hosts if it commits. |
651 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( | 654 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( |
652 GetSwappedOutRenderViewHost(instance)); | 655 GetSwappedOutRenderViewHost(instance)); |
653 if (new_render_view_host) { | 656 if (new_render_view_host) { |
654 // Prevent the process from exiting while we're trying to use it. | 657 // Prevent the process from exiting while we're trying to use it. |
655 if (!swapped_out) | 658 if (!swapped_out) |
656 new_render_view_host->GetProcess()->AddPendingView(); | 659 new_render_view_host->GetProcess()->AddPendingView(); |
657 } else { | 660 } else { |
658 // Create a new RenderViewHost if we don't find an existing one. | 661 // Create a new RenderViewHost if we don't find an existing one. |
659 new_render_view_host = static_cast<RenderViewHostImpl*>( | 662 new_render_view_host = static_cast<RenderViewHostImpl*>( |
660 RenderViewHostFactory::Create(instance, | 663 RenderViewHostFactory::Create(instance, |
661 render_view_delegate_, | 664 render_view_delegate_, |
662 render_widget_delegate_, | 665 render_widget_delegate_, |
663 MSG_ROUTING_NONE, | 666 MSG_ROUTING_NONE, |
664 MSG_ROUTING_NONE, | 667 MSG_ROUTING_NONE, |
665 swapped_out)); | 668 swapped_out, |
669 hidden)); | |
666 | 670 |
667 // If the new RVH is swapped out already, store it. Otherwise prevent the | 671 // If the new RVH is swapped out already, store it. Otherwise prevent the |
668 // process from exiting while we're trying to navigate in it. | 672 // process from exiting while we're trying to navigate in it. |
669 if (swapped_out) { | 673 if (swapped_out) { |
670 swapped_out_hosts_[instance->GetId()] = new_render_view_host; | 674 swapped_out_hosts_[instance->GetId()] = new_render_view_host; |
671 } else { | 675 } else { |
672 new_render_view_host->GetProcess()->AddPendingView(); | 676 new_render_view_host->GetProcess()->AddPendingView(); |
673 } | 677 } |
674 | 678 |
675 bool success = InitRenderView(new_render_view_host, opener_route_id); | 679 bool success = InitRenderView(new_render_view_host, opener_route_id); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 } | 843 } |
840 } | 844 } |
841 | 845 |
842 // Finally we delete the gathered RVHs, which should not indirectly | 846 // Finally we delete the gathered RVHs, which should not indirectly |
843 // delete each other. | 847 // delete each other. |
844 for (size_t i = 0; i < rvhs_to_be_deleted.size(); ++i) | 848 for (size_t i = 0; i < rvhs_to_be_deleted.size(); ++i) |
845 rvhs_to_be_deleted[i]->Shutdown(); | 849 rvhs_to_be_deleted[i]->Shutdown(); |
846 } | 850 } |
847 | 851 |
848 RenderViewHostImpl* RenderViewHostManager::UpdateRendererStateForNavigate( | 852 RenderViewHostImpl* RenderViewHostManager::UpdateRendererStateForNavigate( |
849 const NavigationEntryImpl& entry) { | 853 const NavigationEntryImpl& entry, bool hidden) { |
850 // If we are cross-navigating, then we want to get back to normal and navigate | 854 // If we are cross-navigating, then we want to get back to normal and navigate |
851 // as usual. | 855 // as usual. |
852 if (cross_navigation_pending_) { | 856 if (cross_navigation_pending_) { |
853 if (pending_render_view_host_) | 857 if (pending_render_view_host_) |
854 CancelPending(); | 858 CancelPending(); |
855 cross_navigation_pending_ = false; | 859 cross_navigation_pending_ = false; |
856 } | 860 } |
857 | 861 |
858 // render_view_host_ will not be deleted before the end of this method, so we | 862 // render_view_host_ will not be deleted before the end of this method, so we |
859 // don't have to worry about this SiteInstance's ref count dropping to zero. | 863 // don't have to worry about this SiteInstance's ref count dropping to zero. |
(...skipping 27 matching lines...) Expand all Loading... | |
887 // we are staying in the same BrowsingInstance. This allows the pending RVH | 891 // we are staying in the same BrowsingInstance. This allows the pending RVH |
888 // to send cross-process script calls to its opener(s). | 892 // to send cross-process script calls to its opener(s). |
889 int opener_route_id = MSG_ROUTING_NONE; | 893 int opener_route_id = MSG_ROUTING_NONE; |
890 if (new_instance->IsRelatedSiteInstance(curr_instance)) { | 894 if (new_instance->IsRelatedSiteInstance(curr_instance)) { |
891 opener_route_id = | 895 opener_route_id = |
892 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 896 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
893 } | 897 } |
894 | 898 |
895 // Create a non-swapped-out pending RVH with the given opener and navigate | 899 // Create a non-swapped-out pending RVH with the given opener and navigate |
896 // it. | 900 // it. |
897 int route_id = CreateRenderView(new_instance, opener_route_id, false); | 901 int route_id = CreateRenderView(new_instance, |
902 opener_route_id, | |
903 false, | |
904 hidden); | |
Charlie Reis
2013/08/19 22:18:02
Style nit: No need for one param-per-line on funct
jamesr
2013/08/19 23:50:39
Hmm. We're inconsistent on this, but sure.
| |
898 if (route_id == MSG_ROUTING_NONE) | 905 if (route_id == MSG_ROUTING_NONE) |
899 return NULL; | 906 return NULL; |
900 | 907 |
901 // Check if our current RVH is live before we set up a transition. | 908 // Check if our current RVH is live before we set up a transition. |
902 if (!render_view_host_->IsRenderViewLive()) { | 909 if (!render_view_host_->IsRenderViewLive()) { |
903 if (!cross_navigation_pending_) { | 910 if (!cross_navigation_pending_) { |
904 // The current RVH is not live. There's no reason to sit around with a | 911 // The current RVH is not live. There's no reason to sit around with a |
905 // sad tab or a newly created RVH while we wait for the pending RVH to | 912 // sad tab or a newly created RVH while we wait for the pending RVH to |
906 // navigate. Just switch to the pending RVH now and go back to non | 913 // navigate. Just switch to the pending RVH now and go back to non |
907 // cross-navigating (Note that we don't care about on{before}unload | 914 // cross-navigating (Note that we don't care about on{before}unload |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( | 1060 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
1054 SiteInstance* instance) { | 1061 SiteInstance* instance) { |
1055 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 1062 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
1056 if (iter != swapped_out_hosts_.end()) | 1063 if (iter != swapped_out_hosts_.end()) |
1057 return iter->second; | 1064 return iter->second; |
1058 | 1065 |
1059 return NULL; | 1066 return NULL; |
1060 } | 1067 } |
1061 | 1068 |
1062 } // namespace content | 1069 } // namespace content |
OLD | NEW |