| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 int routing_id, | 76 int routing_id, |
| 77 int main_frame_routing_id) { | 77 int main_frame_routing_id) { |
| 78 // Create a RenderViewHost, once we have an instance. It is important to | 78 // Create a RenderViewHost, once we have an instance. It is important to |
| 79 // immediately give this SiteInstance to a RenderViewHost so that it is | 79 // immediately give this SiteInstance to a RenderViewHost so that it is |
| 80 // ref counted. | 80 // ref counted. |
| 81 if (!site_instance) | 81 if (!site_instance) |
| 82 site_instance = SiteInstance::Create(browser_context); | 82 site_instance = SiteInstance::Create(browser_context); |
| 83 render_view_host_ = static_cast<RenderViewHostImpl*>( | 83 render_view_host_ = static_cast<RenderViewHostImpl*>( |
| 84 RenderViewHostFactory::Create( | 84 RenderViewHostFactory::Create( |
| 85 site_instance, render_view_delegate_, render_widget_delegate_, | 85 site_instance, render_view_delegate_, render_widget_delegate_, |
| 86 routing_id, main_frame_routing_id, false)); | 86 routing_id, main_frame_routing_id, false, delegate_->IsHidden())); |
| 87 | 87 |
| 88 // Keep track of renderer processes as they start to shut down or are | 88 // Keep track of renderer processes as they start to shut down or are |
| 89 // crashed/killed. | 89 // crashed/killed. |
| 90 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | 90 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 91 NotificationService::AllSources()); | 91 NotificationService::AllSources()); |
| 92 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, | 92 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, |
| 93 NotificationService::AllSources()); | 93 NotificationService::AllSources()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 RenderViewHostImpl* RenderViewHostManager::current_host() const { | 96 RenderViewHostImpl* RenderViewHostManager::current_host() const { |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 // SiteInstance to a RenderViewHost (if it is different than our current | 635 // SiteInstance to a RenderViewHost (if it is different than our current |
| 636 // SiteInstance), so that it is ref counted. This will happen in | 636 // SiteInstance), so that it is ref counted. This will happen in |
| 637 // CreateRenderView. | 637 // CreateRenderView. |
| 638 return curr_instance->GetRelatedSiteInstance(dest_url); | 638 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 639 } | 639 } |
| 640 } | 640 } |
| 641 | 641 |
| 642 int RenderViewHostManager::CreateRenderView( | 642 int RenderViewHostManager::CreateRenderView( |
| 643 SiteInstance* instance, | 643 SiteInstance* instance, |
| 644 int opener_route_id, | 644 int opener_route_id, |
| 645 bool swapped_out) { | 645 bool swapped_out, |
| 646 bool hidden) { |
| 646 CHECK(instance); | 647 CHECK(instance); |
| 648 DCHECK(!swapped_out || hidden); // Swapped out views should always be hidden. |
| 647 | 649 |
| 648 // Check if we've already created an RVH for this SiteInstance. If so, try | 650 // 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 | 651 // 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. | 652 // remove it from the list of swapped out hosts if it commits. |
| 651 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( | 653 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( |
| 652 GetSwappedOutRenderViewHost(instance)); | 654 GetSwappedOutRenderViewHost(instance)); |
| 653 if (new_render_view_host) { | 655 if (new_render_view_host) { |
| 654 // Prevent the process from exiting while we're trying to use it. | 656 // Prevent the process from exiting while we're trying to use it. |
| 655 if (!swapped_out) | 657 if (!swapped_out) |
| 656 new_render_view_host->GetProcess()->AddPendingView(); | 658 new_render_view_host->GetProcess()->AddPendingView(); |
| 657 } else { | 659 } else { |
| 658 // Create a new RenderViewHost if we don't find an existing one. | 660 // Create a new RenderViewHost if we don't find an existing one. |
| 659 new_render_view_host = static_cast<RenderViewHostImpl*>( | 661 new_render_view_host = static_cast<RenderViewHostImpl*>( |
| 660 RenderViewHostFactory::Create(instance, | 662 RenderViewHostFactory::Create(instance, |
| 661 render_view_delegate_, | 663 render_view_delegate_, |
| 662 render_widget_delegate_, | 664 render_widget_delegate_, |
| 663 MSG_ROUTING_NONE, | 665 MSG_ROUTING_NONE, |
| 664 MSG_ROUTING_NONE, | 666 MSG_ROUTING_NONE, |
| 665 swapped_out)); | 667 swapped_out, |
| 668 hidden)); |
| 666 | 669 |
| 667 // If the new RVH is swapped out already, store it. Otherwise prevent the | 670 // 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. | 671 // process from exiting while we're trying to navigate in it. |
| 669 if (swapped_out) { | 672 if (swapped_out) { |
| 670 swapped_out_hosts_[instance->GetId()] = new_render_view_host; | 673 swapped_out_hosts_[instance->GetId()] = new_render_view_host; |
| 671 } else { | 674 } else { |
| 672 new_render_view_host->GetProcess()->AddPendingView(); | 675 new_render_view_host->GetProcess()->AddPendingView(); |
| 673 } | 676 } |
| 674 | 677 |
| 675 bool success = InitRenderView(new_render_view_host, opener_route_id); | 678 bool success = InitRenderView(new_render_view_host, opener_route_id); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 // we are staying in the same BrowsingInstance. This allows the pending RVH | 890 // we are staying in the same BrowsingInstance. This allows the pending RVH |
| 888 // to send cross-process script calls to its opener(s). | 891 // to send cross-process script calls to its opener(s). |
| 889 int opener_route_id = MSG_ROUTING_NONE; | 892 int opener_route_id = MSG_ROUTING_NONE; |
| 890 if (new_instance->IsRelatedSiteInstance(curr_instance)) { | 893 if (new_instance->IsRelatedSiteInstance(curr_instance)) { |
| 891 opener_route_id = | 894 opener_route_id = |
| 892 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 895 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
| 893 } | 896 } |
| 894 | 897 |
| 895 // Create a non-swapped-out pending RVH with the given opener and navigate | 898 // Create a non-swapped-out pending RVH with the given opener and navigate |
| 896 // it. | 899 // it. |
| 897 int route_id = CreateRenderView(new_instance, opener_route_id, false); | 900 int route_id = CreateRenderView(new_instance, opener_route_id, false, |
| 901 delegate_->IsHidden()); |
| 898 if (route_id == MSG_ROUTING_NONE) | 902 if (route_id == MSG_ROUTING_NONE) |
| 899 return NULL; | 903 return NULL; |
| 900 | 904 |
| 901 // Check if our current RVH is live before we set up a transition. | 905 // Check if our current RVH is live before we set up a transition. |
| 902 if (!render_view_host_->IsRenderViewLive()) { | 906 if (!render_view_host_->IsRenderViewLive()) { |
| 903 if (!cross_navigation_pending_) { | 907 if (!cross_navigation_pending_) { |
| 904 // The current RVH is not live. There's no reason to sit around with a | 908 // 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 | 909 // 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 | 910 // 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 | 911 // 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( | 1057 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
| 1054 SiteInstance* instance) { | 1058 SiteInstance* instance) { |
| 1055 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 1059 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
| 1056 if (iter != swapped_out_hosts_.end()) | 1060 if (iter != swapped_out_hosts_.end()) |
| 1057 return iter->second; | 1061 return iter->second; |
| 1058 | 1062 |
| 1059 return NULL; | 1063 return NULL; |
| 1060 } | 1064 } |
| 1061 | 1065 |
| 1062 } // namespace content | 1066 } // namespace content |
| OLD | NEW |