| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 #if defined(TOOLKIT_GTK) | 41 #if defined(TOOLKIT_GTK) |
| 42 #include "content/browser/renderer_host/backing_store_gtk.h" | 42 #include "content/browser/renderer_host/backing_store_gtk.h" |
| 43 #elif defined(OS_MACOSX) | 43 #elif defined(OS_MACOSX) |
| 44 #include "content/browser/renderer_host/backing_store_mac.h" | 44 #include "content/browser/renderer_host/backing_store_mac.h" |
| 45 #endif | 45 #endif |
| 46 | 46 |
| 47 using base::Time; | 47 using base::Time; |
| 48 using base::TimeDelta; | 48 using base::TimeDelta; |
| 49 using base::TimeTicks; | 49 using base::TimeTicks; |
| 50 using content::RenderWidgetHostViewPort; | |
| 51 using content::UserMetricsAction; | |
| 52 using WebKit::WebGestureEvent; | 50 using WebKit::WebGestureEvent; |
| 53 using WebKit::WebInputEvent; | 51 using WebKit::WebInputEvent; |
| 54 using WebKit::WebKeyboardEvent; | 52 using WebKit::WebKeyboardEvent; |
| 55 using WebKit::WebMouseEvent; | 53 using WebKit::WebMouseEvent; |
| 56 using WebKit::WebMouseWheelEvent; | 54 using WebKit::WebMouseWheelEvent; |
| 57 using WebKit::WebTextDirection; | 55 using WebKit::WebTextDirection; |
| 58 | 56 |
| 57 namespace { |
| 58 |
| 59 // How long to (synchronously) wait for the renderer to respond with a | 59 // How long to (synchronously) wait for the renderer to respond with a |
| 60 // PaintRect message, when our backing-store is invalid, before giving up and | 60 // PaintRect message, when our backing-store is invalid, before giving up and |
| 61 // returning a null or incorrectly sized backing-store from GetBackingStore. | 61 // returning a null or incorrectly sized backing-store from GetBackingStore. |
| 62 // This timeout impacts the "choppiness" of our window resize perf. | 62 // This timeout impacts the "choppiness" of our window resize perf. |
| 63 static const int kPaintMsgTimeoutMS = 40; | 63 static const int kPaintMsgTimeoutMS = 40; |
| 64 | 64 |
| 65 // How long to wait before we consider a renderer hung. | 65 // How long to wait before we consider a renderer hung. |
| 66 static const int kHungRendererDelayMs = 20000; | 66 static const int kHungRendererDelayMs = 20000; |
| 67 | 67 |
| 68 namespace { | |
| 69 | |
| 70 // Returns |true| if the two wheel events should be coalesced. | 68 // Returns |true| if the two wheel events should be coalesced. |
| 71 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, | 69 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, |
| 72 const WebMouseWheelEvent& new_event) { | 70 const WebMouseWheelEvent& new_event) { |
| 73 return last_event.modifiers == new_event.modifiers && | 71 return last_event.modifiers == new_event.modifiers && |
| 74 last_event.scrollByPage == new_event.scrollByPage && | 72 last_event.scrollByPage == new_event.scrollByPage && |
| 75 last_event.hasPreciseScrollingDeltas | 73 last_event.hasPreciseScrollingDeltas |
| 76 == new_event.hasPreciseScrollingDeltas && | 74 == new_event.hasPreciseScrollingDeltas && |
| 77 last_event.phase == new_event.phase && | 75 last_event.phase == new_event.phase && |
| 78 last_event.momentumPhase == new_event.momentumPhase; | 76 last_event.momentumPhase == new_event.momentumPhase; |
| 79 } | 77 } |
| 80 | 78 |
| 81 } // namespace | 79 } // namespace |
| 82 | 80 |
| 81 namespace content { |
| 82 |
| 83 // static | 83 // static |
| 84 RenderWidgetHost* RenderWidgetHost::FromIPCChannelListener( | 84 RenderWidgetHost* RenderWidgetHost::FromIPCChannelListener( |
| 85 IPC::Channel::Listener* listener) { | 85 IPC::Channel::Listener* listener) { |
| 86 return static_cast<RenderWidgetHost*>( | 86 return static_cast<RenderWidgetHost*>( |
| 87 static_cast<RenderWidgetHostImpl*>(listener)); | 87 static_cast<RenderWidgetHostImpl*>(listener)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 // static | 90 // static |
| 91 const RenderWidgetHost* RenderWidgetHost::FromIPCChannelListener( | 91 const RenderWidgetHost* RenderWidgetHost::FromIPCChannelListener( |
| 92 const IPC::Channel::Listener* listener) { | 92 const IPC::Channel::Listener* listener) { |
| 93 return static_cast<const RenderWidgetHost*>( | 93 return static_cast<const RenderWidgetHost*>( |
| 94 static_cast<const RenderWidgetHostImpl*>(listener)); | 94 static_cast<const RenderWidgetHostImpl*>(listener)); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 void RenderWidgetHost::RemoveAllBackingStores() { | 98 void RenderWidgetHost::RemoveAllBackingStores() { |
| 99 BackingStoreManager::RemoveAllBackingStores(); | 99 BackingStoreManager::RemoveAllBackingStores(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // static | 102 // static |
| 103 size_t RenderWidgetHost::BackingStoreMemorySize() { | 103 size_t RenderWidgetHost::BackingStoreMemorySize() { |
| 104 return BackingStoreManager::MemorySize(); | 104 return BackingStoreManager::MemorySize(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /////////////////////////////////////////////////////////////////////////////// | 107 /////////////////////////////////////////////////////////////////////////////// |
| 108 // RenderWidgetHostImpl | 108 // RenderWidgetHostImpl |
| 109 | 109 |
| 110 RenderWidgetHostImpl::RenderWidgetHostImpl(content::RenderProcessHost* process, | 110 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderProcessHost* process, |
| 111 int routing_id) | 111 int routing_id) |
| 112 : view_(NULL), | 112 : view_(NULL), |
| 113 renderer_initialized_(false), | 113 renderer_initialized_(false), |
| 114 hung_renderer_delay_ms_(kHungRendererDelayMs), | 114 hung_renderer_delay_ms_(kHungRendererDelayMs), |
| 115 process_(process), | 115 process_(process), |
| 116 routing_id_(routing_id), | 116 routing_id_(routing_id), |
| 117 renderer_accessible_(false), | 117 renderer_accessible_(false), |
| 118 surface_id_(0), | 118 surface_id_(0), |
| 119 is_loading_(false), | 119 is_loading_(false), |
| 120 is_hidden_(false), | 120 is_hidden_(false), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 surface_id_ = 0; | 182 surface_id_ = 0; |
| 183 | 183 |
| 184 process_->Release(routing_id_); | 184 process_->Release(routing_id_); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // static | 187 // static |
| 188 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { | 188 RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { |
| 189 return rwh->AsRenderWidgetHostImpl(); | 189 return rwh->AsRenderWidgetHostImpl(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void RenderWidgetHostImpl::SetView(content::RenderWidgetHostView* view) { | 192 void RenderWidgetHostImpl::SetView(RenderWidgetHostView* view) { |
| 193 view_ = RenderWidgetHostViewPort::FromRWHV(view); | 193 view_ = RenderWidgetHostViewPort::FromRWHV(view); |
| 194 | 194 |
| 195 if (!view_) { | 195 if (!view_) { |
| 196 GpuSurfaceTracker::Get()->SetSurfaceHandle( | 196 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
| 197 surface_id_, gfx::GLSurfaceHandle()); | 197 surface_id_, gfx::GLSurfaceHandle()); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 content::RenderProcessHost* RenderWidgetHostImpl::GetProcess() const { | 201 RenderProcessHost* RenderWidgetHostImpl::GetProcess() const { |
| 202 return process_; | 202 return process_; |
| 203 } | 203 } |
| 204 | 204 |
| 205 int RenderWidgetHostImpl::GetRoutingID() const { | 205 int RenderWidgetHostImpl::GetRoutingID() const { |
| 206 return routing_id_; | 206 return routing_id_; |
| 207 } | 207 } |
| 208 | 208 |
| 209 content::RenderWidgetHostView* RenderWidgetHostImpl::GetView() const { | 209 RenderWidgetHostView* RenderWidgetHostImpl::GetView() const { |
| 210 return view_; | 210 return view_; |
| 211 } | 211 } |
| 212 | 212 |
| 213 RenderWidgetHostImpl* RenderWidgetHostImpl::AsRenderWidgetHostImpl() { | 213 RenderWidgetHostImpl* RenderWidgetHostImpl::AsRenderWidgetHostImpl() { |
| 214 return this; | 214 return this; |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool RenderWidgetHostImpl::OnMessageReceivedForTesting( | 217 bool RenderWidgetHostImpl::OnMessageReceivedForTesting( |
| 218 const IPC::Message& msg) { | 218 const IPC::Message& msg) { |
| 219 return OnMessageReceived(msg); | 219 return OnMessageReceived(msg); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 IPC_MESSAGE_HANDLER(ViewHostMsg_CreatePluginContainer, | 316 IPC_MESSAGE_HANDLER(ViewHostMsg_CreatePluginContainer, |
| 317 OnMsgCreatePluginContainer) | 317 OnMsgCreatePluginContainer) |
| 318 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyPluginContainer, | 318 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyPluginContainer, |
| 319 OnMsgDestroyPluginContainer) | 319 OnMsgDestroyPluginContainer) |
| 320 #endif | 320 #endif |
| 321 IPC_MESSAGE_UNHANDLED(handled = false) | 321 IPC_MESSAGE_UNHANDLED(handled = false) |
| 322 IPC_END_MESSAGE_MAP_EX() | 322 IPC_END_MESSAGE_MAP_EX() |
| 323 | 323 |
| 324 if (!msg_is_ok) { | 324 if (!msg_is_ok) { |
| 325 // The message de-serialization failed. Kill the renderer process. | 325 // The message de-serialization failed. Kill the renderer process. |
| 326 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); | 326 RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); |
| 327 GetProcess()->ReceivedBadMessage(); | 327 GetProcess()->ReceivedBadMessage(); |
| 328 } | 328 } |
| 329 return handled; | 329 return handled; |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool RenderWidgetHostImpl::Send(IPC::Message* msg) { | 332 bool RenderWidgetHostImpl::Send(IPC::Message* msg) { |
| 333 return process_->Send(msg); | 333 return process_->Send(msg); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void RenderWidgetHostImpl::WasHidden() { | 336 void RenderWidgetHostImpl::WasHidden() { |
| 337 is_hidden_ = true; | 337 is_hidden_ = true; |
| 338 | 338 |
| 339 // Don't bother reporting hung state when we aren't the active tab. | 339 // Don't bother reporting hung state when we aren't the active tab. |
| 340 StopHangMonitorTimeout(); | 340 StopHangMonitorTimeout(); |
| 341 | 341 |
| 342 // If we have a renderer, then inform it that we are being hidden so it can | 342 // If we have a renderer, then inform it that we are being hidden so it can |
| 343 // reduce its resource utilization. | 343 // reduce its resource utilization. |
| 344 Send(new ViewMsg_WasHidden(routing_id_)); | 344 Send(new ViewMsg_WasHidden(routing_id_)); |
| 345 | 345 |
| 346 // Tell the RenderProcessHost we were hidden. | 346 // Tell the RenderProcessHost we were hidden. |
| 347 process_->WidgetHidden(); | 347 process_->WidgetHidden(); |
| 348 | 348 |
| 349 bool is_visible = false; | 349 bool is_visible = false; |
| 350 content::NotificationService::current()->Notify( | 350 NotificationService::current()->Notify( |
| 351 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 351 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 352 content::Source<RenderWidgetHost>(this), | 352 Source<RenderWidgetHost>(this), |
| 353 content::Details<bool>(&is_visible)); | 353 Details<bool>(&is_visible)); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void RenderWidgetHostImpl::WasRestored() { | 356 void RenderWidgetHostImpl::WasRestored() { |
| 357 // When we create the widget, it is created as *not* hidden. | 357 // When we create the widget, it is created as *not* hidden. |
| 358 if (!is_hidden_) | 358 if (!is_hidden_) |
| 359 return; | 359 return; |
| 360 is_hidden_ = false; | 360 is_hidden_ = false; |
| 361 | 361 |
| 362 BackingStore* backing_store = BackingStoreManager::Lookup(this); | 362 BackingStore* backing_store = BackingStoreManager::Lookup(this); |
| 363 // If we already have a backing store for this widget, then we don't need to | 363 // If we already have a backing store for this widget, then we don't need to |
| 364 // repaint on restore _unless_ we know that our backing store is invalid. | 364 // repaint on restore _unless_ we know that our backing store is invalid. |
| 365 // When accelerated compositing is on, we must always repaint, even when | 365 // When accelerated compositing is on, we must always repaint, even when |
| 366 // the backing store exists. | 366 // the backing store exists. |
| 367 bool needs_repainting; | 367 bool needs_repainting; |
| 368 if (needs_repainting_on_restore_ || !backing_store || | 368 if (needs_repainting_on_restore_ || !backing_store || |
| 369 is_accelerated_compositing_active()) { | 369 is_accelerated_compositing_active()) { |
| 370 needs_repainting = true; | 370 needs_repainting = true; |
| 371 needs_repainting_on_restore_ = false; | 371 needs_repainting_on_restore_ = false; |
| 372 } else { | 372 } else { |
| 373 needs_repainting = false; | 373 needs_repainting = false; |
| 374 } | 374 } |
| 375 Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); | 375 Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); |
| 376 | 376 |
| 377 process_->WidgetRestored(); | 377 process_->WidgetRestored(); |
| 378 | 378 |
| 379 bool is_visible = true; | 379 bool is_visible = true; |
| 380 content::NotificationService::current()->Notify( | 380 NotificationService::current()->Notify( |
| 381 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 381 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 382 content::Source<RenderWidgetHost>(this), | 382 Source<RenderWidgetHost>(this), |
| 383 content::Details<bool>(&is_visible)); | 383 Details<bool>(&is_visible)); |
| 384 | 384 |
| 385 // It's possible for our size to be out of sync with the renderer. The | 385 // It's possible for our size to be out of sync with the renderer. The |
| 386 // following is one case that leads to this: | 386 // following is one case that leads to this: |
| 387 // 1. WasResized -> Send ViewMsg_Resize to render | 387 // 1. WasResized -> Send ViewMsg_Resize to render |
| 388 // 2. WasResized -> do nothing as resize_ack_pending_ is true | 388 // 2. WasResized -> do nothing as resize_ack_pending_ is true |
| 389 // 3. WasHidden | 389 // 3. WasHidden |
| 390 // 4. OnMsgUpdateRect from (1) processed. Does NOT invoke WasResized as view | 390 // 4. OnMsgUpdateRect from (1) processed. Does NOT invoke WasResized as view |
| 391 // is hidden. Now renderer/browser out of sync with what they think size | 391 // is hidden. Now renderer/browser out of sync with what they think size |
| 392 // is. | 392 // is. |
| 393 // By invoking WasResized the renderer is updated as necessary. WasResized | 393 // By invoking WasResized the renderer is updated as necessary. WasResized |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 950 |
| 951 bool RenderWidgetHostImpl::IsFullscreen() const { | 951 bool RenderWidgetHostImpl::IsFullscreen() const { |
| 952 return false; | 952 return false; |
| 953 } | 953 } |
| 954 | 954 |
| 955 void RenderWidgetHostImpl::SetShouldAutoResize(bool enable) { | 955 void RenderWidgetHostImpl::SetShouldAutoResize(bool enable) { |
| 956 should_auto_resize_ = enable; | 956 should_auto_resize_ = enable; |
| 957 } | 957 } |
| 958 | 958 |
| 959 void RenderWidgetHostImpl::Destroy() { | 959 void RenderWidgetHostImpl::Destroy() { |
| 960 content::NotificationService::current()->Notify( | 960 NotificationService::current()->Notify( |
| 961 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 961 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 962 content::Source<RenderWidgetHost>(this), | 962 Source<RenderWidgetHost>(this), |
| 963 content::NotificationService::NoDetails()); | 963 NotificationService::NoDetails()); |
| 964 | 964 |
| 965 // Tell the view to die. | 965 // Tell the view to die. |
| 966 // Note that in the process of the view shutting down, it can call a ton | 966 // Note that in the process of the view shutting down, it can call a ton |
| 967 // of other messages on us. So if you do any other deinitialization here, | 967 // of other messages on us. So if you do any other deinitialization here, |
| 968 // do it after this call to view_->Destroy(). | 968 // do it after this call to view_->Destroy(). |
| 969 if (view_) | 969 if (view_) |
| 970 view_->Destroy(); | 970 view_->Destroy(); |
| 971 | 971 |
| 972 delete this; | 972 delete this; |
| 973 } | 973 } |
| 974 | 974 |
| 975 void RenderWidgetHostImpl::CheckRendererIsUnresponsive() { | 975 void RenderWidgetHostImpl::CheckRendererIsUnresponsive() { |
| 976 // If we received a call to StopHangMonitorTimeout. | 976 // If we received a call to StopHangMonitorTimeout. |
| 977 if (time_when_considered_hung_.is_null()) | 977 if (time_when_considered_hung_.is_null()) |
| 978 return; | 978 return; |
| 979 | 979 |
| 980 // If we have not waited long enough, then wait some more. | 980 // If we have not waited long enough, then wait some more. |
| 981 Time now = Time::Now(); | 981 Time now = Time::Now(); |
| 982 if (now < time_when_considered_hung_) { | 982 if (now < time_when_considered_hung_) { |
| 983 StartHangMonitorTimeout(time_when_considered_hung_ - now); | 983 StartHangMonitorTimeout(time_when_considered_hung_ - now); |
| 984 return; | 984 return; |
| 985 } | 985 } |
| 986 | 986 |
| 987 // OK, looks like we have a hung renderer! | 987 // OK, looks like we have a hung renderer! |
| 988 content::NotificationService::current()->Notify( | 988 NotificationService::current()->Notify( |
| 989 content::NOTIFICATION_RENDERER_PROCESS_HANG, | 989 NOTIFICATION_RENDERER_PROCESS_HANG, |
| 990 content::Source<RenderWidgetHost>(this), | 990 Source<RenderWidgetHost>(this), |
| 991 content::NotificationService::NoDetails()); | 991 NotificationService::NoDetails()); |
| 992 is_unresponsive_ = true; | 992 is_unresponsive_ = true; |
| 993 NotifyRendererUnresponsive(); | 993 NotifyRendererUnresponsive(); |
| 994 } | 994 } |
| 995 | 995 |
| 996 void RenderWidgetHostImpl::RendererIsResponsive() { | 996 void RenderWidgetHostImpl::RendererIsResponsive() { |
| 997 if (is_unresponsive_) { | 997 if (is_unresponsive_) { |
| 998 is_unresponsive_ = false; | 998 is_unresponsive_ = false; |
| 999 NotifyRendererResponsive(); | 999 NotifyRendererResponsive(); |
| 1000 } | 1000 } |
| 1001 } | 1001 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 // Note that we ignore the position. | 1051 // Note that we ignore the position. |
| 1052 if (view_) { | 1052 if (view_) { |
| 1053 view_->SetBounds(pos); | 1053 view_->SetBounds(pos); |
| 1054 Send(new ViewMsg_Move_ACK(routing_id_)); | 1054 Send(new ViewMsg_Move_ACK(routing_id_)); |
| 1055 } | 1055 } |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 void RenderWidgetHostImpl::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { | 1058 void RenderWidgetHostImpl::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { |
| 1059 PaintAtSizeAckDetails details = {tag, size}; | 1059 PaintAtSizeAckDetails details = {tag, size}; |
| 1060 gfx::Size size_details = size; | 1060 gfx::Size size_details = size; |
| 1061 content::NotificationService::current()->Notify( | 1061 NotificationService::current()->Notify( |
| 1062 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | 1062 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, |
| 1063 content::Source<RenderWidgetHost>(this), | 1063 Source<RenderWidgetHost>(this), |
| 1064 content::Details<PaintAtSizeAckDetails>(&details)); | 1064 Details<PaintAtSizeAckDetails>(&details)); |
| 1065 } | 1065 } |
| 1066 | 1066 |
| 1067 void RenderWidgetHostImpl::OnMsgUpdateRect( | 1067 void RenderWidgetHostImpl::OnMsgUpdateRect( |
| 1068 const ViewHostMsg_UpdateRect_Params& params) { | 1068 const ViewHostMsg_UpdateRect_Params& params) { |
| 1069 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect"); | 1069 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect"); |
| 1070 TimeTicks paint_start = TimeTicks::Now(); | 1070 TimeTicks paint_start = TimeTicks::Now(); |
| 1071 | 1071 |
| 1072 // Update our knowledge of the RenderWidget's size. | 1072 // Update our knowledge of the RenderWidget's size. |
| 1073 current_size_ = params.view_size; | 1073 current_size_ = params.view_size; |
| 1074 // Update our knowledge of the RenderWidget's scroll offset. | 1074 // Update our knowledge of the RenderWidget's scroll offset. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1100 DCHECK(!params.bitmap_rect.IsEmpty()); | 1100 DCHECK(!params.bitmap_rect.IsEmpty()); |
| 1101 const size_t size = params.bitmap_rect.height() * | 1101 const size_t size = params.bitmap_rect.height() * |
| 1102 params.bitmap_rect.width() * 4; | 1102 params.bitmap_rect.width() * 4; |
| 1103 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); | 1103 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); |
| 1104 | 1104 |
| 1105 // If gpu process does painting, scroll_rect and copy_rects are always empty | 1105 // If gpu process does painting, scroll_rect and copy_rects are always empty |
| 1106 // and backing store is never used. | 1106 // and backing store is never used. |
| 1107 if (dib) { | 1107 if (dib) { |
| 1108 if (dib->size() < size) { | 1108 if (dib->size() < size) { |
| 1109 DLOG(WARNING) << "Transport DIB too small for given rectangle"; | 1109 DLOG(WARNING) << "Transport DIB too small for given rectangle"; |
| 1110 content::RecordAction( | 1110 RecordAction(UserMetricsAction("BadMessageTerminate_RWH1")); |
| 1111 UserMetricsAction("BadMessageTerminate_RWH1")); | |
| 1112 GetProcess()->ReceivedBadMessage(); | 1111 GetProcess()->ReceivedBadMessage(); |
| 1113 } else { | 1112 } else { |
| 1114 UNSHIPPED_TRACE_EVENT_INSTANT2("test_latency", "UpdateRect", | 1113 UNSHIPPED_TRACE_EVENT_INSTANT2("test_latency", "UpdateRect", |
| 1115 "x+y", params.bitmap_rect.x() + params.bitmap_rect.y(), | 1114 "x+y", params.bitmap_rect.x() + params.bitmap_rect.y(), |
| 1116 "color", 0xffffff & *static_cast<uint32*>(dib->memory())); | 1115 "color", 0xffffff & *static_cast<uint32*>(dib->memory())); |
| 1117 UNSHIPPED_TRACE_EVENT_INSTANT1("test_latency", "UpdateRectWidth", | 1116 UNSHIPPED_TRACE_EVENT_INSTANT1("test_latency", "UpdateRectWidth", |
| 1118 "width", params.bitmap_rect.width()); | 1117 "width", params.bitmap_rect.width()); |
| 1119 | 1118 |
| 1120 // Scroll the backing store. | 1119 // Scroll the backing store. |
| 1121 if (!params.scroll_rect.IsEmpty()) { | 1120 if (!params.scroll_rect.IsEmpty()) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 return; | 1185 return; |
| 1187 | 1186 |
| 1188 // Now paint the view. Watch out: it might be destroyed already. | 1187 // Now paint the view. Watch out: it might be destroyed already. |
| 1189 if (view_ && !is_accelerated_compositing_active_) { | 1188 if (view_ && !is_accelerated_compositing_active_) { |
| 1190 view_being_painted_ = true; | 1189 view_being_painted_ = true; |
| 1191 view_->DidUpdateBackingStore(params.scroll_rect, params.dx, params.dy, | 1190 view_->DidUpdateBackingStore(params.scroll_rect, params.dx, params.dy, |
| 1192 params.copy_rects); | 1191 params.copy_rects); |
| 1193 view_being_painted_ = false; | 1192 view_being_painted_ = false; |
| 1194 } | 1193 } |
| 1195 | 1194 |
| 1196 content::NotificationService::current()->Notify( | 1195 NotificationService::current()->Notify( |
| 1197 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | 1196 NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
| 1198 content::Source<RenderWidgetHost>(this), | 1197 Source<RenderWidgetHost>(this), |
| 1199 content::NotificationService::NoDetails()); | 1198 NotificationService::NoDetails()); |
| 1200 | 1199 |
| 1201 // If we got a resize ack, then perhaps we have another resize to send? | 1200 // If we got a resize ack, then perhaps we have another resize to send? |
| 1202 bool is_resize_ack = | 1201 bool is_resize_ack = |
| 1203 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 1202 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
| 1204 if (is_resize_ack && view_) { | 1203 if (is_resize_ack && view_) { |
| 1205 gfx::Rect view_bounds = view_->GetViewBounds(); | 1204 gfx::Rect view_bounds = view_->GetViewBounds(); |
| 1206 if (current_size_ != view_bounds.size()) | 1205 if (current_size_ != view_bounds.size()) |
| 1207 WasResized(); | 1206 WasResized(); |
| 1208 } | 1207 } |
| 1209 | 1208 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1230 // Log the time delta for processing an input event. | 1229 // Log the time delta for processing an input event. |
| 1231 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; | 1230 TimeDelta delta = TimeTicks::Now() - input_event_start_time_; |
| 1232 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); | 1231 UMA_HISTOGRAM_TIMES("MPArch.RWH_InputEventDelta", delta); |
| 1233 | 1232 |
| 1234 // Cancel pending hung renderer checks since the renderer is responsive. | 1233 // Cancel pending hung renderer checks since the renderer is responsive. |
| 1235 if (--in_flight_event_count_ == 0) | 1234 if (--in_flight_event_count_ == 0) |
| 1236 StopHangMonitorTimeout(); | 1235 StopHangMonitorTimeout(); |
| 1237 | 1236 |
| 1238 int type = static_cast<int>(event_type); | 1237 int type = static_cast<int>(event_type); |
| 1239 if (type < WebInputEvent::Undefined) { | 1238 if (type < WebInputEvent::Undefined) { |
| 1240 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 1239 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
| 1241 process_->ReceivedBadMessage(); | 1240 process_->ReceivedBadMessage(); |
| 1242 } else if (type == WebInputEvent::MouseMove) { | 1241 } else if (type == WebInputEvent::MouseMove) { |
| 1243 mouse_move_pending_ = false; | 1242 mouse_move_pending_ = false; |
| 1244 | 1243 |
| 1245 // now, we can send the next mouse move event | 1244 // now, we can send the next mouse move event |
| 1246 if (next_mouse_move_.get()) { | 1245 if (next_mouse_move_.get()) { |
| 1247 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); | 1246 DCHECK(next_mouse_move_->type == WebInputEvent::MouseMove); |
| 1248 ForwardMouseEvent(*next_mouse_move_); | 1247 ForwardMouseEvent(*next_mouse_move_); |
| 1249 } | 1248 } |
| 1250 } else if (WebInputEvent::isKeyboardEventType(type)) { | 1249 } else if (WebInputEvent::isKeyboardEventType(type)) { |
| 1251 ProcessKeyboardEventAck(type, processed); | 1250 ProcessKeyboardEventAck(type, processed); |
| 1252 } else if (type == WebInputEvent::MouseWheel) { | 1251 } else if (type == WebInputEvent::MouseWheel) { |
| 1253 ProcessWheelAck(processed); | 1252 ProcessWheelAck(processed); |
| 1254 } else if (WebInputEvent::isTouchEventType(type)) { | 1253 } else if (WebInputEvent::isTouchEventType(type)) { |
| 1255 ProcessTouchAck(event_type, processed); | 1254 ProcessTouchAck(event_type, processed); |
| 1256 } | 1255 } |
| 1257 | 1256 |
| 1258 // This is used only for testing, and the other end does not use the | 1257 // This is used only for testing, and the other end does not use the |
| 1259 // source object. On linux, specifying | 1258 // source object. On linux, specifying |
| 1260 // content::Source<RenderWidgetHost> results in a very strange | 1259 // Source<RenderWidgetHost> results in a very strange |
| 1261 // runtime error in the epilogue of the enclosing | 1260 // runtime error in the epilogue of the enclosing |
| 1262 // (OnMsgInputEventAck) method, but not on other platforms; using | 1261 // (OnMsgInputEventAck) method, but not on other platforms; using |
| 1263 // 'void' instead is just as safe (since content::NotificationSource | 1262 // 'void' instead is just as safe (since NotificationSource |
| 1264 // is not actually typesafe) and avoids this error. | 1263 // is not actually typesafe) and avoids this error. |
| 1265 content::NotificationService::current()->Notify( | 1264 NotificationService::current()->Notify( |
| 1266 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, | 1265 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_INPUT_EVENT_ACK, |
| 1267 content::Source<void>(this), | 1266 Source<void>(this), |
| 1268 content::Details<int>(&type)); | 1267 Details<int>(&type)); |
| 1269 } | 1268 } |
| 1270 | 1269 |
| 1271 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { | 1270 void RenderWidgetHostImpl::ProcessWheelAck(bool processed) { |
| 1272 mouse_wheel_pending_ = false; | 1271 mouse_wheel_pending_ = false; |
| 1273 | 1272 |
| 1274 // Now send the next (coalesced) mouse wheel event. | 1273 // Now send the next (coalesced) mouse wheel event. |
| 1275 if (!coalesced_mouse_wheel_events_.empty()) { | 1274 if (!coalesced_mouse_wheel_events_.empty()) { |
| 1276 WebMouseWheelEvent next_wheel_event = | 1275 WebMouseWheelEvent next_wheel_event = |
| 1277 coalesced_mouse_wheel_events_.front(); | 1276 coalesced_mouse_wheel_events_.front(); |
| 1278 coalesced_mouse_wheel_events_.pop_front(); | 1277 coalesced_mouse_wheel_events_.pop_front(); |
| 1279 ForwardWheelEvent(next_wheel_event); | 1278 ForwardWheelEvent(next_wheel_event); |
| 1280 } | 1279 } |
| 1281 | 1280 |
| 1282 if (!processed && !is_hidden_ && view_) | 1281 if (!processed && !is_hidden_ && view_) |
| 1283 view_->UnhandledWheelEvent(current_wheel_event_); | 1282 view_->UnhandledWheelEvent(current_wheel_event_); |
| 1284 } | 1283 } |
| 1285 | 1284 |
| 1286 void RenderWidgetHostImpl::ProcessTouchAck( | 1285 void RenderWidgetHostImpl::ProcessTouchAck( |
| 1287 WebInputEvent::Type type, bool processed) { | 1286 WebInputEvent::Type type, bool processed) { |
| 1288 if (view_) | 1287 if (view_) |
| 1289 view_->ProcessTouchAck(type, processed); | 1288 view_->ProcessTouchAck(type, processed); |
| 1290 } | 1289 } |
| 1291 | 1290 |
| 1292 void RenderWidgetHostImpl::OnMsgFocus() { | 1291 void RenderWidgetHostImpl::OnMsgFocus() { |
| 1293 // Only RenderViewHost can deal with that message. | 1292 // Only RenderViewHost can deal with that message. |
| 1294 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH4")); | 1293 RecordAction(UserMetricsAction("BadMessageTerminate_RWH4")); |
| 1295 GetProcess()->ReceivedBadMessage(); | 1294 GetProcess()->ReceivedBadMessage(); |
| 1296 } | 1295 } |
| 1297 | 1296 |
| 1298 void RenderWidgetHostImpl::OnMsgBlur() { | 1297 void RenderWidgetHostImpl::OnMsgBlur() { |
| 1299 // Only RenderViewHost can deal with that message. | 1298 // Only RenderViewHost can deal with that message. |
| 1300 content::RecordAction(UserMetricsAction("BadMessageTerminate_RWH5")); | 1299 RecordAction(UserMetricsAction("BadMessageTerminate_RWH5")); |
| 1301 GetProcess()->ReceivedBadMessage(); | 1300 GetProcess()->ReceivedBadMessage(); |
| 1302 } | 1301 } |
| 1303 | 1302 |
| 1304 void RenderWidgetHostImpl::OnMsgDidChangeNumTouchEvents(int count) { | 1303 void RenderWidgetHostImpl::OnMsgDidChangeNumTouchEvents(int count) { |
| 1305 has_touch_handler_ = count > 0; | 1304 has_touch_handler_ = count > 0; |
| 1306 } | 1305 } |
| 1307 | 1306 |
| 1308 void RenderWidgetHostImpl::OnMsgSetCursor(const WebCursor& cursor) { | 1307 void RenderWidgetHostImpl::OnMsgSetCursor(const WebCursor& cursor) { |
| 1309 if (!view_) { | 1308 if (!view_) { |
| 1310 return; | 1309 return; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 Send(new ViewMsg_ScrollFocusedEditableNodeIntoRect(GetRoutingID(), rect)); | 1555 Send(new ViewMsg_ScrollFocusedEditableNodeIntoRect(GetRoutingID(), rect)); |
| 1557 } | 1556 } |
| 1558 | 1557 |
| 1559 void RenderWidgetHostImpl::SelectRange(const gfx::Point& start, | 1558 void RenderWidgetHostImpl::SelectRange(const gfx::Point& start, |
| 1560 const gfx::Point& end) { | 1559 const gfx::Point& end) { |
| 1561 Send(new ViewMsg_SelectRange(GetRoutingID(), start, end)); | 1560 Send(new ViewMsg_SelectRange(GetRoutingID(), start, end)); |
| 1562 } | 1561 } |
| 1563 | 1562 |
| 1564 void RenderWidgetHostImpl::Undo() { | 1563 void RenderWidgetHostImpl::Undo() { |
| 1565 Send(new ViewMsg_Undo(GetRoutingID())); | 1564 Send(new ViewMsg_Undo(GetRoutingID())); |
| 1566 content::RecordAction(UserMetricsAction("Undo")); | 1565 RecordAction(UserMetricsAction("Undo")); |
| 1567 } | 1566 } |
| 1568 | 1567 |
| 1569 void RenderWidgetHostImpl::Redo() { | 1568 void RenderWidgetHostImpl::Redo() { |
| 1570 Send(new ViewMsg_Redo(GetRoutingID())); | 1569 Send(new ViewMsg_Redo(GetRoutingID())); |
| 1571 content::RecordAction(UserMetricsAction("Redo")); | 1570 RecordAction(UserMetricsAction("Redo")); |
| 1572 } | 1571 } |
| 1573 | 1572 |
| 1574 void RenderWidgetHostImpl::Cut() { | 1573 void RenderWidgetHostImpl::Cut() { |
| 1575 Send(new ViewMsg_Cut(GetRoutingID())); | 1574 Send(new ViewMsg_Cut(GetRoutingID())); |
| 1576 content::RecordAction(UserMetricsAction("Cut")); | 1575 RecordAction(UserMetricsAction("Cut")); |
| 1577 } | 1576 } |
| 1578 | 1577 |
| 1579 void RenderWidgetHostImpl::Copy() { | 1578 void RenderWidgetHostImpl::Copy() { |
| 1580 Send(new ViewMsg_Copy(GetRoutingID())); | 1579 Send(new ViewMsg_Copy(GetRoutingID())); |
| 1581 content::RecordAction(UserMetricsAction("Copy")); | 1580 RecordAction(UserMetricsAction("Copy")); |
| 1582 } | 1581 } |
| 1583 | 1582 |
| 1584 void RenderWidgetHostImpl::CopyToFindPboard() { | 1583 void RenderWidgetHostImpl::CopyToFindPboard() { |
| 1585 #if defined(OS_MACOSX) | 1584 #if defined(OS_MACOSX) |
| 1586 // Windows/Linux don't have the concept of a find pasteboard. | 1585 // Windows/Linux don't have the concept of a find pasteboard. |
| 1587 Send(new ViewMsg_CopyToFindPboard(GetRoutingID())); | 1586 Send(new ViewMsg_CopyToFindPboard(GetRoutingID())); |
| 1588 content::RecordAction(UserMetricsAction("CopyToFindPboard")); | 1587 RecordAction(UserMetricsAction("CopyToFindPboard")); |
| 1589 #endif | 1588 #endif |
| 1590 } | 1589 } |
| 1591 | 1590 |
| 1592 void RenderWidgetHostImpl::Paste() { | 1591 void RenderWidgetHostImpl::Paste() { |
| 1593 Send(new ViewMsg_Paste(GetRoutingID())); | 1592 Send(new ViewMsg_Paste(GetRoutingID())); |
| 1594 content::RecordAction(UserMetricsAction("Paste")); | 1593 RecordAction(UserMetricsAction("Paste")); |
| 1595 } | 1594 } |
| 1596 | 1595 |
| 1597 void RenderWidgetHostImpl::PasteAndMatchStyle() { | 1596 void RenderWidgetHostImpl::PasteAndMatchStyle() { |
| 1598 Send(new ViewMsg_PasteAndMatchStyle(GetRoutingID())); | 1597 Send(new ViewMsg_PasteAndMatchStyle(GetRoutingID())); |
| 1599 content::RecordAction(UserMetricsAction("PasteAndMatchStyle")); | 1598 RecordAction(UserMetricsAction("PasteAndMatchStyle")); |
| 1600 } | 1599 } |
| 1601 | 1600 |
| 1602 void RenderWidgetHostImpl::Delete() { | 1601 void RenderWidgetHostImpl::Delete() { |
| 1603 Send(new ViewMsg_Delete(GetRoutingID())); | 1602 Send(new ViewMsg_Delete(GetRoutingID())); |
| 1604 content::RecordAction(UserMetricsAction("DeleteSelection")); | 1603 RecordAction(UserMetricsAction("DeleteSelection")); |
| 1605 } | 1604 } |
| 1606 | 1605 |
| 1607 void RenderWidgetHostImpl::SelectAll() { | 1606 void RenderWidgetHostImpl::SelectAll() { |
| 1608 Send(new ViewMsg_SelectAll(GetRoutingID())); | 1607 Send(new ViewMsg_SelectAll(GetRoutingID())); |
| 1609 content::RecordAction(UserMetricsAction("SelectAll")); | 1608 RecordAction(UserMetricsAction("SelectAll")); |
| 1610 } | 1609 } |
| 1611 bool RenderWidgetHostImpl::GotResponseToLockMouseRequest(bool allowed) { | 1610 bool RenderWidgetHostImpl::GotResponseToLockMouseRequest(bool allowed) { |
| 1612 if (!allowed) { | 1611 if (!allowed) { |
| 1613 RejectMouseLockOrUnlockIfNecessary(); | 1612 RejectMouseLockOrUnlockIfNecessary(); |
| 1614 return false; | 1613 return false; |
| 1615 } else { | 1614 } else { |
| 1616 if (!pending_mouse_lock_request_) { | 1615 if (!pending_mouse_lock_request_) { |
| 1617 // This is possible, e.g., the plugin sends us an unlock request before | 1616 // This is possible, e.g., the plugin sends us an unlock request before |
| 1618 // the user allows to lock to mouse. | 1617 // the user allows to lock to mouse. |
| 1619 return false; | 1618 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1638 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); | 1637 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); |
| 1639 } | 1638 } |
| 1640 | 1639 |
| 1641 // static | 1640 // static |
| 1642 void RenderWidgetHostImpl::AcknowledgePostSubBuffer(int32 route_id, | 1641 void RenderWidgetHostImpl::AcknowledgePostSubBuffer(int32 route_id, |
| 1643 int gpu_host_id) { | 1642 int gpu_host_id) { |
| 1644 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 1643 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
| 1645 if (ui_shim) | 1644 if (ui_shim) |
| 1646 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); | 1645 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); |
| 1647 } | 1646 } |
| 1647 |
| 1648 } // namespace content |
| OLD | NEW |