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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 int routing_id, | 77 int routing_id, |
78 int main_frame_routing_id) { | 78 int main_frame_routing_id) { |
79 // 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 |
80 // immediately give this SiteInstance to a RenderViewHost so that it is | 80 // immediately give this SiteInstance to a RenderViewHost so that it is |
81 // ref counted. | 81 // ref counted. |
82 if (!site_instance) | 82 if (!site_instance) |
83 site_instance = SiteInstance::Create(browser_context); | 83 site_instance = SiteInstance::Create(browser_context); |
84 render_view_host_ = static_cast<RenderViewHostImpl*>( | 84 render_view_host_ = static_cast<RenderViewHostImpl*>( |
85 RenderViewHostFactory::Create( | 85 RenderViewHostFactory::Create( |
86 site_instance, render_view_delegate_, render_widget_delegate_, | 86 site_instance, render_view_delegate_, render_widget_delegate_, |
87 routing_id, main_frame_routing_id, false, delegate_->IsHidden())); | 87 routing_id, main_frame_routing_id, false, |
| 88 delegate_->IsHidden())); |
| 89 render_view_host_->AttachToFrameTree(); |
88 | 90 |
89 // Keep track of renderer processes as they start to shut down or are | 91 // Keep track of renderer processes as they start to shut down or are |
90 // crashed/killed. | 92 // crashed/killed. |
91 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | 93 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
92 NotificationService::AllSources()); | 94 NotificationService::AllSources()); |
93 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, | 95 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, |
94 NotificationService::AllSources()); | 96 NotificationService::AllSources()); |
95 } | 97 } |
96 | 98 |
97 RenderViewHostImpl* RenderViewHostManager::current_host() const { | 99 RenderViewHostImpl* RenderViewHostManager::current_host() const { |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 if (will_focus_location_bar) | 732 if (will_focus_location_bar) |
731 delegate_->SetFocusToLocationBar(false); | 733 delegate_->SetFocusToLocationBar(false); |
732 return; | 734 return; |
733 } | 735 } |
734 | 736 |
735 // Remember if the page was focused so we can focus the new renderer in | 737 // Remember if the page was focused so we can focus the new renderer in |
736 // that case. | 738 // that case. |
737 bool focus_render_view = !will_focus_location_bar && | 739 bool focus_render_view = !will_focus_location_bar && |
738 render_view_host_->GetView() && render_view_host_->GetView()->HasFocus(); | 740 render_view_host_->GetView() && render_view_host_->GetView()->HasFocus(); |
739 | 741 |
740 // Swap in the pending view and make it active. | 742 // Swap in the pending view and make it active. Also ensure the FrameTree |
| 743 // stays in sync. |
741 RenderViewHostImpl* old_render_view_host = render_view_host_; | 744 RenderViewHostImpl* old_render_view_host = render_view_host_; |
742 render_view_host_ = pending_render_view_host_; | 745 render_view_host_ = pending_render_view_host_; |
743 pending_render_view_host_ = NULL; | 746 pending_render_view_host_ = NULL; |
| 747 render_view_host_->AttachToFrameTree(); |
744 | 748 |
745 // The process will no longer try to exit, so we can decrement the count. | 749 // The process will no longer try to exit, so we can decrement the count. |
746 render_view_host_->GetProcess()->RemovePendingView(); | 750 render_view_host_->GetProcess()->RemovePendingView(); |
747 | 751 |
748 // Hide the old view before showing the new view. This has the potential to | 752 // Hide the old view before showing the new view. This has the potential to |
749 // reduce peak memory usage, by freeing up a large resource before allocating | 753 // reduce peak memory usage, by freeing up a large resource before allocating |
750 // a new large resource. | 754 // a new large resource. |
751 if (old_render_view_host->GetView()) { | 755 if (old_render_view_host->GetView()) { |
752 old_render_view_host->GetView()->Hide(); | 756 old_render_view_host->GetView()->Hide(); |
753 old_render_view_host->WasSwappedOut(); | 757 old_render_view_host->WasSwappedOut(); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( | 1051 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
1048 SiteInstance* instance) { | 1052 SiteInstance* instance) { |
1049 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 1053 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
1050 if (iter != swapped_out_hosts_.end()) | 1054 if (iter != swapped_out_hosts_.end()) |
1051 return iter->second; | 1055 return iter->second; |
1052 | 1056 |
1053 return NULL; | 1057 return NULL; |
1054 } | 1058 } |
1055 | 1059 |
1056 } // namespace content | 1060 } // namespace content |
OLD | NEW |