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

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: Rebase + addressed some of Nasko's comments 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 == STATE_LIVE ||
155 rvh_state == STATE_WAITING_FOR_UNLOAD_ACK ||
156 rvh_state == STATE_WAITING_FOR_COMMIT ||
157 rvh_state == 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 frames_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_ = STATE_SWAPPED_OUT;
224 } else {
225 rvh_state_ = 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 SetState(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 SetState(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 SetState(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));
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 STATE_WAITING_FOR_UNLOAD_ACK:
796 SetState(STATE_WAITING_FOR_COMMIT);
797 break;
798 case STATE_PENDING_SWAP_OUT:
799 SetState(STATE_SWAPPED_OUT);
800 break;
801 case 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_ == STATE_WAITING_FOR_UNLOAD_ACK) {
814 if (instance_->active_view_count())
815 SetState(STATE_PENDING_SWAP_OUT);
816 else
817 SetPendingShutdown(pending_delete_on_swap_out);
818 } else if (rvh_state_ == STATE_WAITING_FOR_COMMIT ||
819 (rvh_state_ == STATE_LIVE && !IsRenderViewLive())) {
820 SetState(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 SetState(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 SetState(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_ == 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())
1475 return; 1490 return;
1476 1491
1477 // Cache the main frame id, so we can use it for creating the frame tree 1492 // Cache the main frame id, so we can use it for creating the frame tree
1478 // root node when needed. 1493 // root node when needed.
1479 if (PageTransitionIsMainFrame(validated_params.transition)) { 1494 if (PageTransitionIsMainFrame(validated_params.transition)) {
1480 if (main_frame_id_ == -1) { 1495 if (main_frame_id_ == -1) {
1481 main_frame_id_ = validated_params.frame_id; 1496 main_frame_id_ = validated_params.frame_id;
1482 } else { 1497 } else {
1483 // TODO(nasko): We plan to remove the usage of frame_id in navigation 1498 // 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 1499 // and move to routing ids. This is in place to ensure that a
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 delegate_->UpdateTitle(this, page_id, title, 1566 delegate_->UpdateTitle(this, page_id, title,
1552 WebTextDirectionToChromeTextDirection( 1567 WebTextDirectionToChromeTextDirection(
1553 title_direction)); 1568 title_direction));
1554 } 1569 }
1555 1570
1556 void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) { 1571 void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) {
1557 delegate_->UpdateEncoding(this, encoding_name); 1572 delegate_->UpdateEncoding(this, encoding_name);
1558 } 1573 }
1559 1574
1560 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) { 1575 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) {
1561 if (!is_swapped_out_) 1576 if (IsRVHStateActive(rvh_state_))
1562 delegate_->UpdateTargetURL(page_id, url); 1577 delegate_->UpdateTargetURL(page_id, url);
1563 1578
1564 // Send a notification back to the renderer that we are ready to 1579 // Send a notification back to the renderer that we are ready to
1565 // receive more target urls. 1580 // receive more target urls.
1566 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID())); 1581 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID()));
1567 } 1582 }
1568 1583
1569 void RenderViewHostImpl::OnUpdateInspectorSetting( 1584 void RenderViewHostImpl::OnUpdateInspectorSetting(
1570 const std::string& key, const std::string& value) { 1585 const std::string& key, const std::string& value) {
1571 GetContentClient()->browser()->UpdateInspectorSetting( 1586 GetContentClient()->browser()->UpdateInspectorSetting(
1572 this, key, value); 1587 this, key, value);
1573 } 1588 }
1574 1589
1575 void RenderViewHostImpl::OnClose() { 1590 void RenderViewHostImpl::OnClose() {
1576 // If the renderer is telling us to close, it has already run the unload 1591 // If the renderer is telling us to close, it has already run the unload
1577 // events, and we can take the fast path. 1592 // events, and we can take the fast path.
1578 ClosePageIgnoringUnloadEvents(); 1593 ClosePageIgnoringUnloadEvents();
1579 } 1594 }
1580 1595
1581 void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) { 1596 void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) {
1582 if (!is_swapped_out_) 1597 if (IsRVHStateActive(rvh_state_))
1583 delegate_->RequestMove(pos); 1598 delegate_->RequestMove(pos);
1584 Send(new ViewMsg_Move_ACK(GetRoutingID())); 1599 Send(new ViewMsg_Move_ACK(GetRoutingID()));
1585 } 1600 }
1586 1601
1587 void RenderViewHostImpl::OnDidStartLoading() { 1602 void RenderViewHostImpl::OnDidStartLoading() {
1588 delegate_->DidStartLoading(this); 1603 delegate_->DidStartLoading(this);
1589 } 1604 }
1590 1605
1591 void RenderViewHostImpl::OnDidStopLoading() { 1606 void RenderViewHostImpl::OnDidStopLoading() {
1592 delegate_->DidStopLoading(this); 1607 delegate_->DidStopLoading(this);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 1840
1826 void RenderViewHostImpl::OnShouldCloseACK( 1841 void RenderViewHostImpl::OnShouldCloseACK(
1827 bool proceed, 1842 bool proceed,
1828 const base::TimeTicks& renderer_before_unload_start_time, 1843 const base::TimeTicks& renderer_before_unload_start_time,
1829 const base::TimeTicks& renderer_before_unload_end_time) { 1844 const base::TimeTicks& renderer_before_unload_end_time) {
1830 decrement_in_flight_event_count(); 1845 decrement_in_flight_event_count();
1831 StopHangMonitorTimeout(); 1846 StopHangMonitorTimeout();
1832 // If this renderer navigated while the beforeunload request was in flight, we 1847 // 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 1848 // may have cleared this state in OnNavigate, in which case we can ignore
1834 // this message. 1849 // this message.
1835 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_) 1850 if (!is_waiting_for_beforeunload_ack_ || rvh_state_ != STATE_LIVE)
1836 return; 1851 return;
1837 1852
1838 is_waiting_for_beforeunload_ack_ = false; 1853 is_waiting_for_beforeunload_ack_ = false;
1839 1854
1840 RenderViewHostDelegate::RendererManagement* management_delegate = 1855 RenderViewHostDelegate::RendererManagement* management_delegate =
1841 delegate_->GetRendererManagementDelegate(); 1856 delegate_->GetRendererManagementDelegate();
1842 if (management_delegate) { 1857 if (management_delegate) {
1843 base::TimeTicks before_unload_end_time; 1858 base::TimeTicks before_unload_end_time;
1844 if (!send_should_close_start_time_.is_null() && 1859 if (!send_should_close_start_time_.is_null() &&
1845 !renderer_before_unload_start_time.is_null() && 1860 !renderer_before_unload_start_time.is_null() &&
(...skipping 22 matching lines...) Expand all
1868 delegate_->DidCancelLoading(); 1883 delegate_->DidCancelLoading();
1869 } 1884 }
1870 1885
1871 void RenderViewHostImpl::OnClosePageACK() { 1886 void RenderViewHostImpl::OnClosePageACK() {
1872 decrement_in_flight_event_count(); 1887 decrement_in_flight_event_count();
1873 ClosePageIgnoringUnloadEvents(); 1888 ClosePageIgnoringUnloadEvents();
1874 } 1889 }
1875 1890
1876 void RenderViewHostImpl::NotifyRendererUnresponsive() { 1891 void RenderViewHostImpl::NotifyRendererUnresponsive() {
1877 delegate_->RendererUnresponsive( 1892 delegate_->RendererUnresponsive(
1878 this, is_waiting_for_beforeunload_ack_, is_waiting_for_unload_ack_); 1893 this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK());
1879 } 1894 }
1880 1895
1881 void RenderViewHostImpl::NotifyRendererResponsive() { 1896 void RenderViewHostImpl::NotifyRendererResponsive() {
1882 delegate_->RendererResponsive(this); 1897 delegate_->RendererResponsive(this);
1883 } 1898 }
1884 1899
1885 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture, 1900 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture,
1886 bool last_unlocked_by_target) { 1901 bool last_unlocked_by_target) {
1887 delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target); 1902 delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target);
1888 } 1903 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 #endif 1988 #endif
1974 1989
1975 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) { 1990 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) {
1976 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation)); 1991 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation));
1977 } 1992 }
1978 1993
1979 void RenderViewHostImpl::ToggleSpeechInput() { 1994 void RenderViewHostImpl::ToggleSpeechInput() {
1980 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID())); 1995 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID()));
1981 } 1996 }
1982 1997
1998 bool RenderViewHostImpl::IsWaitingForUnloadACK() const {
1999 return rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK ||
2000 rvh_state_ == STATE_WAITING_FOR_CLOSE ||
2001 rvh_state_ == STATE_PENDING_SHUTDOWN ||
2002 rvh_state_ == STATE_PENDING_SWAP_OUT;
2003 }
2004
1983 bool RenderViewHostImpl::CanCommitURL(const GURL& url) { 2005 bool RenderViewHostImpl::CanCommitURL(const GURL& url) {
1984 // TODO(creis): We should also check for WebUI pages here. Also, when the 2006 // 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 2007 // out-of-process iframes implementation is ready, we should check for
1986 // cross-site URLs that are not allowed to commit in this process. 2008 // cross-site URLs that are not allowed to commit in this process.
1987 2009
1988 // Give the client a chance to disallow URLs from committing. 2010 // Give the client a chance to disallow URLs from committing.
1989 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); 2011 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url);
1990 } 2012 }
1991 2013
1992 void RenderViewHostImpl::ExitFullscreen() { 2014 void RenderViewHostImpl::ExitFullscreen() {
1993 RejectMouseLockOrUnlockIfNecessary(); 2015 RejectMouseLockOrUnlockIfNecessary();
1994 // Notify delegate_ and renderer of fullscreen state change. 2016 // Notify delegate_ and renderer of fullscreen state change.
1995 OnToggleFullscreen(false); 2017 OnToggleFullscreen(false);
1996 } 2018 }
1997 2019
1998 WebPreferences RenderViewHostImpl::GetWebkitPreferences() { 2020 WebPreferences RenderViewHostImpl::GetWebkitPreferences() {
1999 return delegate_->GetWebkitPrefs(); 2021 return delegate_->GetWebkitPrefs();
2000 } 2022 }
2001 2023
2002 void RenderViewHostImpl::DisownOpener() { 2024 void RenderViewHostImpl::DisownOpener() {
2003 // This should only be called when swapped out. 2025 // This should only be called when swapped out.
2004 DCHECK(is_swapped_out_); 2026 DCHECK(rvh_state_ == STATE_SWAPPED_OUT);
2005 2027
2006 Send(new ViewMsg_DisownOpener(GetRoutingID())); 2028 Send(new ViewMsg_DisownOpener(GetRoutingID()));
2007 } 2029 }
2008 2030
2009 void RenderViewHostImpl::SetAccessibilityCallbackForTesting( 2031 void RenderViewHostImpl::SetAccessibilityCallbackForTesting(
2010 const base::Callback<void(ui::AXEvent)>& callback) { 2032 const base::Callback<void(ui::AXEvent)>& callback) {
2011 accessibility_testing_callback_ = callback; 2033 accessibility_testing_callback_ = callback;
2012 } 2034 }
2013 2035
2014 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) { 2036 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) { 2107 const gfx::Point& location, const blink::WebPluginAction& action) {
2086 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action)); 2108 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action));
2087 } 2109 }
2088 2110
2089 void RenderViewHostImpl::NotifyMoveOrResizeStarted() { 2111 void RenderViewHostImpl::NotifyMoveOrResizeStarted() {
2090 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID())); 2112 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID()));
2091 } 2113 }
2092 2114
2093 void RenderViewHostImpl::OnAccessibilityEvents( 2115 void RenderViewHostImpl::OnAccessibilityEvents(
2094 const std::vector<AccessibilityHostMsg_EventParams>& params) { 2116 const std::vector<AccessibilityHostMsg_EventParams>& params) {
2095 if (view_ && !is_swapped_out_) { 2117 if (view_ && IsRVHStateActive(rvh_state_)) {
2096 view_->CreateBrowserAccessibilityManagerIfNeeded(); 2118 view_->CreateBrowserAccessibilityManagerIfNeeded();
2097 BrowserAccessibilityManager* manager = 2119 BrowserAccessibilityManager* manager =
2098 view_->GetBrowserAccessibilityManager(); 2120 view_->GetBrowserAccessibilityManager();
2099 if (manager) 2121 if (manager)
2100 manager->OnAccessibilityEvents(params); 2122 manager->OnAccessibilityEvents(params);
2101 } 2123 }
2102 2124
2103 // Always send an ACK or the renderer can be in a bad state. 2125 // Always send an ACK or the renderer can be in a bad state.
2104 Send(new AccessibilityMsg_Events_ACK(GetRoutingID())); 2126 Send(new AccessibilityMsg_Events_ACK(GetRoutingID()));
2105 2127
(...skipping 11 matching lines...) Expand all
2117 if (!ax_tree_) 2139 if (!ax_tree_)
2118 ax_tree_.reset(new ui::AXTree(update)); 2140 ax_tree_.reset(new ui::AXTree(update));
2119 else 2141 else
2120 CHECK(ax_tree_->Unserialize(update)) << ax_tree_->error(); 2142 CHECK(ax_tree_->Unserialize(update)) << ax_tree_->error();
2121 accessibility_testing_callback_.Run(param.event_type); 2143 accessibility_testing_callback_.Run(param.event_type);
2122 } 2144 }
2123 } 2145 }
2124 2146
2125 void RenderViewHostImpl::OnAccessibilityLocationChanges( 2147 void RenderViewHostImpl::OnAccessibilityLocationChanges(
2126 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { 2148 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
2127 if (view_ && !is_swapped_out_) { 2149 if (view_ && IsRVHStateActive(rvh_state_)) {
2128 view_->CreateBrowserAccessibilityManagerIfNeeded(); 2150 view_->CreateBrowserAccessibilityManagerIfNeeded();
2129 BrowserAccessibilityManager* manager = 2151 BrowserAccessibilityManager* manager =
2130 view_->GetBrowserAccessibilityManager(); 2152 view_->GetBrowserAccessibilityManager();
2131 if (manager) 2153 if (manager)
2132 manager->OnLocationChanges(params); 2154 manager->OnLocationChanges(params);
2133 } 2155 }
2134 } 2156 }
2135 2157
2136 void RenderViewHostImpl::OnScriptEvalResponse(int id, 2158 void RenderViewHostImpl::OnScriptEvalResponse(int id,
2137 const base::ListValue& result) { 2159 const base::ListValue& result) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 params.item_height, 2244 params.item_height,
2223 params.item_font_size, 2245 params.item_font_size,
2224 params.selected_item, 2246 params.selected_item,
2225 params.popup_items, 2247 params.popup_items,
2226 params.right_aligned, 2248 params.right_aligned,
2227 params.allow_multiple_selection); 2249 params.allow_multiple_selection);
2228 } 2250 }
2229 } 2251 }
2230 #endif 2252 #endif
2231 2253
2232 void RenderViewHostImpl::SetSwappedOut(bool is_swapped_out) { 2254 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) {
2233 // We update the number of RenderViews in a SiteInstance when the 2255 // We update the number of RenderViews in a SiteInstance when the
2234 // swapped out status of this RenderView gets flipped. 2256 // swapped out status of this RenderView gets flipped to/from live.
2235 if (is_swapped_out_ && !is_swapped_out) 2257 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state))
2236 instance_->increment_active_view_count(); 2258 instance_->increment_active_view_count();
2237 else if (!is_swapped_out_ && is_swapped_out) 2259 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state))
2238 instance_->decrement_active_view_count(); 2260 instance_->decrement_active_view_count();
2239 2261
2240 is_swapped_out_ = is_swapped_out; 2262 // Whenever we change the RVH state to and from live or swapped out state, we
2263 // should not be waiting for beforeunload or unload acks. We clear them here
2264 // to be safe, since they can cause navigations to be ignored in OnNavigate.
2265 if (rvh_state == STATE_LIVE ||
2266 rvh_state == STATE_SWAPPED_OUT ||
2267 rvh_state_ == STATE_LIVE ||
2268 rvh_state_ == STATE_SWAPPED_OUT) {
2269 is_waiting_for_beforeunload_ack_ = false;
2270 }
2271 rvh_state_ = rvh_state;
2241 2272
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 } 2273 }
2249 2274
2250 bool RenderViewHostImpl::CanAccessFilesOfPageState( 2275 bool RenderViewHostImpl::CanAccessFilesOfPageState(
2251 const PageState& state) const { 2276 const PageState& state) const {
2252 ChildProcessSecurityPolicyImpl* policy = 2277 ChildProcessSecurityPolicyImpl* policy =
2253 ChildProcessSecurityPolicyImpl::GetInstance(); 2278 ChildProcessSecurityPolicyImpl::GetInstance();
2254 2279
2255 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); 2280 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles();
2256 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); 2281 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin();
2257 file != file_paths.end(); ++file) { 2282 file != file_paths.end(); ++file) {
2258 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) 2283 if (!policy->CanReadFile(GetProcess()->GetID(), *file))
2259 return false; 2284 return false;
2260 } 2285 }
2261 return true; 2286 return true;
2262 } 2287 }
2263 2288
2264 void RenderViewHostImpl::AttachToFrameTree() { 2289 void RenderViewHostImpl::AttachToFrameTree() {
2265 FrameTree* frame_tree = delegate_->GetFrameTree(); 2290 FrameTree* frame_tree = delegate_->GetFrameTree();
2266 2291
2267 frame_tree->ResetForMainFrameSwap(); 2292 frame_tree->ResetForMainFrameSwap();
2268 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) { 2293 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) {
2269 frame_tree->OnFirstNavigationAfterSwap(main_frame_id()); 2294 frame_tree->OnFirstNavigationAfterSwap(main_frame_id());
2270 } 2295 }
2271 } 2296 }
2272 2297
2273 } // namespace content 2298 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698