Chromium Code Reviews| 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/renderer_host/render_view_host_impl.h" | 5 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 has_accessed_initial_document_(false), | 206 has_accessed_initial_document_(false), |
| 207 main_frame_routing_id_(main_frame_routing_id), | 207 main_frame_routing_id_(main_frame_routing_id), |
| 208 run_modal_reply_msg_(NULL), | 208 run_modal_reply_msg_(NULL), |
| 209 run_modal_opener_id_(MSG_ROUTING_NONE), | 209 run_modal_opener_id_(MSG_ROUTING_NONE), |
| 210 is_waiting_for_beforeunload_ack_(false), | 210 is_waiting_for_beforeunload_ack_(false), |
| 211 unload_ack_is_for_cross_site_transition_(false), | 211 unload_ack_is_for_cross_site_transition_(false), |
| 212 are_javascript_messages_suppressed_(false), | 212 are_javascript_messages_suppressed_(false), |
| 213 sudden_termination_allowed_(false), | 213 sudden_termination_allowed_(false), |
| 214 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), | 214 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 215 virtual_keyboard_requested_(false), | 215 virtual_keyboard_requested_(false), |
| 216 copy_requests_(0), | |
| 216 weak_factory_(this) { | 217 weak_factory_(this) { |
| 217 DCHECK(instance_.get()); | 218 DCHECK(instance_.get()); |
| 218 CHECK(delegate_); // http://crbug.com/82827 | 219 CHECK(delegate_); // http://crbug.com/82827 |
| 219 | 220 |
| 220 GetProcess()->EnableSendQueue(); | 221 GetProcess()->EnableSendQueue(); |
| 221 | 222 |
| 222 if (swapped_out) { | 223 if (swapped_out) { |
| 223 rvh_state_ = STATE_SWAPPED_OUT; | 224 rvh_state_ = STATE_SWAPPED_OUT; |
| 224 } else { | 225 } else { |
| 225 rvh_state_ = STATE_DEFAULT; | 226 rvh_state_ = STATE_DEFAULT; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 249 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, | 250 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, |
| 250 base::Unretained(ResourceDispatcherHostImpl::Get()), | 251 base::Unretained(ResourceDispatcherHostImpl::Get()), |
| 251 GetProcess()->GetID(), GetRoutingID())); | 252 GetProcess()->GetID(), GetRoutingID())); |
| 252 } | 253 } |
| 253 | 254 |
| 254 delegate_->RenderViewDeleted(this); | 255 delegate_->RenderViewDeleted(this); |
| 255 | 256 |
| 256 // Be sure to clean up any leftover state from cross-site requests. | 257 // Be sure to clean up any leftover state from cross-site requests. |
| 257 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( | 258 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( |
| 258 GetProcess()->GetID(), GetRoutingID(), false); | 259 GetProcess()->GetID(), GetRoutingID(), false); |
| 259 | 260 |
|
nasko
2014/03/26 22:48:27
Since we don't want to delete this object before a
mfomitchev
2014/03/27 21:51:34
Done.
| |
| 260 // If this was swapped out, it already decremented the active view | 261 // If this was swapped out, it already decremented the active view |
| 261 // count of the SiteInstance it belongs to. | 262 // count of the SiteInstance it belongs to. |
| 262 if (IsRVHStateActive(rvh_state_)) | 263 if (IsRVHStateActive(rvh_state_)) |
| 263 instance_->decrement_active_view_count(); | 264 instance_->decrement_active_view_count(); |
| 264 } | 265 } |
| 265 | 266 |
| 266 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { | 267 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { |
| 267 return delegate_; | 268 return delegate_; |
| 268 } | 269 } |
| 269 | 270 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 | 638 |
| 638 switch (rvh_state_) { | 639 switch (rvh_state_) { |
| 639 case STATE_WAITING_FOR_UNLOAD_ACK: | 640 case STATE_WAITING_FOR_UNLOAD_ACK: |
| 640 SetState(STATE_WAITING_FOR_COMMIT); | 641 SetState(STATE_WAITING_FOR_COMMIT); |
| 641 break; | 642 break; |
| 642 case STATE_PENDING_SWAP_OUT: | 643 case STATE_PENDING_SWAP_OUT: |
| 643 SetState(STATE_SWAPPED_OUT); | 644 SetState(STATE_SWAPPED_OUT); |
| 644 break; | 645 break; |
| 645 case STATE_PENDING_SHUTDOWN: | 646 case STATE_PENDING_SHUTDOWN: |
| 646 DCHECK(!pending_shutdown_on_swap_out_.is_null()); | 647 DCHECK(!pending_shutdown_on_swap_out_.is_null()); |
| 647 pending_shutdown_on_swap_out_.Run(); | 648 if (copy_requests_ == 0) |
| 649 pending_shutdown_on_swap_out_.Run(); | |
| 648 break; | 650 break; |
| 649 default: | 651 default: |
| 650 NOTREACHED(); | 652 NOTREACHED(); |
| 651 } | 653 } |
| 652 } | 654 } |
| 653 | 655 |
| 654 void RenderViewHostImpl::WasSwappedOut( | 656 void RenderViewHostImpl::WasSwappedOut( |
| 655 const base::Closure& pending_delete_on_swap_out) { | 657 const base::Closure& pending_delete_on_swap_out) { |
| 656 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); | 658 if (copy_requests_ == 0) |
|
nasko
2014/03/26 22:48:27
nit: A comment explaining why we aren't sending th
mfomitchev
2014/03/27 21:51:34
Done.
| |
| 659 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); | |
| 657 if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) { | 660 if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) { |
| 658 SetState(STATE_PENDING_SWAP_OUT); | 661 SetState(STATE_PENDING_SWAP_OUT); |
| 659 if (!instance_->active_view_count()) | 662 if (!instance_->active_view_count() || |
| 663 (instance_->active_view_count() - copy_requests_) == 0) { | |
|
clamy
2014/03/27 15:59:36
I don't think this is correct. If you have 2 copy
mfomitchev
2014/03/27 21:51:34
Ok, so the reason we were doing this was that RVH
| |
| 660 SetPendingShutdown(pending_delete_on_swap_out); | 664 SetPendingShutdown(pending_delete_on_swap_out); |
| 665 } | |
| 661 } else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) { | 666 } else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) { |
| 662 SetState(STATE_SWAPPED_OUT); | 667 SetState(STATE_SWAPPED_OUT); |
| 663 } else if (rvh_state_ == STATE_DEFAULT) { | 668 } else if (rvh_state_ == STATE_DEFAULT) { |
| 664 // When the RenderView is not live, the RenderFrameHostManager will call | 669 // When the RenderView is not live, the RenderFrameHostManager will call |
| 665 // CommitPending directly, without calling SwapOut on the old RVH. This will | 670 // CommitPending directly, without calling SwapOut on the old RVH. This will |
| 666 // cause WasSwappedOut to be called directly on the live old RVH. | 671 // cause WasSwappedOut to be called directly on the live old RVH. |
| 667 DCHECK(!IsRenderViewLive()); | 672 DCHECK(!IsRenderViewLive()); |
| 668 SetState(STATE_SWAPPED_OUT); | 673 SetState(STATE_SWAPPED_OUT); |
| 669 } else { | 674 } else { |
| 670 NOTREACHED(); | 675 NOTREACHED(); |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1702 const GetAudioOutputControllersCallback& callback) const { | 1707 const GetAudioOutputControllersCallback& callback) const { |
| 1703 AudioRendererHost* audio_host = | 1708 AudioRendererHost* audio_host = |
| 1704 static_cast<RenderProcessHostImpl*>(GetProcess())->audio_renderer_host(); | 1709 static_cast<RenderProcessHostImpl*>(GetProcess())->audio_renderer_host(); |
| 1705 audio_host->GetOutputControllers(GetRoutingID(), callback); | 1710 audio_host->GetOutputControllers(GetRoutingID(), callback); |
| 1706 } | 1711 } |
| 1707 | 1712 |
| 1708 void RenderViewHostImpl::ClearFocusedElement() { | 1713 void RenderViewHostImpl::ClearFocusedElement() { |
| 1709 Send(new ViewMsg_ClearFocusedElement(GetRoutingID())); | 1714 Send(new ViewMsg_ClearFocusedElement(GetRoutingID())); |
| 1710 } | 1715 } |
| 1711 | 1716 |
| 1717 void RenderViewHostImpl::CopyFromBackingStoreCallback( | |
| 1718 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 1719 bool success, | |
| 1720 const SkBitmap& bitmap) { | |
| 1721 --copy_requests_; | |
| 1722 callback.Run(success, bitmap); | |
| 1723 if (copy_requests_ == 0) { | |
| 1724 if (!IsRVHStateActive(rvh_state_)) { | |
|
nasko
2014/03/26 22:48:27
Since we are only trying to delay the shutdown, th
mfomitchev
2014/03/27 21:51:34
This looks fine to me, maybe I am missing somethin
| |
| 1725 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); | |
| 1726 instance_->decrement_active_view_count(); | |
|
nasko
2014/03/26 22:48:27
A comment explaining what we are doing here is def
mfomitchev
2014/03/27 21:51:34
Think it should be more clear now with pending_shu
| |
| 1727 } | |
| 1728 | |
| 1729 if (rvh_state_ == STATE_PENDING_SHUTDOWN) { | |
| 1730 DCHECK(!pending_shutdown_on_swap_out_.is_null()); | |
| 1731 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
|
mfomitchev
2014/03/26 18:59:30
I am wondering if we can have a situation where th
clamy
2014/03/27 15:59:36
What pending_shutdown_on_swap_out_ does is remove
mfomitchev
2014/03/27 21:51:34
Added pending_shutdown_on_copy_requests_done_ to a
| |
| 1732 pending_shutdown_on_swap_out_); | |
|
nasko
2014/03/26 22:48:27
I don't see why we need to delay the shutdown here
mfomitchev
2014/03/27 21:51:34
Done. Sadrul mentioned that he saw something on th
| |
| 1733 } | |
| 1734 } | |
| 1735 } | |
| 1736 | |
| 1737 void RenderViewHostImpl::CopyFromBackingStore( | |
| 1738 const gfx::Rect& src_rect, | |
| 1739 const gfx::Size& accelerated_dst_size, | |
| 1740 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 1741 const SkBitmap::Config& bitmap_config) { | |
| 1742 DCHECK(IsRVHStateActive(rvh_state_)); | |
| 1743 if (!IsRVHStateActive(rvh_state_)) { | |
| 1744 callback.Run(false, SkBitmap()); | |
| 1745 return; | |
| 1746 } | |
| 1747 ++copy_requests_; | |
| 1748 RenderWidgetHostImpl::CopyFromBackingStore(src_rect, accelerated_dst_size, | |
| 1749 base::Bind(&RenderViewHostImpl::CopyFromBackingStoreCallback, | |
| 1750 weak_factory_.GetWeakPtr(), | |
| 1751 callback), | |
| 1752 bitmap_config); | |
| 1753 } | |
| 1754 | |
| 1712 void RenderViewHostImpl::Zoom(PageZoom zoom) { | 1755 void RenderViewHostImpl::Zoom(PageZoom zoom) { |
| 1713 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); | 1756 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); |
| 1714 } | 1757 } |
| 1715 | 1758 |
| 1716 void RenderViewHostImpl::ReloadFrame() { | 1759 void RenderViewHostImpl::ReloadFrame() { |
| 1717 Send(new ViewMsg_ReloadFrame(GetRoutingID())); | 1760 Send(new ViewMsg_ReloadFrame(GetRoutingID())); |
| 1718 } | 1761 } |
| 1719 | 1762 |
| 1720 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) { | 1763 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) { |
| 1721 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size)); | 1764 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size)); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 params.allow_multiple_selection); | 1938 params.allow_multiple_selection); |
| 1896 } | 1939 } |
| 1897 } | 1940 } |
| 1898 #endif | 1941 #endif |
| 1899 | 1942 |
| 1900 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) { | 1943 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) { |
| 1901 // We update the number of RenderViews in a SiteInstance when the | 1944 // We update the number of RenderViews in a SiteInstance when the |
| 1902 // swapped out status of this RenderView gets flipped to/from live. | 1945 // swapped out status of this RenderView gets flipped to/from live. |
| 1903 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state)) | 1946 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state)) |
| 1904 instance_->increment_active_view_count(); | 1947 instance_->increment_active_view_count(); |
| 1905 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state)) | 1948 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state) && |
| 1949 copy_requests_ == 0) | |
| 1906 instance_->decrement_active_view_count(); | 1950 instance_->decrement_active_view_count(); |
| 1907 | 1951 |
| 1908 // Whenever we change the RVH state to and from live or swapped out state, we | 1952 // Whenever we change the RVH state to and from live or swapped out state, we |
| 1909 // should not be waiting for beforeunload or unload acks. We clear them here | 1953 // should not be waiting for beforeunload or unload acks. We clear them here |
| 1910 // to be safe, since they can cause navigations to be ignored in OnNavigate. | 1954 // to be safe, since they can cause navigations to be ignored in OnNavigate. |
| 1911 if (rvh_state == STATE_DEFAULT || | 1955 if (rvh_state == STATE_DEFAULT || |
| 1912 rvh_state == STATE_SWAPPED_OUT || | 1956 rvh_state == STATE_SWAPPED_OUT || |
| 1913 rvh_state_ == STATE_DEFAULT || | 1957 rvh_state_ == STATE_DEFAULT || |
| 1914 rvh_state_ == STATE_SWAPPED_OUT) { | 1958 rvh_state_ == STATE_SWAPPED_OUT) { |
| 1915 is_waiting_for_beforeunload_ack_ = false; | 1959 is_waiting_for_beforeunload_ack_ = false; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1932 return true; | 1976 return true; |
| 1933 } | 1977 } |
| 1934 | 1978 |
| 1935 void RenderViewHostImpl::AttachToFrameTree() { | 1979 void RenderViewHostImpl::AttachToFrameTree() { |
| 1936 FrameTree* frame_tree = delegate_->GetFrameTree(); | 1980 FrameTree* frame_tree = delegate_->GetFrameTree(); |
| 1937 | 1981 |
| 1938 frame_tree->ResetForMainFrameSwap(); | 1982 frame_tree->ResetForMainFrameSwap(); |
| 1939 } | 1983 } |
| 1940 | 1984 |
| 1941 } // namespace content | 1985 } // namespace content |
| OLD | NEW |