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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 11606005: Browser Plugin: Simplify BrowserPluginGuestHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 8 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
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/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "content/browser/browser_plugin/browser_plugin_embedder.h" 10 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
11 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" 11 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h"
12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 12 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h" 13 #include "content/browser/renderer_host/render_view_host_impl.h"
14 #include "content/browser/renderer_host/render_widget_host_impl.h" 14 #include "content/browser/renderer_host/render_widget_host_impl.h"
15 #include "content/browser/web_contents/web_contents_impl.h" 15 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/common/browser_plugin_messages.h" 16 #include "content/common/browser_plugin_messages.h"
17 #include "content/common/content_constants_internal.h" 17 #include "content/common/content_constants_internal.h"
18 #include "content/common/drag_messages.h"
18 #include "content/common/view_messages.h" 19 #include "content/common/view_messages.h"
19 #include "content/port/browser/render_view_host_delegate_view.h" 20 #include "content/port/browser/render_view_host_delegate_view.h"
20 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
23 #include "content/public/browser/render_widget_host_view.h" 24 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/resource_request_details.h" 25 #include "content/public/browser/resource_request_details.h"
25 #include "content/public/browser/user_metrics.h" 26 #include "content/public/browser/user_metrics.h"
26 #include "content/public/browser/web_contents_view.h" 27 #include "content/public/browser/web_contents_view.h"
27 #include "content/public/common/result_codes.h" 28 #include "content/public/common/result_codes.h"
(...skipping 18 matching lines...) Expand all
46 WebContentsImpl* web_contents, 47 WebContentsImpl* web_contents,
47 const BrowserPluginHostMsg_CreateGuest_Params& params) 48 const BrowserPluginHostMsg_CreateGuest_Params& params)
48 : WebContentsObserver(web_contents), 49 : WebContentsObserver(web_contents),
49 embedder_web_contents_(NULL), 50 embedder_web_contents_(NULL),
50 instance_id_(instance_id), 51 instance_id_(instance_id),
51 #if defined(OS_WIN) 52 #if defined(OS_WIN)
52 damage_buffer_size_(0), 53 damage_buffer_size_(0),
53 remote_damage_buffer_handle_(0), 54 remote_damage_buffer_handle_(0),
54 #endif 55 #endif
55 damage_buffer_scale_factor_(1.0f), 56 damage_buffer_scale_factor_(1.0f),
56 pending_update_counter_(0),
57 guest_hang_timeout_( 57 guest_hang_timeout_(
58 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), 58 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)),
59 focused_(params.focused), 59 focused_(params.focused),
60 visible_(params.visible), 60 visible_(params.visible),
61 auto_size_enabled_(params.auto_size_params.enable), 61 auto_size_enabled_(params.auto_size_params.enable),
62 max_auto_size_(params.auto_size_params.max_size), 62 max_auto_size_(params.auto_size_params.max_size),
63 min_auto_size_(params.auto_size_params.min_size) { 63 min_auto_size_(params.auto_size_params.min_size) {
64 DCHECK(web_contents); 64 DCHECK(web_contents);
65 } 65 }
66 66
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 resource_redirect_details->new_url, 105 resource_redirect_details->new_url,
106 is_top_level); 106 is_top_level);
107 break; 107 break;
108 } 108 }
109 default: 109 default:
110 NOTREACHED() << "Unexpected notification sent."; 110 NOTREACHED() << "Unexpected notification sent.";
111 break; 111 break;
112 } 112 }
113 } 113 }
114 114
115 bool BrowserPluginGuest::ViewTakeFocus(bool reverse) {
116 SendMessageToEmbedder(
117 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(),
118 instance_id(),
119 reverse));
120 return true;
121 }
122
123 void BrowserPluginGuest::Go(int relative_index) { 115 void BrowserPluginGuest::Go(int relative_index) {
124 web_contents()->GetController().GoToOffset(relative_index); 116 web_contents()->GetController().GoToOffset(relative_index);
125 } 117 }
126 118
127 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host, 119 bool BrowserPluginGuest::CanDownload(RenderViewHost* render_view_host,
128 int request_id, 120 int request_id,
129 const std::string& request_method) { 121 const std::string& request_method) {
130 // TODO(fsamuel): We disable downloads in guests for now, but we will later 122 // TODO(fsamuel): We disable downloads in guests for now, but we will later
131 // expose API to allow embedders to handle them. 123 // expose API to allow embedders to handle them.
132 // Note: it seems content_shell ignores this. This should be fixed 124 // Note: it seems content_shell ignores this. This should be fixed
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 const FileChooserParams& params) { 158 const FileChooserParams& params) {
167 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); 159 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params);
168 } 160 }
169 161
170 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { 162 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() {
171 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will 163 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will
172 // manage the focus ourselves. 164 // manage the focus ourselves.
173 return false; 165 return false;
174 } 166 }
175 167
176 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) {
177 SendMessageToEmbedder(
178 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(),
179 instance_id(),
180 accept));
181 }
182
183 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { 168 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) {
184 visible_ = visible; 169 visible_ = visible;
185 if (embedder_visible && visible) 170 if (embedder_visible && visible)
186 web_contents()->WasShown(); 171 web_contents()->WasShown();
187 else 172 else
188 web_contents()->WasHidden(); 173 web_contents()->WasHidden();
189 } 174 }
190 175
191 void BrowserPluginGuest::DragStatusUpdate(WebKit::WebDragStatus drag_status, 176 void BrowserPluginGuest::DragStatusUpdate(WebKit::WebDragStatus drag_status,
192 const WebDropData& drop_data, 177 const WebDropData& drop_data,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 web_contents()->GetRenderViewHost()->Send(new ViewMsg_Repaint( 220 web_contents()->GetRenderViewHost()->Send(new ViewMsg_Repaint(
236 web_contents()->GetRenderViewHost()->GetRoutingID(), 221 web_contents()->GetRenderViewHost()->GetRoutingID(),
237 max_auto_size_)); 222 max_auto_size_));
238 } else if (!auto_size_enabled_ && old_auto_size_enabled) { 223 } else if (!auto_size_enabled_ && old_auto_size_enabled) {
239 web_contents()->GetRenderViewHost()->DisableAutoResize( 224 web_contents()->GetRenderViewHost()->DisableAutoResize(
240 resize_guest_params.view_size); 225 resize_guest_params.view_size);
241 } 226 }
242 Resize(embedder_web_contents_->GetRenderViewHost(), resize_guest_params); 227 Resize(embedder_web_contents_->GetRenderViewHost(), resize_guest_params);
243 } 228 }
244 229
245 void BrowserPluginGuest::UpdateDragCursor(WebKit::WebDragOperation operation) {
246 RenderViewHostImpl* embedder_render_view_host =
247 static_cast<RenderViewHostImpl*>(
248 embedder_web_contents_->GetRenderViewHost());
249 CHECK(embedder_render_view_host);
250 RenderViewHostDelegateView* view =
251 embedder_render_view_host->GetDelegate()->GetDelegateView();
252 if (view)
253 view->UpdateDragCursor(operation);
254 }
255
256 WebContents* BrowserPluginGuest::GetWebContents() { 230 WebContents* BrowserPluginGuest::GetWebContents() {
257 return web_contents(); 231 return web_contents();
258 } 232 }
259 233
260 void BrowserPluginGuest::Terminate() { 234 void BrowserPluginGuest::Terminate() {
261 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Terminate")); 235 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Terminate"));
262 base::ProcessHandle process_handle = 236 base::ProcessHandle process_handle =
263 web_contents()->GetRenderProcessHost()->GetHandle(); 237 web_contents()->GetRenderProcessHost()->GetHandle();
264 base::KillProcess(process_handle, RESULT_CODE_KILLED, false); 238 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
265 } 239 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 321
348 int BrowserPluginGuest::embedder_routing_id() const { 322 int BrowserPluginGuest::embedder_routing_id() const {
349 return embedder_web_contents_->GetRoutingID(); 323 return embedder_web_contents_->GetRoutingID();
350 } 324 }
351 325
352 bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const { 326 bool BrowserPluginGuest::InAutoSizeBounds(const gfx::Size& size) const {
353 return size.width() <= max_auto_size_.width() && 327 return size.width() <= max_auto_size_.width() &&
354 size.height() <= max_auto_size_.height(); 328 size.height() <= max_auto_size_.height();
355 } 329 }
356 330
357 void BrowserPluginGuest::UpdateRect(
358 RenderViewHost* render_view_host,
359 const ViewHostMsg_UpdateRect_Params& params) {
360 BrowserPluginMsg_UpdateRect_Params relay_params;
361 relay_params.view_size = params.view_size;
362 relay_params.scale_factor = params.scale_factor;
363 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
364 params.flags);
365
366 // HW accelerated case, acknowledge resize only
367 if (!params.needs_ack) {
368 #if defined(OS_MACOSX)
369 relay_params.damage_buffer_identifier = 0;
370 #else
371 relay_params.damage_buffer_identifier = TransportDIB::DefaultHandleValue();
372 #endif
373 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(
374 embedder_routing_id(),
375 instance_id(),
376 0,
377 relay_params));
378 return;
379 }
380
381 // Only copy damage if the guest is in autosize mode and the guest's view size
382 // is less than the maximum size or the guest's view size is equal to the
383 // damage buffer's size and the guest's scale factor is equal to the damage
384 // buffer's scale factor.
385 // The scaling change can happen due to asynchronous updates of the DPI on a
386 // resolution change.
387 if (((auto_size_enabled_ && InAutoSizeBounds(params.view_size)) ||
388 (params.view_size.width() == damage_view_size().width() &&
389 params.view_size.height() == damage_view_size().height())) &&
390 params.scale_factor == damage_buffer_scale_factor()) {
391 TransportDIB* dib = render_view_host->GetProcess()->
392 GetTransportDIB(params.bitmap);
393 if (dib) {
394 #if defined(OS_WIN)
395 size_t guest_damage_buffer_size = params.bitmap_rect.width() *
396 params.bitmap_rect.height() * 4;
397 size_t embedder_damage_buffer_size = damage_buffer_size_;
398 #else
399 size_t guest_damage_buffer_size = dib->size();
400 size_t embedder_damage_buffer_size = damage_buffer_->size();
401 #endif
402 void* guest_memory = dib->memory();
403 void* embedder_memory = damage_buffer_->memory();
404 size_t size = std::min(guest_damage_buffer_size,
405 embedder_damage_buffer_size);
406 memcpy(embedder_memory, guest_memory, size);
407 }
408 }
409 #if defined(OS_MACOSX)
410 relay_params.damage_buffer_identifier = damage_buffer_->id();
411 #elif defined(OS_WIN)
412 // On Windows, the handle used locally differs from the handle received from
413 // the embedder process, since we duplicate the remote handle.
414 relay_params.damage_buffer_identifier = remote_damage_buffer_handle_;
415 #else
416 relay_params.damage_buffer_identifier = damage_buffer_->handle();
417 #endif
418 relay_params.bitmap_rect = params.bitmap_rect;
419 relay_params.scroll_delta = params.scroll_delta;
420 relay_params.scroll_rect = params.scroll_rect;
421 relay_params.copy_rects = params.copy_rects;
422
423 // We need to send the ACK to the same render_view_host that issued
424 // the UpdateRect. We keep track of this correspondence via a message_id.
425 int message_id = pending_update_counter_++;
426 pending_updates_.AddWithID(render_view_host, message_id);
427
428 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(),
429 instance_id(),
430 message_id,
431 relay_params));
432 }
433
434 void BrowserPluginGuest::UpdateRectACK( 331 void BrowserPluginGuest::UpdateRectACK(
435 int message_id,
436 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, 332 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
437 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { 333 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
438 RenderViewHost* render_view_host = pending_updates_.Lookup(message_id); 334 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost();
439 // If the guest has crashed since it sent the initial ViewHostMsg_UpdateRect 335 render_view_host->Send(
440 // then the pending_updates_ map will have been cleared. 336 new ViewMsg_UpdateRect_ACK(render_view_host->GetRoutingID()));
441 if (render_view_host) {
442 pending_updates_.Remove(message_id);
443 render_view_host->Send(
444 new ViewMsg_UpdateRect_ACK(render_view_host->GetRoutingID()));
445 }
446 SetSize(auto_size_params, resize_guest_params); 337 SetSize(auto_size_params, resize_guest_params);
447 } 338 }
448 339
449 void BrowserPluginGuest::HandleInputEvent(RenderViewHost* render_view_host, 340 void BrowserPluginGuest::HandleInputEvent(RenderViewHost* render_view_host,
450 const gfx::Rect& guest_window_rect, 341 const gfx::Rect& guest_window_rect,
451 const gfx::Rect& guest_screen_rect, 342 const gfx::Rect& guest_screen_rect,
452 const WebKit::WebInputEvent& event) { 343 const WebKit::WebInputEvent& event) {
453 guest_window_rect_ = guest_window_rect; 344 guest_window_rect_ = guest_window_rect;
454 guest_screen_rect_ = guest_screen_rect; 345 guest_screen_rect_ = guest_screen_rect;
455 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 346 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
456 web_contents()->GetRenderViewHost()); 347 web_contents()->GetRenderViewHost());
457 348
458 IPC::Message* message = NULL; 349 IPC::Message* message = NULL;
459 350
460 // TODO(fsamuel): What should we do for keyboard_shortcut field? 351 // TODO(fsamuel): What should we do for keyboard_shortcut field?
461 if (event.type == WebKit::WebInputEvent::KeyDown) { 352 if (event.type == WebKit::WebInputEvent::KeyDown) {
462 CHECK_EQ(sizeof(WebKit::WebKeyboardEvent), event.size); 353 CHECK_EQ(sizeof(WebKit::WebKeyboardEvent), event.size);
463 WebKit::WebKeyboardEvent key_event; 354 WebKit::WebKeyboardEvent key_event;
464 memcpy(&key_event, &event, event.size); 355 memcpy(&key_event, &event, event.size);
465 key_event.type = WebKit::WebInputEvent::RawKeyDown; 356 key_event.type = WebKit::WebInputEvent::RawKeyDown;
466 message = new ViewMsg_HandleInputEvent(routing_id(), &key_event, false); 357 message = new ViewMsg_HandleInputEvent(routing_id(), &key_event, false);
467 } else { 358 } else {
468 message = new ViewMsg_HandleInputEvent(routing_id(), &event, false); 359 message = new ViewMsg_HandleInputEvent(routing_id(), &event, false);
469 } 360 }
470 361
471 guest_rvh->Send(message); 362 guest_rvh->Send(message);
472 guest_rvh->StartHangMonitorTimeout(guest_hang_timeout_); 363 guest_rvh->StartHangMonitorTimeout(guest_hang_timeout_);
473 } 364 }
474 365
475 void BrowserPluginGuest::HandleInputEventAck(RenderViewHost* render_view_host,
476 bool handled) {
477 RenderViewHostImpl* guest_rvh =
478 static_cast<RenderViewHostImpl*>(render_view_host);
479 guest_rvh->StopHangMonitorTimeout();
480 }
481
482 void BrowserPluginGuest::Stop() { 366 void BrowserPluginGuest::Stop() {
483 web_contents()->Stop(); 367 web_contents()->Stop();
484 } 368 }
485 369
486 void BrowserPluginGuest::Reload() { 370 void BrowserPluginGuest::Reload() {
487 // TODO(fsamuel): Don't check for repost because we don't want to show 371 // TODO(fsamuel): Don't check for repost because we don't want to show
488 // Chromium's repost warning. We might want to implement a separate API 372 // Chromium's repost warning. We might want to implement a separate API
489 // for registering a callback if a repost is about to happen. 373 // for registering a callback if a repost is about to happen.
490 web_contents()->GetController().Reload(false); 374 web_contents()->GetController().Reload(false);
491 } 375 }
492 376
493 void BrowserPluginGuest::SetFocus(bool focused) { 377 void BrowserPluginGuest::SetFocus(bool focused) {
494 if (focused_ == focused) 378 if (focused_ == focused)
495 return; 379 return;
496 focused_ = focused; 380 focused_ = focused;
497 Send(new ViewMsg_SetFocus(routing_id(), focused)); 381 Send(new ViewMsg_SetFocus(routing_id(), focused));
498 } 382 }
499 383
500 void BrowserPluginGuest::ShowWidget(RenderViewHost* render_view_host,
501 int route_id,
502 const gfx::Rect& initial_pos) {
503 gfx::Rect screen_pos(initial_pos);
504 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin());
505 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id,
506 screen_pos);
507 }
508
509 #if defined(OS_MACOSX)
510 void BrowserPluginGuest::ShowPopup(RenderViewHost* render_view_host,
511 const ViewHostMsg_ShowPopup_Params& params) {
512 gfx::Rect translated_bounds(params.bounds);
513 translated_bounds.Offset(guest_window_rect_.OffsetFromOrigin());
514 BrowserPluginPopupMenuHelper popup_menu_helper(
515 embedder_web_contents_->GetRenderViewHost(), render_view_host);
516 popup_menu_helper.ShowPopupMenu(translated_bounds,
517 params.item_height,
518 params.item_font_size,
519 params.selected_item,
520 params.popup_items,
521 params.right_aligned,
522 params.allow_multiple_selection);
523 }
524 #endif
525
526 void BrowserPluginGuest::SetCursor(const WebCursor& cursor) {
527 SendMessageToEmbedder(new BrowserPluginMsg_SetCursor(embedder_routing_id(),
528 instance_id(),
529 cursor));
530 }
531
532 void BrowserPluginGuest::DidStartProvisionalLoadForFrame( 384 void BrowserPluginGuest::DidStartProvisionalLoadForFrame(
533 int64 frame_id, 385 int64 frame_id,
534 int64 parent_frame_id, 386 int64 parent_frame_id,
535 bool is_main_frame, 387 bool is_main_frame,
536 const GURL& validated_url, 388 const GURL& validated_url,
537 bool is_error_page, 389 bool is_error_page,
538 RenderViewHost* render_view_host) { 390 RenderViewHost* render_view_host) {
539 // Inform the embedder of the loadStart. 391 // Inform the embedder of the loadStart.
540 SendMessageToEmbedder( 392 SendMessageToEmbedder(
541 new BrowserPluginMsg_LoadStart(embedder_routing_id(), 393 new BrowserPluginMsg_LoadStart(embedder_routing_id(),
(...skipping 14 matching lines...) Expand all
556 RemoveChars(net::ErrorToString(error_code), "net::", &error_type); 408 RemoveChars(net::ErrorToString(error_code), "net::", &error_type);
557 // Inform the embedder of the loadAbort. 409 // Inform the embedder of the loadAbort.
558 SendMessageToEmbedder( 410 SendMessageToEmbedder(
559 new BrowserPluginMsg_LoadAbort(embedder_routing_id(), 411 new BrowserPluginMsg_LoadAbort(embedder_routing_id(),
560 instance_id(), 412 instance_id(),
561 validated_url, 413 validated_url,
562 is_main_frame, 414 is_main_frame,
563 error_type)); 415 error_type));
564 } 416 }
565 417
418 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
419 embedder_web_contents_->Send(msg);
420 }
421
566 void BrowserPluginGuest::LoadRedirect( 422 void BrowserPluginGuest::LoadRedirect(
567 const GURL& old_url, 423 const GURL& old_url,
568 const GURL& new_url, 424 const GURL& new_url,
569 bool is_top_level) { 425 bool is_top_level) {
570 SendMessageToEmbedder( 426 SendMessageToEmbedder(
571 new BrowserPluginMsg_LoadRedirect(embedder_routing_id(), 427 new BrowserPluginMsg_LoadRedirect(embedder_routing_id(),
572 instance_id(), 428 instance_id(),
573 old_url, 429 old_url,
574 new_url, 430 new_url,
575 is_top_level)); 431 is_top_level));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); 472 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_);
617 } 473 }
618 } 474 }
619 475
620 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { 476 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) {
621 int process_id = web_contents()->GetRenderProcessHost()->GetID(); 477 int process_id = web_contents()->GetRenderProcessHost()->GetID();
622 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(), 478 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(),
623 instance_id(), 479 instance_id(),
624 process_id, 480 process_id,
625 status)); 481 status));
626 IDMap<RenderViewHost>::const_iterator iter(&pending_updates_);
627 while (!iter.IsAtEnd()) {
628 pending_updates_.Remove(iter.GetCurrentKey());
629 iter.Advance();
630 }
631
632 switch (status) { 482 switch (status) {
633 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: 483 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
634 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Killed")); 484 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Killed"));
635 break; 485 break;
636 case base::TERMINATION_STATUS_PROCESS_CRASHED: 486 case base::TERMINATION_STATUS_PROCESS_CRASHED:
637 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Crashed")); 487 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Crashed"));
638 break; 488 break;
639 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: 489 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
640 RecordAction(UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath")); 490 RecordAction(UserMetricsAction("BrowserPlugin.Guest.AbnormalDeath"));
641 break; 491 break;
642 default: 492 default:
643 break; 493 break;
644 } 494 }
645 } 495 }
646 496
647 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 497 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) {
648 embedder_web_contents_->Send(msg); 498 bool handled = true;
499 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
500 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnHandleInputEventAck)
501 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
502 OnHasTouchEventHandlers)
503 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor)
504 #if defined(OS_MACOSX)
505 // MacOSX creates and populates platform-specific select drop-down menus
506 // whereas other platforms merely create a popup window that the guest
507 // renderer process paints inside.
508 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup)
509 #endif
510 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget)
511 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
512 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect)
514 IPC_MESSAGE_UNHANDLED(handled = false)
515 IPC_END_MESSAGE_MAP()
516 return handled;
517 }
518
519 void BrowserPluginGuest::OnHandleInputEventAck(
520 WebKit::WebInputEvent::Type event_type,
521 InputEventAckState ack_result) {
522 RenderViewHostImpl* guest_rvh =
523 static_cast<RenderViewHostImpl*>(web_contents()->GetRenderViewHost());
524 guest_rvh->StopHangMonitorTimeout();
525 }
526
527 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) {
528 SendMessageToEmbedder(
529 new BrowserPluginMsg_ShouldAcceptTouchEvents(embedder_routing_id(),
530 instance_id(),
531 accept));
532 }
533
534 void BrowserPluginGuest::OnSetCursor(const WebCursor& cursor) {
535 SendMessageToEmbedder(new BrowserPluginMsg_SetCursor(embedder_routing_id(),
536 instance_id(),
537 cursor));
538 }
539
540 #if defined(OS_MACOSX)
541 void BrowserPluginGuest::OnShowPopup(
542 const ViewHostMsg_ShowPopup_Params& params) {
543 gfx::Rect translated_bounds(params.bounds);
544 translated_bounds.Offset(guest_window_rect_.OffsetFromOrigin());
545 BrowserPluginPopupMenuHelper popup_menu_helper(
546 embedder_web_contents_->GetRenderViewHost(),
547 web_contents()->GetRenderViewHost());
548 popup_menu_helper.ShowPopupMenu(translated_bounds,
549 params.item_height,
550 params.item_font_size,
551 params.selected_item,
552 params.popup_items,
553 params.right_aligned,
554 params.allow_multiple_selection);
555 }
556 #endif
557
558 void BrowserPluginGuest::OnShowWidget(int route_id,
559 const gfx::Rect& initial_pos) {
560 gfx::Rect screen_pos(initial_pos);
561 screen_pos.Offset(guest_screen_rect_.OffsetFromOrigin());
562 static_cast<WebContentsImpl*>(web_contents())->ShowCreatedWidget(route_id,
563 screen_pos);
564 }
565
566 void BrowserPluginGuest::OnTakeFocus(bool reverse) {
567 SendMessageToEmbedder(
568 new BrowserPluginMsg_AdvanceFocus(embedder_routing_id(),
569 instance_id(),
570 reverse));
571 }
572
573 void BrowserPluginGuest::OnUpdateDragCursor(
574 WebKit::WebDragOperation operation) {
575 RenderViewHostImpl* embedder_render_view_host =
576 static_cast<RenderViewHostImpl*>(
577 embedder_web_contents_->GetRenderViewHost());
578 CHECK(embedder_render_view_host);
579 RenderViewHostDelegateView* view =
580 embedder_render_view_host->GetDelegate()->GetDelegateView();
581 if (view)
582 view->UpdateDragCursor(operation);
583 }
584
585 void BrowserPluginGuest::OnUpdateRect(
586 const ViewHostMsg_UpdateRect_Params& params) {
587
588 BrowserPluginMsg_UpdateRect_Params relay_params;
589 relay_params.view_size = params.view_size;
590 relay_params.scale_factor = params.scale_factor;
591 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
592 params.flags);
593
594 // HW accelerated case, acknowledge resize only
595 if (!params.needs_ack) {
596 #if defined(OS_MACOSX)
597 relay_params.damage_buffer_identifier = 0;
598 #else
599 relay_params.damage_buffer_identifier = TransportDIB::DefaultHandleValue();
600 #endif
601 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(
602 embedder_routing_id(),
603 instance_id(),
604 relay_params));
605 return;
606 }
607
608 RenderViewHost* render_view_host = web_contents()->GetRenderViewHost();
609 // Only copy damage if the guest is in autosize mode and the guest's view size
610 // is less than the maximum size or the guest's view size is equal to the
611 // damage buffer's size and the guest's scale factor is equal to the damage
612 // buffer's scale factor.
613 // The scaling change can happen due to asynchronous updates of the DPI on a
614 // resolution change.
615 if (((auto_size_enabled_ && InAutoSizeBounds(params.view_size)) ||
616 (params.view_size.width() == damage_view_size().width() &&
617 params.view_size.height() == damage_view_size().height())) &&
618 params.scale_factor == damage_buffer_scale_factor()) {
619 TransportDIB* dib = render_view_host->GetProcess()->
620 GetTransportDIB(params.bitmap);
621 if (dib) {
622 #if defined(OS_WIN)
623 size_t guest_damage_buffer_size = params.bitmap_rect.width() *
624 params.bitmap_rect.height() * 4;
625 size_t embedder_damage_buffer_size = damage_buffer_size_;
626 #else
627 size_t guest_damage_buffer_size = dib->size();
628 size_t embedder_damage_buffer_size = damage_buffer_->size();
629 #endif
630 void* guest_memory = dib->memory();
631 void* embedder_memory = damage_buffer_->memory();
632 size_t size = std::min(guest_damage_buffer_size,
633 embedder_damage_buffer_size);
634 memcpy(embedder_memory, guest_memory, size);
635 }
636 }
637 #if defined(OS_MACOSX)
638 relay_params.damage_buffer_identifier = damage_buffer_->id();
639 #elif defined(OS_WIN)
640 // On Windows, the handle used locally differs from the handle received from
641 // the embedder process, since we duplicate the remote handle.
642 relay_params.damage_buffer_identifier = remote_damage_buffer_handle_;
643 #else
644 relay_params.damage_buffer_identifier = damage_buffer_->handle();
645 #endif
646 relay_params.bitmap_rect = params.bitmap_rect;
647 relay_params.scroll_delta = params.scroll_delta;
648 relay_params.scroll_rect = params.scroll_rect;
649 relay_params.copy_rects = params.copy_rects;
650
651 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(),
652 instance_id(),
653 relay_params));
649 } 654 }
650 655
651 } // namespace content 656 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/browser_plugin/browser_plugin_guest_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698