| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "content/browser/gpu/gpu_process_host.h" | 18 #include "content/browser/gpu/gpu_process_host.h" |
| 19 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 19 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 20 #include "content/browser/gpu/gpu_surface_tracker.h" | 20 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 21 #include "content/browser/renderer_host/backing_store.h" | 21 #include "content/browser/renderer_host/backing_store.h" |
| 22 #include "content/browser/renderer_host/backing_store_manager.h" | 22 #include "content/browser/renderer_host/backing_store_manager.h" |
| 23 #include "content/browser/renderer_host/render_process_host_impl.h" | 23 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 24 #include "content/browser/renderer_host/render_view_host_impl.h" | 24 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 25 #include "content/browser/renderer_host/render_widget_helper.h" | 25 #include "content/browser/renderer_host/render_widget_helper.h" |
| 26 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 26 #include "content/browser/renderer_host/tap_suppression_controller.h" | 27 #include "content/browser/renderer_host/tap_suppression_controller.h" |
| 27 #include "content/common/accessibility_messages.h" | 28 #include "content/common/accessibility_messages.h" |
| 28 #include "content/common/gpu/gpu_messages.h" | 29 #include "content/common/gpu/gpu_messages.h" |
| 29 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
| 30 #include "content/port/browser/render_widget_host_view_port.h" | 31 #include "content/port/browser/render_widget_host_view_port.h" |
| 31 #include "content/public/browser/native_web_keyboard_event.h" | 32 #include "content/public/browser/native_web_keyboard_event.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
| 34 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
| 35 #include "content/public/common/content_switches.h" | 36 #include "content/public/common/content_switches.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 92 } |
| 92 | 93 |
| 93 // static | 94 // static |
| 94 size_t RenderWidgetHost::BackingStoreMemorySize() { | 95 size_t RenderWidgetHost::BackingStoreMemorySize() { |
| 95 return BackingStoreManager::MemorySize(); | 96 return BackingStoreManager::MemorySize(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 /////////////////////////////////////////////////////////////////////////////// | 99 /////////////////////////////////////////////////////////////////////////////// |
| 99 // RenderWidgetHostImpl | 100 // RenderWidgetHostImpl |
| 100 | 101 |
| 101 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderProcessHost* process, | 102 RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, |
| 103 RenderProcessHost* process, |
| 102 int routing_id) | 104 int routing_id) |
| 103 : view_(NULL), | 105 : view_(NULL), |
| 104 renderer_initialized_(false), | 106 renderer_initialized_(false), |
| 105 hung_renderer_delay_ms_(kHungRendererDelayMs), | 107 hung_renderer_delay_ms_(kHungRendererDelayMs), |
| 108 delegate_(delegate), |
| 106 process_(process), | 109 process_(process), |
| 107 routing_id_(routing_id), | 110 routing_id_(routing_id), |
| 108 surface_id_(0), | 111 surface_id_(0), |
| 109 is_loading_(false), | 112 is_loading_(false), |
| 110 is_hidden_(false), | 113 is_hidden_(false), |
| 111 is_fullscreen_(false), | 114 is_fullscreen_(false), |
| 112 is_accelerated_compositing_active_(false), | 115 is_accelerated_compositing_active_(false), |
| 113 repaint_ack_pending_(false), | 116 repaint_ack_pending_(false), |
| 114 resize_ack_pending_(false), | 117 resize_ack_pending_(false), |
| 115 should_auto_resize_(false), | 118 should_auto_resize_(false), |
| 116 mouse_move_pending_(false), | 119 mouse_move_pending_(false), |
| 117 mouse_wheel_pending_(false), | 120 mouse_wheel_pending_(false), |
| 118 needs_repainting_on_restore_(false), | 121 needs_repainting_on_restore_(false), |
| 119 is_unresponsive_(false), | 122 is_unresponsive_(false), |
| 120 in_flight_event_count_(0), | 123 in_flight_event_count_(0), |
| 121 in_get_backing_store_(false), | 124 in_get_backing_store_(false), |
| 122 abort_get_backing_store_(false), | 125 abort_get_backing_store_(false), |
| 123 view_being_painted_(false), | 126 view_being_painted_(false), |
| 124 ignore_input_events_(false), | 127 ignore_input_events_(false), |
| 125 text_direction_updated_(false), | 128 text_direction_updated_(false), |
| 126 text_direction_(WebKit::WebTextDirectionLeftToRight), | 129 text_direction_(WebKit::WebTextDirectionLeftToRight), |
| 127 text_direction_canceled_(false), | 130 text_direction_canceled_(false), |
| 128 suppress_next_char_events_(false), | 131 suppress_next_char_events_(false), |
| 129 pending_mouse_lock_request_(false), | 132 pending_mouse_lock_request_(false), |
| 130 has_touch_handler_(false), | 133 has_touch_handler_(false), |
| 131 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 134 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 132 tap_suppression_controller_(new TapSuppressionController(this)) { | 135 tap_suppression_controller_(new TapSuppressionController(this)) { |
| 136 CHECK(delegate_); |
| 133 if (routing_id_ == MSG_ROUTING_NONE) { | 137 if (routing_id_ == MSG_ROUTING_NONE) { |
| 134 routing_id_ = process_->GetNextRoutingID(); | 138 routing_id_ = process_->GetNextRoutingID(); |
| 135 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 139 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 136 process_->GetID(), | 140 process_->GetID(), |
| 137 routing_id_); | 141 routing_id_); |
| 138 } else { | 142 } else { |
| 139 // TODO(piman): This is a O(N) lookup, where we could forward the | 143 // TODO(piman): This is a O(N) lookup, where we could forward the |
| 140 // information from the RenderWidgetHelper. The problem is that doing so | 144 // information from the RenderWidgetHelper. The problem is that doing so |
| 141 // currently leaks outside of content all the way to chrome classes, and | 145 // currently leaks outside of content all the way to chrome classes, and |
| 142 // would be a layering violation. Since we don't expect more than a few | 146 // would be a layering violation. Since we don't expect more than a few |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 return view_->GetCompositingSurface(); | 212 return view_->GetCompositingSurface(); |
| 209 return gfx::GLSurfaceHandle(); | 213 return gfx::GLSurfaceHandle(); |
| 210 } | 214 } |
| 211 | 215 |
| 212 void RenderWidgetHostImpl::CompositingSurfaceUpdated() { | 216 void RenderWidgetHostImpl::CompositingSurfaceUpdated() { |
| 213 GpuSurfaceTracker::Get()->SetSurfaceHandle( | 217 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
| 214 surface_id_, GetCompositingSurface()); | 218 surface_id_, GetCompositingSurface()); |
| 215 process_->SurfaceUpdated(surface_id_); | 219 process_->SurfaceUpdated(surface_id_); |
| 216 } | 220 } |
| 217 | 221 |
| 218 bool RenderWidgetHostImpl::PreHandleKeyboardEvent( | |
| 219 const NativeWebKeyboardEvent& event, | |
| 220 bool* is_keyboard_shortcut) { | |
| 221 return false; | |
| 222 } | |
| 223 | |
| 224 void RenderWidgetHostImpl::Init() { | 222 void RenderWidgetHostImpl::Init() { |
| 225 DCHECK(process_->HasConnection()); | 223 DCHECK(process_->HasConnection()); |
| 226 | 224 |
| 227 renderer_initialized_ = true; | 225 renderer_initialized_ = true; |
| 228 | 226 |
| 229 GpuSurfaceTracker::Get()->SetSurfaceHandle( | 227 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
| 230 surface_id_, GetCompositingSurface()); | 228 surface_id_, GetCompositingSurface()); |
| 231 | 229 |
| 232 // Send the ack along with the information on placement. | 230 // Send the ack along with the information on placement. |
| 233 Send(new ViewMsg_CreatingNew_ACK(routing_id_, GetNativeViewId())); | 231 Send(new ViewMsg_CreatingNew_ACK(routing_id_, GetNativeViewId())); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 if (!key_event.skip_in_browser) { | 845 if (!key_event.skip_in_browser) { |
| 848 // We need to set |suppress_next_char_events_| to true if | 846 // We need to set |suppress_next_char_events_| to true if |
| 849 // PreHandleKeyboardEvent() returns true, but |this| may already be | 847 // PreHandleKeyboardEvent() returns true, but |this| may already be |
| 850 // destroyed at that time. So set |suppress_next_char_events_| true here, | 848 // destroyed at that time. So set |suppress_next_char_events_| true here, |
| 851 // then revert it afterwards when necessary. | 849 // then revert it afterwards when necessary. |
| 852 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 850 if (key_event.type == WebKeyboardEvent::RawKeyDown) |
| 853 suppress_next_char_events_ = true; | 851 suppress_next_char_events_ = true; |
| 854 | 852 |
| 855 // Tab switching/closing accelerators aren't sent to the renderer to avoid | 853 // Tab switching/closing accelerators aren't sent to the renderer to avoid |
| 856 // a hung/malicious renderer from interfering. | 854 // a hung/malicious renderer from interfering. |
| 857 if (PreHandleKeyboardEvent(key_event, &is_keyboard_shortcut)) | 855 if (delegate_->PreHandleKeyboardEvent(key_event, &is_keyboard_shortcut)) |
| 858 return; | 856 return; |
| 859 | 857 |
| 860 if (key_event.type == WebKeyboardEvent::RawKeyDown) | 858 if (key_event.type == WebKeyboardEvent::RawKeyDown) |
| 861 suppress_next_char_events_ = false; | 859 suppress_next_char_events_ = false; |
| 862 } | 860 } |
| 863 | 861 |
| 864 // Don't add this key to the queue if we have no way to send the message... | 862 // Don't add this key to the queue if we have no way to send the message... |
| 865 if (!process_->HasConnection()) | 863 if (!process_->HasConnection()) |
| 866 return; | 864 return; |
| 867 | 865 |
| 868 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 866 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
| 869 // renderer and we need to give something to the UnhandledInputEvent | 867 // renderer and we need to give something to the HandleKeyboardEvent |
| 870 // handler. | 868 // handler. |
| 871 key_queue_.push_back(key_event); | 869 key_queue_.push_back(key_event); |
| 872 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 870 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
| 873 | 871 |
| 874 // Only forward the non-native portions of our event. | 872 // Only forward the non-native portions of our event. |
| 875 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 873 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
| 876 is_keyboard_shortcut); | 874 is_keyboard_shortcut); |
| 877 } | 875 } |
| 878 } | 876 } |
| 879 | 877 |
| (...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 | 1590 |
| 1593 #if defined(OS_MACOSX) | 1591 #if defined(OS_MACOSX) |
| 1594 if (!is_hidden_ && view_->PostProcessEventForPluginIme(front_item)) | 1592 if (!is_hidden_ && view_->PostProcessEventForPluginIme(front_item)) |
| 1595 return; | 1593 return; |
| 1596 #endif | 1594 #endif |
| 1597 | 1595 |
| 1598 // We only send unprocessed key event upwards if we are not hidden, | 1596 // We only send unprocessed key event upwards if we are not hidden, |
| 1599 // because the user has moved away from us and no longer expect any effect | 1597 // because the user has moved away from us and no longer expect any effect |
| 1600 // of this key event. | 1598 // of this key event. |
| 1601 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { | 1599 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { |
| 1602 UnhandledKeyboardEvent(front_item); | 1600 delegate_->HandleKeyboardEvent(front_item); |
| 1603 | 1601 |
| 1604 // WARNING: This RenderWidgetHostImpl can be deallocated at this point | 1602 // WARNING: This RenderWidgetHostImpl can be deallocated at this point |
| 1605 // (i.e. in the case of Ctrl+W, where the call to | 1603 // (i.e. in the case of Ctrl+W, where the call to |
| 1606 // UnhandledKeyboardEvent destroys this RenderWidgetHostImpl). | 1604 // HandleKeyboardEvent destroys this RenderWidgetHostImpl). |
| 1607 } | 1605 } |
| 1608 } | 1606 } |
| 1609 } | 1607 } |
| 1610 | 1608 |
| 1611 void RenderWidgetHostImpl::ActivateDeferredPluginHandles() { | 1609 void RenderWidgetHostImpl::ActivateDeferredPluginHandles() { |
| 1612 #if !defined(USE_AURA) | 1610 #if !defined(USE_AURA) |
| 1613 if (view_ == NULL) | 1611 if (view_ == NULL) |
| 1614 return; | 1612 return; |
| 1615 | 1613 |
| 1616 for (int i = 0; i < static_cast<int>(deferred_plugin_handles_.size()); i++) { | 1614 for (int i = 0; i < static_cast<int>(deferred_plugin_handles_.size()); i++) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 // indicate that no callback is in progress (i.e. without this line | 1778 // indicate that no callback is in progress (i.e. without this line |
| 1781 // DelayedAutoResized will not get called again). | 1779 // DelayedAutoResized will not get called again). |
| 1782 new_auto_size_.SetSize(0, 0); | 1780 new_auto_size_.SetSize(0, 0); |
| 1783 if (!should_auto_resize_) | 1781 if (!should_auto_resize_) |
| 1784 return; | 1782 return; |
| 1785 | 1783 |
| 1786 OnRenderAutoResized(new_size); | 1784 OnRenderAutoResized(new_size); |
| 1787 } | 1785 } |
| 1788 | 1786 |
| 1789 } // namespace content | 1787 } // namespace content |
| OLD | NEW |