OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/render_view_host_impl.h" | 5 #include "content/browser/renderer_host/render_view_host_impl.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... |
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/content_switches_internal.h" | 44 #include "content/common/content_switches_internal.h" |
44 #include "content/common/desktop_notification_messages.h" | 45 #include "content/common/desktop_notification_messages.h" |
45 #include "content/common/drag_messages.h" | 46 #include "content/common/drag_messages.h" |
46 #include "content/common/input_messages.h" | 47 #include "content/common/input_messages.h" |
47 #include "content/common/inter_process_time_ticks_converter.h" | 48 #include "content/common/inter_process_time_ticks_converter.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 144 } |
144 } | 145 } |
145 #endif | 146 #endif |
146 | 147 |
147 } // namespace | 148 } // namespace |
148 | 149 |
149 /////////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////////// |
150 // RenderViewHost, public: | 151 // RenderViewHost, public: |
151 | 152 |
152 // static | 153 // static |
| 154 bool RenderViewHostImpl::IsRVHStateActive(RenderViewHostImplState rvh_state) { |
| 155 if (rvh_state == STATE_DEFAULT || |
| 156 rvh_state == STATE_WAITING_FOR_UNLOAD_ACK || |
| 157 rvh_state == STATE_WAITING_FOR_COMMIT || |
| 158 rvh_state == STATE_WAITING_FOR_CLOSE) |
| 159 return true; |
| 160 return false; |
| 161 } |
| 162 |
| 163 // static |
153 RenderViewHost* RenderViewHost::FromID(int render_process_id, | 164 RenderViewHost* RenderViewHost::FromID(int render_process_id, |
154 int render_view_id) { | 165 int render_view_id) { |
155 return RenderViewHostImpl::FromID(render_process_id, render_view_id); | 166 return RenderViewHostImpl::FromID(render_process_id, render_view_id); |
156 } | 167 } |
157 | 168 |
158 // static | 169 // static |
159 RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) { | 170 RenderViewHost* RenderViewHost::From(RenderWidgetHost* rwh) { |
160 DCHECK(rwh->IsRenderView()); | 171 DCHECK(rwh->IsRenderView()); |
161 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh)); | 172 return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(rwh)); |
162 } | 173 } |
(...skipping 16 matching lines...) Expand all Loading... |
179 RenderViewHostDelegate* delegate, | 190 RenderViewHostDelegate* delegate, |
180 RenderWidgetHostDelegate* widget_delegate, | 191 RenderWidgetHostDelegate* widget_delegate, |
181 int routing_id, | 192 int routing_id, |
182 int main_frame_routing_id, | 193 int main_frame_routing_id, |
183 bool swapped_out, | 194 bool swapped_out, |
184 bool hidden) | 195 bool hidden) |
185 : RenderWidgetHostImpl(widget_delegate, | 196 : RenderWidgetHostImpl(widget_delegate, |
186 instance->GetProcess(), | 197 instance->GetProcess(), |
187 routing_id, | 198 routing_id, |
188 hidden), | 199 hidden), |
| 200 frames_ref_count_(0), |
189 delegate_(delegate), | 201 delegate_(delegate), |
190 instance_(static_cast<SiteInstanceImpl*>(instance)), | 202 instance_(static_cast<SiteInstanceImpl*>(instance)), |
191 waiting_for_drag_context_response_(false), | 203 waiting_for_drag_context_response_(false), |
192 enabled_bindings_(0), | 204 enabled_bindings_(0), |
193 navigations_suspended_(false), | 205 navigations_suspended_(false), |
194 has_accessed_initial_document_(false), | 206 has_accessed_initial_document_(false), |
195 is_swapped_out_(swapped_out), | |
196 main_frame_id_(-1), | 207 main_frame_id_(-1), |
197 main_frame_routing_id_(main_frame_routing_id), | 208 main_frame_routing_id_(main_frame_routing_id), |
198 run_modal_reply_msg_(NULL), | 209 run_modal_reply_msg_(NULL), |
199 run_modal_opener_id_(MSG_ROUTING_NONE), | 210 run_modal_opener_id_(MSG_ROUTING_NONE), |
200 is_waiting_for_beforeunload_ack_(false), | 211 is_waiting_for_beforeunload_ack_(false), |
201 is_waiting_for_unload_ack_(false), | |
202 has_timed_out_on_unload_(false), | |
203 unload_ack_is_for_cross_site_transition_(false), | 212 unload_ack_is_for_cross_site_transition_(false), |
204 are_javascript_messages_suppressed_(false), | 213 are_javascript_messages_suppressed_(false), |
205 sudden_termination_allowed_(false), | 214 sudden_termination_allowed_(false), |
206 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), | 215 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
207 virtual_keyboard_requested_(false) { | 216 virtual_keyboard_requested_(false), |
| 217 weak_factory_(this) { |
208 DCHECK(instance_.get()); | 218 DCHECK(instance_.get()); |
209 CHECK(delegate_); // http://crbug.com/82827 | 219 CHECK(delegate_); // http://crbug.com/82827 |
210 | 220 |
211 GetProcess()->EnableSendQueue(); | 221 GetProcess()->EnableSendQueue(); |
212 | 222 |
213 if (!swapped_out) | 223 if (swapped_out) { |
| 224 rvh_state_ = STATE_SWAPPED_OUT; |
| 225 } else { |
| 226 rvh_state_ = STATE_DEFAULT; |
214 instance_->increment_active_view_count(); | 227 instance_->increment_active_view_count(); |
| 228 } |
215 | 229 |
216 if (ResourceDispatcherHostImpl::Get()) { | 230 if (ResourceDispatcherHostImpl::Get()) { |
217 BrowserThread::PostTask( | 231 BrowserThread::PostTask( |
218 BrowserThread::IO, FROM_HERE, | 232 BrowserThread::IO, FROM_HERE, |
219 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated, | 233 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostCreated, |
220 base::Unretained(ResourceDispatcherHostImpl::Get()), | 234 base::Unretained(ResourceDispatcherHostImpl::Get()), |
221 GetProcess()->GetID(), GetRoutingID())); | 235 GetProcess()->GetID(), GetRoutingID())); |
222 } | 236 } |
223 | 237 |
224 #if defined(OS_ANDROID) | 238 #if defined(OS_ANDROID) |
225 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this)); | 239 media_player_manager_.reset(BrowserMediaPlayerManager::Create(this)); |
226 #endif | 240 #endif |
| 241 |
| 242 unload_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( |
| 243 &RenderViewHostImpl::OnSwappedOut, weak_factory_.GetWeakPtr(), true))); |
227 } | 244 } |
228 | 245 |
229 RenderViewHostImpl::~RenderViewHostImpl() { | 246 RenderViewHostImpl::~RenderViewHostImpl() { |
230 if (ResourceDispatcherHostImpl::Get()) { | 247 if (ResourceDispatcherHostImpl::Get()) { |
231 BrowserThread::PostTask( | 248 BrowserThread::PostTask( |
232 BrowserThread::IO, FROM_HERE, | 249 BrowserThread::IO, FROM_HERE, |
233 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, | 250 base::Bind(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, |
234 base::Unretained(ResourceDispatcherHostImpl::Get()), | 251 base::Unretained(ResourceDispatcherHostImpl::Get()), |
235 GetProcess()->GetID(), GetRoutingID())); | 252 GetProcess()->GetID(), GetRoutingID())); |
236 } | 253 } |
237 | 254 |
238 delegate_->RenderViewDeleted(this); | 255 delegate_->RenderViewDeleted(this); |
239 | 256 |
240 // Be sure to clean up any leftover state from cross-site requests. | 257 // Be sure to clean up any leftover state from cross-site requests. |
241 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( | 258 CrossSiteRequestManager::GetInstance()->SetHasPendingCrossSiteRequest( |
242 GetProcess()->GetID(), GetRoutingID(), false); | 259 GetProcess()->GetID(), GetRoutingID(), false); |
243 | 260 |
244 // If this was swapped out, it already decremented the active view | 261 // If this was swapped out, it already decremented the active view |
245 // count of the SiteInstance it belongs to. | 262 // count of the SiteInstance it belongs to. |
246 if (!is_swapped_out_) | 263 if (IsRVHStateActive(rvh_state_)) |
247 instance_->decrement_active_view_count(); | 264 instance_->decrement_active_view_count(); |
248 } | 265 } |
249 | 266 |
250 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { | 267 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { |
251 return delegate_; | 268 return delegate_; |
252 } | 269 } |
253 | 270 |
254 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { | 271 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { |
255 return instance_.get(); | 272 return instance_.get(); |
256 } | 273 } |
(...skipping 30 matching lines...) Expand all Loading... |
287 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext()); | 304 delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext()); |
288 params.web_preferences = delegate_->GetWebkitPrefs(); | 305 params.web_preferences = delegate_->GetWebkitPrefs(); |
289 params.view_id = GetRoutingID(); | 306 params.view_id = GetRoutingID(); |
290 params.main_frame_routing_id = main_frame_routing_id_; | 307 params.main_frame_routing_id = main_frame_routing_id_; |
291 params.surface_id = surface_id(); | 308 params.surface_id = surface_id(); |
292 params.session_storage_namespace_id = | 309 params.session_storage_namespace_id = |
293 delegate_->GetSessionStorageNamespace(instance_)->id(); | 310 delegate_->GetSessionStorageNamespace(instance_)->id(); |
294 params.frame_name = frame_name; | 311 params.frame_name = frame_name; |
295 // Ensure the RenderView sets its opener correctly. | 312 // Ensure the RenderView sets its opener correctly. |
296 params.opener_route_id = opener_route_id; | 313 params.opener_route_id = opener_route_id; |
297 params.swapped_out = is_swapped_out_; | 314 params.swapped_out = !IsRVHStateActive(rvh_state_); |
298 params.hidden = is_hidden(); | 315 params.hidden = is_hidden(); |
299 params.next_page_id = next_page_id; | 316 params.next_page_id = next_page_id; |
300 GetWebScreenInfo(¶ms.screen_info); | 317 GetWebScreenInfo(¶ms.screen_info); |
301 params.accessibility_mode = accessibility_mode(); | 318 params.accessibility_mode = accessibility_mode(); |
302 params.allow_partial_swap = !GetProcess()->IsGuest(); | 319 params.allow_partial_swap = !GetProcess()->IsGuest(); |
303 | 320 |
304 Send(new ViewMsg_New(params)); | 321 Send(new ViewMsg_New(params)); |
305 | 322 |
306 // If it's enabled, tell the renderer to set up the Javascript bindings for | 323 // If it's enabled, tell the renderer to set up the Javascript bindings for |
307 // sending messages back to the browser. | 324 // sending messages back to the browser. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_DEFAULT); |
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 Loading... |
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_DEFAULT); |
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 Loading... |
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()) |
745 StopHangMonitorTimeout(); | 754 return; |
746 is_waiting_for_unload_ack_ = false; | 755 unload_event_monitor_timeout_->Stop(); |
747 has_timed_out_on_unload_ = timed_out; | 756 if (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(); | 757 base::ProcessHandle process_handle = GetProcess()->GetHandle(); |
774 int views = 0; | 758 int views = 0; |
775 | 759 |
776 // Count the number of active widget hosts for the process, which | 760 // Count the number of active widget hosts for the process, which |
777 // is equivalent to views using the process as of this writing. | 761 // is equivalent to views using the process as of this writing. |
778 scoped_ptr<RenderWidgetHostIterator> widgets( | 762 scoped_ptr<RenderWidgetHostIterator> widgets( |
779 RenderWidgetHost::GetRenderWidgetHosts()); | 763 RenderWidgetHost::GetRenderWidgetHosts()); |
780 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 764 while (RenderWidgetHost* widget = widgets->GetNextHost()) { |
781 if (widget->GetProcess()->GetID() == GetProcess()->GetID()) | 765 if (widget->GetProcess()->GetID() == GetProcess()->GetID()) |
782 ++views; | 766 ++views; |
(...skipping 16 matching lines...) Expand all Loading... |
799 | 783 |
800 // Log a histogram point to help us diagnose how many of those kills | 784 // 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 | 785 // we have performed. 1 is the enum value for RendererType Normal for |
802 // the histogram. | 786 // the histogram. |
803 UMA_HISTOGRAM_PERCENTAGE( | 787 UMA_HISTOGRAM_PERCENTAGE( |
804 "BrowserRenderProcessHost.ChildKillsUnresponsive", 1); | 788 "BrowserRenderProcessHost.ChildKillsUnresponsive", 1); |
805 } | 789 } |
806 } | 790 } |
807 } | 791 } |
808 | 792 |
809 // Inform the renderer that it can exit if no one else is using it. | 793 switch (rvh_state_) { |
| 794 case STATE_WAITING_FOR_UNLOAD_ACK: |
| 795 SetState(STATE_WAITING_FOR_COMMIT); |
| 796 break; |
| 797 case STATE_PENDING_SWAP_OUT: |
| 798 SetState(STATE_SWAPPED_OUT); |
| 799 break; |
| 800 case STATE_PENDING_SHUTDOWN: |
| 801 DCHECK(!pending_shutdown_on_swap_out_.is_null()); |
| 802 pending_shutdown_on_swap_out_.Run(); |
| 803 break; |
| 804 default: |
| 805 NOTREACHED(); |
| 806 } |
| 807 } |
| 808 |
| 809 void RenderViewHostImpl::WasSwappedOut( |
| 810 const base::Closure& pending_delete_on_swap_out) { |
810 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); | 811 Send(new ViewMsg_WasSwappedOut(GetRoutingID())); |
| 812 if (rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK) { |
| 813 if (instance_->active_view_count()) |
| 814 SetState(STATE_PENDING_SWAP_OUT); |
| 815 else |
| 816 SetPendingShutdown(pending_delete_on_swap_out); |
| 817 } else if (rvh_state_ == STATE_WAITING_FOR_COMMIT) { |
| 818 SetState(STATE_SWAPPED_OUT); |
| 819 } else if (rvh_state_ == STATE_DEFAULT) { |
| 820 // When the RenderView is not live, the RenderFrameHostManager will call |
| 821 // CommitPending directly, without calling SwapOut on the old RVH. This will |
| 822 // cause WasSwappedOut to be called directly on the live old RVH. |
| 823 DCHECK(!IsRenderViewLive()); |
| 824 SetState(STATE_SWAPPED_OUT); |
| 825 } else { |
| 826 NOTREACHED(); |
| 827 } |
| 828 } |
| 829 |
| 830 void RenderViewHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { |
| 831 pending_shutdown_on_swap_out_ = on_swap_out; |
| 832 SetState(STATE_PENDING_SHUTDOWN); |
811 } | 833 } |
812 | 834 |
813 void RenderViewHostImpl::ClosePage() { | 835 void RenderViewHostImpl::ClosePage() { |
814 // Start the hang monitor in case the renderer hangs in the unload handler. | 836 SetState(STATE_WAITING_FOR_CLOSE); |
815 is_waiting_for_unload_ack_ = true; | |
816 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); | 837 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); |
817 | 838 |
818 if (IsRenderViewLive()) { | 839 if (IsRenderViewLive()) { |
819 // Since we are sending an IPC message to the renderer, increase the event | 840 // 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 | 841 // count to prevent the hang monitor timeout from being stopped by input |
821 // event acknowledgements. | 842 // event acknowledgements. |
822 increment_in_flight_event_count(); | 843 increment_in_flight_event_count(); |
823 | 844 |
824 // TODO(creis): Should this be moved to Shutdown? It may not be called for | 845 // TODO(creis): Should this be moved to Shutdown? It may not be called for |
825 // RenderViewHosts that have been swapped out. | 846 // RenderViewHosts that have been swapped out. |
826 NotificationService::current()->Notify( | 847 NotificationService::current()->Notify( |
827 NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, | 848 NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, |
828 Source<RenderViewHost>(this), | 849 Source<RenderViewHost>(this), |
829 NotificationService::NoDetails()); | 850 NotificationService::NoDetails()); |
830 | 851 |
831 Send(new ViewMsg_ClosePage(GetRoutingID())); | 852 Send(new ViewMsg_ClosePage(GetRoutingID())); |
832 } else { | 853 } else { |
833 // This RenderViewHost doesn't have a live renderer, so just skip the unload | 854 // This RenderViewHost doesn't have a live renderer, so just skip the unload |
834 // event and close the page. | 855 // event and close the page. |
835 ClosePageIgnoringUnloadEvents(); | 856 ClosePageIgnoringUnloadEvents(); |
836 } | 857 } |
837 } | 858 } |
838 | 859 |
839 void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() { | 860 void RenderViewHostImpl::ClosePageIgnoringUnloadEvents() { |
840 StopHangMonitorTimeout(); | 861 StopHangMonitorTimeout(); |
841 is_waiting_for_beforeunload_ack_ = false; | 862 is_waiting_for_beforeunload_ack_ = false; |
842 is_waiting_for_unload_ack_ = false; | |
843 | 863 |
844 sudden_termination_allowed_ = true; | 864 sudden_termination_allowed_ = true; |
845 delegate_->Close(this); | 865 delegate_->Close(this); |
846 } | 866 } |
847 | 867 |
848 bool RenderViewHostImpl::HasPendingCrossSiteRequest() { | 868 bool RenderViewHostImpl::HasPendingCrossSiteRequest() { |
849 return CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest( | 869 return CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest( |
850 GetProcess()->GetID(), GetRoutingID()); | 870 GetProcess()->GetID(), GetRoutingID()); |
851 } | 871 } |
852 | 872 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, | 1025 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, |
1006 key, true)); | 1026 key, true)); |
1007 javascript_callbacks_.insert(std::make_pair(key, callback)); | 1027 javascript_callbacks_.insert(std::make_pair(key, callback)); |
1008 } | 1028 } |
1009 | 1029 |
1010 void RenderViewHostImpl::JavaScriptDialogClosed( | 1030 void RenderViewHostImpl::JavaScriptDialogClosed( |
1011 IPC::Message* reply_msg, | 1031 IPC::Message* reply_msg, |
1012 bool success, | 1032 bool success, |
1013 const base::string16& user_input) { | 1033 const base::string16& user_input) { |
1014 GetProcess()->SetIgnoreInputEvents(false); | 1034 GetProcess()->SetIgnoreInputEvents(false); |
1015 bool is_waiting = | 1035 bool is_waiting = is_waiting_for_beforeunload_ack_ || IsWaitingForUnloadACK(); |
1016 is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_; | |
1017 | 1036 |
1018 // If we are executing as part of (before)unload event handling, we don't | 1037 // 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 | 1038 // 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 | 1039 // leave the current page. In this case, use the regular timeout value used |
1021 // during the (before)unload handling. | 1040 // during the (before)unload handling. |
1022 if (is_waiting) { | 1041 if (is_waiting) { |
1023 StartHangMonitorTimeout(TimeDelta::FromMilliseconds( | 1042 StartHangMonitorTimeout(TimeDelta::FromMilliseconds( |
1024 success ? kUnloadTimeoutMS : hung_renderer_delay_ms_)); | 1043 success ? kUnloadTimeoutMS : hung_renderer_delay_ms_)); |
1025 } | 1044 } |
1026 | 1045 |
1027 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, | 1046 ViewHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, |
1028 success, user_input); | 1047 success, user_input); |
1029 Send(reply_msg); | 1048 Send(reply_msg); |
1030 | 1049 |
1031 // If we are waiting for an unload or beforeunload ack and the user has | 1050 // 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 | 1051 // suppressed messages, kill the tab immediately; a page that's spamming |
1033 // alerts in onbeforeunload is presumably malicious, so there's no point in | 1052 // alerts in onbeforeunload is presumably malicious, so there's no point in |
1034 // continuing to run its script and dragging out the process. | 1053 // continuing to run its script and dragging out the process. |
1035 // This must be done after sending the reply since RenderView can't close | 1054 // This must be done after sending the reply since RenderView can't close |
1036 // correctly while waiting for a response. | 1055 // correctly while waiting for a response. |
1037 if (is_waiting && are_javascript_messages_suppressed_) | 1056 if (is_waiting && are_javascript_messages_suppressed_) |
1038 delegate_->RendererUnresponsive( | 1057 delegate_->RendererUnresponsive( |
1039 this, is_waiting_for_beforeunload_ack_, is_waiting_for_unload_ack_); | 1058 this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK()); |
1040 } | 1059 } |
1041 | 1060 |
1042 void RenderViewHostImpl::DragSourceEndedAt( | 1061 void RenderViewHostImpl::DragSourceEndedAt( |
1043 int client_x, int client_y, int screen_x, int screen_y, | 1062 int client_x, int client_y, int screen_x, int screen_y, |
1044 WebDragOperation operation) { | 1063 WebDragOperation operation) { |
1045 Send(new DragMsg_SourceEndedOrMoved( | 1064 Send(new DragMsg_SourceEndedOrMoved( |
1046 GetRoutingID(), | 1065 GetRoutingID(), |
1047 gfx::Point(client_x, client_y), | 1066 gfx::Point(client_x, client_y), |
1048 gfx::Point(screen_x, screen_y), | 1067 gfx::Point(screen_x, screen_y), |
1049 true, operation)); | 1068 true, operation)); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 | 1204 |
1186 /////////////////////////////////////////////////////////////////////////////// | 1205 /////////////////////////////////////////////////////////////////////////////// |
1187 // RenderViewHostImpl, IPC message handlers: | 1206 // RenderViewHostImpl, IPC message handlers: |
1188 | 1207 |
1189 bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1208 bool RenderViewHostImpl::OnMessageReceived(const IPC::Message& msg) { |
1190 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this)) | 1209 if (!BrowserMessageFilter::CheckCanDispatchOnUI(msg, this)) |
1191 return true; | 1210 return true; |
1192 | 1211 |
1193 // Filter out most IPC messages if this renderer is swapped out. | 1212 // Filter out most IPC messages if this renderer is swapped out. |
1194 // We still want to handle certain ACKs to keep our state consistent. | 1213 // We still want to handle certain ACKs to keep our state consistent. |
1195 if (is_swapped_out_) { | 1214 if (IsSwappedOut()) { |
1196 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) { | 1215 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) { |
1197 // If this is a synchronous message and we decided not to handle it, | 1216 // 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 | 1217 // we must send an error reply, or else the renderer will be stuck |
1199 // and won't respond to future requests. | 1218 // and won't respond to future requests. |
1200 if (msg.is_sync()) { | 1219 if (msg.is_sync()) { |
1201 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 1220 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
1202 reply->set_reply_error(); | 1221 reply->set_reply_error(); |
1203 Send(reply); | 1222 Send(reply); |
1204 } | 1223 } |
1205 // Don't continue looking for someone to handle it. | 1224 // Don't continue looking for someone to handle it. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1352 } | 1371 } |
1353 | 1372 |
1354 void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id) { | 1373 void RenderViewHostImpl::CreateNewFullscreenWidget(int route_id) { |
1355 delegate_->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id); | 1374 delegate_->CreateNewFullscreenWidget(GetProcess()->GetID(), route_id); |
1356 } | 1375 } |
1357 | 1376 |
1358 void RenderViewHostImpl::OnShowView(int route_id, | 1377 void RenderViewHostImpl::OnShowView(int route_id, |
1359 WindowOpenDisposition disposition, | 1378 WindowOpenDisposition disposition, |
1360 const gfx::Rect& initial_pos, | 1379 const gfx::Rect& initial_pos, |
1361 bool user_gesture) { | 1380 bool user_gesture) { |
1362 if (!is_swapped_out_) { | 1381 if (IsRVHStateActive(rvh_state_)) { |
1363 delegate_->ShowCreatedWindow( | 1382 delegate_->ShowCreatedWindow( |
1364 route_id, disposition, initial_pos, user_gesture); | 1383 route_id, disposition, initial_pos, user_gesture); |
1365 } | 1384 } |
1366 Send(new ViewMsg_Move_ACK(route_id)); | 1385 Send(new ViewMsg_Move_ACK(route_id)); |
1367 } | 1386 } |
1368 | 1387 |
1369 void RenderViewHostImpl::OnShowWidget(int route_id, | 1388 void RenderViewHostImpl::OnShowWidget(int route_id, |
1370 const gfx::Rect& initial_pos) { | 1389 const gfx::Rect& initial_pos) { |
1371 if (!is_swapped_out_) | 1390 if (IsRVHStateActive(rvh_state_)) |
1372 delegate_->ShowCreatedWidget(route_id, initial_pos); | 1391 delegate_->ShowCreatedWidget(route_id, initial_pos); |
1373 Send(new ViewMsg_Move_ACK(route_id)); | 1392 Send(new ViewMsg_Move_ACK(route_id)); |
1374 } | 1393 } |
1375 | 1394 |
1376 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) { | 1395 void RenderViewHostImpl::OnShowFullscreenWidget(int route_id) { |
1377 if (!is_swapped_out_) | 1396 if (IsRVHStateActive(rvh_state_)) |
1378 delegate_->ShowCreatedFullscreenWidget(route_id); | 1397 delegate_->ShowCreatedFullscreenWidget(route_id); |
1379 Send(new ViewMsg_Move_ACK(route_id)); | 1398 Send(new ViewMsg_Move_ACK(route_id)); |
1380 } | 1399 } |
1381 | 1400 |
1382 void RenderViewHostImpl::OnRunModal(int opener_id, IPC::Message* reply_msg) { | 1401 void RenderViewHostImpl::OnRunModal(int opener_id, IPC::Message* reply_msg) { |
1383 DCHECK(!run_modal_reply_msg_); | 1402 DCHECK(!run_modal_reply_msg_); |
1384 run_modal_reply_msg_ = reply_msg; | 1403 run_modal_reply_msg_ = reply_msg; |
1385 run_modal_opener_id_ = opener_id; | 1404 run_modal_opener_id_ = opener_id; |
1386 | 1405 |
1387 RecordAction(base::UserMetricsAction("ShowModalDialog")); | 1406 RecordAction(base::UserMetricsAction("ShowModalDialog")); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 OnShouldCloseACK(true, send_should_close_start_time_, | 1482 OnShouldCloseACK(true, send_should_close_start_time_, |
1464 base::TimeTicks::Now()); | 1483 base::TimeTicks::Now()); |
1465 return; | 1484 return; |
1466 } | 1485 } |
1467 | 1486 |
1468 // If we're waiting for an unload ack from this renderer and we receive a | 1487 // If we're waiting for an unload ack from this renderer and we receive a |
1469 // Navigate message, then the renderer was navigating before it received the | 1488 // Navigate message, then the renderer was navigating before it received the |
1470 // unload request. It will either respond to the unload request soon or our | 1489 // unload request. It will either respond to the unload request soon or our |
1471 // timer will expire. Either way, we should ignore this message, because we | 1490 // timer will expire. Either way, we should ignore this message, because we |
1472 // have already committed to closing this renderer. | 1491 // have already committed to closing this renderer. |
1473 if (is_waiting_for_unload_ack_) | 1492 if (IsWaitingForUnloadACK()) |
1474 return; | 1493 return; |
1475 | 1494 |
1476 // Cache the main frame id, so we can use it for creating the frame tree | 1495 // Cache the main frame id, so we can use it for creating the frame tree |
1477 // root node when needed. | 1496 // root node when needed. |
1478 if (PageTransitionIsMainFrame(validated_params.transition)) { | 1497 if (PageTransitionIsMainFrame(validated_params.transition)) { |
1479 if (main_frame_id_ == -1) { | 1498 if (main_frame_id_ == -1) { |
1480 main_frame_id_ = validated_params.frame_id; | 1499 main_frame_id_ = validated_params.frame_id; |
1481 } else { | 1500 } else { |
1482 // TODO(nasko): We plan to remove the usage of frame_id in navigation | 1501 // TODO(nasko): We plan to remove the usage of frame_id in navigation |
1483 // and move to routing ids. This is in place to ensure that a | 1502 // 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 Loading... |
1550 delegate_->UpdateTitle(this, page_id, title, | 1569 delegate_->UpdateTitle(this, page_id, title, |
1551 WebTextDirectionToChromeTextDirection( | 1570 WebTextDirectionToChromeTextDirection( |
1552 title_direction)); | 1571 title_direction)); |
1553 } | 1572 } |
1554 | 1573 |
1555 void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) { | 1574 void RenderViewHostImpl::OnUpdateEncoding(const std::string& encoding_name) { |
1556 delegate_->UpdateEncoding(this, encoding_name); | 1575 delegate_->UpdateEncoding(this, encoding_name); |
1557 } | 1576 } |
1558 | 1577 |
1559 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) { | 1578 void RenderViewHostImpl::OnUpdateTargetURL(int32 page_id, const GURL& url) { |
1560 if (!is_swapped_out_) | 1579 if (IsRVHStateActive(rvh_state_)) |
1561 delegate_->UpdateTargetURL(page_id, url); | 1580 delegate_->UpdateTargetURL(page_id, url); |
1562 | 1581 |
1563 // Send a notification back to the renderer that we are ready to | 1582 // Send a notification back to the renderer that we are ready to |
1564 // receive more target urls. | 1583 // receive more target urls. |
1565 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID())); | 1584 Send(new ViewMsg_UpdateTargetURL_ACK(GetRoutingID())); |
1566 } | 1585 } |
1567 | 1586 |
1568 void RenderViewHostImpl::OnUpdateInspectorSetting( | 1587 void RenderViewHostImpl::OnUpdateInspectorSetting( |
1569 const std::string& key, const std::string& value) { | 1588 const std::string& key, const std::string& value) { |
1570 GetContentClient()->browser()->UpdateInspectorSetting( | 1589 GetContentClient()->browser()->UpdateInspectorSetting( |
1571 this, key, value); | 1590 this, key, value); |
1572 } | 1591 } |
1573 | 1592 |
1574 void RenderViewHostImpl::OnClose() { | 1593 void RenderViewHostImpl::OnClose() { |
1575 // If the renderer is telling us to close, it has already run the unload | 1594 // If the renderer is telling us to close, it has already run the unload |
1576 // events, and we can take the fast path. | 1595 // events, and we can take the fast path. |
1577 ClosePageIgnoringUnloadEvents(); | 1596 ClosePageIgnoringUnloadEvents(); |
1578 } | 1597 } |
1579 | 1598 |
1580 void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) { | 1599 void RenderViewHostImpl::OnRequestMove(const gfx::Rect& pos) { |
1581 if (!is_swapped_out_) | 1600 if (IsRVHStateActive(rvh_state_)) |
1582 delegate_->RequestMove(pos); | 1601 delegate_->RequestMove(pos); |
1583 Send(new ViewMsg_Move_ACK(GetRoutingID())); | 1602 Send(new ViewMsg_Move_ACK(GetRoutingID())); |
1584 } | 1603 } |
1585 | 1604 |
1586 void RenderViewHostImpl::OnDidStartLoading() { | 1605 void RenderViewHostImpl::OnDidStartLoading() { |
1587 delegate_->DidStartLoading(this); | 1606 delegate_->DidStartLoading(this); |
1588 } | 1607 } |
1589 | 1608 |
1590 void RenderViewHostImpl::OnDidStopLoading() { | 1609 void RenderViewHostImpl::OnDidStopLoading() { |
1591 delegate_->DidStopLoading(this); | 1610 delegate_->DidStopLoading(this); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 | 1829 |
1811 void RenderViewHostImpl::OnShouldCloseACK( | 1830 void RenderViewHostImpl::OnShouldCloseACK( |
1812 bool proceed, | 1831 bool proceed, |
1813 const base::TimeTicks& renderer_before_unload_start_time, | 1832 const base::TimeTicks& renderer_before_unload_start_time, |
1814 const base::TimeTicks& renderer_before_unload_end_time) { | 1833 const base::TimeTicks& renderer_before_unload_end_time) { |
1815 decrement_in_flight_event_count(); | 1834 decrement_in_flight_event_count(); |
1816 StopHangMonitorTimeout(); | 1835 StopHangMonitorTimeout(); |
1817 // If this renderer navigated while the beforeunload request was in flight, we | 1836 // If this renderer navigated while the beforeunload request was in flight, we |
1818 // may have cleared this state in OnNavigate, in which case we can ignore | 1837 // may have cleared this state in OnNavigate, in which case we can ignore |
1819 // this message. | 1838 // this message. |
1820 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_) | 1839 if (!is_waiting_for_beforeunload_ack_ || rvh_state_ != STATE_DEFAULT) |
1821 return; | 1840 return; |
1822 | 1841 |
1823 is_waiting_for_beforeunload_ack_ = false; | 1842 is_waiting_for_beforeunload_ack_ = false; |
1824 | 1843 |
1825 RenderViewHostDelegate::RendererManagement* management_delegate = | 1844 RenderViewHostDelegate::RendererManagement* management_delegate = |
1826 delegate_->GetRendererManagementDelegate(); | 1845 delegate_->GetRendererManagementDelegate(); |
1827 if (management_delegate) { | 1846 if (management_delegate) { |
1828 base::TimeTicks before_unload_end_time; | 1847 base::TimeTicks before_unload_end_time; |
1829 if (!send_should_close_start_time_.is_null() && | 1848 if (!send_should_close_start_time_.is_null() && |
1830 !renderer_before_unload_start_time.is_null() && | 1849 !renderer_before_unload_start_time.is_null() && |
(...skipping 22 matching lines...) Expand all Loading... |
1853 delegate_->DidCancelLoading(); | 1872 delegate_->DidCancelLoading(); |
1854 } | 1873 } |
1855 | 1874 |
1856 void RenderViewHostImpl::OnClosePageACK() { | 1875 void RenderViewHostImpl::OnClosePageACK() { |
1857 decrement_in_flight_event_count(); | 1876 decrement_in_flight_event_count(); |
1858 ClosePageIgnoringUnloadEvents(); | 1877 ClosePageIgnoringUnloadEvents(); |
1859 } | 1878 } |
1860 | 1879 |
1861 void RenderViewHostImpl::NotifyRendererUnresponsive() { | 1880 void RenderViewHostImpl::NotifyRendererUnresponsive() { |
1862 delegate_->RendererUnresponsive( | 1881 delegate_->RendererUnresponsive( |
1863 this, is_waiting_for_beforeunload_ack_, is_waiting_for_unload_ack_); | 1882 this, is_waiting_for_beforeunload_ack_, IsWaitingForUnloadACK()); |
1864 } | 1883 } |
1865 | 1884 |
1866 void RenderViewHostImpl::NotifyRendererResponsive() { | 1885 void RenderViewHostImpl::NotifyRendererResponsive() { |
1867 delegate_->RendererResponsive(this); | 1886 delegate_->RendererResponsive(this); |
1868 } | 1887 } |
1869 | 1888 |
1870 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture, | 1889 void RenderViewHostImpl::RequestToLockMouse(bool user_gesture, |
1871 bool last_unlocked_by_target) { | 1890 bool last_unlocked_by_target) { |
1872 delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target); | 1891 delegate_->RequestToLockMouse(user_gesture, last_unlocked_by_target); |
1873 } | 1892 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 #endif | 1977 #endif |
1959 | 1978 |
1960 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) { | 1979 void RenderViewHostImpl::SendOrientationChangeEvent(int orientation) { |
1961 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation)); | 1980 Send(new ViewMsg_OrientationChangeEvent(GetRoutingID(), orientation)); |
1962 } | 1981 } |
1963 | 1982 |
1964 void RenderViewHostImpl::ToggleSpeechInput() { | 1983 void RenderViewHostImpl::ToggleSpeechInput() { |
1965 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID())); | 1984 Send(new InputTagSpeechMsg_ToggleSpeechInput(GetRoutingID())); |
1966 } | 1985 } |
1967 | 1986 |
| 1987 bool RenderViewHostImpl::IsWaitingForUnloadACK() const { |
| 1988 return rvh_state_ == STATE_WAITING_FOR_UNLOAD_ACK || |
| 1989 rvh_state_ == STATE_WAITING_FOR_CLOSE || |
| 1990 rvh_state_ == STATE_PENDING_SHUTDOWN || |
| 1991 rvh_state_ == STATE_PENDING_SWAP_OUT; |
| 1992 } |
| 1993 |
1968 bool RenderViewHostImpl::CanCommitURL(const GURL& url) { | 1994 bool RenderViewHostImpl::CanCommitURL(const GURL& url) { |
1969 // TODO(creis): We should also check for WebUI pages here. Also, when the | 1995 // TODO(creis): We should also check for WebUI pages here. Also, when the |
1970 // out-of-process iframes implementation is ready, we should check for | 1996 // out-of-process iframes implementation is ready, we should check for |
1971 // cross-site URLs that are not allowed to commit in this process. | 1997 // cross-site URLs that are not allowed to commit in this process. |
1972 | 1998 |
1973 // Give the client a chance to disallow URLs from committing. | 1999 // Give the client a chance to disallow URLs from committing. |
1974 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); | 2000 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); |
1975 } | 2001 } |
1976 | 2002 |
1977 void RenderViewHostImpl::ExitFullscreen() { | 2003 void RenderViewHostImpl::ExitFullscreen() { |
1978 RejectMouseLockOrUnlockIfNecessary(); | 2004 RejectMouseLockOrUnlockIfNecessary(); |
1979 // Notify delegate_ and renderer of fullscreen state change. | 2005 // Notify delegate_ and renderer of fullscreen state change. |
1980 OnToggleFullscreen(false); | 2006 OnToggleFullscreen(false); |
1981 } | 2007 } |
1982 | 2008 |
1983 WebPreferences RenderViewHostImpl::GetWebkitPreferences() { | 2009 WebPreferences RenderViewHostImpl::GetWebkitPreferences() { |
1984 return delegate_->GetWebkitPrefs(); | 2010 return delegate_->GetWebkitPrefs(); |
1985 } | 2011 } |
1986 | 2012 |
1987 void RenderViewHostImpl::DisownOpener() { | 2013 void RenderViewHostImpl::DisownOpener() { |
1988 // This should only be called when swapped out. | 2014 // This should only be called when swapped out. |
1989 DCHECK(is_swapped_out_); | 2015 DCHECK(IsSwappedOut()); |
1990 | 2016 |
1991 Send(new ViewMsg_DisownOpener(GetRoutingID())); | 2017 Send(new ViewMsg_DisownOpener(GetRoutingID())); |
1992 } | 2018 } |
1993 | 2019 |
1994 void RenderViewHostImpl::SetAccessibilityCallbackForTesting( | 2020 void RenderViewHostImpl::SetAccessibilityCallbackForTesting( |
1995 const base::Callback<void(ui::AXEvent)>& callback) { | 2021 const base::Callback<void(ui::AXEvent)>& callback) { |
1996 accessibility_testing_callback_ = callback; | 2022 accessibility_testing_callback_ = callback; |
1997 } | 2023 } |
1998 | 2024 |
1999 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) { | 2025 void RenderViewHostImpl::UpdateWebkitPreferences(const WebPreferences& prefs) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2060 const gfx::Point& location, const blink::WebPluginAction& action) { | 2086 const gfx::Point& location, const blink::WebPluginAction& action) { |
2061 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action)); | 2087 Send(new ViewMsg_PluginActionAt(GetRoutingID(), location, action)); |
2062 } | 2088 } |
2063 | 2089 |
2064 void RenderViewHostImpl::NotifyMoveOrResizeStarted() { | 2090 void RenderViewHostImpl::NotifyMoveOrResizeStarted() { |
2065 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID())); | 2091 Send(new ViewMsg_MoveOrResizeStarted(GetRoutingID())); |
2066 } | 2092 } |
2067 | 2093 |
2068 void RenderViewHostImpl::OnAccessibilityEvents( | 2094 void RenderViewHostImpl::OnAccessibilityEvents( |
2069 const std::vector<AccessibilityHostMsg_EventParams>& params) { | 2095 const std::vector<AccessibilityHostMsg_EventParams>& params) { |
2070 if (view_ && !is_swapped_out_) { | 2096 if (view_ && IsRVHStateActive(rvh_state_)) { |
2071 view_->CreateBrowserAccessibilityManagerIfNeeded(); | 2097 view_->CreateBrowserAccessibilityManagerIfNeeded(); |
2072 BrowserAccessibilityManager* manager = | 2098 BrowserAccessibilityManager* manager = |
2073 view_->GetBrowserAccessibilityManager(); | 2099 view_->GetBrowserAccessibilityManager(); |
2074 if (manager) | 2100 if (manager) |
2075 manager->OnAccessibilityEvents(params); | 2101 manager->OnAccessibilityEvents(params); |
2076 } | 2102 } |
2077 | 2103 |
2078 // Always send an ACK or the renderer can be in a bad state. | 2104 // Always send an ACK or the renderer can be in a bad state. |
2079 Send(new AccessibilityMsg_Events_ACK(GetRoutingID())); | 2105 Send(new AccessibilityMsg_Events_ACK(GetRoutingID())); |
2080 | 2106 |
(...skipping 11 matching lines...) Expand all Loading... |
2092 if (!ax_tree_) | 2118 if (!ax_tree_) |
2093 ax_tree_.reset(new ui::AXTree(update)); | 2119 ax_tree_.reset(new ui::AXTree(update)); |
2094 else | 2120 else |
2095 CHECK(ax_tree_->Unserialize(update)) << ax_tree_->error(); | 2121 CHECK(ax_tree_->Unserialize(update)) << ax_tree_->error(); |
2096 accessibility_testing_callback_.Run(param.event_type); | 2122 accessibility_testing_callback_.Run(param.event_type); |
2097 } | 2123 } |
2098 } | 2124 } |
2099 | 2125 |
2100 void RenderViewHostImpl::OnAccessibilityLocationChanges( | 2126 void RenderViewHostImpl::OnAccessibilityLocationChanges( |
2101 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { | 2127 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { |
2102 if (view_ && !is_swapped_out_) { | 2128 if (view_ && IsRVHStateActive(rvh_state_)) { |
2103 view_->CreateBrowserAccessibilityManagerIfNeeded(); | 2129 view_->CreateBrowserAccessibilityManagerIfNeeded(); |
2104 BrowserAccessibilityManager* manager = | 2130 BrowserAccessibilityManager* manager = |
2105 view_->GetBrowserAccessibilityManager(); | 2131 view_->GetBrowserAccessibilityManager(); |
2106 if (manager) | 2132 if (manager) |
2107 manager->OnLocationChanges(params); | 2133 manager->OnLocationChanges(params); |
2108 } | 2134 } |
2109 } | 2135 } |
2110 | 2136 |
2111 void RenderViewHostImpl::OnScriptEvalResponse(int id, | 2137 void RenderViewHostImpl::OnScriptEvalResponse(int id, |
2112 const base::ListValue& result) { | 2138 const base::ListValue& result) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 params.item_height, | 2223 params.item_height, |
2198 params.item_font_size, | 2224 params.item_font_size, |
2199 params.selected_item, | 2225 params.selected_item, |
2200 params.popup_items, | 2226 params.popup_items, |
2201 params.right_aligned, | 2227 params.right_aligned, |
2202 params.allow_multiple_selection); | 2228 params.allow_multiple_selection); |
2203 } | 2229 } |
2204 } | 2230 } |
2205 #endif | 2231 #endif |
2206 | 2232 |
2207 void RenderViewHostImpl::SetSwappedOut(bool is_swapped_out) { | 2233 void RenderViewHostImpl::SetState(RenderViewHostImplState rvh_state) { |
2208 // We update the number of RenderViews in a SiteInstance when the | 2234 // We update the number of RenderViews in a SiteInstance when the |
2209 // swapped out status of this RenderView gets flipped. | 2235 // swapped out status of this RenderView gets flipped to/from live. |
2210 if (is_swapped_out_ && !is_swapped_out) | 2236 if (!IsRVHStateActive(rvh_state_) && IsRVHStateActive(rvh_state)) |
2211 instance_->increment_active_view_count(); | 2237 instance_->increment_active_view_count(); |
2212 else if (!is_swapped_out_ && is_swapped_out) | 2238 else if (IsRVHStateActive(rvh_state_) && !IsRVHStateActive(rvh_state)) |
2213 instance_->decrement_active_view_count(); | 2239 instance_->decrement_active_view_count(); |
2214 | 2240 |
2215 is_swapped_out_ = is_swapped_out; | 2241 // Whenever we change the RVH state to and from live or swapped out state, we |
| 2242 // should not be waiting for beforeunload or unload acks. We clear them here |
| 2243 // to be safe, since they can cause navigations to be ignored in OnNavigate. |
| 2244 if (rvh_state == STATE_DEFAULT || |
| 2245 rvh_state == STATE_SWAPPED_OUT || |
| 2246 rvh_state_ == STATE_DEFAULT || |
| 2247 rvh_state_ == STATE_SWAPPED_OUT) { |
| 2248 is_waiting_for_beforeunload_ack_ = false; |
| 2249 } |
| 2250 rvh_state_ = rvh_state; |
2216 | 2251 |
2217 // Whenever we change swap out state, we should not be waiting for | |
2218 // beforeunload or unload acks. We clear them here to be safe, since they | |
2219 // can cause navigations to be ignored in OnNavigate. | |
2220 is_waiting_for_beforeunload_ack_ = false; | |
2221 is_waiting_for_unload_ack_ = false; | |
2222 has_timed_out_on_unload_ = false; | |
2223 } | 2252 } |
2224 | 2253 |
2225 bool RenderViewHostImpl::CanAccessFilesOfPageState( | 2254 bool RenderViewHostImpl::CanAccessFilesOfPageState( |
2226 const PageState& state) const { | 2255 const PageState& state) const { |
2227 ChildProcessSecurityPolicyImpl* policy = | 2256 ChildProcessSecurityPolicyImpl* policy = |
2228 ChildProcessSecurityPolicyImpl::GetInstance(); | 2257 ChildProcessSecurityPolicyImpl::GetInstance(); |
2229 | 2258 |
2230 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); | 2259 const std::vector<base::FilePath>& file_paths = state.GetReferencedFiles(); |
2231 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); | 2260 for (std::vector<base::FilePath>::const_iterator file = file_paths.begin(); |
2232 file != file_paths.end(); ++file) { | 2261 file != file_paths.end(); ++file) { |
2233 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) | 2262 if (!policy->CanReadFile(GetProcess()->GetID(), *file)) |
2234 return false; | 2263 return false; |
2235 } | 2264 } |
2236 return true; | 2265 return true; |
2237 } | 2266 } |
2238 | 2267 |
2239 void RenderViewHostImpl::AttachToFrameTree() { | 2268 void RenderViewHostImpl::AttachToFrameTree() { |
2240 FrameTree* frame_tree = delegate_->GetFrameTree(); | 2269 FrameTree* frame_tree = delegate_->GetFrameTree(); |
2241 | 2270 |
2242 frame_tree->ResetForMainFrameSwap(); | 2271 frame_tree->ResetForMainFrameSwap(); |
2243 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) { | 2272 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) { |
2244 frame_tree->OnFirstNavigationAfterSwap(main_frame_id()); | 2273 frame_tree->OnFirstNavigationAfterSwap(main_frame_id()); |
2245 } | 2274 } |
2246 } | 2275 } |
2247 | 2276 |
2248 } // namespace content | 2277 } // namespace content |
OLD | NEW |