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); |
| 724 |
| 725 // Tell the old render view to run its onbeforeunload handler, since it |
| 726 // doesn't otherwise know that the cross-site request is happening. This |
| 727 // will trigger a call to ShouldClosePage with the reply. |
| 728 render_view_host_->FirePageBeforeUnload(true); |
| 729 } else { |
| 730 // As the render_view_host_ is already swapped out, we do not need |
| 731 // to instruct it to run its beforeunload or unload handlers. Therefore, |
| 732 // we also do not need to suspend outgoing navigation messages and can |
| 733 // just let the new pending_render_view_host_ immediately navigate. |
| 734 } |
718 | 735 |
719 // We now have a pending RVH. | 736 // We now have a pending RVH. |
720 DCHECK(!cross_navigation_pending_); | 737 DCHECK(!cross_navigation_pending_); |
721 cross_navigation_pending_ = true; | 738 cross_navigation_pending_ = true; |
722 | 739 |
723 // 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 | |
725 // will trigger a call to ShouldClosePage with the reply. | |
726 render_view_host_->FirePageBeforeUnload(true); | |
727 | |
728 return pending_render_view_host_; | 740 return pending_render_view_host_; |
729 } else { | 741 } else { |
730 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive()) | 742 if (pending_web_ui_.get() && render_view_host_->IsRenderViewLive()) |
731 pending_web_ui_->RenderViewReused(render_view_host_); | 743 pending_web_ui_->RenderViewReused(render_view_host_); |
732 | 744 |
733 // The renderer can exit view source mode when any error or cancellation | 745 // The renderer can exit view source mode when any error or cancellation |
734 // happen. We must overwrite to recover the mode. | 746 // happen. We must overwrite to recover the mode. |
735 if (entry.IsViewSourceMode()) { | 747 if (entry.IsViewSourceMode()) { |
736 render_view_host_->Send( | 748 render_view_host_->Send( |
737 new ViewMsg_EnableViewSourceMode(render_view_host_->routing_id())); | 749 new ViewMsg_EnableViewSourceMode(render_view_host_->routing_id())); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 } | 816 } |
805 } | 817 } |
806 | 818 |
807 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 819 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
808 if (!rvh->site_instance()) | 820 if (!rvh->site_instance()) |
809 return false; | 821 return false; |
810 | 822 |
811 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 823 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
812 swapped_out_hosts_.end(); | 824 swapped_out_hosts_.end(); |
813 } | 825 } |
OLD | NEW |