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_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "content/browser/gpu/gpu_process_host.h" | 27 #include "content/browser/gpu/gpu_process_host.h" |
28 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 28 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
29 #include "content/browser/gpu/gpu_surface_tracker.h" | 29 #include "content/browser/gpu/gpu_surface_tracker.h" |
30 #include "content/browser/renderer_host/backing_store.h" | 30 #include "content/browser/renderer_host/backing_store.h" |
31 #include "content/browser/renderer_host/backing_store_manager.h" | 31 #include "content/browser/renderer_host/backing_store_manager.h" |
32 #include "content/browser/renderer_host/dip_util.h" | 32 #include "content/browser/renderer_host/dip_util.h" |
33 #include "content/browser/renderer_host/input/input_router_impl.h" | 33 #include "content/browser/renderer_host/input/input_router_impl.h" |
34 #include "content/browser/renderer_host/input/synthetic_gesture.h" | 34 #include "content/browser/renderer_host/input/synthetic_gesture.h" |
35 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" | 35 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" |
36 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" | 36 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" |
| 37 #include "content/browser/renderer_host/input/timeout_monitor.h" |
37 #include "content/browser/renderer_host/overscroll_controller.h" | 38 #include "content/browser/renderer_host/overscroll_controller.h" |
38 #include "content/browser/renderer_host/render_process_host_impl.h" | 39 #include "content/browser/renderer_host/render_process_host_impl.h" |
39 #include "content/browser/renderer_host/render_view_host_impl.h" | 40 #include "content/browser/renderer_host/render_view_host_impl.h" |
40 #include "content/browser/renderer_host/render_widget_helper.h" | 41 #include "content/browser/renderer_host/render_widget_helper.h" |
41 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 42 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
42 #include "content/common/accessibility_messages.h" | 43 #include "content/common/accessibility_messages.h" |
43 #include "content/common/content_constants_internal.h" | 44 #include "content/common/content_constants_internal.h" |
44 #include "content/common/gpu/gpu_messages.h" | 45 #include "content/common/gpu/gpu_messages.h" |
45 #include "content/common/input_messages.h" | 46 #include "content/common/input_messages.h" |
46 #include "content/common/view_messages.h" | 47 #include "content/common/view_messages.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 accessibility_mode_ = | 227 accessibility_mode_ = |
227 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); | 228 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
228 | 229 |
229 input_router_.reset(new InputRouterImpl(process_, this, this, routing_id_)); | 230 input_router_.reset(new InputRouterImpl(process_, this, this, routing_id_)); |
230 | 231 |
231 #if defined(USE_AURA) | 232 #if defined(USE_AURA) |
232 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> | 233 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
233 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 234 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
234 SetOverscrollControllerEnabled(overscroll_enabled); | 235 SetOverscrollControllerEnabled(overscroll_enabled); |
235 #endif | 236 #endif |
| 237 |
| 238 if (GetProcess()->IsGuest() || !CommandLine::ForCurrentProcess()->HasSwitch( |
| 239 switches::kDisableHangMonitor)) { |
| 240 hang_monitor_timeout_.reset(new TimeoutMonitor( |
| 241 base::Bind(&RenderWidgetHostImpl::RendererIsUnresponsive, |
| 242 weak_factory_.GetWeakPtr()))); |
| 243 } |
236 } | 244 } |
237 | 245 |
238 RenderWidgetHostImpl::~RenderWidgetHostImpl() { | 246 RenderWidgetHostImpl::~RenderWidgetHostImpl() { |
239 SetView(NULL); | 247 SetView(NULL); |
240 | 248 |
241 // Clear our current or cached backing store if either remains. | 249 // Clear our current or cached backing store if either remains. |
242 BackingStoreManager::RemoveBackingStore(this); | 250 BackingStoreManager::RemoveBackingStore(this); |
243 | 251 |
244 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); | 252 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); |
245 surface_id_ = 0; | 253 surface_id_ = 0; |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 | 898 |
891 // Send out a request to the renderer to paint the view if required. | 899 // Send out a request to the renderer to paint the view if required. |
892 repaint_start_time_ = TimeTicks::Now(); | 900 repaint_start_time_ = TimeTicks::Now(); |
893 repaint_ack_pending_ = true; | 901 repaint_ack_pending_ = true; |
894 TRACE_EVENT_ASYNC_BEGIN0( | 902 TRACE_EVENT_ASYNC_BEGIN0( |
895 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); | 903 "renderer_host", "RenderWidgetHostImpl::repaint_ack_pending_", this); |
896 Send(new ViewMsg_Repaint(routing_id_, current_size_)); | 904 Send(new ViewMsg_Repaint(routing_id_, current_size_)); |
897 return true; | 905 return true; |
898 } | 906 } |
899 | 907 |
900 void RenderWidgetHostImpl::StartHangMonitorTimeout(TimeDelta delay) { | 908 void RenderWidgetHostImpl::StartHangMonitorTimeout(base::TimeDelta delay) { |
901 if (!GetProcess()->IsGuest() && CommandLine::ForCurrentProcess()->HasSwitch( | 909 if (hang_monitor_timeout_) |
902 switches::kDisableHangMonitor)) { | 910 hang_monitor_timeout_->Start(delay); |
903 return; | |
904 } | |
905 | |
906 // Set time_when_considered_hung_ if it's null. Also, update | |
907 // time_when_considered_hung_ if the caller's request is sooner than the | |
908 // existing one. This will have the side effect that the existing timeout will | |
909 // be forgotten. | |
910 Time requested_end_time = Time::Now() + delay; | |
911 if (time_when_considered_hung_.is_null() || | |
912 time_when_considered_hung_ > requested_end_time) | |
913 time_when_considered_hung_ = requested_end_time; | |
914 | |
915 // If we already have a timer with the same or shorter duration, then we can | |
916 // wait for it to finish. | |
917 if (hung_renderer_timer_.IsRunning() && | |
918 hung_renderer_timer_.GetCurrentDelay() <= delay) { | |
919 // If time_when_considered_hung_ was null, this timer may fire early. | |
920 // CheckRendererIsUnresponsive handles that by calling | |
921 // StartHangMonitorTimeout with the remaining time. | |
922 // If time_when_considered_hung_ was non-null, it means we still haven't | |
923 // heard from the renderer so we leave time_when_considered_hung_ as is. | |
924 return; | |
925 } | |
926 | |
927 // Either the timer is not yet running, or we need to adjust the timer to | |
928 // fire sooner. | |
929 time_when_considered_hung_ = requested_end_time; | |
930 hung_renderer_timer_.Stop(); | |
931 hung_renderer_timer_.Start(FROM_HERE, delay, this, | |
932 &RenderWidgetHostImpl::CheckRendererIsUnresponsive); | |
933 } | 911 } |
934 | 912 |
935 void RenderWidgetHostImpl::RestartHangMonitorTimeout() { | 913 void RenderWidgetHostImpl::RestartHangMonitorTimeout() { |
936 // Setting to null will cause StartHangMonitorTimeout to restart the timer. | 914 if (hang_monitor_timeout_) |
937 time_when_considered_hung_ = Time(); | 915 hang_monitor_timeout_->Restart( |
938 StartHangMonitorTimeout( | 916 base::TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); |
939 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); | |
940 } | 917 } |
941 | 918 |
942 void RenderWidgetHostImpl::StopHangMonitorTimeout() { | 919 void RenderWidgetHostImpl::StopHangMonitorTimeout() { |
943 time_when_considered_hung_ = Time(); | 920 if (hang_monitor_timeout_) |
| 921 hang_monitor_timeout_->Stop(); |
944 RendererIsResponsive(); | 922 RendererIsResponsive(); |
945 // We do not bother to stop the hung_renderer_timer_ here in case it will be | |
946 // started again shortly, which happens to be the common use case. | |
947 } | 923 } |
948 | 924 |
949 void RenderWidgetHostImpl::EnableFullAccessibilityMode() { | 925 void RenderWidgetHostImpl::EnableFullAccessibilityMode() { |
950 SetAccessibilityMode(AccessibilityModeComplete); | 926 SetAccessibilityMode(AccessibilityModeComplete); |
951 } | 927 } |
952 | 928 |
953 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 929 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
954 ForwardMouseEventWithLatencyInfo( | 930 ForwardMouseEventWithLatencyInfo( |
955 MouseEventWithLatencyInfo(mouse_event, | 931 MouseEventWithLatencyInfo(mouse_event, |
956 CreateRWHLatencyInfoIfNotExist(NULL))); | 932 CreateRWHLatencyInfoIfNotExist(NULL))); |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 // Tell the view to die. | 1367 // Tell the view to die. |
1392 // Note that in the process of the view shutting down, it can call a ton | 1368 // Note that in the process of the view shutting down, it can call a ton |
1393 // of other messages on us. So if you do any other deinitialization here, | 1369 // of other messages on us. So if you do any other deinitialization here, |
1394 // do it after this call to view_->Destroy(). | 1370 // do it after this call to view_->Destroy(). |
1395 if (view_) | 1371 if (view_) |
1396 view_->Destroy(); | 1372 view_->Destroy(); |
1397 | 1373 |
1398 delete this; | 1374 delete this; |
1399 } | 1375 } |
1400 | 1376 |
1401 void RenderWidgetHostImpl::CheckRendererIsUnresponsive() { | 1377 void RenderWidgetHostImpl::RendererIsUnresponsive() { |
1402 // If we received a call to StopHangMonitorTimeout. | |
1403 if (time_when_considered_hung_.is_null()) | |
1404 return; | |
1405 | |
1406 // If we have not waited long enough, then wait some more. | |
1407 Time now = Time::Now(); | |
1408 if (now < time_when_considered_hung_) { | |
1409 StartHangMonitorTimeout(time_when_considered_hung_ - now); | |
1410 return; | |
1411 } | |
1412 | |
1413 // OK, looks like we have a hung renderer! | |
1414 NotificationService::current()->Notify( | 1378 NotificationService::current()->Notify( |
1415 NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 1379 NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
1416 Source<RenderWidgetHost>(this), | 1380 Source<RenderWidgetHost>(this), |
1417 NotificationService::NoDetails()); | 1381 NotificationService::NoDetails()); |
1418 is_unresponsive_ = true; | 1382 is_unresponsive_ = true; |
1419 NotifyRendererUnresponsive(); | 1383 NotifyRendererUnresponsive(); |
1420 } | 1384 } |
1421 | 1385 |
1422 void RenderWidgetHostImpl::RendererIsResponsive() { | 1386 void RenderWidgetHostImpl::RendererIsResponsive() { |
1423 if (is_unresponsive_) { | 1387 if (is_unresponsive_) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 | 1494 |
1531 bool RenderWidgetHostImpl::OnSwapCompositorFrame( | 1495 bool RenderWidgetHostImpl::OnSwapCompositorFrame( |
1532 const IPC::Message& message) { | 1496 const IPC::Message& message) { |
1533 ViewHostMsg_SwapCompositorFrame::Param param; | 1497 ViewHostMsg_SwapCompositorFrame::Param param; |
1534 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) | 1498 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, ¶m)) |
1535 return false; | 1499 return false; |
1536 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 1500 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
1537 uint32 output_surface_id = param.a; | 1501 uint32 output_surface_id = param.a; |
1538 param.b.AssignTo(frame.get()); | 1502 param.b.AssignTo(frame.get()); |
1539 | 1503 |
| 1504 bool fixed_page_scale = |
| 1505 frame->metadata.min_page_scale_factor == |
| 1506 frame->metadata.max_page_scale_factor; |
| 1507 int updated_view_flags = fixed_page_scale ? InputRouter::FIXED_PAGE_SCALE |
| 1508 : InputRouter::VIEW_FLAGS_NONE; |
| 1509 input_router_->OnViewUpdated(updated_view_flags); |
| 1510 |
1540 if (view_) { | 1511 if (view_) { |
1541 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); | 1512 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); |
1542 view_->DidReceiveRendererFrame(); | 1513 view_->DidReceiveRendererFrame(); |
1543 } else { | 1514 } else { |
1544 cc::CompositorFrameAck ack; | 1515 cc::CompositorFrameAck ack; |
1545 if (frame->gl_frame_data) { | 1516 if (frame->gl_frame_data) { |
1546 ack.gl_frame_data = frame->gl_frame_data.Pass(); | 1517 ack.gl_frame_data = frame->gl_frame_data.Pass(); |
1547 ack.gl_frame_data->sync_point = 0; | 1518 ack.gl_frame_data->sync_point = 0; |
1548 } else if (frame->delegated_frame_data) { | 1519 } else if (frame->delegated_frame_data) { |
1549 cc::TransferableResource::ReturnResources( | 1520 cc::TransferableResource::ReturnResources( |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2495 continue; | 2466 continue; |
2496 } | 2467 } |
2497 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 2468 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
2498 if (rwhi_set.insert(rwhi).second) | 2469 if (rwhi_set.insert(rwhi).second) |
2499 rwhi->FrameSwapped(latency_info); | 2470 rwhi->FrameSwapped(latency_info); |
2500 } | 2471 } |
2501 } | 2472 } |
2502 } | 2473 } |
2503 | 2474 |
2504 } // namespace content | 2475 } // namespace content |
OLD | NEW |