Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / content / browser / frame_host / render_widget_host_view_guest.cc
blobf5a04c4cc6fb1e2c152e847173fabf94ac7f013d
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind_helpers.h"
6 #include "base/command_line.h"
7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "cc/surfaces/surface.h"
10 #include "cc/surfaces/surface_factory.h"
11 #include "cc/surfaces/surface_manager.h"
12 #include "cc/surfaces/surface_sequence.h"
13 #include "content/browser/browser_plugin/browser_plugin_guest.h"
14 #include "content/browser/compositor/surface_utils.h"
15 #include "content/browser/frame_host/render_widget_host_view_guest.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/common/browser_plugin/browser_plugin_messages.h"
18 #include "content/common/frame_messages.h"
19 #include "content/common/gpu/gpu_messages.h"
20 #include "content/common/input/web_touch_event_traits.h"
21 #include "content/common/view_messages.h"
22 #include "content/common/webplugin_geometry.h"
23 #include "content/public/common/content_switches.h"
24 #include "skia/ext/platform_canvas.h"
25 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
27 #if defined(OS_MACOSX)
28 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_helper.h"
29 #endif
31 #if defined(USE_AURA)
32 #include "content/browser/renderer_host/ui_events_helper.h"
33 #endif
35 namespace content {
37 namespace {
39 #if defined(USE_AURA)
40 blink::WebGestureEvent CreateFlingCancelEvent(double time_stamp) {
41 blink::WebGestureEvent gesture_event;
42 gesture_event.timeStampSeconds = time_stamp;
43 gesture_event.type = blink::WebGestureEvent::GestureFlingCancel;
44 gesture_event.sourceDevice = blink::WebGestureDeviceTouchscreen;
45 return gesture_event;
47 #endif // defined(USE_AURA)
49 } // namespace
51 RenderWidgetHostViewGuest::RenderWidgetHostViewGuest(
52 RenderWidgetHost* widget_host,
53 BrowserPluginGuest* guest,
54 base::WeakPtr<RenderWidgetHostViewBase> platform_view)
55 : RenderWidgetHostViewChildFrame(widget_host),
56 // |guest| is NULL during test.
57 guest_(guest ? guest->AsWeakPtr() : base::WeakPtr<BrowserPluginGuest>()),
58 platform_view_(platform_view) {
59 #if defined(USE_AURA)
60 gesture_recognizer_.reset(ui::GestureRecognizer::Create());
61 gesture_recognizer_->AddGestureEventHelper(this);
62 #endif // defined(USE_AURA)
65 RenderWidgetHostViewGuest::~RenderWidgetHostViewGuest() {
66 #if defined(USE_AURA)
67 gesture_recognizer_->RemoveGestureEventHelper(this);
68 #endif // defined(USE_AURA)
71 bool RenderWidgetHostViewGuest::OnMessageReceivedFromEmbedder(
72 const IPC::Message& message,
73 RenderWidgetHostImpl* embedder) {
74 bool handled = true;
75 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(RenderWidgetHostViewGuest, message,
76 embedder)
77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent,
78 OnHandleInputEvent)
79 IPC_MESSAGE_UNHANDLED(handled = false)
80 IPC_END_MESSAGE_MAP()
81 return handled;
84 void RenderWidgetHostViewGuest::Show() {
85 // If the WebContents associated with us showed an interstitial page in the
86 // beginning, the teardown path might call WasShown() while |host_| is in
87 // the process of destruction. Avoid calling WasShown below in this case.
88 // TODO(lazyboy): We shouldn't be showing interstitial pages in guests in the
89 // first place: http://crbug.com/273089.
91 // |guest_| is NULL during test.
92 if ((guest_ && guest_->is_in_destruction()) || !host_->is_hidden())
93 return;
94 // Make sure the size of this view matches the size of the WebContentsView.
95 // The two sizes may fall out of sync if we switch RenderWidgetHostViews,
96 // resize, and then switch page, as is the case with interstitial pages.
97 // NOTE: |guest_| is NULL in unit tests.
98 if (guest_)
99 SetSize(guest_->web_contents()->GetViewBounds().size());
100 host_->WasShown(ui::LatencyInfo());
103 void RenderWidgetHostViewGuest::Hide() {
104 // |guest_| is NULL during test.
105 if ((guest_ && guest_->is_in_destruction()) || host_->is_hidden())
106 return;
107 host_->WasHidden();
110 void RenderWidgetHostViewGuest::SetSize(const gfx::Size& size) {
111 size_ = size;
112 host_->WasResized();
115 void RenderWidgetHostViewGuest::SetBounds(const gfx::Rect& rect) {
116 SetSize(rect.size());
119 void RenderWidgetHostViewGuest::Focus() {
120 // InterstitialPageImpl focuses views directly, so we place focus logic here.
121 // InterstitialPages are not WebContents, and so BrowserPluginGuest does not
122 // have direct access to the interstitial page's RenderWidgetHost.
123 if (guest_)
124 guest_->SetFocus(host_, true, blink::WebFocusTypeNone);
127 bool RenderWidgetHostViewGuest::HasFocus() const {
128 if (!guest_)
129 return false;
130 return guest_->focused();
133 #if defined(USE_AURA)
134 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent(
135 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
136 // TODO(fsamuel): Currently we will only take this codepath if the guest has
137 // requested touch events. A better solution is to always forward touchpresses
138 // to the embedder process to target a BrowserPlugin, and then route all
139 // subsequent touch points of that touchdown to the appropriate guest until
140 // that touch point is released.
141 ScopedVector<ui::TouchEvent> events;
142 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, LOCAL_COORDINATES))
143 return;
145 ui::EventResult result = (ack_result ==
146 INPUT_EVENT_ACK_STATE_CONSUMED) ? ui::ER_HANDLED : ui::ER_UNHANDLED;
147 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(),
148 end = events.end(); iter != end; ++iter) {
149 if (!gesture_recognizer_->ProcessTouchEventPreDispatch(*iter, this))
150 continue;
152 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
153 gestures.reset(gesture_recognizer_->AckTouchEvent(
154 (*iter)->unique_event_id(), result, this));
155 ProcessGestures(gestures.get());
158 #endif
160 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const {
161 if (!guest_)
162 return gfx::Rect();
164 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView();
165 gfx::Rect embedder_bounds;
166 if (rwhv)
167 embedder_bounds = rwhv->GetViewBounds();
168 return gfx::Rect(
169 guest_->GetScreenCoordinates(embedder_bounds.origin()), size_);
172 void RenderWidgetHostViewGuest::RenderProcessGone(
173 base::TerminationStatus status,
174 int error_code) {
175 // The |platform_view_| gets destroyed before we get here if this view
176 // is for an InterstitialPage.
177 if (platform_view_)
178 platform_view_->RenderProcessGone(status, error_code);
180 // Destroy the guest view instance only, so we don't end up calling
181 // platform_view_->Destroy().
182 DestroyGuestView();
185 void RenderWidgetHostViewGuest::Destroy() {
186 // The RenderWidgetHost's destruction led here, so don't call it.
187 DestroyGuestView();
189 if (platform_view_) // The platform view might have been destroyed already.
190 platform_view_->Destroy();
193 gfx::Size RenderWidgetHostViewGuest::GetPhysicalBackingSize() const {
194 return RenderWidgetHostViewBase::GetPhysicalBackingSize();
197 base::string16 RenderWidgetHostViewGuest::GetSelectedText() const {
198 return platform_view_->GetSelectedText();
201 void RenderWidgetHostViewGuest::SetTooltipText(
202 const base::string16& tooltip_text) {
203 if (guest_)
204 guest_->SetTooltipText(tooltip_text);
207 void RenderWidgetHostViewGuest::OnSwapCompositorFrame(
208 uint32 output_surface_id,
209 scoped_ptr<cc::CompositorFrame> frame) {
210 if (!guest_ || !guest_->attached()) {
211 // We shouldn't hang on to a surface while we are detached.
212 ClearCompositorSurfaceIfNecessary();
213 return;
216 last_scroll_offset_ = frame->metadata.root_scroll_offset;
217 // When not using surfaces, the frame just gets proxied to
218 // the embedder's renderer to be composited.
219 if (!frame->delegated_frame_data || !use_surfaces_) {
220 guest_->SwapCompositorFrame(output_surface_id,
221 host_->GetProcess()->GetID(),
222 host_->GetRoutingID(),
223 frame.Pass());
224 return;
227 cc::RenderPass* root_pass =
228 frame->delegated_frame_data->render_pass_list.back();
230 gfx::Size frame_size = root_pass->output_rect.size();
231 float scale_factor = frame->metadata.device_scale_factor;
233 guest_->UpdateGuestSizeIfNecessary(frame_size, scale_factor);
235 // Check whether we need to recreate the cc::Surface, which means the child
236 // frame renderer has changed its output surface, or size, or scale factor.
237 if (output_surface_id != last_output_surface_id_ && surface_factory_) {
238 surface_factory_->Destroy(surface_id_);
239 surface_factory_.reset();
241 if (output_surface_id != last_output_surface_id_ ||
242 frame_size != current_surface_size_ ||
243 scale_factor != current_surface_scale_factor_ ||
244 guest_->has_attached_since_surface_set()) {
245 ClearCompositorSurfaceIfNecessary();
246 last_output_surface_id_ = output_surface_id;
247 current_surface_size_ = frame_size;
248 current_surface_scale_factor_ = scale_factor;
251 if (!surface_factory_) {
252 cc::SurfaceManager* manager = GetSurfaceManager();
253 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this));
256 if (surface_id_.is_null()) {
257 surface_id_ = id_allocator_->GenerateId();
258 surface_factory_->Create(surface_id_);
260 cc::SurfaceSequence sequence = cc::SurfaceSequence(
261 id_allocator_->id_namespace(), next_surface_sequence_++);
262 // The renderer process will satisfy this dependency when it creates a
263 // SurfaceLayer.
264 cc::SurfaceManager* manager = GetSurfaceManager();
265 manager->GetSurfaceForId(surface_id_)->AddDestructionDependency(sequence);
266 guest_->SetChildFrameSurface(surface_id_, frame_size, scale_factor,
267 sequence);
270 cc::SurfaceFactory::DrawCallback ack_callback = base::Bind(
271 &RenderWidgetHostViewChildFrame::SurfaceDrawn,
272 RenderWidgetHostViewChildFrame::AsWeakPtr(), output_surface_id);
273 ack_pending_count_++;
274 // If this value grows very large, something is going wrong.
275 DCHECK(ack_pending_count_ < 1000);
276 surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback);
279 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) {
280 if (!platform_view_) {
281 // In theory, we can get here if there's a delay between DestroyGuestView()
282 // being called and when our destructor is invoked.
283 return false;
286 return platform_view_->OnMessageReceived(msg);
289 void RenderWidgetHostViewGuest::InitAsChild(
290 gfx::NativeView parent_view) {
291 platform_view_->InitAsChild(parent_view);
294 void RenderWidgetHostViewGuest::InitAsPopup(
295 RenderWidgetHostView* parent_host_view, const gfx::Rect& bounds) {
296 // This should never get called.
297 NOTREACHED();
300 void RenderWidgetHostViewGuest::InitAsFullscreen(
301 RenderWidgetHostView* reference_host_view) {
302 // This should never get called.
303 NOTREACHED();
306 gfx::NativeView RenderWidgetHostViewGuest::GetNativeView() const {
307 if (!guest_)
308 return gfx::NativeView();
310 RenderWidgetHostView* rwhv = guest_->GetOwnerRenderWidgetHostView();
311 if (!rwhv)
312 return gfx::NativeView();
313 return rwhv->GetNativeView();
316 gfx::NativeViewId RenderWidgetHostViewGuest::GetNativeViewId() const {
317 if (!guest_)
318 return static_cast<gfx::NativeViewId>(NULL);
320 RenderWidgetHostView* rwhv = guest_->GetOwnerRenderWidgetHostView();
321 if (!rwhv)
322 return static_cast<gfx::NativeViewId>(NULL);
323 return rwhv->GetNativeViewId();
326 gfx::NativeViewAccessible RenderWidgetHostViewGuest::GetNativeViewAccessible() {
327 if (!guest_)
328 return gfx::NativeViewAccessible();
330 RenderWidgetHostView* rwhv = guest_->GetOwnerRenderWidgetHostView();
331 if (!rwhv)
332 return gfx::NativeViewAccessible();
333 return rwhv->GetNativeViewAccessible();
336 void RenderWidgetHostViewGuest::MovePluginWindows(
337 const std::vector<WebPluginGeometry>& moves) {
338 platform_view_->MovePluginWindows(moves);
341 void RenderWidgetHostViewGuest::UpdateCursor(const WebCursor& cursor) {
342 // InterstitialPages are not WebContents so we cannot intercept
343 // ViewHostMsg_SetCursor for interstitial pages in BrowserPluginGuest.
344 // All guest RenderViewHosts have RenderWidgetHostViewGuests however,
345 // and so we will always hit this code path.
346 if (!guest_)
347 return;
348 guest_->SendMessageToEmbedder(
349 new BrowserPluginMsg_SetCursor(guest_->browser_plugin_instance_id(),
350 cursor));
354 void RenderWidgetHostViewGuest::SetIsLoading(bool is_loading) {
355 platform_view_->SetIsLoading(is_loading);
358 void RenderWidgetHostViewGuest::TextInputStateChanged(
359 const ViewHostMsg_TextInputState_Params& params) {
360 if (!guest_)
361 return;
363 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView();
364 if (!rwhv)
365 return;
366 // Forward the information to embedding RWHV.
367 rwhv->TextInputStateChanged(params);
370 void RenderWidgetHostViewGuest::ImeCancelComposition() {
371 if (!guest_)
372 return;
374 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView();
375 if (!rwhv)
376 return;
377 // Forward the information to embedding RWHV.
378 rwhv->ImeCancelComposition();
381 #if defined(OS_MACOSX) || defined(USE_AURA)
382 void RenderWidgetHostViewGuest::ImeCompositionRangeChanged(
383 const gfx::Range& range,
384 const std::vector<gfx::Rect>& character_bounds) {
385 if (!guest_)
386 return;
388 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView();
389 if (!rwhv)
390 return;
391 std::vector<gfx::Rect> guest_character_bounds;
392 for (size_t i = 0; i < character_bounds.size(); ++i) {
393 guest_character_bounds.push_back(gfx::Rect(
394 guest_->GetScreenCoordinates(character_bounds[i].origin()),
395 character_bounds[i].size()));
397 // Forward the information to embedding RWHV.
398 rwhv->ImeCompositionRangeChanged(range, guest_character_bounds);
400 #endif
402 void RenderWidgetHostViewGuest::SelectionChanged(const base::string16& text,
403 size_t offset,
404 const gfx::Range& range) {
405 platform_view_->SelectionChanged(text, offset, range);
408 void RenderWidgetHostViewGuest::SelectionBoundsChanged(
409 const ViewHostMsg_SelectionBounds_Params& params) {
410 if (!guest_)
411 return;
413 RenderWidgetHostViewBase* rwhv = GetOwnerRenderWidgetHostView();
414 if (!rwhv)
415 return;
416 ViewHostMsg_SelectionBounds_Params guest_params(params);
417 guest_params.anchor_rect.set_origin(
418 guest_->GetScreenCoordinates(params.anchor_rect.origin()));
419 guest_params.focus_rect.set_origin(
420 guest_->GetScreenCoordinates(params.focus_rect.origin()));
421 rwhv->SelectionBoundsChanged(guest_params);
424 void RenderWidgetHostViewGuest::SetBackgroundColor(SkColor color) {
425 // Content embedders can toggle opaque backgrounds through this API.
426 // We plumb the value here so that BrowserPlugin updates its compositing
427 // state in response to this change. We also want to preserve this flag
428 // after recovering from a crash so we let BrowserPluginGuest store it.
429 if (!guest_)
430 return;
431 RenderWidgetHostViewBase::SetBackgroundColor(color);
432 bool opaque = GetBackgroundOpaque();
433 host_->SetBackgroundOpaque(opaque);
434 guest_->SetContentsOpaque(opaque);
437 bool RenderWidgetHostViewGuest::LockMouse() {
438 return platform_view_->LockMouse();
441 void RenderWidgetHostViewGuest::UnlockMouse() {
442 return platform_view_->UnlockMouse();
445 void RenderWidgetHostViewGuest::GetScreenInfo(blink::WebScreenInfo* results) {
446 if (!guest_)
447 return;
448 RenderWidgetHostViewBase* embedder_view = GetOwnerRenderWidgetHostView();
449 if (embedder_view)
450 embedder_view->GetScreenInfo(results);
453 #if defined(OS_MACOSX)
454 void RenderWidgetHostViewGuest::SetActive(bool active) {
455 platform_view_->SetActive(active);
458 void RenderWidgetHostViewGuest::SetWindowVisibility(bool visible) {
459 platform_view_->SetWindowVisibility(visible);
462 void RenderWidgetHostViewGuest::WindowFrameChanged() {
463 platform_view_->WindowFrameChanged();
466 void RenderWidgetHostViewGuest::ShowDefinitionForSelection() {
467 if (!guest_)
468 return;
470 gfx::Point origin;
471 gfx::Rect guest_bounds = GetViewBounds();
472 RenderWidgetHostView* rwhv = guest_->GetOwnerRenderWidgetHostView();
473 gfx::Rect embedder_bounds;
474 if (rwhv)
475 embedder_bounds = rwhv->GetViewBounds();
477 gfx::Vector2d guest_offset = gfx::Vector2d(
478 // Horizontal offset of guest from embedder.
479 guest_bounds.x() - embedder_bounds.x(),
480 // Vertical offset from guest's top to embedder's bottom edge.
481 embedder_bounds.bottom() - guest_bounds.y());
483 RenderWidgetHostViewMacDictionaryHelper helper(platform_view_.get());
484 helper.SetTargetView(rwhv);
485 helper.set_offset(guest_offset);
486 helper.ShowDefinitionForSelection();
489 bool RenderWidgetHostViewGuest::SupportsSpeech() const {
490 return platform_view_->SupportsSpeech();
493 void RenderWidgetHostViewGuest::SpeakSelection() {
494 platform_view_->SpeakSelection();
497 bool RenderWidgetHostViewGuest::IsSpeaking() const {
498 return platform_view_->IsSpeaking();
501 void RenderWidgetHostViewGuest::StopSpeaking() {
502 platform_view_->StopSpeaking();
505 bool RenderWidgetHostViewGuest::PostProcessEventForPluginIme(
506 const NativeWebKeyboardEvent& event) {
507 return false;
510 #endif // defined(OS_MACOSX)
512 #if defined(OS_ANDROID) || defined(USE_AURA)
513 void RenderWidgetHostViewGuest::ShowDisambiguationPopup(
514 const gfx::Rect& rect_pixels,
515 const SkBitmap& zoomed_bitmap) {
517 #endif // defined(OS_ANDROID) || defined(USE_AURA)
519 #if defined(OS_ANDROID)
520 void RenderWidgetHostViewGuest::LockCompositingSurface() {
523 void RenderWidgetHostViewGuest::UnlockCompositingSurface() {
525 #endif // defined(OS_ANDROID)
527 #if defined(OS_WIN)
528 void RenderWidgetHostViewGuest::SetParentNativeViewAccessible(
529 gfx::NativeViewAccessible accessible_parent) {
532 gfx::NativeViewId RenderWidgetHostViewGuest::GetParentForWindowlessPlugin()
533 const {
534 return NULL;
536 #endif
538 void RenderWidgetHostViewGuest::DestroyGuestView() {
539 host_->SetView(NULL);
540 host_ = NULL;
541 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
544 bool RenderWidgetHostViewGuest::CanDispatchToConsumer(
545 ui::GestureConsumer* consumer) {
546 CHECK_EQ(static_cast<RenderWidgetHostViewGuest*>(consumer), this);
547 return true;
550 void RenderWidgetHostViewGuest::DispatchGestureEvent(
551 ui::GestureEvent* event) {
552 ForwardGestureEventToRenderer(event);
555 void RenderWidgetHostViewGuest::DispatchCancelTouchEvent(
556 ui::TouchEvent* event) {
557 if (!host_)
558 return;
560 blink::WebTouchEvent cancel_event;
561 // TODO(rbyers): This event has no touches in it. Don't we need to know what
562 // touches are currently active in order to cancel them all properly?
563 WebTouchEventTraits::ResetType(blink::WebInputEvent::TouchCancel,
564 event->time_stamp().InSecondsF(),
565 &cancel_event);
567 host_->ForwardTouchEventWithLatencyInfo(cancel_event, *event->latency());
570 bool RenderWidgetHostViewGuest::ForwardGestureEventToRenderer(
571 ui::GestureEvent* gesture) {
572 #if defined(USE_AURA)
573 if (!host_)
574 return false;
576 if ((gesture->type() == ui::ET_GESTURE_PINCH_BEGIN ||
577 gesture->type() == ui::ET_GESTURE_PINCH_UPDATE ||
578 gesture->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) {
579 return true;
582 blink::WebGestureEvent web_gesture =
583 MakeWebGestureEventFromUIEvent(*gesture);
584 const gfx::Point& client_point = gesture->location();
585 const gfx::Point& screen_point = gesture->location();
587 web_gesture.x = client_point.x();
588 web_gesture.y = client_point.y();
589 web_gesture.globalX = screen_point.x();
590 web_gesture.globalY = screen_point.y();
592 if (web_gesture.type == blink::WebGestureEvent::Undefined)
593 return false;
594 if (web_gesture.type == blink::WebGestureEvent::GestureTapDown) {
595 host_->ForwardGestureEvent(
596 CreateFlingCancelEvent(gesture->time_stamp().InSecondsF()));
598 host_->ForwardGestureEvent(web_gesture);
599 return true;
600 #else
601 return false;
602 #endif
605 void RenderWidgetHostViewGuest::ProcessGestures(
606 ui::GestureRecognizer::Gestures* gestures) {
607 if ((gestures == NULL) || gestures->empty())
608 return;
609 for (ui::GestureRecognizer::Gestures::iterator g_it = gestures->begin();
610 g_it != gestures->end();
611 ++g_it) {
612 ForwardGestureEventToRenderer(*g_it);
616 RenderWidgetHostViewBase*
617 RenderWidgetHostViewGuest::GetOwnerRenderWidgetHostView() const {
618 return static_cast<RenderWidgetHostViewBase*>(
619 guest_->GetOwnerRenderWidgetHostView());
622 void RenderWidgetHostViewGuest::OnHandleInputEvent(
623 RenderWidgetHostImpl* embedder,
624 int browser_plugin_instance_id,
625 const gfx::Rect& guest_window_rect,
626 const blink::WebInputEvent* event) {
627 if (blink::WebInputEvent::isMouseEventType(event->type)) {
628 host_->ForwardMouseEvent(
629 *static_cast<const blink::WebMouseEvent*>(event));
630 return;
633 if (event->type == blink::WebInputEvent::MouseWheel) {
634 host_->ForwardWheelEvent(
635 *static_cast<const blink::WebMouseWheelEvent*>(event));
636 return;
639 if (blink::WebInputEvent::isKeyboardEventType(event->type)) {
640 if (!embedder->GetLastKeyboardEvent())
641 return;
642 NativeWebKeyboardEvent keyboard_event(*embedder->GetLastKeyboardEvent());
643 host_->ForwardKeyboardEvent(keyboard_event);
644 return;
647 if (blink::WebInputEvent::isTouchEventType(event->type)) {
648 if (event->type == blink::WebInputEvent::TouchStart &&
649 !embedder->GetView()->HasFocus()) {
650 embedder->GetView()->Focus();
653 host_->ForwardTouchEventWithLatencyInfo(
654 *static_cast<const blink::WebTouchEvent*>(event),
655 ui::LatencyInfo());
656 return;
659 if (blink::WebInputEvent::isGestureEventType(event->type)) {
660 host_->ForwardGestureEvent(
661 *static_cast<const blink::WebGestureEvent*>(event));
662 return;
666 } // namespace content