| 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { | 315 void BrowserPluginGuest::DidStopLoading(RenderViewHost* render_view_host) { |
| 314 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), | 316 SendMessageToEmbedder(new BrowserPluginMsg_LoadStop(embedder_routing_id(), |
| 315 instance_id())); | 317 instance_id())); |
| 316 } | 318 } |
| 317 | 319 |
| 318 void BrowserPluginGuest::RenderViewReady() { | 320 void BrowserPluginGuest::RenderViewReady() { |
| 319 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 321 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
| 320 // here (see http://crbug.com/158151). | 322 // here (see http://crbug.com/158151). |
| 321 Send(new ViewMsg_SetFocus(routing_id(), focused_)); | 323 Send(new ViewMsg_SetFocus(routing_id(), focused_)); |
| 322 UpdateVisibility(); | 324 UpdateVisibility(); |
| 323 if (auto_size_enabled_) { | 325 RenderViewHost* rvh = web_contents()->GetRenderViewHost(); |
| 324 web_contents()->GetRenderViewHost()->EnableAutoResize( | 326 if (auto_size_enabled_) |
| 325 min_auto_size_, max_auto_size_); | 327 rvh->EnableAutoResize(min_auto_size_, max_auto_size_); |
| 326 } else { | 328 else |
| 327 web_contents()->GetRenderViewHost()->DisableAutoResize(damage_view_size_); | 329 rvh->DisableAutoResize(damage_view_size_); |
| 328 } | 330 |
| 331 rvh->Send(new ViewMsg_SetName(rvh->GetRoutingID(), name_)); |
| 329 } | 332 } |
| 330 | 333 |
| 331 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { | 334 void BrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
| 332 int process_id = web_contents()->GetRenderProcessHost()->GetID(); | 335 int process_id = web_contents()->GetRenderProcessHost()->GetID(); |
| 333 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(), | 336 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(embedder_routing_id(), |
| 334 instance_id(), | 337 instance_id(), |
| 335 process_id, | 338 process_id, |
| 336 status)); | 339 status)); |
| 337 switch (status) { | 340 switch (status) { |
| 338 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 341 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 358 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 361 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
| 359 #if defined(OS_MACOSX) | 362 #if defined(OS_MACOSX) |
| 360 // MacOSX creates and populates platform-specific select drop-down menus | 363 // MacOSX creates and populates platform-specific select drop-down menus |
| 361 // whereas other platforms merely create a popup window that the guest | 364 // whereas other platforms merely create a popup window that the guest |
| 362 // renderer process paints inside. | 365 // renderer process paints inside. |
| 363 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) | 366 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowPopup, OnShowPopup) |
| 364 #endif | 367 #endif |
| 365 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 368 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
| 366 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 369 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
| 367 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) | 370 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) |
| 371 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 368 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 372 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
| 369 IPC_MESSAGE_UNHANDLED(handled = false) | 373 IPC_MESSAGE_UNHANDLED(handled = false) |
| 370 IPC_END_MESSAGE_MAP() | 374 IPC_END_MESSAGE_MAP() |
| 371 return handled; | 375 return handled; |
| 372 } | 376 } |
| 373 | 377 |
| 374 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { | 378 void BrowserPluginGuest::OnGo(int instance_id, int relative_index) { |
| 375 web_contents()->GetController().GoToOffset(relative_index); | 379 web_contents()->GetController().GoToOffset(relative_index); |
| 376 } | 380 } |
| 377 | 381 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 OnResizeGuest(instance_id_, resize_guest_params); | 493 OnResizeGuest(instance_id_, resize_guest_params); |
| 490 } | 494 } |
| 491 | 495 |
| 492 void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { | 496 void BrowserPluginGuest::OnSetFocus(int instance_id, bool focused) { |
| 493 if (focused_ == focused) | 497 if (focused_ == focused) |
| 494 return; | 498 return; |
| 495 focused_ = focused; | 499 focused_ = focused; |
| 496 Send(new ViewMsg_SetFocus(routing_id(), focused)); | 500 Send(new ViewMsg_SetFocus(routing_id(), focused)); |
| 497 } | 501 } |
| 498 | 502 |
| 503 void BrowserPluginGuest::OnSetName(int instance_id, const std::string& name) { |
| 504 if (name == name_) |
| 505 return; |
| 506 name_ = name; |
| 507 web_contents()->GetRenderViewHost()->Send(new ViewMsg_SetName( |
| 508 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 509 name)); |
| 510 } |
| 511 |
| 499 void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) { | 512 void BrowserPluginGuest::OnSetVisibility(int instance_id, bool visible) { |
| 500 visible_ = visible; | 513 visible_ = visible; |
| 501 BrowserPluginEmbedder* embedder = | 514 BrowserPluginEmbedder* embedder = |
| 502 embedder_web_contents_->GetBrowserPluginEmbedder(); | 515 embedder_web_contents_->GetBrowserPluginEmbedder(); |
| 503 if (embedder->visible() && visible) | 516 if (embedder->visible() && visible) |
| 504 web_contents()->WasShown(); | 517 web_contents()->WasShown(); |
| 505 else | 518 else |
| 506 web_contents()->WasHidden(); | 519 web_contents()->WasHidden(); |
| 507 } | 520 } |
| 508 | 521 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 RenderViewHostImpl* embedder_render_view_host = | 599 RenderViewHostImpl* embedder_render_view_host = |
| 587 static_cast<RenderViewHostImpl*>( | 600 static_cast<RenderViewHostImpl*>( |
| 588 embedder_web_contents_->GetRenderViewHost()); | 601 embedder_web_contents_->GetRenderViewHost()); |
| 589 CHECK(embedder_render_view_host); | 602 CHECK(embedder_render_view_host); |
| 590 RenderViewHostDelegateView* view = | 603 RenderViewHostDelegateView* view = |
| 591 embedder_render_view_host->GetDelegate()->GetDelegateView(); | 604 embedder_render_view_host->GetDelegate()->GetDelegateView(); |
| 592 if (view) | 605 if (view) |
| 593 view->UpdateDragCursor(operation); | 606 view->UpdateDragCursor(operation); |
| 594 } | 607 } |
| 595 | 608 |
| 609 void BrowserPluginGuest::OnUpdateFrameName(int frame_id, |
| 610 bool is_top_level, |
| 611 const std::string& name) { |
| 612 if (!is_top_level) |
| 613 return; |
| 614 |
| 615 name_ = name; |
| 616 SendMessageToEmbedder(new BrowserPluginMsg_UpdatedName( |
| 617 embedder_routing_id(), |
| 618 instance_id_, |
| 619 name)); |
| 620 } |
| 621 |
| 596 void BrowserPluginGuest::OnUpdateRect( | 622 void BrowserPluginGuest::OnUpdateRect( |
| 597 const ViewHostMsg_UpdateRect_Params& params) { | 623 const ViewHostMsg_UpdateRect_Params& params) { |
| 598 | 624 |
| 599 BrowserPluginMsg_UpdateRect_Params relay_params; | 625 BrowserPluginMsg_UpdateRect_Params relay_params; |
| 600 relay_params.view_size = params.view_size; | 626 relay_params.view_size = params.view_size; |
| 601 relay_params.scale_factor = params.scale_factor; | 627 relay_params.scale_factor = params.scale_factor; |
| 602 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 628 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 603 params.flags); | 629 params.flags); |
| 604 | 630 |
| 605 // HW accelerated case, acknowledge resize only | 631 // HW accelerated case, acknowledge resize only |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 relay_params.scroll_delta = params.scroll_delta; | 672 relay_params.scroll_delta = params.scroll_delta; |
| 647 relay_params.scroll_rect = params.scroll_rect; | 673 relay_params.scroll_rect = params.scroll_rect; |
| 648 relay_params.copy_rects = params.copy_rects; | 674 relay_params.copy_rects = params.copy_rects; |
| 649 | 675 |
| 650 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), | 676 SendMessageToEmbedder(new BrowserPluginMsg_UpdateRect(embedder_routing_id(), |
| 651 instance_id(), | 677 instance_id(), |
| 652 relay_params)); | 678 relay_params)); |
| 653 } | 679 } |
| 654 | 680 |
| 655 } // namespace content | 681 } // namespace content |
| OLD | NEW |