Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Side by Side Diff: content/browser/tab_contents/render_view_host_manager.cc

Issue 9288037: Do not filter IPC messages until the new RVH commits, to avoid a race. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comment as well. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/tab_contents/render_view_host_manager.h" 5 #include "content/browser/tab_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/logging.h" 10 #include "base/logging.h"
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 // handlers if the current RVH isn't live.) 691 // handlers if the current RVH isn't live.)
692 CommitPending(); 692 CommitPending();
693 return render_view_host_; 693 return render_view_host_;
694 } else { 694 } else {
695 NOTREACHED(); 695 NOTREACHED();
696 return render_view_host_; 696 return render_view_host_;
697 } 697 }
698 } 698 }
699 // Otherwise, it's safe to treat this as a pending cross-site transition. 699 // Otherwise, it's safe to treat this as a pending cross-site transition.
700 700
701 // It is possible that a previous cross-site navigation caused 701 // Make sure the old render view stops, in case a load is in progress.
702 // render_view_host_ to be swapped out and we are still waiting for 702 render_view_host_->Send(new ViewMsg_Stop(render_view_host_->routing_id()));
703 // the old pending_render_view_host_ to inform us about the committed
704 // navigation.
705 if (!render_view_host_->is_swapped_out()) {
706 // Make sure the old render view stops, in case a load is in progress.
707 render_view_host_->Send(
708 new ViewMsg_Stop(render_view_host_->routing_id()));
709 703
710 // Suspend the new render view (i.e., don't let it send the cross-site 704 // Suspend the new render view (i.e., don't let it send the cross-site
711 // Navigate message) until we hear back from the old renderer's 705 // Navigate message) until we hear back from the old renderer's
712 // onbeforeunload handler. If the handler returns false, we'll have to 706 // onbeforeunload handler. If the handler returns false, we'll have to
713 // cancel the request. 707 // cancel the request.
714 DCHECK(!pending_render_view_host_->are_navigations_suspended()); 708 DCHECK(!pending_render_view_host_->are_navigations_suspended());
715 pending_render_view_host_->SetNavigationsSuspended(true); 709 pending_render_view_host_->SetNavigationsSuspended(true);
716 710
717 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site 711 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site
718 // request, so that ResourceDispatcherHost will know to tell us to run the 712 // request, so that ResourceDispatcherHost will know to tell us to run the
719 // old page's onunload handler before it sends the response. 713 // old page's onunload handler before it sends the response.
720 pending_render_view_host_->SetHasPendingCrossSiteRequest(true, -1); 714 pending_render_view_host_->SetHasPendingCrossSiteRequest(true, -1);
721
722 // Tell the old render view to run its onbeforeunload handler, since it
723 // doesn't otherwise know that the cross-site request is happening. This
724 // will trigger a call to ShouldClosePage with the reply.
725 render_view_host_->FirePageBeforeUnload(true);
726 } else {
727 // As the render_view_host_ is already swapped out, we do not need
728 // to instruct it to run its beforeunload or unload handlers. Therefore,
729 // we also do not need to suspend outgoing navigation messages and can
730 // just let the new pending_render_view_host_ immediately navigate.
731 }
732 715
733 // We now have a pending RVH. 716 // We now have a pending RVH.
734 DCHECK(!cross_navigation_pending_); 717 DCHECK(!cross_navigation_pending_);
735 cross_navigation_pending_ = true; 718 cross_navigation_pending_ = true;
736 719
720 // Tell the old render view to run its onbeforeunload handler, since it
721 // doesn't otherwise know that the cross-site request is happening. This
722 // will trigger a call to ShouldClosePage with the reply.
723 render_view_host_->FirePageBeforeUnload(true);
724
737 return pending_render_view_host_; 725 return pending_render_view_host_;
738 } else { 726 } else {
739 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive()) 727 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive())
740 pending_web_ui_->GetController()->RenderViewReused(render_view_host_); 728 pending_web_ui_->GetController()->RenderViewReused(render_view_host_);
741 729
742 // The renderer can exit view source mode when any error or cancellation 730 // The renderer can exit view source mode when any error or cancellation
743 // happen. We must overwrite to recover the mode. 731 // happen. We must overwrite to recover the mode.
744 if (entry.IsViewSourceMode()) { 732 if (entry.IsViewSourceMode()) {
745 render_view_host_->Send( 733 render_view_host_->Send(
746 new ViewMsg_EnableViewSourceMode(render_view_host_->routing_id())); 734 new ViewMsg_EnableViewSourceMode(render_view_host_->routing_id()));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 } 799 }
812 } 800 }
813 801
814 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { 802 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) {
815 if (!rvh->site_instance()) 803 if (!rvh->site_instance())
816 return false; 804 return false;
817 805
818 return swapped_out_hosts_.find(rvh->site_instance()->id()) != 806 return swapped_out_hosts_.find(rvh->site_instance()->id()) !=
819 swapped_out_hosts_.end(); 807 swapped_out_hosts_.end();
820 } 808 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698