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/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
14 #include "content/browser/child_process_security_policy_impl.h" | 14 #include "content/browser/child_process_security_policy_impl.h" |
15 #include "content/browser/frame_host/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
16 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 16 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
18 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 19 #include "content/browser/renderer_host/render_widget_host_impl.h" |
20 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 20 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
21 #include "content/browser/web_contents/web_contents_impl.h" | 21 #include "content/browser/web_contents/web_contents_impl.h" |
22 #include "content/browser/web_contents/web_contents_view_guest.h" | 22 #include "content/browser/web_contents/web_contents_view_guest.h" |
23 #include "content/common/browser_plugin/browser_plugin_constants.h" | 23 #include "content/common/browser_plugin/browser_plugin_constants.h" |
24 #include "content/common/browser_plugin/browser_plugin_messages.h" | 24 #include "content/common/browser_plugin/browser_plugin_messages.h" |
25 #include "content/common/content_constants_internal.h" | 25 #include "content/common/content_constants_internal.h" |
26 #include "content/common/drag_messages.h" | 26 #include "content/common/drag_messages.h" |
27 #include "content/common/frame_messages.h" | 27 #include "content/common/frame_messages.h" |
| 28 #include "content/common/host_shared_bitmap_manager.h" |
28 #include "content/common/input_messages.h" | 29 #include "content/common/input_messages.h" |
29 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
30 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
31 #include "content/public/browser/browser_plugin_guest_manager.h" | 32 #include "content/public/browser/browser_plugin_guest_manager.h" |
32 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
34 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
35 #include "content/public/browser/web_contents_observer.h" | 36 #include "content/public/browser/web_contents_observer.h" |
36 #include "content/public/common/drop_data.h" | 37 #include "content/public/common/drop_data.h" |
37 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | 38 #include "third_party/WebKit/public/platform/WebCursorInfo.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { | 304 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
304 embedder_visible_ = visible; | 305 embedder_visible_ = visible; |
305 UpdateVisibility(); | 306 UpdateVisibility(); |
306 } | 307 } |
307 | 308 |
308 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { | 309 void BrowserPluginGuest::PointerLockPermissionResponse(bool allow) { |
309 SendMessageToEmbedder( | 310 SendMessageToEmbedder( |
310 new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow)); | 311 new BrowserPluginMsg_SetMouseLock(browser_plugin_instance_id(), allow)); |
311 } | 312 } |
312 | 313 |
| 314 void BrowserPluginGuest::SwapCompositorFrame( |
| 315 uint32 output_surface_id, |
| 316 int host_process_id, |
| 317 int host_routing_id, |
| 318 scoped_ptr<cc::CompositorFrame> frame) { |
| 319 if (!attached()) { |
| 320 // If the guest doesn't have an embedder then there's nothing to give the |
| 321 // the frame to. |
| 322 return; |
| 323 } |
| 324 |
| 325 gfx::Size view_size(frame->metadata.root_layer_size.width(), |
| 326 frame->metadata.root_layer_size.height()); |
| 327 if (last_seen_view_size_ != view_size) { |
| 328 delegate_->GuestSizeChanged(last_seen_view_size_, view_size); |
| 329 last_seen_view_size_ = view_size; |
| 330 } |
| 331 |
| 332 base::SharedMemoryHandle software_frame_handle = |
| 333 base::SharedMemory::NULLHandle(); |
| 334 if (frame->software_frame_data) { |
| 335 cc::SoftwareFrameData* frame_data = frame->software_frame_data.get(); |
| 336 scoped_ptr<cc::SharedBitmap> bitmap = |
| 337 HostSharedBitmapManager::current()->GetSharedBitmapFromId( |
| 338 frame_data->size, frame_data->bitmap_id); |
| 339 if (!bitmap) |
| 340 return; |
| 341 |
| 342 RenderWidgetHostView* embedder_rwhv = |
| 343 GetEmbedderRenderWidgetHostView(); |
| 344 base::ProcessHandle embedder_pid = |
| 345 embedder_rwhv->GetRenderWidgetHost()->GetProcess()->GetHandle(); |
| 346 |
| 347 bitmap->memory()->ShareToProcess(embedder_pid, &software_frame_handle); |
| 348 } |
| 349 |
| 350 FrameMsg_CompositorFrameSwapped_Params guest_params; |
| 351 frame->AssignTo(&guest_params.frame); |
| 352 guest_params.output_surface_id = output_surface_id; |
| 353 guest_params.producing_route_id = host_routing_id; |
| 354 guest_params.producing_host_id = host_process_id; |
| 355 guest_params.shared_memory_handle = software_frame_handle; |
| 356 |
| 357 SendMessageToEmbedder( |
| 358 new BrowserPluginMsg_CompositorFrameSwapped( |
| 359 browser_plugin_instance_id(), guest_params)); |
| 360 } |
| 361 |
313 WebContentsImpl* BrowserPluginGuest::GetWebContents() const { | 362 WebContentsImpl* BrowserPluginGuest::GetWebContents() const { |
314 return static_cast<WebContentsImpl*>(web_contents()); | 363 return static_cast<WebContentsImpl*>(web_contents()); |
315 } | 364 } |
316 | 365 |
317 gfx::Point BrowserPluginGuest::GetScreenCoordinates( | 366 gfx::Point BrowserPluginGuest::GetScreenCoordinates( |
318 const gfx::Point& relative_position) const { | 367 const gfx::Point& relative_position) const { |
319 if (!attached()) | 368 if (!attached()) |
320 return relative_position; | 369 return relative_position; |
321 | 370 |
322 gfx::Point screen_pos(relative_position); | 371 gfx::Point screen_pos(relative_position); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 #endif | 493 #endif |
445 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 494 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
446 OnHasTouchEventHandlers) | 495 OnHasTouchEventHandlers) |
447 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 496 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
448 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | 497 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) |
449 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 498 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
450 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 499 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
451 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, | 500 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, |
452 OnTextInputStateChanged) | 501 OnTextInputStateChanged) |
453 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 502 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
454 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | |
455 IPC_MESSAGE_UNHANDLED(handled = false) | 503 IPC_MESSAGE_UNHANDLED(handled = false) |
456 IPC_END_MESSAGE_MAP() | 504 IPC_END_MESSAGE_MAP() |
457 return handled; | 505 return handled; |
458 } | 506 } |
459 | 507 |
460 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message, | 508 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message, |
461 RenderFrameHost* render_frame_host) { | 509 RenderFrameHost* render_frame_host) { |
462 // This will eventually be the home for more IPC handlers that depend on | 510 // This will eventually be the home for more IPC handlers that depend on |
463 // RenderFrameHost. Until more are moved here, though, the IPC_* macros won't | 511 // RenderFrameHost. Until more are moved here, though, the IPC_* macros won't |
464 // compile if there are no handlers for a platform. So we have both #if guards | 512 // compile if there are no handlers for a platform. So we have both #if guards |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 mouse_locked_ = true; | 724 mouse_locked_ = true; |
677 } | 725 } |
678 | 726 |
679 void BrowserPluginGuest::OnPluginDestroyed(int browser_plugin_instance_id) { | 727 void BrowserPluginGuest::OnPluginDestroyed(int browser_plugin_instance_id) { |
680 Destroy(); | 728 Destroy(); |
681 } | 729 } |
682 | 730 |
683 void BrowserPluginGuest::OnResizeGuest( | 731 void BrowserPluginGuest::OnResizeGuest( |
684 int browser_plugin_instance_id, | 732 int browser_plugin_instance_id, |
685 const BrowserPluginHostMsg_ResizeGuest_Params& params) { | 733 const BrowserPluginHostMsg_ResizeGuest_Params& params) { |
686 if (!params.size_changed) | 734 // If we are setting the size for the first time before navigating then |
687 return; | |
688 // BrowserPlugin manages resize flow control itself and does not depend | |
689 // on RenderWidgetHost's mechanisms for flow control, so we reset those flags | |
690 // here. If we are setting the size for the first time before navigating then | |
691 // BrowserPluginGuest does not yet have a RenderViewHost. | 735 // BrowserPluginGuest does not yet have a RenderViewHost. |
692 if (GetWebContents()->GetRenderViewHost()) { | 736 if (guest_device_scale_factor_ != params.scale_factor && |
| 737 GetWebContents()->GetRenderViewHost()) { |
693 RenderWidgetHostImpl* render_widget_host = | 738 RenderWidgetHostImpl* render_widget_host = |
694 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost()); | 739 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost()); |
695 render_widget_host->ResetSizeAndRepaintPendingFlags(); | 740 guest_device_scale_factor_ = params.scale_factor; |
696 | 741 render_widget_host->NotifyScreenInfoChanged(); |
697 if (guest_device_scale_factor_ != params.scale_factor) { | |
698 guest_device_scale_factor_ = params.scale_factor; | |
699 render_widget_host->NotifyScreenInfoChanged(); | |
700 } | |
701 } | 742 } |
702 | 743 |
703 if (last_seen_browser_plugin_size_ != params.view_size) { | 744 if (last_seen_browser_plugin_size_ != params.view_size) { |
704 delegate_->ElementSizeChanged(last_seen_browser_plugin_size_, | 745 delegate_->ElementSizeChanged(last_seen_browser_plugin_size_, |
705 params.view_size); | 746 params.view_size); |
706 last_seen_browser_plugin_size_ = params.view_size; | 747 last_seen_browser_plugin_size_ = params.view_size; |
707 } | 748 } |
708 | 749 |
709 // Just resize the WebContents and repaint if needed. | 750 // Just resize the WebContents and repaint if needed. |
710 if (!params.view_size.IsEmpty()) | 751 if (!params.view_size.IsEmpty()) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 void BrowserPluginGuest::OnShowWidget(int route_id, | 864 void BrowserPluginGuest::OnShowWidget(int route_id, |
824 const gfx::Rect& initial_pos) { | 865 const gfx::Rect& initial_pos) { |
825 GetWebContents()->ShowCreatedWidget(route_id, initial_pos); | 866 GetWebContents()->ShowCreatedWidget(route_id, initial_pos); |
826 } | 867 } |
827 | 868 |
828 void BrowserPluginGuest::OnTakeFocus(bool reverse) { | 869 void BrowserPluginGuest::OnTakeFocus(bool reverse) { |
829 SendMessageToEmbedder( | 870 SendMessageToEmbedder( |
830 new BrowserPluginMsg_AdvanceFocus(browser_plugin_instance_id(), reverse)); | 871 new BrowserPluginMsg_AdvanceFocus(browser_plugin_instance_id(), reverse)); |
831 } | 872 } |
832 | 873 |
833 void BrowserPluginGuest::OnUpdateRect( | |
834 const ViewHostMsg_UpdateRect_Params& params) { | |
835 BrowserPluginMsg_UpdateRect_Params relay_params; | |
836 relay_params.view_size = params.view_size; | |
837 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | |
838 params.flags); | |
839 | |
840 if (last_seen_view_size_ != params.view_size) { | |
841 delegate_->GuestSizeChanged(last_seen_view_size_, params.view_size); | |
842 last_seen_view_size_ = params.view_size; | |
843 } | |
844 | |
845 SendMessageToEmbedder( | |
846 new BrowserPluginMsg_UpdateRect(browser_plugin_instance_id(), | |
847 relay_params)); | |
848 } | |
849 | |
850 void BrowserPluginGuest::OnTextInputStateChanged( | 874 void BrowserPluginGuest::OnTextInputStateChanged( |
851 const ViewHostMsg_TextInputState_Params& params) { | 875 const ViewHostMsg_TextInputState_Params& params) { |
852 // Save the state of text input so we can restore it on focus. | 876 // Save the state of text input so we can restore it on focus. |
853 last_text_input_type_ = params.type; | 877 last_text_input_type_ = params.type; |
854 last_input_mode_ = params.mode; | 878 last_input_mode_ = params.mode; |
855 last_can_compose_inline_ = params.can_compose_inline; | 879 last_can_compose_inline_ = params.can_compose_inline; |
856 | 880 |
857 static_cast<RenderWidgetHostViewBase*>( | 881 static_cast<RenderWidgetHostViewBase*>( |
858 web_contents()->GetRenderWidgetHostView())->TextInputStateChanged(params); | 882 web_contents()->GetRenderWidgetHostView())->TextInputStateChanged(params); |
859 } | 883 } |
860 | 884 |
861 void BrowserPluginGuest::OnImeCancelComposition() { | 885 void BrowserPluginGuest::OnImeCancelComposition() { |
862 static_cast<RenderWidgetHostViewBase*>( | 886 static_cast<RenderWidgetHostViewBase*>( |
863 web_contents()->GetRenderWidgetHostView())->ImeCancelComposition(); | 887 web_contents()->GetRenderWidgetHostView())->ImeCancelComposition(); |
864 } | 888 } |
865 | 889 |
866 #if defined(OS_MACOSX) || defined(USE_AURA) | 890 #if defined(OS_MACOSX) || defined(USE_AURA) |
867 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 891 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
868 const gfx::Range& range, | 892 const gfx::Range& range, |
869 const std::vector<gfx::Rect>& character_bounds) { | 893 const std::vector<gfx::Rect>& character_bounds) { |
870 static_cast<RenderWidgetHostViewBase*>( | 894 static_cast<RenderWidgetHostViewBase*>( |
871 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 895 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
872 range, character_bounds); | 896 range, character_bounds); |
873 } | 897 } |
874 #endif | 898 #endif |
875 | 899 |
876 } // namespace content | 900 } // namespace content |
OLD | NEW |