Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_guest.cc

Issue 100473010: Adding RenderWidgetHostViewChildFrame for OOPIF view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed broken unit test Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
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 "content/browser/browser_plugin/browser_plugin_guest.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h"
11 #include "content/browser/renderer_host/render_widget_host_view_guest.h"
12 #include "content/common/browser_plugin/browser_plugin_messages.h"
13 #include "content/common/gpu/gpu_messages.h"
14 #include "content/common/view_messages.h"
15 #include "content/common/webplugin_geometry.h"
16 #include "content/public/common/content_switches.h"
17 #include "skia/ext/platform_canvas.h"
18 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
19
20 #if defined(OS_MACOSX)
21 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h"
22 #endif
23
24 #if defined(OS_WIN) || defined(USE_AURA)
25 #include "content/browser/renderer_host/ui_events_helper.h"
26 #endif
27
28 namespace content {
29
30 namespace {
31
32 #if defined(OS_WIN) || defined(USE_AURA)
33 bool ShouldSendPinchGesture() {
34 static bool pinch_allowed =
35 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePinch);
36 return pinch_allowed;
37 }
38
39 blink::WebGestureEvent CreateFlingCancelEvent(double time_stamp) {
40 blink::WebGestureEvent gesture_event;
41 gesture_event.timeStampSeconds = time_stamp;
42 gesture_event.type = blink::WebGestureEvent::GestureFlingCancel;
43 gesture_event.sourceDevice = blink::WebGestureEvent::Touchscreen;
44 return gesture_event;
45 }
46 #endif // defined(OS_WIN) || defined(USE_AURA)
47
48 } // namespace
49
50 RenderWidgetHostViewGuest::RenderWidgetHostViewGuest(
51 RenderWidgetHost* widget_host,
52 BrowserPluginGuest* guest,
53 RenderWidgetHostView* platform_view)
54 : host_(RenderWidgetHostImpl::From(widget_host)),
55 guest_(guest),
56 platform_view_(static_cast<RenderWidgetHostViewPort*>(platform_view)) {
57 #if defined(OS_WIN) || defined(USE_AURA)
58 gesture_recognizer_.reset(ui::GestureRecognizer::Create());
59 gesture_recognizer_->AddGestureEventHelper(this);
60 #endif // defined(OS_WIN) || defined(USE_AURA)
61 host_->SetView(this);
62 }
63
64 RenderWidgetHostViewGuest::~RenderWidgetHostViewGuest() {
65 #if defined(OS_WIN) || defined(USE_AURA)
66 gesture_recognizer_->RemoveGestureEventHelper(this);
67 #endif // defined(OS_WIN) || defined(USE_AURA)
68 }
69
70 RenderWidgetHost* RenderWidgetHostViewGuest::GetRenderWidgetHost() const {
71 return host_;
72 }
73
74 void RenderWidgetHostViewGuest::WasShown() {
75 // If the WebContents associated with us showed an interstitial page in the
76 // beginning, the teardown path might call WasShown() while |host_| is in
77 // the process of destruction. Avoid calling WasShown below in this case.
78 // TODO(lazyboy): We shouldn't be showing interstitial pages in guests in the
79 // first place: http://crbug.com/273089.
80 //
81 // |guest_| is NULL during test.
82 if ((guest_ && guest_->is_in_destruction()) || !host_->is_hidden())
83 return;
84 host_->WasShown();
85 }
86
87 void RenderWidgetHostViewGuest::WasHidden() {
88 // |guest_| is NULL during test.
89 if ((guest_ && guest_->is_in_destruction()) || host_->is_hidden())
90 return;
91 host_->WasHidden();
92 }
93
94 void RenderWidgetHostViewGuest::SetSize(const gfx::Size& size) {
95 size_ = size;
96 host_->WasResized();
97 }
98
99 gfx::Rect RenderWidgetHostViewGuest::GetBoundsInRootWindow() {
100 // We do not have any root window specific parts in this view.
101 return GetViewBounds();
102 }
103
104 gfx::GLSurfaceHandle RenderWidgetHostViewGuest::GetCompositingSurface() {
105 return gfx::GLSurfaceHandle(gfx::kNullPluginWindow, gfx::TEXTURE_TRANSPORT);
106 }
107
108 #if defined(OS_WIN) || defined(USE_AURA)
109 void RenderWidgetHostViewGuest::ProcessAckedTouchEvent(
110 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
111 // TODO(fsamuel): Currently we will only take this codepath if the guest has
112 // requested touch events. A better solution is to always forward touchpresses
113 // to the embedder process to target a BrowserPlugin, and then route all
114 // subsequent touch points of that touchdown to the appropriate guest until
115 // that touch point is released.
116 ScopedVector<ui::TouchEvent> events;
117 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events, LOCAL_COORDINATES))
118 return;
119
120 ui::EventResult result = (ack_result ==
121 INPUT_EVENT_ACK_STATE_CONSUMED) ? ui::ER_HANDLED : ui::ER_UNHANDLED;
122 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(),
123 end = events.end(); iter != end; ++iter) {
124 scoped_ptr<ui::GestureRecognizer::Gestures> gestures;
125 gestures.reset(gesture_recognizer_->ProcessTouchEventForGesture(
126 *(*iter), result, this));
127 ProcessGestures(gestures.get());
128 }
129 }
130 #endif
131
132 void RenderWidgetHostViewGuest::Show() {
133 WasShown();
134 }
135
136 void RenderWidgetHostViewGuest::Hide() {
137 WasHidden();
138 }
139
140 bool RenderWidgetHostViewGuest::IsShowing() {
141 return !host_->is_hidden();
142 }
143
144 gfx::Rect RenderWidgetHostViewGuest::GetViewBounds() const {
145 RenderWidgetHostViewPort* rwhv = static_cast<RenderWidgetHostViewPort*>(
146 guest_->GetEmbedderRenderWidgetHostView());
147 gfx::Rect embedder_bounds;
148 if (rwhv)
149 embedder_bounds = rwhv->GetViewBounds();
150 gfx::Rect shifted_rect = guest_->ToGuestRect(embedder_bounds);
151 shifted_rect.set_width(size_.width());
152 shifted_rect.set_height(size_.height());
153 return shifted_rect;
154 }
155
156 void RenderWidgetHostViewGuest::RenderProcessGone(
157 base::TerminationStatus status,
158 int error_code) {
159 platform_view_->RenderProcessGone(status, error_code);
160 // Destroy the guest view instance only, so we don't end up calling
161 // platform_view_->Destroy().
162 DestroyGuestView();
163 }
164
165 void RenderWidgetHostViewGuest::Destroy() {
166 // The RenderWidgetHost's destruction led here, so don't call it.
167 DestroyGuestView();
168
169 platform_view_->Destroy();
170 }
171
172 void RenderWidgetHostViewGuest::SetTooltipText(
173 const base::string16& tooltip_text) {
174 platform_view_->SetTooltipText(tooltip_text);
175 }
176
177 void RenderWidgetHostViewGuest::AcceleratedSurfaceInitialized(int host_id,
178 int route_id) {
179 }
180
181 void RenderWidgetHostViewGuest::AcceleratedSurfaceBuffersSwapped(
182 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
183 int gpu_host_id) {
184 // If accelerated surface buffers are getting swapped then we're not using
185 // the software path.
186 guest_->clear_damage_buffer();
187 BrowserPluginMsg_BuffersSwapped_Params guest_params;
188 guest_params.size = params.size;
189 guest_params.mailbox_name = params.mailbox_name;
190 guest_params.route_id = params.route_id;
191 guest_params.host_id = gpu_host_id;
192 guest_->SendMessageToEmbedder(
193 new BrowserPluginMsg_BuffersSwapped(guest_->instance_id(), guest_params));
194 }
195
196 void RenderWidgetHostViewGuest::AcceleratedSurfacePostSubBuffer(
197 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
198 int gpu_host_id) {
199 NOTREACHED();
200 }
201
202 void RenderWidgetHostViewGuest::OnSwapCompositorFrame(
203 uint32 output_surface_id,
204 scoped_ptr<cc::CompositorFrame> frame) {
205 if (frame->software_frame_data) {
206 cc::SoftwareFrameData* frame_data = frame->software_frame_data.get();
207 #ifdef OS_WIN
208 base::SharedMemory shared_memory(frame_data->handle, true,
209 host_->GetProcess()->GetHandle());
210 #else
211 base::SharedMemory shared_memory(frame_data->handle, true);
212 #endif
213
214 RenderWidgetHostView* embedder_view =
215 guest_->GetEmbedderRenderWidgetHostView();
216 base::ProcessHandle embedder_pid =
217 embedder_view->GetRenderWidgetHost()->GetProcess()->GetHandle();
218
219 shared_memory.GiveToProcess(embedder_pid, &frame_data->handle);
220 }
221
222 guest_->clear_damage_buffer();
223 guest_->SendMessageToEmbedder(
224 new BrowserPluginMsg_CompositorFrameSwapped(
225 guest_->instance_id(),
226 *frame,
227 host_->GetRoutingID(),
228 output_surface_id,
229 host_->GetProcess()->GetID()));
230 }
231
232 void RenderWidgetHostViewGuest::SetBounds(const gfx::Rect& rect) {
233 SetSize(rect.size());
234 }
235
236 bool RenderWidgetHostViewGuest::OnMessageReceived(const IPC::Message& msg) {
237 return platform_view_->OnMessageReceived(msg);
238 }
239
240 void RenderWidgetHostViewGuest::InitAsChild(
241 gfx::NativeView parent_view) {
242 platform_view_->InitAsChild(parent_view);
243 }
244
245 void RenderWidgetHostViewGuest::InitAsPopup(
246 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) {
247 // This should never get called.
248 NOTREACHED();
249 }
250
251 void RenderWidgetHostViewGuest::InitAsFullscreen(
252 RenderWidgetHostView* reference_host_view) {
253 // This should never get called.
254 NOTREACHED();
255 }
256
257 gfx::NativeView RenderWidgetHostViewGuest::GetNativeView() const {
258 return guest_->GetEmbedderRenderWidgetHostView()->GetNativeView();
259 }
260
261 gfx::NativeViewId RenderWidgetHostViewGuest::GetNativeViewId() const {
262 if (guest_->GetEmbedderRenderWidgetHostView())
263 return guest_->GetEmbedderRenderWidgetHostView()->GetNativeViewId();
264 return static_cast<gfx::NativeViewId>(NULL);
265 }
266
267 gfx::NativeViewAccessible RenderWidgetHostViewGuest::GetNativeViewAccessible() {
268 return guest_->GetEmbedderRenderWidgetHostView()->GetNativeViewAccessible();
269 }
270
271 void RenderWidgetHostViewGuest::MovePluginWindows(
272 const gfx::Vector2d& scroll_offset,
273 const std::vector<WebPluginGeometry>& moves) {
274 platform_view_->MovePluginWindows(scroll_offset, moves);
275 }
276
277 void RenderWidgetHostViewGuest::Focus() {
278 }
279
280 void RenderWidgetHostViewGuest::Blur() {
281 }
282
283 bool RenderWidgetHostViewGuest::HasFocus() const {
284 return false;
285 }
286
287 bool RenderWidgetHostViewGuest::IsSurfaceAvailableForCopy() const {
288 NOTIMPLEMENTED();
289 return false;
290 }
291
292 void RenderWidgetHostViewGuest::UpdateCursor(const WebCursor& cursor) {
293 platform_view_->UpdateCursor(cursor);
294 }
295
296 void RenderWidgetHostViewGuest::SetIsLoading(bool is_loading) {
297 platform_view_->SetIsLoading(is_loading);
298 }
299
300 void RenderWidgetHostViewGuest::TextInputTypeChanged(
301 ui::TextInputType type,
302 ui::TextInputMode input_mode,
303 bool can_compose_inline) {
304 RenderWidgetHostViewPort::FromRWHV(
305 guest_->GetEmbedderRenderWidgetHostView())->
306 TextInputTypeChanged(type, input_mode, can_compose_inline);
307 }
308
309 void RenderWidgetHostViewGuest::ImeCancelComposition() {
310 platform_view_->ImeCancelComposition();
311 }
312
313 #if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
314 void RenderWidgetHostViewGuest::ImeCompositionRangeChanged(
315 const gfx::Range& range,
316 const std::vector<gfx::Rect>& character_bounds) {
317 }
318 #endif
319
320 void RenderWidgetHostViewGuest::DidUpdateBackingStore(
321 const gfx::Rect& scroll_rect,
322 const gfx::Vector2d& scroll_delta,
323 const std::vector<gfx::Rect>& copy_rects,
324 const ui::LatencyInfo& latency_info) {
325 NOTREACHED();
326 }
327
328 void RenderWidgetHostViewGuest::SelectionChanged(const base::string16& text,
329 size_t offset,
330 const gfx::Range& range) {
331 platform_view_->SelectionChanged(text, offset, range);
332 }
333
334 void RenderWidgetHostViewGuest::SelectionBoundsChanged(
335 const ViewHostMsg_SelectionBounds_Params& params) {
336 platform_view_->SelectionBoundsChanged(params);
337 }
338
339 void RenderWidgetHostViewGuest::ScrollOffsetChanged() {
340 }
341
342 BackingStore* RenderWidgetHostViewGuest::AllocBackingStore(
343 const gfx::Size& size) {
344 NOTREACHED();
345 return NULL;
346 }
347
348 void RenderWidgetHostViewGuest::CopyFromCompositingSurface(
349 const gfx::Rect& src_subrect,
350 const gfx::Size& /* dst_size */,
351 const base::Callback<void(bool, const SkBitmap&)>& callback) {
352 callback.Run(false, SkBitmap());
353 }
354
355 void RenderWidgetHostViewGuest::CopyFromCompositingSurfaceToVideoFrame(
356 const gfx::Rect& src_subrect,
357 const scoped_refptr<media::VideoFrame>& target,
358 const base::Callback<void(bool)>& callback) {
359 NOTIMPLEMENTED();
360 callback.Run(false);
361 }
362
363 bool RenderWidgetHostViewGuest::CanCopyToVideoFrame() const {
364 return false;
365 }
366
367 void RenderWidgetHostViewGuest::AcceleratedSurfaceSuspend() {
368 NOTREACHED();
369 }
370
371 void RenderWidgetHostViewGuest::AcceleratedSurfaceRelease() {
372 }
373
374 bool RenderWidgetHostViewGuest::HasAcceleratedSurface(
375 const gfx::Size& desired_size) {
376 return false;
377 }
378
379 void RenderWidgetHostViewGuest::SetBackground(const SkBitmap& background) {
380 platform_view_->SetBackground(background);
381 }
382
383 #if defined(OS_WIN) && !defined(USE_AURA)
384 void RenderWidgetHostViewGuest::SetClickthroughRegion(SkRegion* region) {
385 }
386 #endif
387
388 void RenderWidgetHostViewGuest::SetHasHorizontalScrollbar(
389 bool has_horizontal_scrollbar) {
390 platform_view_->SetHasHorizontalScrollbar(has_horizontal_scrollbar);
391 }
392
393 void RenderWidgetHostViewGuest::SetScrollOffsetPinning(
394 bool is_pinned_to_left, bool is_pinned_to_right) {
395 platform_view_->SetScrollOffsetPinning(
396 is_pinned_to_left, is_pinned_to_right);
397 }
398
399 void RenderWidgetHostViewGuest::OnAcceleratedCompositingStateChange() {
400 }
401
402 bool RenderWidgetHostViewGuest::LockMouse() {
403 return platform_view_->LockMouse();
404 }
405
406 void RenderWidgetHostViewGuest::UnlockMouse() {
407 return platform_view_->UnlockMouse();
408 }
409
410 void RenderWidgetHostViewGuest::GetScreenInfo(blink::WebScreenInfo* results) {
411 RenderWidgetHostViewPort* embedder_view =
412 RenderWidgetHostViewPort::FromRWHV(
413 guest_->GetEmbedderRenderWidgetHostView());
414 if (embedder_view)
415 embedder_view->GetScreenInfo(results);
416 }
417
418 void RenderWidgetHostViewGuest::OnAccessibilityEvents(
419 const std::vector<AccessibilityHostMsg_EventParams>& params) {
420 }
421
422 #if defined(OS_MACOSX)
423 void RenderWidgetHostViewGuest::SetActive(bool active) {
424 platform_view_->SetActive(active);
425 }
426
427 void RenderWidgetHostViewGuest::SetTakesFocusOnlyOnMouseDown(bool flag) {
428 platform_view_->SetTakesFocusOnlyOnMouseDown(flag);
429 }
430
431 void RenderWidgetHostViewGuest::SetWindowVisibility(bool visible) {
432 platform_view_->SetWindowVisibility(visible);
433 }
434
435 void RenderWidgetHostViewGuest::WindowFrameChanged() {
436 platform_view_->WindowFrameChanged();
437 }
438
439 void RenderWidgetHostViewGuest::ShowDefinitionForSelection() {
440 gfx::Point origin;
441 gfx::Rect guest_bounds = GetViewBounds();
442 gfx::Rect embedder_bounds =
443 guest_->GetEmbedderRenderWidgetHostView()->GetViewBounds();
444
445 gfx::Vector2d guest_offset = gfx::Vector2d(
446 // Horizontal offset of guest from embedder.
447 guest_bounds.x() - embedder_bounds.x(),
448 // Vertical offset from guest's top to embedder's bottom edge.
449 embedder_bounds.bottom() - guest_bounds.y());
450
451 RenderWidgetHostViewMacDictionaryHelper helper(platform_view_);
452 helper.SetTargetView(guest_->GetEmbedderRenderWidgetHostView());
453 helper.set_offset(guest_offset);
454 helper.ShowDefinitionForSelection();
455 }
456
457 bool RenderWidgetHostViewGuest::SupportsSpeech() const {
458 return platform_view_->SupportsSpeech();
459 }
460
461 void RenderWidgetHostViewGuest::SpeakSelection() {
462 platform_view_->SpeakSelection();
463 }
464
465 bool RenderWidgetHostViewGuest::IsSpeaking() const {
466 return platform_view_->IsSpeaking();
467 }
468
469 void RenderWidgetHostViewGuest::StopSpeaking() {
470 platform_view_->StopSpeaking();
471 }
472
473 void RenderWidgetHostViewGuest::AboutToWaitForBackingStoreMsg() {
474 NOTREACHED();
475 }
476
477 bool RenderWidgetHostViewGuest::PostProcessEventForPluginIme(
478 const NativeWebKeyboardEvent& event) {
479 return false;
480 }
481
482 #endif // defined(OS_MACOSX)
483
484 #if defined(OS_ANDROID)
485 void RenderWidgetHostViewGuest::ShowDisambiguationPopup(
486 const gfx::Rect& target_rect,
487 const SkBitmap& zoomed_bitmap) {
488 }
489
490 void RenderWidgetHostViewGuest::HasTouchEventHandlers(bool need_touch_events) {
491 }
492 #endif // defined(OS_ANDROID)
493
494 #if defined(TOOLKIT_GTK)
495 GdkEventButton* RenderWidgetHostViewGuest::GetLastMouseDown() {
496 return NULL;
497 }
498
499 gfx::NativeView RenderWidgetHostViewGuest::BuildInputMethodsGtkMenu() {
500 return platform_view_->BuildInputMethodsGtkMenu();
501 }
502 #endif // defined(TOOLKIT_GTK)
503
504 #if defined(OS_WIN) && !defined(USE_AURA)
505 void RenderWidgetHostViewGuest::WillWmDestroy() {
506 }
507 #endif
508
509 #if defined(OS_WIN) && defined(USE_AURA)
510 void RenderWidgetHostViewGuest::SetParentNativeViewAccessible(
511 gfx::NativeViewAccessible accessible_parent) {
512 }
513
514 gfx::NativeViewId RenderWidgetHostViewGuest::GetParentForWindowlessPlugin()
515 const {
516 return NULL;
517 }
518 #endif
519
520 void RenderWidgetHostViewGuest::DestroyGuestView() {
521 host_->SetView(NULL);
522 host_ = NULL;
523 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
524 }
525
526 bool RenderWidgetHostViewGuest::CanDispatchToConsumer(
527 ui::GestureConsumer* consumer) {
528 CHECK_EQ(static_cast<RenderWidgetHostViewGuest*>(consumer), this);
529 return true;
530 }
531
532 void RenderWidgetHostViewGuest::DispatchPostponedGestureEvent(
533 ui::GestureEvent* event) {
534 ForwardGestureEventToRenderer(event);
535 }
536
537 void RenderWidgetHostViewGuest::DispatchCancelTouchEvent(
538 ui::TouchEvent* event) {
539 if (!host_)
540 return;
541
542 blink::WebTouchEvent cancel_event;
543 cancel_event.type = blink::WebInputEvent::TouchCancel;
544 cancel_event.timeStampSeconds = event->time_stamp().InSecondsF();
545 host_->ForwardTouchEventWithLatencyInfo(cancel_event, *event->latency());
546 }
547
548 bool RenderWidgetHostViewGuest::ForwardGestureEventToRenderer(
549 ui::GestureEvent* gesture) {
550 #if defined(OS_WIN) || defined(USE_AURA)
551 if (!host_)
552 return false;
553
554 // Pinch gestures are disabled by default on windows desktop. See
555 // crbug.com/128477 and crbug.com/148816
556 if ((gesture->type() == ui::ET_GESTURE_PINCH_BEGIN ||
557 gesture->type() == ui::ET_GESTURE_PINCH_UPDATE ||
558 gesture->type() == ui::ET_GESTURE_PINCH_END) &&
559 !ShouldSendPinchGesture()) {
560 return true;
561 }
562
563 blink::WebGestureEvent web_gesture =
564 MakeWebGestureEventFromUIEvent(*gesture);
565 const gfx::Point& client_point = gesture->location();
566 const gfx::Point& screen_point = gesture->location();
567
568 web_gesture.x = client_point.x();
569 web_gesture.y = client_point.y();
570 web_gesture.globalX = screen_point.x();
571 web_gesture.globalY = screen_point.y();
572
573 if (web_gesture.type == blink::WebGestureEvent::Undefined)
574 return false;
575 if (web_gesture.type == blink::WebGestureEvent::GestureTapDown) {
576 host_->ForwardGestureEvent(
577 CreateFlingCancelEvent(gesture->time_stamp().InSecondsF()));
578 }
579 host_->ForwardGestureEvent(web_gesture);
580 return true;
581 #else
582 return false;
583 #endif
584 }
585
586 void RenderWidgetHostViewGuest::ProcessGestures(
587 ui::GestureRecognizer::Gestures* gestures) {
588 if ((gestures == NULL) || gestures->empty())
589 return;
590 for (ui::GestureRecognizer::Gestures::iterator g_it = gestures->begin();
591 g_it != gestures->end();
592 ++g_it) {
593 ForwardGestureEventToRenderer(*g_it);
594 }
595 }
596
597
598 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698