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 <math.h> | 7 #include <math.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "cc/output/compositor_frame.h" | 22 #include "cc/output/compositor_frame.h" |
23 #include "cc/output/compositor_frame_ack.h" | 23 #include "cc/output/compositor_frame_ack.h" |
24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 24 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
25 #include "content/browser/gpu/compositor_util.h" | 25 #include "content/browser/gpu/compositor_util.h" |
26 #include "content/browser/gpu/gpu_process_host.h" | 26 #include "content/browser/gpu/gpu_process_host.h" |
27 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 27 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
28 #include "content/browser/gpu/gpu_surface_tracker.h" | 28 #include "content/browser/gpu/gpu_surface_tracker.h" |
29 #include "content/browser/renderer_host/backing_store.h" | 29 #include "content/browser/renderer_host/backing_store.h" |
30 #include "content/browser/renderer_host/backing_store_manager.h" | 30 #include "content/browser/renderer_host/backing_store_manager.h" |
31 #include "content/browser/renderer_host/dip_util.h" | 31 #include "content/browser/renderer_host/dip_util.h" |
| 32 #include "content/browser/renderer_host/input/buffered_input_router.h" |
32 #include "content/browser/renderer_host/input/immediate_input_router.h" | 33 #include "content/browser/renderer_host/input/immediate_input_router.h" |
33 #include "content/browser/renderer_host/overscroll_controller.h" | 34 #include "content/browser/renderer_host/overscroll_controller.h" |
34 #include "content/browser/renderer_host/render_process_host_impl.h" | 35 #include "content/browser/renderer_host/render_process_host_impl.h" |
35 #include "content/browser/renderer_host/render_view_host_impl.h" | 36 #include "content/browser/renderer_host/render_view_host_impl.h" |
36 #include "content/browser/renderer_host/render_widget_helper.h" | 37 #include "content/browser/renderer_host/render_widget_helper.h" |
37 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 38 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
38 #include "content/common/accessibility_messages.h" | 39 #include "content/common/accessibility_messages.h" |
39 #include "content/common/content_constants_internal.h" | 40 #include "content/common/content_constants_internal.h" |
40 #include "content/common/gpu/gpu_messages.h" | 41 #include "content/common/gpu/gpu_messages.h" |
41 #include "content/common/input_messages.h" | 42 #include "content/common/input_messages.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 // Otherwise we'll notify the process host when we are first shown. | 183 // Otherwise we'll notify the process host when we are first shown. |
183 if (!hidden) | 184 if (!hidden) |
184 process_->WidgetRestored(); | 185 process_->WidgetRestored(); |
185 | 186 |
186 accessibility_mode_ = | 187 accessibility_mode_ = |
187 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); | 188 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode(); |
188 | 189 |
189 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) | 190 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
190 g_created_callbacks.Get().at(i).Run(this); | 191 g_created_callbacks.Get().at(i).Run(this); |
191 | 192 |
192 input_router_.reset(new ImmediateInputRouter(process, this, routing_id_)); | 193 input_router_ = CreateInputRouter(); |
193 | 194 |
194 #if defined(USE_AURA) | 195 #if defined(USE_AURA) |
195 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> | 196 bool overscroll_enabled = CommandLine::ForCurrentProcess()-> |
196 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; | 197 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0"; |
197 SetOverscrollControllerEnabled(overscroll_enabled); | 198 SetOverscrollControllerEnabled(overscroll_enabled); |
198 #endif | 199 #endif |
199 } | 200 } |
200 | 201 |
201 RenderWidgetHostImpl::~RenderWidgetHostImpl() { | 202 RenderWidgetHostImpl::~RenderWidgetHostImpl() { |
202 SetView(NULL); | 203 SetView(NULL); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (!enabled) | 372 if (!enabled) |
372 overscroll_controller_.reset(); | 373 overscroll_controller_.reset(); |
373 else if (!overscroll_controller_) | 374 else if (!overscroll_controller_) |
374 overscroll_controller_.reset(new OverscrollController(this)); | 375 overscroll_controller_.reset(new OverscrollController(this)); |
375 } | 376 } |
376 | 377 |
377 void RenderWidgetHostImpl::SuppressNextCharEvents() { | 378 void RenderWidgetHostImpl::SuppressNextCharEvents() { |
378 suppress_next_char_events_ = true; | 379 suppress_next_char_events_ = true; |
379 } | 380 } |
380 | 381 |
| 382 void RenderWidgetHostImpl::FlushInput() { |
| 383 input_router_->Flush(); |
| 384 } |
| 385 |
381 void RenderWidgetHostImpl::Init() { | 386 void RenderWidgetHostImpl::Init() { |
382 DCHECK(process_->HasConnection()); | 387 DCHECK(process_->HasConnection()); |
383 | 388 |
384 renderer_initialized_ = true; | 389 renderer_initialized_ = true; |
385 | 390 |
386 GpuSurfaceTracker::Get()->SetSurfaceHandle( | 391 GpuSurfaceTracker::Get()->SetSurfaceHandle( |
387 surface_id_, GetCompositingSurface()); | 392 surface_id_, GetCompositingSurface()); |
388 | 393 |
389 // Send the ack along with the information on placement. | 394 // Send the ack along with the information on placement. |
390 Send(new ViewMsg_CreatingNew_ACK(routing_id_)); | 395 Send(new ViewMsg_CreatingNew_ACK(routing_id_)); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 if (!msg_is_ok) { | 476 if (!msg_is_ok) { |
472 // The message de-serialization failed. Kill the renderer process. | 477 // The message de-serialization failed. Kill the renderer process. |
473 RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); | 478 RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); |
474 GetProcess()->ReceivedBadMessage(); | 479 GetProcess()->ReceivedBadMessage(); |
475 } | 480 } |
476 return handled; | 481 return handled; |
477 } | 482 } |
478 | 483 |
479 bool RenderWidgetHostImpl::Send(IPC::Message* msg) { | 484 bool RenderWidgetHostImpl::Send(IPC::Message* msg) { |
480 if (IPC_MESSAGE_ID_CLASS(msg->type()) == InputMsgStart) | 485 if (IPC_MESSAGE_ID_CLASS(msg->type()) == InputMsgStart) |
481 return input_router_->SendInput(msg); | 486 return input_router_->SendInput(make_scoped_ptr(msg)); |
482 | 487 |
483 return process_->Send(msg); | 488 return process_->Send(msg); |
484 } | 489 } |
485 | 490 |
486 void RenderWidgetHostImpl::WasHidden() { | 491 void RenderWidgetHostImpl::WasHidden() { |
487 if (is_hidden_) | 492 if (is_hidden_) |
488 return; | 493 return; |
489 | 494 |
490 is_hidden_ = true; | 495 is_hidden_ = true; |
491 | 496 |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 | 1233 |
1229 void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status, | 1234 void RenderWidgetHostImpl::RendererExited(base::TerminationStatus status, |
1230 int exit_code) { | 1235 int exit_code) { |
1231 // Clearing this flag causes us to re-create the renderer when recovering | 1236 // Clearing this flag causes us to re-create the renderer when recovering |
1232 // from a crashed renderer. | 1237 // from a crashed renderer. |
1233 renderer_initialized_ = false; | 1238 renderer_initialized_ = false; |
1234 | 1239 |
1235 waiting_for_screen_rects_ack_ = false; | 1240 waiting_for_screen_rects_ack_ = false; |
1236 | 1241 |
1237 // Reset to ensure that input routing works with a new renderer. | 1242 // Reset to ensure that input routing works with a new renderer. |
1238 input_router_.reset(new ImmediateInputRouter(process_, this, routing_id_)); | 1243 input_router_ = CreateInputRouter(); |
1239 | 1244 |
1240 if (overscroll_controller_) | 1245 if (overscroll_controller_) |
1241 overscroll_controller_->Reset(); | 1246 overscroll_controller_->Reset(); |
1242 | 1247 |
1243 // Must reset these to ensure that keyboard events work with a new renderer. | 1248 // Must reset these to ensure that keyboard events work with a new renderer. |
1244 suppress_next_char_events_ = false; | 1249 suppress_next_char_events_ = false; |
1245 | 1250 |
1246 // Reset some fields in preparation for recovering from a crash. | 1251 // Reset some fields in preparation for recovering from a crash. |
1247 ResetSizeAndRepaintPendingFlags(); | 1252 ResetSizeAndRepaintPendingFlags(); |
1248 current_size_.SetSize(0, 0); | 1253 current_size_.SetSize(0, 0); |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 } | 2100 } |
2096 | 2101 |
2097 bool RenderWidgetHostImpl::OnSendGestureEventImmediately( | 2102 bool RenderWidgetHostImpl::OnSendGestureEventImmediately( |
2098 const GestureEventWithLatencyInfo& gesture_event) { | 2103 const GestureEventWithLatencyInfo& gesture_event) { |
2099 TRACE_EVENT_INSTANT0("input", | 2104 TRACE_EVENT_INSTANT0("input", |
2100 "RenderWidgetHostImpl::OnSendGestureEventImmediately", | 2105 "RenderWidgetHostImpl::OnSendGestureEventImmediately", |
2101 TRACE_EVENT_SCOPE_THREAD); | 2106 TRACE_EVENT_SCOPE_THREAD); |
2102 return !IgnoreInputEvents(); | 2107 return !IgnoreInputEvents(); |
2103 } | 2108 } |
2104 | 2109 |
| 2110 void RenderWidgetHostImpl::SetNeedsFlush() { |
| 2111 if (view_) |
| 2112 view_->OnSetNeedsFlushInput(); |
| 2113 } |
| 2114 |
| 2115 void RenderWidgetHostImpl::DidFlush() { |
| 2116 if (view_) |
| 2117 view_->OnDidFlushInput(); |
| 2118 } |
| 2119 |
2105 void RenderWidgetHostImpl::OnKeyboardEventAck( | 2120 void RenderWidgetHostImpl::OnKeyboardEventAck( |
2106 const NativeWebKeyboardEvent& event, | 2121 const NativeWebKeyboardEvent& event, |
2107 InputEventAckState ack_result) { | 2122 InputEventAckState ack_result) { |
2108 #if defined(OS_MACOSX) | 2123 #if defined(OS_MACOSX) |
2109 if (!is_hidden() && view_ && view_->PostProcessEventForPluginIme(event)) | 2124 if (!is_hidden() && view_ && view_->PostProcessEventForPluginIme(event)) |
2110 return; | 2125 return; |
2111 #endif | 2126 #endif |
2112 | 2127 |
2113 // We only send unprocessed key event upwards if we are not hidden, | 2128 // We only send unprocessed key event upwards if we are not hidden, |
2114 // because the user has moved away from us and no longer expect any effect | 2129 // because the user has moved away from us and no longer expect any effect |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 // Clear the new_auto_size_ since the empty value is used as a flag to | 2407 // Clear the new_auto_size_ since the empty value is used as a flag to |
2393 // indicate that no callback is in progress (i.e. without this line | 2408 // indicate that no callback is in progress (i.e. without this line |
2394 // DelayedAutoResized will not get called again). | 2409 // DelayedAutoResized will not get called again). |
2395 new_auto_size_.SetSize(0, 0); | 2410 new_auto_size_.SetSize(0, 0); |
2396 if (!should_auto_resize_) | 2411 if (!should_auto_resize_) |
2397 return; | 2412 return; |
2398 | 2413 |
2399 OnRenderAutoResized(new_size); | 2414 OnRenderAutoResized(new_size); |
2400 } | 2415 } |
2401 | 2416 |
| 2417 scoped_ptr<InputRouter> RenderWidgetHostImpl::CreateInputRouter() { |
| 2418 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2419 switches::kEnableBufferedInputRouter)) { |
| 2420 return scoped_ptr<InputRouter>( |
| 2421 new BufferedInputRouter(process_, this, this, routing_id_)); |
| 2422 } else { |
| 2423 return scoped_ptr<InputRouter>( |
| 2424 new ImmediateInputRouter(process_, this, this, routing_id_)); |
| 2425 } |
| 2426 } |
| 2427 |
2402 void RenderWidgetHostImpl::DetachDelegate() { | 2428 void RenderWidgetHostImpl::DetachDelegate() { |
2403 delegate_ = NULL; | 2429 delegate_ = NULL; |
2404 } | 2430 } |
2405 | 2431 |
2406 void RenderWidgetHostImpl::ComputeTouchLatency( | 2432 void RenderWidgetHostImpl::ComputeTouchLatency( |
2407 const ui::LatencyInfo& latency_info) { | 2433 const ui::LatencyInfo& latency_info) { |
2408 ui::LatencyInfo::LatencyComponent ui_component; | 2434 ui::LatencyInfo::LatencyComponent ui_component; |
2409 ui::LatencyInfo::LatencyComponent rwh_component; | 2435 ui::LatencyInfo::LatencyComponent rwh_component; |
2410 ui::LatencyInfo::LatencyComponent acked_component; | 2436 ui::LatencyInfo::LatencyComponent acked_component; |
2411 | 2437 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 int process_id = (b->first.second >> 32) & 0xffffffff; | 2537 int process_id = (b->first.second >> 32) & 0xffffffff; |
2512 RenderWidgetHost* rwh = | 2538 RenderWidgetHost* rwh = |
2513 RenderWidgetHost::FromID(process_id, routing_id); | 2539 RenderWidgetHost::FromID(process_id, routing_id); |
2514 if (!rwh) | 2540 if (!rwh) |
2515 continue; | 2541 continue; |
2516 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2542 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
2517 } | 2543 } |
2518 } | 2544 } |
2519 | 2545 |
2520 } // namespace content | 2546 } // namespace content |
OLD | NEW |