| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/render_widget_host.h" | 5 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 6 | 6 |
| 7 #include "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process, | 70 RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process, |
| 71 int routing_id) | 71 int routing_id) |
| 72 : renderer_initialized_(false), | 72 : renderer_initialized_(false), |
| 73 renderer_accessible_(false), | 73 renderer_accessible_(false), |
| 74 view_(NULL), | 74 view_(NULL), |
| 75 process_(process), | 75 process_(process), |
| 76 painting_observer_(NULL), | 76 painting_observer_(NULL), |
| 77 routing_id_(routing_id), | 77 routing_id_(routing_id), |
| 78 is_loading_(false), | 78 is_loading_(false), |
| 79 is_hidden_(false), | 79 is_hidden_(false), |
| 80 is_gpu_rendering_active_(false), | 80 is_accelerated_compositing_active_(false), |
| 81 repaint_ack_pending_(false), | 81 repaint_ack_pending_(false), |
| 82 resize_ack_pending_(false), | 82 resize_ack_pending_(false), |
| 83 mouse_move_pending_(false), | 83 mouse_move_pending_(false), |
| 84 mouse_wheel_pending_(false), | 84 mouse_wheel_pending_(false), |
| 85 needs_repainting_on_restore_(false), | 85 needs_repainting_on_restore_(false), |
| 86 is_unresponsive_(false), | 86 is_unresponsive_(false), |
| 87 in_get_backing_store_(false), | 87 in_get_backing_store_(false), |
| 88 view_being_painted_(false), | 88 view_being_painted_(false), |
| 89 ignore_input_events_(false), | 89 ignore_input_events_(false), |
| 90 text_direction_updated_(false), | 90 text_direction_updated_(false), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck) | 150 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck) |
| 151 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect) | 151 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect) |
| 152 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) | 152 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) |
| 153 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) | 153 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) |
| 154 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) | 154 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) |
| 155 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) | 155 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) |
| 156 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateTextInputState, | 156 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeUpdateTextInputState, |
| 157 OnMsgImeUpdateTextInputState) | 157 OnMsgImeUpdateTextInputState) |
| 158 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCancelComposition, | 158 IPC_MESSAGE_HANDLER(ViewHostMsg_ImeCancelComposition, |
| 159 OnMsgImeCancelComposition) | 159 OnMsgImeCancelComposition) |
| 160 IPC_MESSAGE_HANDLER(ViewHostMsg_GpuRenderingActivated, | 160 IPC_MESSAGE_HANDLER(ViewHostMsg_DidActivateAcceleratedCompositing, |
| 161 OnMsgGpuRenderingActivated) | 161 OnMsgDidActivateAcceleratedCompositing) |
| 162 #if defined(OS_MACOSX) | 162 #if defined(OS_MACOSX) |
| 163 IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnMsgGetScreenInfo) | 163 IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnMsgGetScreenInfo) |
| 164 IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnMsgGetWindowRect) | 164 IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnMsgGetWindowRect) |
| 165 IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnMsgGetRootWindowRect) | 165 IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnMsgGetRootWindowRect) |
| 166 IPC_MESSAGE_HANDLER(ViewHostMsg_SetPluginImeEnabled, | 166 IPC_MESSAGE_HANDLER(ViewHostMsg_SetPluginImeEnabled, |
| 167 OnMsgSetPluginImeEnabled) | 167 OnMsgSetPluginImeEnabled) |
| 168 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateFakePluginWindowHandle, | 168 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateFakePluginWindowHandle, |
| 169 OnAllocateFakePluginWindowHandle) | 169 OnAllocateFakePluginWindowHandle) |
| 170 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyFakePluginWindowHandle, | 170 IPC_MESSAGE_HANDLER(ViewHostMsg_DestroyFakePluginWindowHandle, |
| 171 OnDestroyFakePluginWindowHandle) | 171 OnDestroyFakePluginWindowHandle) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 return; | 225 return; |
| 226 is_hidden_ = false; | 226 is_hidden_ = false; |
| 227 | 227 |
| 228 BackingStore* backing_store = BackingStoreManager::Lookup(this); | 228 BackingStore* backing_store = BackingStoreManager::Lookup(this); |
| 229 // If we already have a backing store for this widget, then we don't need to | 229 // If we already have a backing store for this widget, then we don't need to |
| 230 // repaint on restore _unless_ we know that our backing store is invalid. | 230 // repaint on restore _unless_ we know that our backing store is invalid. |
| 231 // When accelerated compositing is on, we must always repaint, even when | 231 // When accelerated compositing is on, we must always repaint, even when |
| 232 // the backing store exists. | 232 // the backing store exists. |
| 233 bool needs_repainting; | 233 bool needs_repainting; |
| 234 if (needs_repainting_on_restore_ || !backing_store || | 234 if (needs_repainting_on_restore_ || !backing_store || |
| 235 is_gpu_rendering_active()) { | 235 is_accelerated_compositing_active()) { |
| 236 needs_repainting = true; | 236 needs_repainting = true; |
| 237 needs_repainting_on_restore_ = false; | 237 needs_repainting_on_restore_ = false; |
| 238 } else { | 238 } else { |
| 239 needs_repainting = false; | 239 needs_repainting = false; |
| 240 } | 240 } |
| 241 Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); | 241 Send(new ViewMsg_WasRestored(routing_id_, needs_repainting)); |
| 242 | 242 |
| 243 process_->WidgetRestored(); | 243 process_->WidgetRestored(); |
| 244 | 244 |
| 245 bool is_visible = true; | 245 bool is_visible = true; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 if (!view_) | 376 if (!view_) |
| 377 return NULL; | 377 return NULL; |
| 378 return view_->AllocBackingStore(size); | 378 return view_->AllocBackingStore(size); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void RenderWidgetHost::DonePaintingToBackingStore() { | 381 void RenderWidgetHost::DonePaintingToBackingStore() { |
| 382 Send(new ViewMsg_UpdateRect_ACK(routing_id())); | 382 Send(new ViewMsg_UpdateRect_ACK(routing_id())); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void RenderWidgetHost::ScheduleComposite() { | 385 void RenderWidgetHost::ScheduleComposite() { |
| 386 DCHECK(!is_hidden_ || !is_gpu_rendering_active_) << | 386 if (is_hidden_ || !is_accelerated_compositing_active_) { |
| 387 "ScheduleCompositeAndSync called while hidden!"; | 387 return; |
| 388 } |
| 388 | 389 |
| 389 // Send out a request to the renderer to paint the view if required. | 390 // Send out a request to the renderer to paint the view if required. |
| 390 if (!repaint_ack_pending_ && !resize_ack_pending_ && !view_being_painted_) { | 391 if (!repaint_ack_pending_ && !resize_ack_pending_ && !view_being_painted_) { |
| 391 repaint_start_time_ = TimeTicks::Now(); | 392 repaint_start_time_ = TimeTicks::Now(); |
| 392 repaint_ack_pending_ = true; | 393 repaint_ack_pending_ = true; |
| 393 Send(new ViewMsg_Repaint(routing_id_, current_size_)); | 394 Send(new ViewMsg_Repaint(routing_id_, current_size_)); |
| 394 } | 395 } |
| 395 | 396 |
| 396 // When we have asked the RenderWidget to resize, and we are still waiting on | 397 // When we have asked the RenderWidget to resize, and we are still waiting on |
| 397 // a response, block for a little while to see if we can't get a response. | 398 // a response, block for a little while to see if we can't get a response. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 626 |
| 626 // Reset some fields in preparation for recovering from a crash. | 627 // Reset some fields in preparation for recovering from a crash. |
| 627 resize_ack_pending_ = false; | 628 resize_ack_pending_ = false; |
| 628 repaint_ack_pending_ = false; | 629 repaint_ack_pending_ = false; |
| 629 | 630 |
| 630 in_flight_size_.SetSize(0, 0); | 631 in_flight_size_.SetSize(0, 0); |
| 631 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); | 632 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); |
| 632 current_size_.SetSize(0, 0); | 633 current_size_.SetSize(0, 0); |
| 633 current_reserved_rect_.SetRect(0, 0, 0, 0); | 634 current_reserved_rect_.SetRect(0, 0, 0, 0); |
| 634 is_hidden_ = false; | 635 is_hidden_ = false; |
| 635 is_gpu_rendering_active_ = false; | 636 is_accelerated_compositing_active_ = false; |
| 636 | 637 |
| 637 if (view_) { | 638 if (view_) { |
| 638 view_->RenderViewGone(); | 639 view_->RenderViewGone(); |
| 639 view_ = NULL; // The View should be deleted by RenderViewGone. | 640 view_ = NULL; // The View should be deleted by RenderViewGone. |
| 640 } | 641 } |
| 641 | 642 |
| 642 BackingStoreManager::RemoveBackingStore(this); | 643 BackingStoreManager::RemoveBackingStore(this); |
| 643 } | 644 } |
| 644 | 645 |
| 645 void RenderWidgetHost::UpdateTextDirection(WebTextDirection direction) { | 646 void RenderWidgetHost::UpdateTextDirection(WebTextDirection direction) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); | 794 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); |
| 794 if (is_repaint_ack) { | 795 if (is_repaint_ack) { |
| 795 repaint_ack_pending_ = false; | 796 repaint_ack_pending_ = false; |
| 796 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; | 797 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; |
| 797 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); | 798 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); |
| 798 } | 799 } |
| 799 | 800 |
| 800 DCHECK(!params.bitmap_rect.IsEmpty()); | 801 DCHECK(!params.bitmap_rect.IsEmpty()); |
| 801 DCHECK(!params.view_size.IsEmpty()); | 802 DCHECK(!params.view_size.IsEmpty()); |
| 802 | 803 |
| 803 if (!is_gpu_rendering_active_) { | 804 if (!is_accelerated_compositing_active_) { |
| 804 const size_t size = params.bitmap_rect.height() * | 805 const size_t size = params.bitmap_rect.height() * |
| 805 params.bitmap_rect.width() * 4; | 806 params.bitmap_rect.width() * 4; |
| 806 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); | 807 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); |
| 807 | 808 |
| 808 // If gpu process does painting, scroll_rect and copy_rects are always empty | 809 // If gpu process does painting, scroll_rect and copy_rects are always empty |
| 809 // and backing store is never used. | 810 // and backing store is never used. |
| 810 if (dib) { | 811 if (dib) { |
| 811 if (dib->size() < size) { | 812 if (dib->size() < size) { |
| 812 DLOG(WARNING) << "Transport DIB too small for given rectangle"; | 813 DLOG(WARNING) << "Transport DIB too small for given rectangle"; |
| 813 process()->ReceivedBadMessage(ViewHostMsg_UpdateRect__ID); | 814 process()->ReceivedBadMessage(ViewHostMsg_UpdateRect__ID); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 840 if (is_hidden_) | 841 if (is_hidden_) |
| 841 return; | 842 return; |
| 842 | 843 |
| 843 // Now paint the view. Watch out: it might be destroyed already. | 844 // Now paint the view. Watch out: it might be destroyed already. |
| 844 if (view_) { | 845 if (view_) { |
| 845 view_->MovePluginWindows(params.plugin_window_moves); | 846 view_->MovePluginWindows(params.plugin_window_moves); |
| 846 // The view_ pointer could be destroyed in the context of MovePluginWindows | 847 // The view_ pointer could be destroyed in the context of MovePluginWindows |
| 847 // which attempts to move the plugin windows and in the process could | 848 // which attempts to move the plugin windows and in the process could |
| 848 // dispatch other window messages which could cause the view to be | 849 // dispatch other window messages which could cause the view to be |
| 849 // destroyed. | 850 // destroyed. |
| 850 if (view_ && !is_gpu_rendering_active_) { | 851 if (view_ && !is_accelerated_compositing_active_) { |
| 851 view_being_painted_ = true; | 852 view_being_painted_ = true; |
| 852 view_->DidUpdateBackingStore(params.scroll_rect, params.dx, params.dy, | 853 view_->DidUpdateBackingStore(params.scroll_rect, params.dx, params.dy, |
| 853 params.copy_rects); | 854 params.copy_rects); |
| 854 view_being_painted_ = false; | 855 view_being_painted_ = false; |
| 855 } | 856 } |
| 856 } | 857 } |
| 857 | 858 |
| 858 if (paint_observer_.get()) | 859 if (paint_observer_.get()) |
| 859 paint_observer_->RenderWidgetHostDidPaint(this); | 860 paint_observer_->RenderWidgetHostDidPaint(this); |
| 860 | 861 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 const gfx::Rect& caret_rect) { | 939 const gfx::Rect& caret_rect) { |
| 939 if (view_) | 940 if (view_) |
| 940 view_->ImeUpdateTextInputState(type, caret_rect); | 941 view_->ImeUpdateTextInputState(type, caret_rect); |
| 941 } | 942 } |
| 942 | 943 |
| 943 void RenderWidgetHost::OnMsgImeCancelComposition() { | 944 void RenderWidgetHost::OnMsgImeCancelComposition() { |
| 944 if (view_) | 945 if (view_) |
| 945 view_->ImeCancelComposition(); | 946 view_->ImeCancelComposition(); |
| 946 } | 947 } |
| 947 | 948 |
| 948 void RenderWidgetHost::OnMsgGpuRenderingActivated(bool activated) { | 949 void RenderWidgetHost::OnMsgDidActivateAcceleratedCompositing(bool activated) { |
| 949 #if defined(OS_MACOSX) | 950 #if defined(OS_MACOSX) |
| 950 bool old_state = is_gpu_rendering_active_; | 951 bool old_state = is_accelerated_compositing_active_; |
| 951 #endif | 952 #endif |
| 952 is_gpu_rendering_active_ = activated; | 953 is_accelerated_compositing_active_ = activated; |
| 953 #if defined(OS_MACOSX) | 954 #if defined(OS_MACOSX) |
| 954 if (old_state != is_gpu_rendering_active_ && view_) | 955 if (old_state != is_accelerated_compositing_active_ && view_) |
| 955 view_->GpuRenderingStateDidChange(); | 956 view_->GpuRenderingStateDidChange(); |
| 957 #elif defined(OS_WIN) |
| 958 view_->ShowCompositorHostWindow(is_accelerated_compositing_active_); |
| 956 #endif | 959 #endif |
| 957 } | 960 } |
| 958 | 961 |
| 959 #if defined(OS_MACOSX) | 962 #if defined(OS_MACOSX) |
| 960 | 963 |
| 961 void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId view, | 964 void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId view, |
| 962 WebScreenInfo* results) { | 965 WebScreenInfo* results) { |
| 963 gfx::NativeView native_view = view_ ? view_->GetNativeView() : NULL; | 966 gfx::NativeView native_view = view_ ? view_->GetNativeView() : NULL; |
| 964 *results = WebScreenInfoFactory::screenInfo(native_view); | 967 *results = WebScreenInfoFactory::screenInfo(native_view); |
| 965 } | 968 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 } | 1047 } |
| 1045 } | 1048 } |
| 1046 | 1049 |
| 1047 void RenderWidgetHost::OnMsgDestroyPluginContainer(gfx::PluginWindowHandle id) { | 1050 void RenderWidgetHost::OnMsgDestroyPluginContainer(gfx::PluginWindowHandle id) { |
| 1048 if (view_) { | 1051 if (view_) { |
| 1049 view_->DestroyPluginContainer(id); | 1052 view_->DestroyPluginContainer(id); |
| 1050 } else { | 1053 } else { |
| 1051 NOTIMPLEMENTED(); | 1054 NOTIMPLEMENTED(); |
| 1052 } | 1055 } |
| 1053 } | 1056 } |
| 1054 | |
| 1055 #endif | 1057 #endif |
| 1056 | 1058 |
| 1057 void RenderWidgetHost::PaintBackingStoreRect( | 1059 void RenderWidgetHost::PaintBackingStoreRect( |
| 1058 TransportDIB::Id bitmap, | 1060 TransportDIB::Id bitmap, |
| 1059 const gfx::Rect& bitmap_rect, | 1061 const gfx::Rect& bitmap_rect, |
| 1060 const std::vector<gfx::Rect>& copy_rects, | 1062 const std::vector<gfx::Rect>& copy_rects, |
| 1061 const gfx::Size& view_size) { | 1063 const gfx::Size& view_size) { |
| 1062 // The view may be destroyed already. | 1064 // The view may be destroyed already. |
| 1063 if (!view_) | 1065 if (!view_) |
| 1064 return; | 1066 return; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 // of this key event. | 1171 // of this key event. |
| 1170 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { | 1172 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { |
| 1171 UnhandledKeyboardEvent(front_item); | 1173 UnhandledKeyboardEvent(front_item); |
| 1172 | 1174 |
| 1173 // WARNING: This RenderWidgetHost can be deallocated at this point | 1175 // WARNING: This RenderWidgetHost can be deallocated at this point |
| 1174 // (i.e. in the case of Ctrl+W, where the call to | 1176 // (i.e. in the case of Ctrl+W, where the call to |
| 1175 // UnhandledKeyboardEvent destroys this RenderWidgetHost). | 1177 // UnhandledKeyboardEvent destroys this RenderWidgetHost). |
| 1176 } | 1178 } |
| 1177 } | 1179 } |
| 1178 } | 1180 } |
| OLD | NEW |