OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/render_view_host_manager.h" | 5 #include "content/browser/tab_contents/render_view_host_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/browser/content_browser_client.h" | 9 #include "content/browser/content_browser_client.h" |
10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 // If the pending view was on the swapped out list, we can remove it. | 631 // If the pending view was on the swapped out list, we can remove it. |
632 swapped_out_hosts_.erase(render_view_host_->site_instance()->id()); | 632 swapped_out_hosts_.erase(render_view_host_->site_instance()->id()); |
633 | 633 |
634 // If the old RVH is live, we are swapping it out and should keep track of it | 634 // If the old RVH is live, we are swapping it out and should keep track of it |
635 // in case we navigate back to it. | 635 // in case we navigate back to it. |
636 if (old_render_view_host->IsRenderViewLive()) { | 636 if (old_render_view_host->IsRenderViewLive()) { |
637 DCHECK(old_render_view_host->is_swapped_out()); | 637 DCHECK(old_render_view_host->is_swapped_out()); |
638 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make | 638 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make |
639 // sure we don't get different rvh instances for the same site instance | 639 // sure we don't get different rvh instances for the same site instance |
640 // in the same rvhmgr. | 640 // in the same rvhmgr. |
641 // TODO(creis): Clean this up, and duplication in SwapInRenderViewHost. | 641 // TODO(creis): Clean this up. |
642 int32 old_site_instance_id = old_render_view_host->site_instance()->id(); | 642 int32 old_site_instance_id = old_render_view_host->site_instance()->id(); |
643 RenderViewHostMap::iterator iter = | 643 RenderViewHostMap::iterator iter = |
644 swapped_out_hosts_.find(old_site_instance_id); | 644 swapped_out_hosts_.find(old_site_instance_id); |
645 if (iter != swapped_out_hosts_.end() && | 645 if (iter != swapped_out_hosts_.end() && |
646 iter->second != old_render_view_host) { | 646 iter->second != old_render_view_host) { |
647 // Shutdown the RVH that will be replaced in the map to avoid a leak. | 647 // Shutdown the RVH that will be replaced in the map to avoid a leak. |
648 iter->second->Shutdown(); | 648 iter->second->Shutdown(); |
649 } | 649 } |
650 swapped_out_hosts_[old_site_instance_id] = old_render_view_host; | 650 swapped_out_hosts_[old_site_instance_id] = old_render_view_host; |
651 } else { | 651 } else { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 804 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); |
805 iter != swapped_out_hosts_.end(); | 805 iter != swapped_out_hosts_.end(); |
806 ++iter) { | 806 ++iter) { |
807 if (iter->second == rvh) { | 807 if (iter->second == rvh) { |
808 swapped_out_hosts_.erase(iter); | 808 swapped_out_hosts_.erase(iter); |
809 break; | 809 break; |
810 } | 810 } |
811 } | 811 } |
812 } | 812 } |
813 | 813 |
814 void RenderViewHostManager::SwapInRenderViewHost(RenderViewHost* rvh) { | |
815 // TODO(creis): Abstract out the common code between this and CommitPending. | |
816 web_ui_.reset(); | |
817 | |
818 // Make sure the current RVH is swapped out so that it filters out any | |
819 // disruptive messages from the renderer. We can pass -1,-1 because there is | |
820 // no pending response in the ResourceDispatcherHost to unpause. | |
821 render_view_host_->SwapOut(-1, -1); | |
822 | |
823 // Swap in the new view and make it active. | |
824 RenderViewHost* old_render_view_host = render_view_host_; | |
825 render_view_host_ = rvh; | |
826 render_view_host_->set_delegate(render_view_delegate_); | |
827 // Remove old RenderWidgetHostView with mocked out methods so it can be | |
828 // replaced with a new one that's a child of |delegate_|'s view. | |
829 scoped_ptr<RenderWidgetHostView> old_view(render_view_host_->view()); | |
830 render_view_host_->SetView(NULL); | |
831 delegate_->CreateViewAndSetSizeForRVH(render_view_host_); | |
832 render_view_host_->ActivateDeferredPluginHandles(); | |
833 // If the view is gone, then this RenderViewHost died while it was hidden. | |
834 // We ignored the RenderViewGone call at the time, so we should send it now | |
835 // to make sure the sad tab shows up, etc. | |
836 if (render_view_host_->view()) { | |
837 // The Hide() is needed to sync the state of |render_view_host_|, which is | |
838 // hidden, with the newly created view, which does not know the | |
839 // RenderViewHost is hidden. | |
840 // TODO(tburkard,cbentzel): Figure out if this hack can be removed | |
841 // (http://crbug.com/79891). | |
842 render_view_host_->view()->Hide(); | |
843 render_view_host_->view()->Show(); | |
844 } | |
845 | |
846 // Hide the current view and prepare to swap it out. | |
847 if (old_render_view_host->view()) { | |
848 old_render_view_host->view()->Hide(); | |
849 old_render_view_host->WasSwappedOut(); | |
850 } | |
851 | |
852 delegate_->UpdateRenderViewSizeForRenderManager(); | |
853 | |
854 RenderViewHostSwitchedDetails details; | |
855 details.new_host = render_view_host_; | |
856 details.old_host = old_render_view_host; | |
857 NotificationService::current()->Notify( | |
858 content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | |
859 Source<NavigationController>(&delegate_->GetControllerForRenderManager()), | |
860 Details<RenderViewHostSwitchedDetails>(&details)); | |
861 | |
862 // If the given RVH was on the swapped out list, we can remove it. | |
863 swapped_out_hosts_.erase(render_view_host_->site_instance()->id()); | |
864 | |
865 // If the old RVH is live, we are swapping it out and should keep track of it | |
866 // in case we navigate back to it. | |
867 if (old_render_view_host->IsRenderViewLive()) { | |
868 DCHECK(old_render_view_host->is_swapped_out()); | |
869 // Temp fix for http://crbug.com/90867 until we do a better cleanup to make | |
870 // sure we don't get different rvh instances for the same site instance | |
871 // in the same rvhmgr. | |
872 // TODO(creis): Clean this up as well as duplication with CommitPending. | |
873 int32 old_site_instance_id = old_render_view_host->site_instance()->id(); | |
874 RenderViewHostMap::iterator iter = | |
875 swapped_out_hosts_.find(old_site_instance_id); | |
876 if (iter != swapped_out_hosts_.end() && | |
877 iter->second != old_render_view_host) { | |
878 // Shutdown the RVH that will be replaced in the map to avoid a leak. | |
879 iter->second->Shutdown(); | |
880 } | |
881 swapped_out_hosts_[old_site_instance_id] = old_render_view_host; | |
882 } else { | |
883 old_render_view_host->Shutdown(); | |
884 } | |
885 | |
886 // Let the task manager know that we've swapped RenderViewHosts, since it | |
887 // might need to update its process groupings. | |
888 delegate_->NotifySwappedFromRenderManager(); | |
889 } | |
890 | |
891 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 814 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
892 if (!rvh->site_instance()) | 815 if (!rvh->site_instance()) |
893 return false; | 816 return false; |
894 | 817 |
895 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 818 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
896 swapped_out_hosts_.end(); | 819 swapped_out_hosts_.end(); |
897 } | 820 } |
OLD | NEW |