Chromium Code Reviews| 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/debugger/devtools_manager.h" | 9 #include "content/browser/debugger/devtools_manager.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 // handlers if the current RVH isn't live.) | 694 // handlers if the current RVH isn't live.) |
| 695 CommitPending(); | 695 CommitPending(); |
| 696 return render_view_host_; | 696 return render_view_host_; |
| 697 } else { | 697 } else { |
| 698 NOTREACHED(); | 698 NOTREACHED(); |
| 699 return render_view_host_; | 699 return render_view_host_; |
| 700 } | 700 } |
| 701 } | 701 } |
| 702 // Otherwise, it's safe to treat this as a pending cross-site transition. | 702 // Otherwise, it's safe to treat this as a pending cross-site transition. |
| 703 | 703 |
| 704 // Make sure the old render view stops, in case a load is in progress. | 704 // It is possible that a previous cross-site navigation caused |
| 705 render_view_host_->Send(new ViewMsg_Stop(render_view_host_->routing_id())); | 705 // render_view_host_ to be swapped out and we are still waiting for |
| 706 // the old pending_render_view_host_ to inform us about the committed | |
| 707 // navigation. | |
| 708 if (!render_view_host_->is_swapped_out()) { | |
| 709 // Make sure the old render view stops, in case a load is in progress. | |
| 710 render_view_host_->Send( | |
| 711 new ViewMsg_Stop(render_view_host_->routing_id())); | |
| 706 | 712 |
| 707 // Suspend the new render view (i.e., don't let it send the cross-site | 713 // Suspend the new render view (i.e., don't let it send the cross-site |
| 708 // Navigate message) until we hear back from the old renderer's | 714 // Navigate message) until we hear back from the old renderer's |
| 709 // onbeforeunload handler. If the handler returns false, we'll have to | 715 // onbeforeunload handler. If the handler returns false, we'll have to |
| 710 // cancel the request. | 716 // cancel the request. |
| 711 DCHECK(!pending_render_view_host_->are_navigations_suspended()); | 717 DCHECK(!pending_render_view_host_->are_navigations_suspended()); |
| 712 pending_render_view_host_->SetNavigationsSuspended(true); | 718 pending_render_view_host_->SetNavigationsSuspended(true); |
| 713 | 719 |
| 714 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site | 720 // Tell the CrossSiteRequestManager that this RVH has a pending cross-site |
| 715 // request, so that ResourceDispatcherHost will know to tell us to run the | 721 // request, so that ResourceDispatcherHost will know to tell us to run the |
| 716 // old page's onunload handler before it sends the response. | 722 // old page's onunload handler before it sends the response. |
| 717 pending_render_view_host_->SetHasPendingCrossSiteRequest(true, -1); | 723 pending_render_view_host_->SetHasPendingCrossSiteRequest(true, -1); |
| 718 | 724 |
| 719 // We now have a pending RVH. | 725 // We now have a pending RVH. |
| 720 DCHECK(!cross_navigation_pending_); | 726 DCHECK(!cross_navigation_pending_); |
| 721 cross_navigation_pending_ = true; | 727 cross_navigation_pending_ = true; |
|
Charlie Reis
2011/11/21 19:29:02
It looks like it might be safe to move this block
battre
2011/11/21 20:59:45
I thought that the delegates in FirePageBeforeUnlo
| |
| 722 | 728 |
| 723 // Tell the old render view to run its onbeforeunload handler, since it | 729 // Tell the old render view to run its onbeforeunload handler, since it |
| 724 // doesn't otherwise know that the cross-site request is happening. This | 730 // doesn't otherwise know that the cross-site request is happening. This |
| 725 // will trigger a call to ShouldClosePage with the reply. | 731 // will trigger a call to ShouldClosePage with the reply. |
| 726 render_view_host_->FirePageBeforeUnload(true); | 732 render_view_host_->FirePageBeforeUnload(true); |
| 733 } else { | |
| 734 // As the render_view_host_ is already swapped out, we do not need | |
| 735 // to instruct it to unload. Therefore, we also do not need to suspend | |
| 736 // outgoing navigation messages | |
|
Charlie Reis
2011/11/21 19:29:02
Nit:
// to instruct it to run its beforeunload or
battre
2011/11/21 20:59:45
I have put this comment into an otherwise empty el
| |
| 737 | |
| 738 // We now have a pending RVH. | |
| 739 DCHECK(!cross_navigation_pending_); | |
| 740 cross_navigation_pending_ = true; | |
| 741 } | |
| 727 | 742 |
| 728 return pending_render_view_host_; | 743 return pending_render_view_host_; |
| 729 } else { | 744 } else { |
| 730 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive()) | 745 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive()) |
| 731 pending_web_ui_->RenderViewReused(render_view_host_); | 746 pending_web_ui_->RenderViewReused(render_view_host_); |
| 732 | 747 |
| 733 // The renderer can exit view source mode when any error or cancellation | 748 // The renderer can exit view source mode when any error or cancellation |
| 734 // happen. We must overwrite to recover the mode. | 749 // happen. We must overwrite to recover the mode. |
| 735 if (entry.IsViewSourceMode()) { | 750 if (entry.IsViewSourceMode()) { |
| 736 render_view_host_->Send( | 751 render_view_host_->Send( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 804 } | 819 } |
| 805 } | 820 } |
| 806 | 821 |
| 807 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 822 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
| 808 if (!rvh->site_instance()) | 823 if (!rvh->site_instance()) |
| 809 return false; | 824 return false; |
| 810 | 825 |
| 811 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 826 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
| 812 swapped_out_hosts_.end(); | 827 swapped_out_hosts_.end(); |
| 813 } | 828 } |
| OLD | NEW |