| 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.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/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" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_state.h" | 16 #include "content/browser/accessibility/browser_accessibility_state.h" |
| 17 #include "content/browser/gpu/gpu_process_host.h" | 17 #include "content/browser/gpu/gpu_process_host.h" |
| 18 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 18 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 19 #include "content/browser/gpu/gpu_surface_tracker.h" |
| 19 #include "content/browser/renderer_host/backing_store.h" | 20 #include "content/browser/renderer_host/backing_store.h" |
| 20 #include "content/browser/renderer_host/backing_store_manager.h" | 21 #include "content/browser/renderer_host/backing_store_manager.h" |
| 21 #include "content/browser/renderer_host/render_process_host_impl.h" | 22 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 22 #include "content/browser/renderer_host/render_widget_helper.h" | 23 #include "content/browser/renderer_host/render_widget_helper.h" |
| 23 #include "content/browser/renderer_host/render_widget_host_view.h" | 24 #include "content/browser/renderer_host/render_widget_host_view.h" |
| 24 #include "content/common/gpu/gpu_messages.h" | 25 #include "content/common/gpu/gpu_messages.h" |
| 25 #include "content/common/view_messages.h" | 26 #include "content/common/view_messages.h" |
| 26 #include "content/public/browser/native_web_keyboard_event.h" | 27 #include "content/public/browser/native_web_keyboard_event.h" |
| 27 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/notification_types.h" | 29 #include "content/public/browser/notification_types.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 /////////////////////////////////////////////////////////////////////////////// | 74 /////////////////////////////////////////////////////////////////////////////// |
| 74 // RenderWidgetHost | 75 // RenderWidgetHost |
| 75 | 76 |
| 76 RenderWidgetHost::RenderWidgetHost(content::RenderProcessHost* process, | 77 RenderWidgetHost::RenderWidgetHost(content::RenderProcessHost* process, |
| 77 int routing_id) | 78 int routing_id) |
| 78 : renderer_initialized_(false), | 79 : renderer_initialized_(false), |
| 79 renderer_accessible_(false), | 80 renderer_accessible_(false), |
| 80 view_(NULL), | 81 view_(NULL), |
| 81 process_(process), | 82 process_(process), |
| 82 routing_id_(routing_id), | 83 routing_id_(routing_id), |
| 84 surface_id_(0), |
| 83 is_loading_(false), | 85 is_loading_(false), |
| 84 is_hidden_(false), | 86 is_hidden_(false), |
| 85 is_accelerated_compositing_active_(false), | 87 is_accelerated_compositing_active_(false), |
| 86 repaint_ack_pending_(false), | 88 repaint_ack_pending_(false), |
| 87 resize_ack_pending_(false), | 89 resize_ack_pending_(false), |
| 88 should_auto_resize_(false), | 90 should_auto_resize_(false), |
| 89 mouse_move_pending_(false), | 91 mouse_move_pending_(false), |
| 90 mouse_wheel_pending_(false), | 92 mouse_wheel_pending_(false), |
| 91 touch_move_pending_(false), | 93 touch_move_pending_(false), |
| 92 touch_event_is_queued_(false), | 94 touch_event_is_queued_(false), |
| 93 needs_repainting_on_restore_(false), | 95 needs_repainting_on_restore_(false), |
| 94 is_unresponsive_(false), | 96 is_unresponsive_(false), |
| 95 in_get_backing_store_(false), | 97 in_get_backing_store_(false), |
| 96 view_being_painted_(false), | 98 view_being_painted_(false), |
| 97 ignore_input_events_(false), | 99 ignore_input_events_(false), |
| 98 text_direction_updated_(false), | 100 text_direction_updated_(false), |
| 99 text_direction_(WebKit::WebTextDirectionLeftToRight), | 101 text_direction_(WebKit::WebTextDirectionLeftToRight), |
| 100 text_direction_canceled_(false), | 102 text_direction_canceled_(false), |
| 101 suppress_next_char_events_(false), | 103 suppress_next_char_events_(false), |
| 102 pending_mouse_lock_request_(false), | 104 pending_mouse_lock_request_(false), |
| 103 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 104 if (routing_id_ == MSG_ROUTING_NONE) | 106 if (routing_id_ == MSG_ROUTING_NONE) { |
| 105 routing_id_ = process_->GetNextRoutingID(); | 107 routing_id_ = process_->GetNextRoutingID(); |
| 108 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
| 109 process_->GetID(), |
| 110 routing_id_); |
| 111 } else { |
| 112 // TODO(piman): This is a O(N) lookup, where we could forward the |
| 113 // information from the RenderWidgetHelper. The problem is that doing so |
| 114 // currently leaks outside of content all the way to chrome classes, and |
| 115 // would be a layering violation. Since we don't expect more than a few |
| 116 // hundreds of RWH, this seems acceptable. Revisit if performance become a |
| 117 // problem, for example by tracking in the RenderWidgetHelper the routing id |
| 118 // (and surface id) that have been created, but whose RWH haven't yet. |
| 119 surface_id_ = GpuSurfaceTracker::Get()->LookupSurfaceForRenderer( |
| 120 process_->GetID(), |
| 121 routing_id_); |
| 122 DCHECK(surface_id_); |
| 123 } |
| 106 | 124 |
| 107 process_->Attach(this, routing_id_); | 125 process_->Attach(this, routing_id_); |
| 108 // Because the widget initializes as is_hidden_ == false, | 126 // Because the widget initializes as is_hidden_ == false, |
| 109 // tell the process host that we're alive. | 127 // tell the process host that we're alive. |
| 110 process_->WidgetRestored(); | 128 process_->WidgetRestored(); |
| 111 | 129 |
| 112 // Enable accessibility if it was manually specified or if it was | 130 // Enable accessibility if it was manually specified or if it was |
| 113 // auto-detected. | 131 // auto-detected. |
| 114 if (CommandLine::ForCurrentProcess()->HasSwitch( | 132 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 115 switches::kForceRendererAccessibility)) { | 133 switches::kForceRendererAccessibility)) { |
| 116 BrowserAccessibilityState::GetInstance()->OnAccessibilityEnabledManually(); | 134 BrowserAccessibilityState::GetInstance()->OnAccessibilityEnabledManually(); |
| 117 EnableRendererAccessibility(); | 135 EnableRendererAccessibility(); |
| 118 } else if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { | 136 } else if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser()) { |
| 119 EnableRendererAccessibility(); | 137 EnableRendererAccessibility(); |
| 120 } | 138 } |
| 121 } | 139 } |
| 122 | 140 |
| 123 RenderWidgetHost::~RenderWidgetHost() { | 141 RenderWidgetHost::~RenderWidgetHost() { |
| 124 SetView(NULL); | 142 SetView(NULL); |
| 125 | 143 |
| 126 // Clear our current or cached backing store if either remains. | 144 // Clear our current or cached backing store if either remains. |
| 127 BackingStoreManager::RemoveBackingStore(this); | 145 BackingStoreManager::RemoveBackingStore(this); |
| 128 | 146 |
| 147 GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); |
| 148 surface_id_ = 0; |
| 149 |
| 129 process_->Release(routing_id_); | 150 process_->Release(routing_id_); |
| 130 } | 151 } |
| 131 | 152 |
| 132 void RenderWidgetHost::SetView(RenderWidgetHostView* view) { | 153 void RenderWidgetHost::SetView(RenderWidgetHostView* view) { |
| 133 view_ = view; | 154 view_ = view; |
| 134 | 155 |
| 135 if (!view_) | 156 if (!view_) { |
| 136 process_->SetCompositingSurface(routing_id_, gfx::kNullPluginWindow); | 157 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
| 158 surface_id_, gfx::kNullPluginWindow); |
| 159 } |
| 137 } | 160 } |
| 138 | 161 |
| 139 gfx::NativeViewId RenderWidgetHost::GetNativeViewId() const { | 162 gfx::NativeViewId RenderWidgetHost::GetNativeViewId() const { |
| 140 if (view_) | 163 if (view_) |
| 141 return view_->GetNativeViewId(); | 164 return view_->GetNativeViewId(); |
| 142 return 0; | 165 return 0; |
| 143 } | 166 } |
| 144 | 167 |
| 145 gfx::PluginWindowHandle RenderWidgetHost::GetCompositingSurface() { | 168 gfx::PluginWindowHandle RenderWidgetHost::GetCompositingSurface() { |
| 146 if (view_) | 169 if (view_) |
| 147 return view_->GetCompositingSurface(); | 170 return view_->GetCompositingSurface(); |
| 148 return gfx::kNullPluginWindow; | 171 return gfx::kNullPluginWindow; |
| 149 } | 172 } |
| 150 | 173 |
| 151 bool RenderWidgetHost::PreHandleKeyboardEvent( | 174 bool RenderWidgetHost::PreHandleKeyboardEvent( |
| 152 const NativeWebKeyboardEvent& event, | 175 const NativeWebKeyboardEvent& event, |
| 153 bool* is_keyboard_shortcut) { | 176 bool* is_keyboard_shortcut) { |
| 154 return false; | 177 return false; |
| 155 } | 178 } |
| 156 | 179 |
| 157 void RenderWidgetHost::Init() { | 180 void RenderWidgetHost::Init() { |
| 158 DCHECK(process_->HasConnection()); | 181 DCHECK(process_->HasConnection()); |
| 159 | 182 |
| 160 renderer_initialized_ = true; | 183 renderer_initialized_ = true; |
| 161 | 184 |
| 162 process_->SetCompositingSurface(routing_id_, | 185 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
| 163 GetCompositingSurface()); | 186 surface_id_, GetCompositingSurface()); |
| 164 | 187 |
| 165 // Send the ack along with the information on placement. | 188 // Send the ack along with the information on placement. |
| 166 Send(new ViewMsg_CreatingNew_ACK(routing_id_, GetNativeViewId())); | 189 Send(new ViewMsg_CreatingNew_ACK(routing_id_, GetNativeViewId())); |
| 167 WasResized(); | 190 WasResized(); |
| 168 } | 191 } |
| 169 | 192 |
| 170 void RenderWidgetHost::Shutdown() { | 193 void RenderWidgetHost::Shutdown() { |
| 171 if (process_->HasConnection()) { | 194 if (process_->HasConnection()) { |
| 172 // Tell the renderer object to close. | 195 // Tell the renderer object to close. |
| 173 process_->ReportExpectingClose(routing_id_); | 196 process_->ReportExpectingClose(routing_id_); |
| (...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); | 1550 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); |
| 1528 } | 1551 } |
| 1529 | 1552 |
| 1530 // static | 1553 // static |
| 1531 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, | 1554 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, |
| 1532 int gpu_host_id) { | 1555 int gpu_host_id) { |
| 1533 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 1556 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
| 1534 if (ui_shim) | 1557 if (ui_shim) |
| 1535 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); | 1558 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); |
| 1536 } | 1559 } |
| OLD | NEW |