| 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/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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 : WebContentsObserver(web_contents), | 49 : WebContentsObserver(web_contents), |
| 50 embedder_web_contents_(NULL), | 50 embedder_web_contents_(NULL), |
| 51 instance_id_(instance_id), | 51 instance_id_(instance_id), |
| 52 damage_buffer_sequence_id_(0), | 52 damage_buffer_sequence_id_(0), |
| 53 damage_buffer_size_(0), | 53 damage_buffer_size_(0), |
| 54 damage_buffer_scale_factor_(1.0f), | 54 damage_buffer_scale_factor_(1.0f), |
| 55 guest_hang_timeout_( | 55 guest_hang_timeout_( |
| 56 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 56 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
| 57 focused_(params.focused), | 57 focused_(params.focused), |
| 58 visible_(params.visible), | 58 visible_(params.visible), |
| 59 name_(params.name), |
| 59 auto_size_enabled_(params.auto_size_params.enable), | 60 auto_size_enabled_(params.auto_size_params.enable), |
| 60 max_auto_size_(params.auto_size_params.max_size), | 61 max_auto_size_(params.auto_size_params.max_size), |
| 61 min_auto_size_(params.auto_size_params.min_size) { | 62 min_auto_size_(params.auto_size_params.min_size) { |
| 62 DCHECK(web_contents); | 63 DCHECK(web_contents); |
| 63 } | 64 } |
| 64 | 65 |
| 65 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 66 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 66 const IPC::Message& message) { | 67 const IPC::Message& message) { |
| 67 bool handled = true; | 68 bool handled = true; |
| 68 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 69 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 69 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 70 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 70 OnDragStatusUpdate) | 71 OnDragStatusUpdate) |
| 71 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) | 72 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) |
| 72 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, | 73 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_HandleInputEvent, |
| 73 OnHandleInputEvent) | 74 OnHandleInputEvent) |
| 74 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) | 75 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) |
| 75 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) | 76 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
| 76 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) | 77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetAutoSize, OnSetSize) |
| 77 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) | 78 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) |
| 79 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetName, OnSetName) |
| 78 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 80 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
| 79 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) | 81 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) |
| 80 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) | 82 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_TerminateGuest, OnTerminateGuest) |
| 81 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) | 83 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK) |
| 82 IPC_MESSAGE_UNHANDLED(handled = false) | 84 IPC_MESSAGE_UNHANDLED(handled = false) |
| 83 IPC_END_MESSAGE_MAP() | 85 IPC_END_MESSAGE_MAP() |
| 84 return handled; | 86 return handled; |
| 85 } | 87 } |
| 86 | 88 |
| 87 void BrowserPluginGuest::Initialize( | 89 void BrowserPluginGuest::Initialize( |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 316 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 315 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), | 317 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), |
| 316 instance_id())); | 318 instance_id())); |
| 317 } | 319 } |
| 318 | 320 |
| 319 void BrowserPluginGuest::RenderViewReady() { | 321 void BrowserPluginGuest::RenderViewReady() { |
| 320 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 322 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 321 // here (see http://crbug.com/158151). | 323 // here (see http://crbug.com/158151). |
| 322 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 324 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
| 323 UpdateVisibility(); | 325 UpdateVisibility(); |
| 324 if (auto_size_enabled_) { | 326 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 325 web_contents()->GetRenderViewHost()->EnableAutoResize( | 327 if (auto_size_enabled_) |
| 326 min_auto_size_, max_auto_size_); | 328 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
| 327 } else { | 329 else |
| 328 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); | 330 rvh->DisableAutoResize(damage_view_size_); |
| 329 } | 331 |
| 332 rvh->Send(new ViewMsg_SetName(rvh->GetRoutingID(), name_)); |
| 330 } | 333 } |
| 331 | 334 |
| 332 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { | 335 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
| 333 int process_id = web_contents()->GetRenderProcessHost()->GetID(); | 336 int process_id = web_contents()->GetRenderProcessHost()->GetID(); |
| 334 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(), | 337 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(), |
| 335 instance_id(), | 338 instance_id(), |
| 336 process_id, | 339 process_id, |
| 337 status)); | 340 status)); |
| 338 switch (status) { | 341 switch (status) { |
| 339 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 342 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 360 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 363 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
| 361 #if defined(OS_MACOSX) | 364 #if defined(OS_MACOSX) |
| 362 // MacOSX creates and populates platform-specific select drop-down menus | 365 // MacOSX creates and populates platform-specific select drop-down menus |
| 363 // whereas other platforms merely create a popup window that the guest | 366 // whereas other platforms merely create a popup window that the guest |
| 364 // renderer process paints inside. | 367 // renderer process paints inside. |
| 365 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 368 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
| 366 #endif | 369 #endif |
| 367 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 370 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 368 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 371 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
| 369 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | 372 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) |
| 373 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 370 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 374 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 371 IPC_MESSAGE_UNHANDLED(handled = false) | 375 IPC_MESSAGE_UNHANDLED(handled = false) |
| 372 IPC_END_MESSAGE_MAP() | 376 IPC_END_MESSAGE_MAP() |
| 373 return handled; | 377 return handled; |
| 374 } | 378 } |
| 375 | 379 |
| 376 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { | 380 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { |
| 377 web_contents()->GetController().GoToOffset(relative_index); | 381 web_contents()->GetController().GoToOffset(relative_index); |
| 378 } | 382 } |
| 379 | 383 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 web_contents()->GetView()->SizeContents(params.view_size); | 463 web_contents()->GetView()->SizeContents(params.view_size); |
| 460 } | 464 } |
| 461 | 465 |
| 462 void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { | 466 void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { |
| 463 if (focused_ == focused) | 467 if (focused_ == focused) |
| 464 return; | 468 return; |
| 465 focused_ = focused; | 469 focused_ = focused; |
| 466 Send(new ViewMsg_SetFocus(routing_id(), focused)); | 470 Send(new ViewMsg_SetFocus(routing_id(), focused)); |
| 467 } | 471 } |
| 468 | 472 |
| 473 void BrowserPluginGuest::OnSetName(int instance_id, const std::string& name) { |
| 474 if (name == name_) |
| 475 return; |
| 476 name_ = name; |
| 477 web_contents()->GetRenderViewHost()->Send(new ViewMsg_SetName( |
| 478 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 479 name)); |
| 480 } |
| 481 |
| 469 void BrowserPluginGuest::OnSetSize( | 482 void BrowserPluginGuest::OnSetSize( |
| 470 int instance_id, | 483 int instance_id, |
| 471 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, | 484 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, |
| 472 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { | 485 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) { |
| 473 bool old_auto_size_enabled = auto_size_enabled_; | 486 bool old_auto_size_enabled = auto_size_enabled_; |
| 474 gfx::Size old_max_size = max_auto_size_; | 487 gfx::Size old_max_size = max_auto_size_; |
| 475 gfx::Size old_min_size = min_auto_size_; | 488 gfx::Size old_min_size = min_auto_size_; |
| 476 auto_size_enabled_ = auto_size_params.enable; | 489 auto_size_enabled_ = auto_size_params.enable; |
| 477 max_auto_size_ = auto_size_params.max_size; | 490 max_auto_size_ = auto_size_params.max_size; |
| 478 min_auto_size_ = auto_size_params.min_size; | 491 min_auto_size_ = auto_size_params.min_size; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 RenderViewHostImpl* embedder_render_view_host = | 613 RenderViewHostImpl* embedder_render_view_host = |
| 601 static_cast<RenderViewHostImpl*>( | 614 static_cast<RenderViewHostImpl*>( |
| 602 embedder_web_contents_->GetRenderViewHost()); | 615 embedder_web_contents_->GetRenderViewHost()); |
| 603 CHECK(embedder_render_view_host); | 616 CHECK(embedder_render_view_host); |
| 604 RenderViewHostDelegateView* view = | 617 RenderViewHostDelegateView* view = |
| 605 embedder_render_view_host->GetDelegate()->GetDelegateView(); | 618 embedder_render_view_host->GetDelegate()->GetDelegateView(); |
| 606 if (view) | 619 if (view) |
| 607 view->UpdateDragCursor(operation); | 620 view->UpdateDragCursor(operation); |
| 608 } | 621 } |
| 609 | 622 |
| 623 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| 624 bool is_top_level, |
| 625 const std::string& name) { |
| 626 if (!is_top_level) |
| 627 return; |
| 628 |
| 629 name_ = name; |
| 630 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 631 embedder_routing_id(), |
| 632 instance_id_, |
| 633 name)); |
| 634 } |
| 635 |
| 610 void BrowserPluginGuest::OnUpdateRect( | 636 void BrowserPluginGuest::OnUpdateRect( |
| 611 const ViewHostMsg_UpdateRect_Params& params) { | 637 const ViewHostMsg_UpdateRect_Params& params) { |
| 612 | 638 |
| 613 BrowserPluginMsg_UpdateRect_Params relay_params; | 639 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 614 relay_params.view_size = params.view_size; | 640 relay_params.view_size = params.view_size; |
| 615 relay_params.scale_factor = params.scale_factor; | 641 relay_params.scale_factor = params.scale_factor; |
| 616 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 642 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 617 params.flags); | 643 params.flags); |
| 618 | 644 |
| 619 // HW accelerated case, acknowledge resize only | 645 // HW accelerated case, acknowledge resize only |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 relay_params.scroll_delta = params.scroll_delta; | 686 relay_params.scroll_delta = params.scroll_delta; |
| 661 relay_params.scroll_rect = params.scroll_rect; | 687 relay_params.scroll_rect = params.scroll_rect; |
| 662 relay_params.copy_rects = params.copy_rects; | 688 relay_params.copy_rects = params.copy_rects; |
| 663 | 689 |
| 664 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 690 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 665 instance_id(), | 691 instance_id(), |
| 666 relay_params)); | 692 relay_params)); |
| 667 } | 693 } |
| 668 | 694 |
| 669 } // namespace content | 695 } // namespace content |
| OLD | NEW |