OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/renderer_host/render_widget_host.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/metrics/stats_counters.h" | 13 #include "base/metrics/stats_counters.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "content/browser/accessibility/browser_accessibility_state.h" | 15 #include "content/browser/accessibility/browser_accessibility_state.h" |
16 #include "content/browser/gpu/gpu_process_host.h" | 16 #include "content/browser/gpu/gpu_process_host.h" |
17 #include "content/browser/renderer_host/backing_store.h" | 17 #include "content/browser/renderer_host/backing_store.h" |
18 #include "content/browser/renderer_host/backing_store_manager.h" | 18 #include "content/browser/renderer_host/backing_store_manager.h" |
19 #include "content/browser/renderer_host/render_process_host.h" | 19 #include "content/browser/renderer_host/render_process_host.h" |
20 #include "content/browser/renderer_host/render_widget_helper.h" | 20 #include "content/browser/renderer_host/render_widget_helper.h" |
21 #include "content/browser/renderer_host/render_widget_host_view.h" | 21 #include "content/browser/renderer_host/render_widget_host_view.h" |
22 #include "content/browser/user_metrics.h" | 22 #include "content/browser/user_metrics.h" |
23 #include "content/common/gpu/gpu_messages.h" | 23 #include "content/common/gpu/gpu_messages.h" |
24 #include "content/common/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/common/result_codes.h" | 25 #include "content/common/result_codes.h" |
26 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
27 #include "content/public/browser/native_web_keyboard_event.h" | 27 #include "content/public/browser/native_web_keyboard_event.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
31 #include "ui/base/keycodes/keyboard_codes.h" | 31 #include "ui/base/keycodes/keyboard_codes.h" |
32 #include "webkit/glue/webcursor.h" | 32 #include "webkit/glue/webcursor.h" |
33 #include "webkit/glue/webpreferences.h" | 33 #include "webkit/glue/webpreferences.h" |
34 #include "webkit/plugins/npapi/webplugin.h" | 34 #include "webkit/plugins/npapi/webplugin.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 GpuProcessHost::SendOnIO( | 259 GpuProcessHost::SendOnIO( |
260 0, | 260 0, |
261 content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | 261 content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
262 new GpuMsg_VisibilityChanged(routing_id_, process()->id(), false)); | 262 new GpuMsg_VisibilityChanged(routing_id_, process()->id(), false)); |
263 | 263 |
264 // Tell the RenderProcessHost we were hidden. | 264 // Tell the RenderProcessHost we were hidden. |
265 process_->WidgetHidden(); | 265 process_->WidgetHidden(); |
266 | 266 |
267 bool is_visible = false; | 267 bool is_visible = false; |
268 NotificationService::current()->Notify( | 268 content::NotificationService::current()->Notify( |
269 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 269 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
270 content::Source<RenderWidgetHost>(this), | 270 content::Source<RenderWidgetHost>(this), |
271 content::Details<bool>(&is_visible)); | 271 content::Details<bool>(&is_visible)); |
272 } | 272 } |
273 | 273 |
274 void RenderWidgetHost::WasRestored() { | 274 void RenderWidgetHost::WasRestored() { |
275 // When we create the widget, it is created as *not* hidden. | 275 // When we create the widget, it is created as *not* hidden. |
276 if (!is_hidden_) | 276 if (!is_hidden_) |
277 return; | 277 return; |
278 is_hidden_ = false; | 278 is_hidden_ = false; |
(...skipping 14 matching lines...) Expand all Loading... |
293 Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); | 293 Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); |
294 | 294 |
295 GpuProcessHost::SendOnIO( | 295 GpuProcessHost::SendOnIO( |
296 0, | 296 0, |
297 content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, | 297 content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
298 new GpuMsg_VisibilityChanged(routing_id_, process()->id(), true)); | 298 new GpuMsg_VisibilityChanged(routing_id_, process()->id(), true)); |
299 | 299 |
300 process_->WidgetRestored(); | 300 process_->WidgetRestored(); |
301 | 301 |
302 bool is_visible = true; | 302 bool is_visible = true; |
303 NotificationService::current()->Notify( | 303 content::NotificationService::current()->Notify( |
304 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 304 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
305 content::Source<RenderWidgetHost>(this), | 305 content::Source<RenderWidgetHost>(this), |
306 content::Details<bool>(&is_visible)); | 306 content::Details<bool>(&is_visible)); |
307 | 307 |
308 // It's possible for our size to be out of sync with the renderer. The | 308 // It's possible for our size to be out of sync with the renderer. The |
309 // following is one case that leads to this: | 309 // following is one case that leads to this: |
310 // 1. WasResized -> Send ViewMsg_Resize to render | 310 // 1. WasResized -> Send ViewMsg_Resize to render |
311 // 2. WasResized -> do nothing as resize_ack_pending_ is true | 311 // 2. WasResized -> do nothing as resize_ack_pending_ is true |
312 // 3. WasHidden | 312 // 3. WasHidden |
313 // 4. OnMsgUpdateRect from (1) processed. Does NOT invoke WasResized as view | 313 // 4. OnMsgUpdateRect from (1) processed. Does NOT invoke WasResized as view |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 | 826 |
827 bool RenderWidgetHost::IsMouseLocked() const { | 827 bool RenderWidgetHost::IsMouseLocked() const { |
828 return view_ ? view_->mouse_locked() : false; | 828 return view_ ? view_->mouse_locked() : false; |
829 } | 829 } |
830 | 830 |
831 bool RenderWidgetHost::IsFullscreen() const { | 831 bool RenderWidgetHost::IsFullscreen() const { |
832 return false; | 832 return false; |
833 } | 833 } |
834 | 834 |
835 void RenderWidgetHost::Destroy() { | 835 void RenderWidgetHost::Destroy() { |
836 NotificationService::current()->Notify( | 836 content::NotificationService::current()->Notify( |
837 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 837 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
838 content::Source<RenderWidgetHost>(this), | 838 content::Source<RenderWidgetHost>(this), |
839 NotificationService::NoDetails()); | 839 content::NotificationService::NoDetails()); |
840 | 840 |
841 // Tell the view to die. | 841 // Tell the view to die. |
842 // Note that in the process of the view shutting down, it can call a ton | 842 // Note that in the process of the view shutting down, it can call a ton |
843 // of other messages on us. So if you do any other deinitialization here, | 843 // of other messages on us. So if you do any other deinitialization here, |
844 // do it after this call to view_->Destroy(). | 844 // do it after this call to view_->Destroy(). |
845 if (view_) | 845 if (view_) |
846 view_->Destroy(); | 846 view_->Destroy(); |
847 | 847 |
848 delete this; | 848 delete this; |
849 } | 849 } |
850 | 850 |
851 void RenderWidgetHost::CheckRendererIsUnresponsive() { | 851 void RenderWidgetHost::CheckRendererIsUnresponsive() { |
852 // If we received a call to StopHangMonitorTimeout. | 852 // If we received a call to StopHangMonitorTimeout. |
853 if (time_when_considered_hung_.is_null()) | 853 if (time_when_considered_hung_.is_null()) |
854 return; | 854 return; |
855 | 855 |
856 // If we have not waited long enough, then wait some more. | 856 // If we have not waited long enough, then wait some more. |
857 Time now = Time::Now(); | 857 Time now = Time::Now(); |
858 if (now < time_when_considered_hung_) { | 858 if (now < time_when_considered_hung_) { |
859 StartHangMonitorTimeout(time_when_considered_hung_ - now); | 859 StartHangMonitorTimeout(time_when_considered_hung_ - now); |
860 return; | 860 return; |
861 } | 861 } |
862 | 862 |
863 // OK, looks like we have a hung renderer! | 863 // OK, looks like we have a hung renderer! |
864 NotificationService::current()->Notify( | 864 content::NotificationService::current()->Notify( |
865 content::NOTIFICATION_RENDERER_PROCESS_HANG, | 865 content::NOTIFICATION_RENDERER_PROCESS_HANG, |
866 content::Source<RenderWidgetHost>(this), | 866 content::Source<RenderWidgetHost>(this), |
867 NotificationService::NoDetails()); | 867 content::NotificationService::NoDetails()); |
868 is_unresponsive_ = true; | 868 is_unresponsive_ = true; |
869 NotifyRendererUnresponsive(); | 869 NotifyRendererUnresponsive(); |
870 } | 870 } |
871 | 871 |
872 void RenderWidgetHost::RendererIsResponsive() { | 872 void RenderWidgetHost::RendererIsResponsive() { |
873 if (is_unresponsive_) { | 873 if (is_unresponsive_) { |
874 is_unresponsive_ = false; | 874 is_unresponsive_ = false; |
875 NotifyRendererResponsive(); | 875 NotifyRendererResponsive(); |
876 } | 876 } |
877 } | 877 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 // Note that we ignore the position. | 927 // Note that we ignore the position. |
928 if (view_) { | 928 if (view_) { |
929 view_->SetBounds(pos); | 929 view_->SetBounds(pos); |
930 Send(new ViewMsg_Move_ACK(routing_id_)); | 930 Send(new ViewMsg_Move_ACK(routing_id_)); |
931 } | 931 } |
932 } | 932 } |
933 | 933 |
934 void RenderWidgetHost::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { | 934 void RenderWidgetHost::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { |
935 PaintAtSizeAckDetails details = {tag, size}; | 935 PaintAtSizeAckDetails details = {tag, size}; |
936 gfx::Size size_details = size; | 936 gfx::Size size_details = size; |
937 NotificationService::current()->Notify( | 937 content::NotificationService::current()->Notify( |
938 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | 938 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, |
939 content::Source<RenderWidgetHost>(this), | 939 content::Source<RenderWidgetHost>(this), |
940 content::Details<PaintAtSizeAckDetails>(&details)); | 940 content::Details<PaintAtSizeAckDetails>(&details)); |
941 } | 941 } |
942 | 942 |
943 void RenderWidgetHost::OnMsgUpdateRect( | 943 void RenderWidgetHost::OnMsgUpdateRect( |
944 const ViewHostMsg_UpdateRect_Params& params) { | 944 const ViewHostMsg_UpdateRect_Params& params) { |
945 TRACE_EVENT0("renderer_host", "RenderWidgetHost::OnMsgUpdateRect"); | 945 TRACE_EVENT0("renderer_host", "RenderWidgetHost::OnMsgUpdateRect"); |
946 TimeTicks paint_start = TimeTicks::Now(); | 946 TimeTicks paint_start = TimeTicks::Now(); |
947 | 947 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 return; | 1031 return; |
1032 | 1032 |
1033 // Now paint the view. Watch out: it might be destroyed already. | 1033 // Now paint the view. Watch out: it might be destroyed already. |
1034 if (view_ && !is_accelerated_compositing_active_) { | 1034 if (view_ && !is_accelerated_compositing_active_) { |
1035 view_being_painted_ = true; | 1035 view_being_painted_ = true; |
1036 view_->DidUpdateBackingStore(params.scroll_rect, params.dx, params.dy, | 1036 view_->DidUpdateBackingStore(params.scroll_rect, params.dx, params.dy, |
1037 params.copy_rects); | 1037 params.copy_rects); |
1038 view_being_painted_ = false; | 1038 view_being_painted_ = false; |
1039 } | 1039 } |
1040 | 1040 |
1041 NotificationService::current()->Notify( | 1041 content::NotificationService::current()->Notify( |
1042 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | 1042 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
1043 content::Source<RenderWidgetHost>(this), | 1043 content::Source<RenderWidgetHost>(this), |
1044 NotificationService::NoDetails()); | 1044 content::NotificationService::NoDetails()); |
1045 | 1045 |
1046 // If we got a resize ack, then perhaps we have another resize to send? | 1046 // If we got a resize ack, then perhaps we have another resize to send? |
1047 if (is_resize_ack && view_) { | 1047 if (is_resize_ack && view_) { |
1048 // WasResized checks the current size and sends the resize update only | 1048 // WasResized checks the current size and sends the resize update only |
1049 // when something was actually changed. | 1049 // when something was actually changed. |
1050 WasResized(); | 1050 WasResized(); |
1051 } | 1051 } |
1052 | 1052 |
1053 // Log the time delta for processing a paint message. | 1053 // Log the time delta for processing a paint message. |
1054 TimeDelta delta = TimeTicks::Now() - paint_start; | 1054 TimeDelta delta = TimeTicks::Now() - paint_start; |
(...skipping 28 matching lines...) Expand all Loading... |
1083 } else if (type == WebInputEvent::MouseWheel) { | 1083 } else if (type == WebInputEvent::MouseWheel) { |
1084 ProcessWheelAck(processed); | 1084 ProcessWheelAck(processed); |
1085 } else if (type == WebInputEvent::TouchMove) { | 1085 } else if (type == WebInputEvent::TouchMove) { |
1086 touch_move_pending_ = false; | 1086 touch_move_pending_ = false; |
1087 if (touch_event_is_queued_) { | 1087 if (touch_event_is_queued_) { |
1088 touch_event_is_queued_ = false; | 1088 touch_event_is_queued_ = false; |
1089 ForwardTouchEvent(queued_touch_event_); | 1089 ForwardTouchEvent(queued_touch_event_); |
1090 } | 1090 } |
1091 } | 1091 } |
1092 // This is used only for testing. | 1092 // This is used only for testing. |
1093 NotificationService::current()->Notify( | 1093 content::NotificationService::current()->Notify( |
1094 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, | 1094 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, |
1095 content::Source<RenderWidgetHost>(this), | 1095 content::Source<RenderWidgetHost>(this), |
1096 content::Details<int>(&type)); | 1096 content::Details<int>(&type)); |
1097 } | 1097 } |
1098 | 1098 |
1099 void RenderWidgetHost::ProcessWheelAck(bool processed) { | 1099 void RenderWidgetHost::ProcessWheelAck(bool processed) { |
1100 mouse_wheel_pending_ = false; | 1100 mouse_wheel_pending_ = false; |
1101 | 1101 |
1102 // Now send the next (coalesced) mouse wheel event. | 1102 // Now send the next (coalesced) mouse wheel event. |
1103 if (!coalesced_mouse_wheel_events_.empty()) { | 1103 if (!coalesced_mouse_wheel_events_.empty()) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 pending_mouse_lock_request_ = false; | 1423 pending_mouse_lock_request_ = false; |
1424 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) { | 1424 if (!view_ || !view_->HasFocus()|| !view_->LockMouse()) { |
1425 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); | 1425 Send(new ViewMsg_LockMouse_ACK(routing_id_, false)); |
1426 return false; | 1426 return false; |
1427 } else { | 1427 } else { |
1428 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); | 1428 Send(new ViewMsg_LockMouse_ACK(routing_id_, true)); |
1429 return true; | 1429 return true; |
1430 } | 1430 } |
1431 } | 1431 } |
1432 } | 1432 } |
OLD | NEW |