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

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.cc

Issue 88503002: Have the unload event execute in background on cross-site navigations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests Created 6 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/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 17 matching lines...) Expand all
28 #include "content/browser/cross_site_request_manager.h" 28 #include "content/browser/cross_site_request_manager.h"
29 #include "content/browser/dom_storage/session_storage_namespace_impl.h" 29 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
30 #include "content/browser/frame_host/frame_tree.h" 30 #include "content/browser/frame_host/frame_tree.h"
31 #include "content/browser/gpu/compositor_util.h" 31 #include "content/browser/gpu/compositor_util.h"
32 #include "content/browser/gpu/gpu_data_manager_impl.h" 32 #include "content/browser/gpu/gpu_data_manager_impl.h"
33 #include "content/browser/gpu/gpu_process_host.h" 33 #include "content/browser/gpu/gpu_process_host.h"
34 #include "content/browser/gpu/gpu_surface_tracker.h" 34 #include "content/browser/gpu/gpu_surface_tracker.h"
35 #include "content/browser/host_zoom_map_impl.h" 35 #include "content/browser/host_zoom_map_impl.h"
36 #include "content/browser/loader/resource_dispatcher_host_impl.h" 36 #include "content/browser/loader/resource_dispatcher_host_impl.h"
37 #include "content/browser/renderer_host/dip_util.h" 37 #include "content/browser/renderer_host/dip_util.h"
38 #include "content/browser/renderer_host/input/timeout_monitor.h"
38 #include "content/browser/renderer_host/media/audio_renderer_host.h" 39 #include "content/browser/renderer_host/media/audio_renderer_host.h"
39 #include "content/browser/renderer_host/render_process_host_impl.h" 40 #include "content/browser/renderer_host/render_process_host_impl.h"
40 #include "content/browser/renderer_host/render_view_host_delegate.h" 41 #include "content/browser/renderer_host/render_view_host_delegate.h"
41 #include "content/common/accessibility_messages.h" 42 #include "content/common/accessibility_messages.h"
42 #include "content/common/browser_plugin/browser_plugin_messages.h" 43 #include "content/common/browser_plugin/browser_plugin_messages.h"
43 #include "content/common/desktop_notification_messages.h" 44 #include "content/common/desktop_notification_messages.h"
44 #include "content/common/drag_messages.h" 45 #include "content/common/drag_messages.h"
45 #include "content/common/input_messages.h" 46 #include "content/common/input_messages.h"
46 #include "content/common/inter_process_time_ticks_converter.h" 47 #include "content/common/inter_process_time_ticks_converter.h"
47 #include "content/common/speech_recognition_messages.h" 48 #include "content/common/speech_recognition_messages.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 143 }
143 } 144 }
144 #endif 145 #endif
145 146
146 } // namespace 147 } // namespace
147 148
148 /////////////////////////////////////////////////////////////////////////////// 149 ///////////////////////////////////////////////////////////////////////////////
149 // RenderViewHost, public: 150 // RenderViewHost, public:
150 151
151 // static 152 // static
153 bool RenderViewHostImpl::IsRVHStateActive(RenderViewHostImplState rvh_state) {
154 if (rvh_state == RVH_STATE_LIVE ||
155 rvh_state == RVH_STATE_WAITING_FOR_UNLOAD_ACK ||
156 rvh_state == RVH_STATE_WAITING_FOR_COMMIT ||
157 rvh_state == RVH_STATE_WAITING_FOR_CLOSE)
158 return true;
159 return false;
160 }
161
162 // static
152 RenderViewHost* RenderViewHost::FromID(int render_process_id, 163 RenderViewHost* RenderViewHost::FromID(int render_process_id,
153 int render_view_id) { 164 int render_view_id) {
154 return RenderViewHostImpl::FromID(render_process_id, render_view_id); 165 return RenderViewHostImpl::FromID(render_process_id, render_view_id);
155 } 166 }
156 167
157 // static 168 // static
158 RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) { 169 RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) {
159 DCHECK(rwh->IsRenderView()); 170 DCHECK(rwh->IsRenderView());
160 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh)); 171 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh));
161 } 172 }
(...skipping 16 matching lines...) Expand all
178 RenderViewHostDelegate* delegate, 189 RenderViewHostDelegate* delegate,
179 RenderWidgetHostDelegate* widget_delegate, 190 RenderWidgetHostDelegate* widget_delegate,
180 int routing_id, 191 int routing_id,
181 int main_frame_routing_id, 192 int main_frame_routing_id,
182 bool swapped_out, 193 bool swapped_out,
183 bool hidden) 194 bool hidden)
184 : RenderWidgetHostImpl(widget_delegate, 195 : RenderWidgetHostImpl(widget_delegate,
185 instance->GetProcess(), 196 instance->GetProcess(),
186 routing_id, 197 routing_id,
187 hidden), 198 hidden),
199 ref_count_(0),
188 delegate_(delegate), 200 delegate_(delegate),
189 instance_(static_cast<SiteInstanceImpl*>(instance)), 201 instance_(static_cast<SiteInstanceImpl*>(instance)),
190 waiting_for_drag_context_response_(false), 202 waiting_for_drag_context_response_(false),
191 enabled_bindings_(0), 203 enabled_bindings_(0),
192 navigations_suspended_(false), 204 navigations_suspended_(false),
193 has_accessed_initial_document_(false), 205 has_accessed_initial_document_(false),
194 is_swapped_out_(swapped_out),
195 main_frame_id_(-1), 206 main_frame_id_(-1),
196 main_frame_routing_id_(main_frame_routing_id), 207 main_frame_routing_id_(main_frame_routing_id),
197 run_modal_reply_msg_(NULL), 208 run_modal_reply_msg_(NULL),
198 run_modal_opener_id_(MSG_ROUTING_NONE), 209 run_modal_opener_id_(MSG_ROUTING_NONE),
199 is_waiting_for_beforeunload_ack_(false), 210 is_waiting_for_beforeunload_ack_(false),
200 is_waiting_for_unload_ack_(false),
201 has_timed_out_on_unload_(false),
202 unload_ack_is_for_cross_site_transition_(false), 211 unload_ack_is_for_cross_site_transition_(false),
203 are_javascript_messages_suppressed_(false), 212 are_javascript_messages_suppressed_(false),
204 sudden_termination_allowed_(false), 213 sudden_termination_allowed_(false),
205 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), 214 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING),
206 virtual_keyboard_requested_(false) { 215 virtual_keyboard_requested_(false),
216 weak_factory_(this) {
207 DCHECK(instance_.get()); 217 DCHECK(instance_.get());
208 CHECK(delegate_); // http://crbug.com/82827 218 CHECK(delegate_); // http://crbug.com/82827
209 219
210 GetProcess()->EnableSendQueue(); 220 GetProcess()->EnableSendQueue();
211 221
212 if (!swapped_out) 222 if (swapped_out) {
223 rvh_state_ = RVH_STATE_SWAPPED_OUT;
224 } else {
225 rvh_state_ = RVH_STATE_LIVE;
213 instance_->increment_active_view_count(); 226 instance_->increment_active_view_count();
227 }
214 228
215 if (ResourceDispatcherHostImpl::Get()) { 229 if (ResourceDispatcherHostImpl::Get()) {
216 BrowserThread::PostTask( 230 BrowserThread::PostTask(
217 BrowserThread::IO, FROM_HERE, 231 BrowserThread::IO, FROM_HERE,
218 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated, 232 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated,
219 base::Unretained(ResourceDispatcherHostImpl::Get()), 233 base::Unretained(ResourceDispatcherHostImpl::Get()),
220 GetProcess()->GetID(), GetRoutingID())); 234 GetProcess()->GetID(), GetRoutingID()));
221 } 235 }
222 236
223 #if defined(OS_ANDROID) 237 #if defined(OS_ANDROID)
224 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this)); 238 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this));
225 #endif 239 #endif
240
241 unload_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind(
242 &RenderViewHostImpl::OnSwappedOut, weak_factory_.GetWeakPtr(), true)));
226 } 243 }
227 244
228 RenderViewHostImpl::~RenderViewHostImpl() { 245 RenderViewHostImpl::~RenderViewHostImpl() {
229 if (ResourceDispatcherHostImpl::Get()) { 246 if (ResourceDispatcherHostImpl::Get()) {
230 BrowserThread::PostTask( 247 BrowserThread::PostTask(
231 BrowserThread::IO, FROM_HERE, 248 BrowserThread::IO, FROM_HERE,
232 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, 249 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted,
233 base::Unretained(ResourceDispatcherHostImpl::Get()), 250 base::Unretained(ResourceDispatcherHostImpl::Get()),
234 GetProcess()->GetID(), GetRoutingID())); 251 GetProcess()->GetID(), GetRoutingID()));
235 } 252 }
236 253
237 delegate_->RenderViewDeleted(this); 254 delegate_->RenderViewDeleted(this);
238 255
239 // Be sure to clean up any leftover state from cross-site requests. 256 // Be sure to clean up any leftover state from cross-site requests.
240 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( 257 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest(
241 GetProcess()->GetID(), GetRoutingID(), false); 258 GetProcess()->GetID(), GetRoutingID(), false);
242 259
243 // If this was swapped out, it already decremented the active view 260 // If this was swapped out, it already decremented the active view
244 // count of the SiteInstance it belongs to. 261 // count of the SiteInstance it belongs to.
245 if (!is_swapped_out_) 262 if (IsRVHStateActive(rvh_state_))
246 instance_->decrement_active_view_count(); 263 instance_->decrement_active_view_count();
247 } 264 }
248 265
249 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { 266 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const {
250 return delegate_; 267 return delegate_;
251 } 268 }
252 269
253 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { 270 SiteInstance* RenderViewHostImpl::GetSiteInstance() const {
254 return instance_.get(); 271 return instance_.get();
255 } 272 }
(...skipping 30 matching lines...) Expand all
286 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext()); 303 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
287 params.web_preferences = delegate_->GetWebkitPrefs(); 304 params.web_preferences = delegate_->GetWebkitPrefs();
288 params.view_id = GetRoutingID(); 305 params.view_id = GetRoutingID();
289 params.main_frame_routing_id = main_frame_routing_id_; 306 params.main_frame_routing_id = main_frame_routing_id_;
290 params.surface_id = surface_id(); 307 params.surface_id = surface_id();
291 params.session_storage_namespace_id = 308 params.session_storage_namespace_id =
292 delegate_->GetSessionStorageNamespace(instance_)->id(); 309 delegate_->GetSessionStorageNamespace(instance_)->id();
293 params.frame_name = frame_name; 310 params.frame_name = frame_name;
294 // Ensure the RenderView sets its opener correctly. 311 // Ensure the RenderView sets its opener correctly.
295 params.opener_route_id = opener_route_id; 312 params.opener_route_id = opener_route_id;
296 params.swapped_out = is_swapped_out_; 313 params.swapped_out = !IsRVHStateActive(rvh_state_);
297 params.hidden = is_hidden(); 314 params.hidden = is_hidden();
298 params.next_page_id = next_page_id; 315 params.next_page_id = next_page_id;
299 GetWebScreenInfo(&params.screen_info); 316 GetWebScreenInfo(&params.screen_info);
300 params.accessibility_mode = accessibility_mode(); 317 params.accessibility_mode = accessibility_mode();
301 params.allow_partial_swap = !GetProcess()->IsGuest(); 318 params.allow_partial_swap = !GetProcess()->IsGuest();
302 319
303 Send(new ViewMsg_New(params)); 320 Send(new ViewMsg_New(params));
304 321
305 // If it's enabled, tell the renderer to set up the Javascript bindings for 322 // If it's enabled, tell the renderer to set up the Javascript bindings for
306 // sending messages back to the browser. 323 // sending messages back to the browser.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (navigations_suspended_) { 603 if (navigations_suspended_) {
587 // Shouldn't be possible to have a second navigation while suspended, since 604 // Shouldn't be possible to have a second navigation while suspended, since
588 // navigations will only be suspended during a cross-site request. If a 605 // navigations will only be suspended during a cross-site request. If a
589 // second navigation occurs, WebContentsImpl will cancel this pending RVH 606 // second navigation occurs, WebContentsImpl will cancel this pending RVH
590 // create a new pending RVH. 607 // create a new pending RVH.
591 DCHECK(!suspended_nav_params_.get()); 608 DCHECK(!suspended_nav_params_.get());
592 suspended_nav_params_.reset(new ViewMsg_Navigate_Params(params)); 609 suspended_nav_params_.reset(new ViewMsg_Navigate_Params(params));
593 } else { 610 } else {
594 // Get back to a clean state, in case we start a new navigation without 611 // Get back to a clean state, in case we start a new navigation without
595 // completing a RVH swap or unload handler. 612 // completing a RVH swap or unload handler.
596 SetSwappedOut(false); 613 SetRVHState(RVH_STATE_LIVE);
597 614
598 Send(new ViewMsg_Navigate(GetRoutingID(), params)); 615 Send(new ViewMsg_Navigate(GetRoutingID(), params));
599 } 616 }
600 617
601 // Force the throbber to start. We do this because WebKit's "started 618 // Force the throbber to start. We do this because WebKit's "started
602 // loading" message will be received asynchronously from the UI of the 619 // loading" message will be received asynchronously from the UI of the
603 // browser. But we want to keep the throbber in sync with what's happening 620 // browser. But we want to keep the throbber in sync with what's happening
604 // in the UI. For example, we want to start throbbing immediately when the 621 // in the UI. For example, we want to start throbbing immediately when the
605 // user naivgates even if the renderer is delayed. There is also an issue 622 // user naivgates even if the renderer is delayed. There is also an issue
606 // with the throbber starting because the WebUI (which controls whether the 623 // with the throbber starting because the WebUI (which controls whether the
(...skipping 22 matching lines...) Expand all
629 bool suspend, 646 bool suspend,
630 const base::TimeTicks& proceed_time) { 647 const base::TimeTicks& proceed_time) {
631 // This should only be called to toggle the state. 648 // This should only be called to toggle the state.
632 DCHECK(navigations_suspended_ != suspend); 649 DCHECK(navigations_suspended_ != suspend);
633 650
634 navigations_suspended_ = suspend; 651 navigations_suspended_ = suspend;
635 if (!suspend && suspended_nav_params_) { 652 if (!suspend && suspended_nav_params_) {
636 // There's navigation message params waiting to be sent. Now that we're not 653 // There's navigation message params waiting to be sent. Now that we're not
637 // suspended anymore, resume navigation by sending them. If we were swapped 654 // suspended anymore, resume navigation by sending them. If we were swapped
638 // out, we should also stop filtering out the IPC messages now. 655 // out, we should also stop filtering out the IPC messages now.
639 SetSwappedOut(false); 656 SetRVHState(RVH_STATE_LIVE);
640 657
641 DCHECK(!proceed_time.is_null()); 658 DCHECK(!proceed_time.is_null());
642 suspended_nav_params_->browser_navigation_start = proceed_time; 659 suspended_nav_params_->browser_navigation_start = proceed_time;
643 Send(new ViewMsg_Navigate(GetRoutingID(), *suspended_nav_params_.get())); 660 Send(new ViewMsg_Navigate(GetRoutingID(), *suspended_nav_params_.get()));
644 suspended_nav_params_.reset(); 661 suspended_nav_params_.reset();
645 } 662 }
646 } 663 }
647 664
648 void RenderViewHostImpl::CancelSuspendedNavigations() { 665 void RenderViewHostImpl::CancelSuspendedNavigations() {
649 // Clear any state if a pending navigation is canceled or pre-empted. 666 // Clear any state if a pending navigation is canceled or pre-empted.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 manager->OnCrossSiteResponse(this, global_request_id, is_transfer, 727 manager->OnCrossSiteResponse(this, global_request_id, is_transfer,
711 transfer_url_chain, referrer, page_transition, 728 transfer_url_chain, referrer, page_transition,
712 frame_id, should_replace_current_entry); 729 frame_id, should_replace_current_entry);
713 } 730 }
714 731
715 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() { 732 void RenderViewHostImpl::SuppressDialogsUntilSwapOut() {
716 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID())); 733 Send(new ViewMsg_SuppressDialogsUntilSwapOut(GetRoutingID()));
717 } 734 }
718 735
719 void RenderViewHostImpl::SwapOut() { 736 void RenderViewHostImpl::SwapOut() {
720 // This will be set back to false in OnSwapOutACK, just before we replace 737 SetRVHState(RVH_STATE_WAITING_FOR_UNLOAD_ACK);
721 // this RVH with the pending RVH. 738 unload_event_monitor_timeout_->Start(
722 is_waiting_for_unload_ack_ = true; 739 base::TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
723 // Start the hang monitor in case the renderer hangs in the unload handler.
724 // Increment the in-flight event count, to ensure that input events won't
725 // cancel the timeout timer.
726 increment_in_flight_event_count();
727 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
nasko 2014/01/23 23:34:58 Why is this removed? It was balanced by StopMonito
clamy 2014/01/24 17:01:54 creis expressed a preference towards not using the
nasko 2014/01/27 19:09:51 If we aren't using the hang monitor anymore, then
clamy 2014/01/28 12:27:21 Done.
728 740
729 if (IsRenderViewLive()) { 741 if (IsRenderViewLive()) {
730 Send(new ViewMsg_SwapOut(GetRoutingID())); 742 Send(new ViewMsg_SwapOut(GetRoutingID()));
731 } else {
732 // This RenderViewHost doesn't have a live renderer, so just skip the unload
733 // event.
734 OnSwappedOut(true);
735 } 743 }
744 delegate_->SwappedOut(this);
736 } 745 }
737 746
738 void RenderViewHostImpl::OnSwapOutACK() { 747 void RenderViewHostImpl::OnSwapOutACK() {
739 OnSwappedOut(false); 748 OnSwappedOut(false);
740 } 749 }
741 750
742 void RenderViewHostImpl::OnSwappedOut(bool timed_out) { 751 void RenderViewHostImpl::OnSwappedOut(bool timed_out) {
743 // Stop the hang monitor now that the unload handler has finished. 752 // Ignore spurious swap out ack.
744 decrement_in_flight_event_count(); 753 if (!IsWaitingForUnloadACK())
754 return;
755 unload_event_monitor_timeout_->Stop();
745 StopHangMonitorTimeout(); 756 StopHangMonitorTimeout();
746 is_waiting_for_unload_ack_ = false; 757 if (timed_out) {
747 has_timed_out_on_unload_ = timed_out;
748 delegate_->SwappedOut(this);
749 }
750
751 void RenderViewHostImpl::WasSwappedOut() {
752 // Don't bother reporting hung state anymore.
753 StopHangMonitorTimeout();
754
755 // If we have timed out on running the unload handler, we consider
756 // the process hung and we should terminate it if there are no other tabs
757 // using the process. If there are other views using this process, the
758 // unresponsive renderer timeout will catch it.
759 bool hung = has_timed_out_on_unload_;
760
761 // Now that we're no longer the active RVH in the tab, start filtering out
762 // most IPC messages. Usually the renderer will have stopped sending
763 // messages as of OnSwapOutACK. However, we may have timed out waiting
764 // for that message, and additional IPC messages may keep streaming in.
765 // We filter them out, as long as that won't cause problems (e.g., we
766 // still allow synchronous messages through).
767 SetSwappedOut(true);
768
769 // If we are not running the renderer in process and no other tab is using
770 // the hung process, consider it eligible to be killed, assuming it is a real
771 // process (unit tests don't have real processes).
772 if (hung) {
773 base::ProcessHandle process_handle = GetProcess()->GetHandle(); 758 base::ProcessHandle process_handle = GetProcess()->GetHandle();
774 int views = 0; 759 int views = 0;
775 760
776 // Count the number of active widget hosts for the process, which 761 // Count the number of active widget hosts for the process, which
777 // is equivalent to views using the process as of this writing. 762 // is equivalent to views using the process as of this writing.
778 scoped_ptr<RenderWidgetHostIterator> widgets( 763 scoped_ptr<RenderWidgetHostIterator> widgets(
779 RenderWidgetHost::GetRenderWidgetHosts()); 764 RenderWidgetHost::GetRenderWidgetHosts());
780 while (RenderWidgetHost* widget = widgets->GetNextHost()) { 765 while (RenderWidgetHost* widget = widgets->GetNextHost()) {
781 if (widget->GetProcess()->GetID() == GetProcess()->GetID()) 766 if (widget->GetProcess()->GetID() == GetProcess()->GetID())
782 ++views; 767 ++views;
(...skipping 16 matching lines...) Expand all
799 784
800 // Log a histogram point to help us diagnose how many of those kills 785 // Log a histogram point to help us diagnose how many of those kills
801 // we have performed. 1 is the enum value for RendererType Normal for 786 // we have performed. 1 is the enum value for RendererType Normal for
802 // the histogram. 787 // the histogram.
803 UMA_HISTOGRAM_PERCENTAGE( 788 UMA_HISTOGRAM_PERCENTAGE(
804 "BrowserRenderProcessHost.ChildKillsUnresponsive", 1); 789 "BrowserRenderProcessHost.ChildKillsUnresponsive", 1);
805 } 790 }
806 } 791 }
807 } 792 }
808 793
809 // Inform the renderer that it can exit if no one else is using it. 794 switch (rvh_state_) {
795 case RVH_STATE_WAITING_FOR_UNLOAD_ACK:
796 SetRVHState(RVH_STATE_WAITING_FOR_COMMIT);
797 break;
798 case RVH_STATE_PENDING_SWAP_OUT:
799 SetRVHState(RVH_STATE_SWAPPED_OUT);
800 break;
801 case RVH_STATE_PENDING_SHUTDOWN:
802 DCHECK(!pending_shutdown_on_swap_out_.is_null());
803 pending_shutdown_on_swap_out_.Run();
804 break;
805 default:
806 NOTREACHED();
807 }
808 }
809
810 void RenderViewHostImpl::WasSwappedOut(
811 const base::Closure& pending_delete_on_swap_out) {
810 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); 812 Send(new ViewMsg_WasSwappedOut(GetRoutingID()));
813 if (rvh_state_ == RVH_STATE_WAITING_FOR_UNLOAD_ACK) {
814 if (instance_->active_view_count())
815 SetRVHState(RVH_STATE_PENDING_SWAP_OUT);
816 else
817 SetPendingShutdown(pending_delete_on_swap_out);
818 } else if (rvh_state_ == RVH_STATE_WAITING_FOR_COMMIT ||
819 (rvh_state_ == RVH_STATE_LIVE && !IsRenderViewLive())) {
nasko 2014/01/23 23:34:58 I'm not sure I understand what the STATE_LIVE chec
clamy 2014/01/24 17:01:54 When the RenderView is not live, the RenderFrameHo
nasko 2014/01/27 19:09:51 It will be better to have them separate. Also, it
clamy 2014/01/28 12:27:21 Done.
820 SetRVHState(RVH_STATE_SWAPPED_OUT);
821 } else {
822 NOTREACHED();
823 }
824 }
825
826 void RenderViewHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) {
827 pending_shutdown_on_swap_out_ = on_swap_out;
828 SetRVHState(RVH_STATE_PENDING_SHUTDOWN);
811 } 829 }
812 830
813 void RenderViewHostImpl::ClosePage() { 831 void RenderViewHostImpl::ClosePage() {
814 // Start the hang monitor in case the renderer hangs in the unload handler. 832 SetRVHState(RVH_STATE_WAITING_FOR_CLOSE);
815 is_waiting_for_unload_ack_ = true;
816 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 833 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
817 834
818 if (IsRenderViewLive()) { 835 if (IsRenderViewLive()) {
819 // Since we are sending an IPC message to the renderer, increase the event 836 // Since we are sending an IPC message to the renderer, increase the event
820 // count to prevent the hang monitor timeout from being stopped by input 837 // count to prevent the hang monitor timeout from being stopped by input
821 // event acknowledgements. 838 // event acknowledgements.
822 increment_in_flight_event_count(); 839 increment_in_flight_event_count();
823 840
824 // TODO(creis): Should this be moved to Shutdown? It may not be called for 841 // TODO(creis): Should this be moved to Shutdown? It may not be called for
825 // RenderViewHosts that have been swapped out. 842 // RenderViewHosts that have been swapped out.
826 NotificationService::current()->Notify( 843 NotificationService::current()->Notify(
827 NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 844 NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
828 Source<RenderViewHost>(this), 845 Source<RenderViewHost>(this),
829 NotificationService::NoDetails()); 846 NotificationService::NoDetails());
830 847
831 Send(new ViewMsg_ClosePage(GetRoutingID())); 848 Send(new ViewMsg_ClosePage(GetRoutingID()));
832 } else { 849 } else {
833 // This RenderViewHost doesn't have a live renderer, so just skip the unload 850 // This RenderViewHost doesn't have a live renderer, so just skip the unload
834 // event and close the page. 851 // event and close the page.
835 ClosePageIgnoringUnloadEvents(); 852 ClosePageIgnoringUnloadEvents();
836 } 853 }
837 } 854 }
838 855
839 void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() { 856 void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() {
840 StopHangMonitorTimeout(); 857 StopHangMonitorTimeout();
841 is_waiting_for_beforeunload_ack_ = false; 858 is_waiting_for_beforeunload_ack_ = false;
842 is_waiting_for_unload_ack_ = false;
843 859
844 sudden_termination_allowed_ = true; 860 sudden_termination_allowed_ = true;
845 delegate_->Close(this); 861 delegate_->Close(this);
846 } 862 }
847 863
848 bool RenderViewHostImpl::HasPendingCrossSiteRequest() { 864 bool RenderViewHostImpl::HasPendingCrossSiteRequest() {
849 return CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest( 865 return CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest(
850 GetProcess()->GetID(), GetRoutingID()); 866 GetProcess()->GetID(), GetRoutingID());
851 } 867 }
852 868
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, 1021 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript,
1006 key, true)); 1022 key, true));
1007 javascript_callbacks_.insert(std::make_pair(key, callback)); 1023 javascript_callbacks_.insert(std::make_pair(key, callback));
1008 } 1024 }
1009 1025
1010 void RenderViewHostImpl::JavaScriptDialogClosed( 1026 void RenderViewHostImpl::JavaScriptDialogClosed(
1011 IPC::Message* reply_msg, 1027 IPC::Message* reply_msg,
1012 bool success, 1028 bool success,
1013 const base::string16& user_input) { 1029 const base::string16& user_input) {
1014 GetProcess()->SetIgnoreInputEvents(false); 1030 GetProcess()->SetIgnoreInputEvents(false);
1015 bool is_waiting = 1031 bool is_waiting = is_waiting_for_beforeunload_ack_ || IsWaitingForUnloadACK();
1016 is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_;
1017 1032
1018 // If we are executing as part of (before)unload event handling, we don't 1033 // If we are executing as part of (before)unload event handling, we don't
1019 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to 1034 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to
1020 // leave the current page. In this case, use the regular timeout value used 1035 // leave the current page. In this case, use the regular timeout value used
1021 // during the (before)unload handling. 1036 // during the (before)unload handling.
1022 if (is_waiting) { 1037 if (is_waiting) {
1023 StartHangMonitorTimeout(TimeDelta::FromMilliseconds( 1038 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
1024 success ? kUnloadTimeoutMS : hung_renderer_delay_ms_)); 1039 success ? kUnloadTimeoutMS : hung_renderer_delay_ms_));
1025 } 1040 }
1026 1041
1027 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, 1042 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg,
1028 success, user_input); 1043 success, user_input);
1029 Send(reply_msg); 1044 Send(reply_msg);
1030 1045
1031 // If we are waiting for an unload or beforeunload ack and the user has 1046 // If we are waiting for an unload or beforeunload ack and the user has
1032 // suppressed messages, kill the tab immediately; a page that's spamming 1047 // suppressed messages, kill the tab immediately; a page that's spamming
1033 // alerts in onbeforeunload is presumably malicious, so there's no point in 1048 // alerts in onbeforeunload is presumably malicious, so there's no point in
1034 // continuing to run its script and dragging out the process. 1049 // continuing to run its script and dragging out the process.
1035 // This must be done after sending the reply since RenderView can't close 1050 // This must be done after sending the reply since RenderView can't close
1036 // correctly while waiting for a response. 1051 // correctly while waiting for a response.
1037 if (is_waiting && are_javascript_messages_suppressed_) 1052 if (is_waiting && are_javascript_messages_suppressed_)
1038 delegate_->RendererUnresponsive( 1053 delegate_->RendererUnresponsive(
1039 this, is_waiting_for_beforeunload_ack_, is_waiting_for_unload_ack_); 1054 this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK());
1040 } 1055 }
1041 1056
1042 void RenderViewHostImpl::DragSourceEndedAt( 1057 void RenderViewHostImpl::DragSourceEndedAt(
1043 int client_x, int client_y, int screen_x, int screen_y, 1058 int client_x, int client_y, int screen_x, int screen_y,
1044 WebDragOperation operation) { 1059 WebDragOperation operation) {
1045 Send(new DragMsg_SourceEndedOrMoved( 1060 Send(new DragMsg_SourceEndedOrMoved(
1046 GetRoutingID(), 1061 GetRoutingID(),
1047 gfx::Point(client_x, client_y), 1062 gfx::Point(client_x, client_y),
1048 gfx::Point(screen_x, screen_y), 1063 gfx::Point(screen_x, screen_y),
1049 true, operation)); 1064 true, operation));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1200
1186 /////////////////////////////////////////////////////////////////////////////// 1201 ///////////////////////////////////////////////////////////////////////////////
1187 // RenderViewHostImpl, IPC message handlers: 1202 // RenderViewHostImpl, IPC message handlers:
1188 1203
1189 bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) { 1204 bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) {
1190 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this)) 1205 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this))
1191 return true; 1206 return true;
1192 1207
1193 // Filter out most IPC messages if this renderer is swapped out. 1208 // Filter out most IPC messages if this renderer is swapped out.
1194 // We still want to handle certain ACKs to keep our state consistent. 1209 // We still want to handle certain ACKs to keep our state consistent.
1195 if (is_swapped_out_) { 1210 if (rvh_state_ == RVH_STATE_SWAPPED_OUT) {
1196 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) { 1211 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) {
1197 // If this is a synchronous message and we decided not to handle it, 1212 // If this is a synchronous message and we decided not to handle it,
1198 // we must send an error reply, or else the renderer will be stuck 1213 // we must send an error reply, or else the renderer will be stuck
1199 // and won't respond to future requests. 1214 // and won't respond to future requests.
1200 if (msg.is_sync()) { 1215 if (msg.is_sync()) {
1201 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); 1216 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
1202 reply->set_reply_error(); 1217 reply->set_reply_error();
1203 Send(reply); 1218 Send(reply);
1204 } 1219 }
1205 // Don't continue looking for someone to handle it. 1220 // Don't continue looking for someone to handle it.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 } 1368 }
1354 1369
1355 void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id) { 1370 void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id) {
1356 delegate_->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id); 1371 delegate_->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id);
1357 } 1372 }
1358 1373
1359 void RenderViewHostImpl::OnShowView(int route_id, 1374 void RenderViewHostImpl::OnShowView(int route_id,
1360 WindowOpenDisposition disposition, 1375 WindowOpenDisposition disposition,
1361 const gfx::Rect& initial_pos, 1376 const gfx::Rect& initial_pos,
1362 bool user_gesture) { 1377 bool user_gesture) {
1363 if (!is_swapped_out_) { 1378 if (IsRVHStateActive(rvh_state_)) {
1364 delegate_->ShowCreatedWindow( 1379 delegate_->ShowCreatedWindow(
1365 route_id, disposition, initial_pos, user_gesture); 1380 route_id, disposition, initial_pos, user_gesture);
1366 } 1381 }
1367 Send(new ViewMsg_Move_ACK(route_id)); 1382 Send(new ViewMsg_Move_ACK(route_id));
1368 } 1383 }
1369 1384
1370 void RenderViewHostImpl::OnShowWidget(int route_id, 1385 void RenderViewHostImpl::OnShowWidget(int route_id,
1371 const gfx::Rect& initial_pos) { 1386 const gfx::Rect& initial_pos) {
1372 if (!is_swapped_out_) 1387 if (IsRVHStateActive(rvh_state_))
1373 delegate_->ShowCreatedWidget(route_id, initial_pos); 1388 delegate_->ShowCreatedWidget(route_id, initial_pos);
1374 Send(new ViewMsg_Move_ACK(route_id)); 1389 Send(new ViewMsg_Move_ACK(route_id));
1375 } 1390 }
1376 1391
1377 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) { 1392 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) {
1378 if (!is_swapped_out_) 1393 if (IsRVHStateActive(rvh_state_))
1379 delegate_->ShowCreatedFullscreenWidget(route_id); 1394 delegate_->ShowCreatedFullscreenWidget(route_id);
1380 Send(new ViewMsg_Move_ACK(route_id)); 1395 Send(new ViewMsg_Move_ACK(route_id));
1381 } 1396 }
1382 1397
1383 void RenderViewHostImpl::OnRunModal(int opener_id, IPC::Message* reply_msg) { 1398 void RenderViewHostImpl::OnRunModal(int opener_id, IPC::Message* reply_msg) {
1384 DCHECK(!run_modal_reply_msg_); 1399 DCHECK(!run_modal_reply_msg_);
1385 run_modal_reply_msg_ = reply_msg; 1400 run_modal_reply_msg_ = reply_msg;
1386 run_modal_opener_id_ = opener_id; 1401 run_modal_opener_id_ = opener_id;
1387 1402
1388 RecordAction(base::UserMetricsAction("ShowModalDialog")); 1403 RecordAction(base::UserMetricsAction("ShowModalDialog"));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 OnShouldCloseACK(true, send_should_close_start_time_, 1479 OnShouldCloseACK(true, send_should_close_start_time_,
1465 base::TimeTicks::Now()); 1480 base::TimeTicks::Now());
1466 return; 1481 return;
1467 } 1482 }
1468 1483
1469 // If we're waiting for an unload ack from this renderer and we receive a 1484 // If we're waiting for an unload ack from this renderer and we receive a
1470 // Navigate message, then the renderer was navigating before it received the 1485 // Navigate message, then the renderer was navigating before it received the
1471 // unload request. It will either respond to the unload request soon or our 1486 // unload request. It will either respond to the unload request soon or our
1472 // timer will expire. Either way, we should ignore this message, because we 1487 // timer will expire. Either way, we should ignore this message, because we
1473 // have already committed to closing this renderer. 1488 // have already committed to closing this renderer.
1474 if (is_waiting_for_unload_ack_) 1489 if (IsWaitingForUnloadACK()) {
nasko 2014/01/23 23:34:58 nit: No need for {}.
clamy 2014/01/24 17:01:54 Done.
1475 return; 1490 return;
1491 }
1476 1492
1477 // Cache the main frame id, so we can use it for creating the frame tree 1493 // Cache the main frame id, so we can use it for creating the frame tree
1478 // root node when needed. 1494 // root node when needed.
1479 if (PageTransitionIsMainFrame(validated_params.transition)) { 1495 if (PageTransitionIsMainFrame(validated_params.transition)) {
1480 if (main_frame_id_ == -1) { 1496 if (main_frame_id_ == -1) {
1481 main_frame_id_ = validated_params.frame_id; 1497 main_frame_id_ = validated_params.frame_id;
1482 } else { 1498 } else {
1483 // TODO(nasko): We plan to remove the usage of frame_id in navigation 1499 // TODO(nasko): We plan to remove the usage of frame_id in navigation
1484 // and move to routing ids. This is in place to ensure that a 1500 // and move to routing ids. This is in place to ensure that a
1485 // renderer is not misbehaving and sending us incorrect data. 1501 // renderer is not misbehaving and sending us incorrect data.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 delegate_->UpdateTitle(this, page_id, title, 1567 delegate_->UpdateTitle(this, page_id, title,
1552 WebTextDirectionToChromeTextDirection( 1568 WebTextDirectionToChromeTextDirection(
1553 title_direction)); 1569 title_direction));
1554 } 1570 }
1555 1571
1556 void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) { 1572 void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) {
1557 delegate_->UpdateEncoding(this, encoding_name); 1573 delegate_->UpdateEncoding(this, encoding_name);
1558 } 1574 }
1559 1575
1560 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) { 1576 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) {
1561 if (!is_swapped_out_) 1577 if (IsRVHStateActive(rvh_state_))
1562 delegate_->UpdateTargetURL(page_id, url); 1578 delegate_->UpdateTargetURL(page_id, url);
1563 1579
1564 // Send a notification back to the renderer that we are ready to 1580 // Send a notification back to the renderer that we are ready to
1565 // receive more target urls. 1581 // receive more target urls.
1566 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID())); 1582 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID()));
1567 } 1583 }
1568 1584
1569 void RenderViewHostImpl::OnUpdateInspectorSetting( 1585 void RenderViewHostImpl::OnUpdateInspectorSetting(
1570 const std::string& key, const std::string& value) { 1586 const std::string& key, const std::string& value) {
1571 GetContentClient()->browser()->UpdateInspectorSetting( 1587 GetContentClient()->browser()->UpdateInspectorSetting(
1572 this, key, value); 1588 this, key, value);
1573 } 1589 }
1574 1590
1575 void RenderViewHostImpl::OnClose() { 1591 void RenderViewHostImpl::OnClose() {
1576 // If the renderer is telling us to close, it has already run the unload 1592 // If the renderer is telling us to close, it has already run the unload
1577 // events, and we can take the fast path. 1593 // events, and we can take the fast path.
1578 ClosePageIgnoringUnloadEvents(); 1594 ClosePageIgnoringUnloadEvents();
1579 } 1595 }
1580 1596
1581 void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) { 1597 void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) {
1582 if (!is_swapped_out_) 1598 if (IsRVHStateActive(rvh_state_))
1583 delegate_->RequestMove(pos); 1599 delegate_->RequestMove(pos);
1584 Send(new ViewMsg_Move_ACK(GetRoutingID())); 1600 Send(new ViewMsg_Move_ACK(GetRoutingID()));
1585 } 1601 }
1586 1602
1587 void RenderViewHostImpl::OnDidStartLoading() { 1603 void RenderViewHostImpl::OnDidStartLoading() {
1588 delegate_->DidStartLoading(this); 1604 delegate_->DidStartLoading(this);
1589 } 1605 }
1590 1606
1591 void RenderViewHostImpl::OnDidStopLoading() { 1607 void RenderViewHostImpl::OnDidStopLoading() {
1592 delegate_->DidStopLoading(this); 1608 delegate_->DidStopLoading(this);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 1841
1826 void RenderViewHostImpl::OnShouldCloseACK( 1842 void RenderViewHostImpl::OnShouldCloseACK(
1827 bool proceed, 1843 bool proceed,
1828 const base::TimeTicks& renderer_before_unload_start_time, 1844 const base::TimeTicks& renderer_before_unload_start_time,
1829 const base::TimeTicks& renderer_before_unload_end_time) { 1845 const base::TimeTicks& renderer_before_unload_end_time) {
1830 decrement_in_flight_event_count(); 1846 decrement_in_flight_event_count();
1831 StopHangMonitorTimeout(); 1847 StopHangMonitorTimeout();
1832 // If this renderer navigated while the beforeunload request was in flight, we 1848 // If this renderer navigated while the beforeunload request was in flight, we
1833 // may have cleared this state in OnNavigate, in which case we can ignore 1849 // may have cleared this state in OnNavigate, in which case we can ignore
1834 // this message. 1850 // this message.
1835 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_) 1851 if (!is_waiting_for_beforeunload_ack_ || rvh_state_ != RVH_STATE_LIVE)
1836 return; 1852 return;
1837 1853
1838 is_waiting_for_beforeunload_ack_ = false; 1854 is_waiting_for_beforeunload_ack_ = false;
1839 1855
1840 RenderViewHostDelegate::RendererManagement* management_delegate = 1856 RenderViewHostDelegate::RendererManagement* management_delegate =
1841 delegate_->GetRendererManagementDelegate(); 1857 delegate_->GetRendererManagementDelegate();
1842 if (management_delegate) { 1858 if (management_delegate) {
1843 base::TimeTicks before_unload_end_time; 1859 base::TimeTicks before_unload_end_time;
1844 if (!send_should_close_start_time_.is_null() && 1860 if (!send_should_close_start_time_.is_null() &&
1845 !renderer_before_unload_start_time.is_null() && 1861 !renderer_before_unload_start_time.is_null() &&
(...skipping 22 matching lines...) Expand all
1868 delegate_->DidCancelLoading(); 1884 delegate_->DidCancelLoading();
1869 } 1885 }
1870 1886
1871 void RenderViewHostImpl::OnClosePageACK() { 1887 void RenderViewHostImpl::OnClosePageACK() {
1872 decrement_in_flight_event_count(); 1888 decrement_in_flight_event_count();
1873 ClosePageIgnoringUnloadEvents(); 1889 ClosePageIgnoringUnloadEvents();
1874 } 1890 }
1875 1891
1876 void RenderViewHostImpl::NotifyRendererUnresponsive() { 1892 void RenderViewHostImpl::NotifyRendererUnresponsive() {
1877 delegate_->RendererUnresponsive( 1893 delegate_->RendererUnresponsive(
1878 this, is_waiting_for_beforeunload_ack_, is_waiting_for_unload_ack_); 1894 this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK());
1879 } 1895 }
1880 1896
1881 void RenderViewHostImpl::NotifyRendererResponsive() { 1897 void RenderViewHostImpl::NotifyRendererResponsive() {
1882 delegate_->RendererResponsive(this); 1898 delegate_->RendererResponsive(this);
1883 } 1899 }
1884 1900
1885 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture, 1901 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture,
1886 bool last_unlocked_by_target) { 1902 bool last_unlocked_by_target) {
1887 delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target); 1903 delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target);
1888 } 1904 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 #endif 1989 #endif
1974 1990
1975 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) { 1991 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) {
1976 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation)); 1992 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation));
1977 } 1993 }
1978 1994
1979 void RenderViewHostImpl::ToggleSpeechInput() { 1995 void RenderViewHostImpl::ToggleSpeechInput() {
1980 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID())); 1996 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID()));
1981 } 1997 }
1982 1998
1999 bool RenderViewHostImpl::IsWaitingForUnloadACK() const {
2000 return rvh_state_ == RVH_STATE_WAITING_FOR_UNLOAD_ACK ||
2001 rvh_state_ == RVH_STATE_WAITING_FOR_CLOSE ||
2002 rvh_state_ == RVH_STATE_PENDING_SHUTDOWN ||
2003 rvh_state_ == RVH_STATE_PENDING_SWAP_OUT;
2004 }
2005
1983 bool RenderViewHostImpl::CanCommitURL(const GURL& url) { 2006 bool RenderViewHostImpl::CanCommitURL(const GURL& url) {
1984 // TODO(creis): We should also check for WebUI pages here. Also, when the 2007 // TODO(creis): We should also check for WebUI pages here. Also, when the
1985 // out-of-process iframes implementation is ready, we should check for 2008 // out-of-process iframes implementation is ready, we should check for
1986 // cross-site URLs that are not allowed to commit in this process. 2009 // cross-site URLs that are not allowed to commit in this process.
1987 2010
1988 // Give the client a chance to disallow URLs from committing. 2011 // Give the client a chance to disallow URLs from committing.
1989 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); 2012 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url);
1990 } 2013 }
1991 2014
1992 void RenderViewHostImpl::ExitFullscreen() { 2015 void RenderViewHostImpl::ExitFullscreen() {
1993 RejectMouseLockOrUnlockIfNecessary(); 2016 RejectMouseLockOrUnlockIfNecessary();
1994 // Notify delegate_ and renderer of fullscreen state change. 2017 // Notify delegate_ and renderer of fullscreen state change.
1995 OnToggleFullscreen(false); 2018 OnToggleFullscreen(false);
1996 } 2019 }
1997 2020
1998 WebPreferences RenderViewHostImpl::GetWebkitPreferences() { 2021 WebPreferences RenderViewHostImpl::GetWebkitPreferences() {
1999 return delegate_->GetWebkitPrefs(); 2022 return delegate_->GetWebkitPrefs();
2000 } 2023 }
2001 2024
2002 void RenderViewHostImpl::DisownOpener() { 2025 void RenderViewHostImpl::DisownOpener() {
2003 // This should only be called when swapped out. 2026 // This should only be called when swapped out.
2004 DCHECK(is_swapped_out_); 2027 DCHECK(rvh_state_ == RVH_STATE_SWAPPED_OUT);
2005 2028
2006 Send(new ViewMsg_DisownOpener(GetRoutingID())); 2029 Send(new ViewMsg_DisownOpener(GetRoutingID()));
2007 } 2030 }
2008 2031
2009 void RenderViewHostImpl::SetAccessibilityCallbackForTesting( 2032 void RenderViewHostImpl::SetAccessibilityCallbackForTesting(
2010 const base::Callback<void(ui::AXEvent)>& callback) { 2033 const base::Callback<void(ui::AXEvent)>& callback) {
2011 accessibility_testing_callback_ = callback; 2034 accessibility_testing_callback_ = callback;
2012 } 2035 }
2013 2036
2014 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) { 2037 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 const gfx::Point& location, const blink::WebPluginAction& action) { 2108 const gfx::Point& location, const blink::WebPluginAction& action) {
2086 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action)); 2109 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action));
2087 } 2110 }
2088 2111
2089 void RenderViewHostImpl::NotifyMoveOrResizeStarted() { 2112 void RenderViewHostImpl::NotifyMoveOrResizeStarted() {
2090 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID())); 2113 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID()));
2091 } 2114 }
2092 2115
2093 void RenderViewHostImpl::OnAccessibilityEvents( 2116 void RenderViewHostImpl::OnAccessibilityEvents(
2094 const std::vector<AccessibilityHostMsg_EventParams>& params) { 2117 const std::vector<AccessibilityHostMsg_EventParams>& params) {
2095 if (view_ && !is_swapped_out_) { 2118 if (view_ && IsRVHStateActive(rvh_state_)) {
2096 view_->CreateBrowserAccessibilityManagerIfNeeded(); 2119 view_->CreateBrowserAccessibilityManagerIfNeeded();
2097 BrowserAccessibilityManager* manager = 2120 BrowserAccessibilityManager* manager =
2098 view_->GetBrowserAccessibilityManager(); 2121 view_->GetBrowserAccessibilityManager();
2099 if (manager) 2122 if (manager)
2100 manager->OnAccessibilityEvents(params); 2123 manager->OnAccessibilityEvents(params);
2101 } 2124 }
2102 2125
2103 // Always send an ACK or the renderer can be in a bad state. 2126 // Always send an ACK or the renderer can be in a bad state.
2104 Send(new AccessibilityMsg_Events_ACK(GetRoutingID())); 2127 Send(new AccessibilityMsg_Events_ACK(GetRoutingID()));
2105 2128
(...skipping 11 matching lines...) Expand all
2117 if (!ax_tree_) 2140 if (!ax_tree_)
2118 ax_tree_.reset(new ui::AXTree(update)); 2141 ax_tree_.reset(new ui::AXTree(update));
2119 else 2142 else
2120 CHECK(ax_tree_->Unserialize(update)) << ax_tree_->error(); 2143 CHECK(ax_tree_->Unserialize(update)) << ax_tree_->error();
2121 accessibility_testing_callback_.Run(param.event_type); 2144 accessibility_testing_callback_.Run(param.event_type);
2122 } 2145 }
2123 } 2146 }
2124 2147
2125 void RenderViewHostImpl::OnAccessibilityLocationChanges( 2148 void RenderViewHostImpl::OnAccessibilityLocationChanges(
2126 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { 2149 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
2127 if (view_ && !is_swapped_out_) { 2150 if (view_ && IsRVHStateActive(rvh_state_)) {
2128 view_->CreateBrowserAccessibilityManagerIfNeeded(); 2151 view_->CreateBrowserAccessibilityManagerIfNeeded();
2129 BrowserAccessibilityManager* manager = 2152 BrowserAccessibilityManager* manager =
2130 view_->GetBrowserAccessibilityManager(); 2153 view_->GetBrowserAccessibilityManager();
2131 if (manager) 2154 if (manager)
2132 manager->OnLocationChanges(params); 2155 manager->OnLocationChanges(params);
2133 } 2156 }
2134 } 2157 }
2135 2158
2136 void RenderViewHostImpl::OnScriptEvalResponse(int id, 2159 void RenderViewHostImpl::OnScriptEvalResponse(int id,
2137 const base::ListValue& result) { 2160 const base::ListValue& result) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 params.item_height, 2245 params.item_height,
2223 params.item_font_size, 2246 params.item_font_size,
2224 params.selected_item, 2247 params.selected_item,
2225 params.popup_items, 2248 params.popup_items,
2226 params.right_aligned, 2249 params.right_aligned,
2227 params.allow_multiple_selection); 2250 params.allow_multiple_selection);
2228 } 2251 }
2229 } 2252 }
2230 #endif 2253 #endif
2231 2254
2232 void RenderViewHostImpl::SetSwappedOut(bool is_swapped_out) { 2255 void RenderViewHostImpl::SetRVHState(RenderViewHostImplState rvh_state) {
2233 // We update the number of RenderViews in a SiteInstance when the 2256 // We update the number of RenderViews in a SiteInstance when the
2234 // swapped out status of this RenderView gets flipped. 2257 // swapped out status of this RenderView gets flipped to/from live.
2235 if (is_swapped_out_ && !is_swapped_out) 2258 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state))
2236 instance_->increment_active_view_count(); 2259 instance_->increment_active_view_count();
2237 else if (!is_swapped_out_ && is_swapped_out) 2260 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state))
2238 instance_->decrement_active_view_count(); 2261 instance_->decrement_active_view_count();
2239 2262
2240 is_swapped_out_ = is_swapped_out; 2263 // Whenever we change the RVH state to and from live or swapped out state, we
2264 // should not be waiting for beforeunload or unload acks. We clear them here
2265 // to be safe, since they can cause navigations to be ignored in OnNavigate.
2266 if (rvh_state == RVH_STATE_LIVE ||
2267 rvh_state == RVH_STATE_SWAPPED_OUT ||
2268 rvh_state_ == RVH_STATE_LIVE ||
2269 rvh_state_ == RVH_STATE_SWAPPED_OUT) {
2270 is_waiting_for_beforeunload_ack_ = false;
2271 }
2272 rvh_state_ = rvh_state;
2241 2273
2242 // Whenever we change swap out state, we should not be waiting for
2243 // beforeunload or unload acks. We clear them here to be safe, since they
2244 // can cause navigations to be ignored in OnNavigate.
2245 is_waiting_for_beforeunload_ack_ = false;
2246 is_waiting_for_unload_ack_ = false;
2247 has_timed_out_on_unload_ = false;
2248 } 2274 }
2249 2275
2250 bool RenderViewHostImpl::CanAccessFilesOfPageState( 2276 bool RenderViewHostImpl::CanAccessFilesOfPageState(
2251 const PageState& state) const { 2277 const PageState& state) const {
2252 ChildProcessSecurityPolicyImpl* policy = 2278 ChildProcessSecurityPolicyImpl* policy =
2253 ChildProcessSecurityPolicyImpl::GetInstance(); 2279 ChildProcessSecurityPolicyImpl::GetInstance();
2254 2280
2255 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); 2281 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles();
2256 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); 2282 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin();
2257 file != file_paths.end(); ++file) { 2283 file != file_paths.end(); ++file) {
2258 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) 2284 if (!policy->CanReadFile(GetProcess()->GetID(), *file))
2259 return false; 2285 return false;
2260 } 2286 }
2261 return true; 2287 return true;
2262 } 2288 }
2263 2289
2264 void RenderViewHostImpl::AttachToFrameTree() { 2290 void RenderViewHostImpl::AttachToFrameTree() {
2265 FrameTree* frame_tree = delegate_->GetFrameTree(); 2291 FrameTree* frame_tree = delegate_->GetFrameTree();
2266 2292
2267 frame_tree->ResetForMainFrameSwap(); 2293 frame_tree->ResetForMainFrameSwap();
2268 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) { 2294 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) {
2269 frame_tree->OnFirstNavigationAfterSwap(main_frame_id()); 2295 frame_tree->OnFirstNavigationAfterSwap(main_frame_id());
2270 } 2296 }
2271 } 2297 }
2272 2298
2273 } // namespace content 2299 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698