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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 enabled_bindings_(0), | 205 enabled_bindings_(0), |
206 navigations_suspended_(false), | 206 navigations_suspended_(false), |
207 has_accessed_initial_document_(false), | 207 has_accessed_initial_document_(false), |
208 main_frame_routing_id_(main_frame_routing_id), | 208 main_frame_routing_id_(main_frame_routing_id), |
209 is_waiting_for_beforeunload_ack_(false), | 209 is_waiting_for_beforeunload_ack_(false), |
210 unload_ack_is_for_cross_site_transition_(false), | 210 unload_ack_is_for_cross_site_transition_(false), |
211 are_javascript_messages_suppressed_(false), | 211 are_javascript_messages_suppressed_(false), |
212 sudden_termination_allowed_(false), | 212 sudden_termination_allowed_(false), |
213 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), | 213 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
214 virtual_keyboard_requested_(false), | 214 virtual_keyboard_requested_(false), |
| 215 copy_requests_(0), |
215 weak_factory_(this) { | 216 weak_factory_(this) { |
216 DCHECK(instance_.get()); | 217 DCHECK(instance_.get()); |
217 CHECK(delegate_); // http://crbug.com/82827 | 218 CHECK(delegate_); // http://crbug.com/82827 |
218 | 219 |
219 GetProcess()->EnableSendQueue(); | 220 GetProcess()->EnableSendQueue(); |
220 | 221 |
221 if (swapped_out) { | 222 if (swapped_out) { |
222 rvh_state_ = STATE_SWAPPED_OUT; | 223 rvh_state_ = STATE_SWAPPED_OUT; |
223 } else { | 224 } else { |
224 rvh_state_ = STATE_DEFAULT; | 225 rvh_state_ = STATE_DEFAULT; |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 702 |
702 switch (rvh_state_) { | 703 switch (rvh_state_) { |
703 case STATE_WAITING_FOR_UNLOAD_ACK: | 704 case STATE_WAITING_FOR_UNLOAD_ACK: |
704 SetState(STATE_WAITING_FOR_COMMIT); | 705 SetState(STATE_WAITING_FOR_COMMIT); |
705 break; | 706 break; |
706 case STATE_PENDING_SWAP_OUT: | 707 case STATE_PENDING_SWAP_OUT: |
707 SetState(STATE_SWAPPED_OUT); | 708 SetState(STATE_SWAPPED_OUT); |
708 break; | 709 break; |
709 case STATE_PENDING_SHUTDOWN: | 710 case STATE_PENDING_SHUTDOWN: |
710 DCHECK(!pending_shutdown_on_swap_out_.is_null()); | 711 DCHECK(!pending_shutdown_on_swap_out_.is_null()); |
711 pending_shutdown_on_swap_out_.Run(); | 712 if (copy_requests_ == 0) |
| 713 pending_shutdown_on_swap_out_.Run(); |
712 break; | 714 break; |
713 default: | 715 default: |
714 NOTREACHED(); | 716 NOTREACHED(); |
715 } | 717 } |
716 } | 718 } |
717 | 719 |
718 void RenderViewHostImpl::WasSwappedOut( | 720 void RenderViewHostImpl::WasSwappedOut( |
719 const base::Closure& pending_delete_on_swap_out) { | 721 const base::Closure& pending_delete_on_swap_out) { |
720 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); | 722 if (copy_requests_ == 0) |
| 723 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); |
721 if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) { | 724 if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) { |
722 SetState(STATE_PENDING_SWAP_OUT); | 725 SetState(STATE_PENDING_SWAP_OUT); |
723 if (!instance_->active_view_count()) | 726 if (!instance_->active_view_count() || |
| 727 (instance_->active_view_count() - copy_requests_) == 0) { |
724 SetPendingShutdown(pending_delete_on_swap_out); | 728 SetPendingShutdown(pending_delete_on_swap_out); |
| 729 } |
725 } else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) { | 730 } else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) { |
726 SetState(STATE_SWAPPED_OUT); | 731 SetState(STATE_SWAPPED_OUT); |
727 } else if (rvh_state_ == STATE_DEFAULT) { | 732 } else if (rvh_state_ == STATE_DEFAULT) { |
728 // When the RenderView is not live, the RenderFrameHostManager will call | 733 // When the RenderView is not live, the RenderFrameHostManager will call |
729 // CommitPending directly, without calling SwapOut on the old RVH. This will | 734 // CommitPending directly, without calling SwapOut on the old RVH. This will |
730 // cause WasSwappedOut to be called directly on the live old RVH. | 735 // cause WasSwappedOut to be called directly on the live old RVH. |
731 DCHECK(!IsRenderViewLive()); | 736 DCHECK(!IsRenderViewLive()); |
732 SetState(STATE_SWAPPED_OUT); | 737 SetState(STATE_SWAPPED_OUT); |
733 } else { | 738 } else { |
734 NOTREACHED(); | 739 NOTREACHED(); |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1787 const GetAudioOutputControllersCallback& callback) const { | 1792 const GetAudioOutputControllersCallback& callback) const { |
1788 AudioRendererHost* audio_host = | 1793 AudioRendererHost* audio_host = |
1789 static_cast<RenderProcessHostImpl*>(GetProcess())->audio_renderer_host(); | 1794 static_cast<RenderProcessHostImpl*>(GetProcess())->audio_renderer_host(); |
1790 audio_host->GetOutputControllers(GetRoutingID(), callback); | 1795 audio_host->GetOutputControllers(GetRoutingID(), callback); |
1791 } | 1796 } |
1792 | 1797 |
1793 void RenderViewHostImpl::ClearFocusedElement() { | 1798 void RenderViewHostImpl::ClearFocusedElement() { |
1794 Send(new ViewMsg_ClearFocusedElement(GetRoutingID())); | 1799 Send(new ViewMsg_ClearFocusedElement(GetRoutingID())); |
1795 } | 1800 } |
1796 | 1801 |
| 1802 void RenderViewHostImpl::CopyFromBackingStoreCallback( |
| 1803 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1804 bool success, |
| 1805 const SkBitmap& bitmap) { |
| 1806 --copy_requests_; |
| 1807 LOG(ERROR) << "Done with a request: " << copy_requests_; |
| 1808 callback.Run(success, bitmap); |
| 1809 if (copy_requests_ == 0) { |
| 1810 if (!IsRVHStateActive(rvh_state_)) { |
| 1811 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); |
| 1812 instance_->decrement_active_view_count(); |
| 1813 } |
| 1814 |
| 1815 if (rvh_state_ == STATE_PENDING_SHUTDOWN) { |
| 1816 DCHECK(!pending_shutdown_on_swap_out_.is_null()); |
| 1817 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1818 pending_shutdown_on_swap_out_); |
| 1819 } |
| 1820 } |
| 1821 } |
| 1822 |
| 1823 void RenderViewHostImpl::CopyFromBackingStore( |
| 1824 const gfx::Rect& src_rect, |
| 1825 const gfx::Size& accelerated_dst_size, |
| 1826 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 1827 DCHECK(IsRVHStateActive(rvh_state_)); |
| 1828 if (!IsRVHStateActive(rvh_state_)) { |
| 1829 callback.Run(false, SkBitmap()); |
| 1830 return; |
| 1831 } |
| 1832 ++copy_requests_; |
| 1833 LOG(ERROR) << "Starting a request: " << copy_requests_; |
| 1834 RenderWidgetHostImpl::CopyFromBackingStore(src_rect, accelerated_dst_size, |
| 1835 base::Bind(&RenderViewHostImpl::CopyFromBackingStoreCallback, |
| 1836 weak_factory_.GetWeakPtr(), |
| 1837 callback)); |
| 1838 } |
| 1839 |
1797 void RenderViewHostImpl::Zoom(PageZoom zoom) { | 1840 void RenderViewHostImpl::Zoom(PageZoom zoom) { |
1798 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); | 1841 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); |
1799 } | 1842 } |
1800 | 1843 |
1801 void RenderViewHostImpl::ReloadFrame() { | 1844 void RenderViewHostImpl::ReloadFrame() { |
1802 Send(new ViewMsg_ReloadFrame(GetRoutingID())); | 1845 Send(new ViewMsg_ReloadFrame(GetRoutingID())); |
1803 } | 1846 } |
1804 | 1847 |
1805 void RenderViewHostImpl::InsertCSS(const base::string16& frame_xpath, | 1848 void RenderViewHostImpl::InsertCSS(const base::string16& frame_xpath, |
1806 const std::string& css) { | 1849 const std::string& css) { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1973 params.allow_multiple_selection); | 2016 params.allow_multiple_selection); |
1974 } | 2017 } |
1975 } | 2018 } |
1976 #endif | 2019 #endif |
1977 | 2020 |
1978 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) { | 2021 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) { |
1979 // We update the number of RenderViews in a SiteInstance when the | 2022 // We update the number of RenderViews in a SiteInstance when the |
1980 // swapped out status of this RenderView gets flipped to/from live. | 2023 // swapped out status of this RenderView gets flipped to/from live. |
1981 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state)) | 2024 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state)) |
1982 instance_->increment_active_view_count(); | 2025 instance_->increment_active_view_count(); |
1983 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state)) | 2026 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state) && |
| 2027 copy_requests_ == 0) |
1984 instance_->decrement_active_view_count(); | 2028 instance_->decrement_active_view_count(); |
1985 | 2029 |
1986 // Whenever we change the RVH state to and from live or swapped out state, we | 2030 // Whenever we change the RVH state to and from live or swapped out state, we |
1987 // should not be waiting for beforeunload or unload acks. We clear them here | 2031 // should not be waiting for beforeunload or unload acks. We clear them here |
1988 // to be safe, since they can cause navigations to be ignored in OnNavigate. | 2032 // to be safe, since they can cause navigations to be ignored in OnNavigate. |
1989 if (rvh_state == STATE_DEFAULT || | 2033 if (rvh_state == STATE_DEFAULT || |
1990 rvh_state == STATE_SWAPPED_OUT || | 2034 rvh_state == STATE_SWAPPED_OUT || |
1991 rvh_state_ == STATE_DEFAULT || | 2035 rvh_state_ == STATE_DEFAULT || |
1992 rvh_state_ == STATE_SWAPPED_OUT) { | 2036 rvh_state_ == STATE_SWAPPED_OUT) { |
1993 is_waiting_for_beforeunload_ack_ = false; | 2037 is_waiting_for_beforeunload_ack_ = false; |
(...skipping 16 matching lines...) Expand all Loading... |
2010 return true; | 2054 return true; |
2011 } | 2055 } |
2012 | 2056 |
2013 void RenderViewHostImpl::AttachToFrameTree() { | 2057 void RenderViewHostImpl::AttachToFrameTree() { |
2014 FrameTree* frame_tree = delegate_->GetFrameTree(); | 2058 FrameTree* frame_tree = delegate_->GetFrameTree(); |
2015 | 2059 |
2016 frame_tree->ResetForMainFrameSwap(); | 2060 frame_tree->ResetForMainFrameSwap(); |
2017 } | 2061 } |
2018 | 2062 |
2019 } // namespace content | 2063 } // namespace content |
OLD | NEW |