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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "content/common/host_shared_bitmap_manager.h" | 28 #include "content/common/host_shared_bitmap_manager.h" |
29 #include "content/common/input_messages.h" | 29 #include "content/common/input_messages.h" |
30 #include "content/common/view_messages.h" | 30 #include "content/common/view_messages.h" |
31 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
32 #include "content/public/browser/browser_plugin_guest_manager.h" | 32 #include "content/public/browser/browser_plugin_guest_manager.h" |
33 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
35 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents_observer.h" | 36 #include "content/public/browser/web_contents_observer.h" |
37 #include "content/public/common/drop_data.h" | 37 #include "content/public/common/drop_data.h" |
38 #include "third_party/WebKit/public/platform/WebCursorInfo.h" | |
39 #include "ui/gfx/geometry/size_conversions.h" | 38 #include "ui/gfx/geometry/size_conversions.h" |
40 | 39 |
41 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 41 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
43 #endif | 42 #endif |
44 | 43 |
45 namespace content { | 44 namespace content { |
46 | 45 |
47 class BrowserPluginGuest::EmbedderWebContentsObserver | 46 class BrowserPluginGuest::EmbedderWebContentsObserver |
48 : public WebContentsObserver { | 47 : public WebContentsObserver { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 100 |
102 void BrowserPluginGuest::WillDestroy() { | 101 void BrowserPluginGuest::WillDestroy() { |
103 is_in_destruction_ = true; | 102 is_in_destruction_ = true; |
104 embedder_web_contents_ = NULL; | 103 embedder_web_contents_ = NULL; |
105 } | 104 } |
106 | 105 |
107 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { | 106 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
108 return weak_ptr_factory_.GetWeakPtr(); | 107 return weak_ptr_factory_.GetWeakPtr(); |
109 } | 108 } |
110 | 109 |
| 110 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, bool focused) { |
| 111 focused_ = focused; |
| 112 rwh->Send(new InputMsg_SetFocus(rwh->GetRoutingID(), focused)); |
| 113 if (!focused && mouse_locked_) |
| 114 OnUnlockMouse(); |
| 115 |
| 116 // Restore the last seen state of text input to the view. |
| 117 RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>( |
| 118 web_contents()->GetRenderWidgetHostView()); |
| 119 if (rwhv) { |
| 120 ViewHostMsg_TextInputState_Params params; |
| 121 params.type = last_text_input_type_; |
| 122 params.mode = last_input_mode_; |
| 123 params.can_compose_inline = last_can_compose_inline_; |
| 124 rwhv->TextInputStateChanged(params); |
| 125 } |
| 126 } |
| 127 |
111 bool BrowserPluginGuest::LockMouse(bool allowed) { | 128 bool BrowserPluginGuest::LockMouse(bool allowed) { |
112 if (!attached() || (mouse_locked_ == allowed)) | 129 if (!attached() || (mouse_locked_ == allowed)) |
113 return false; | 130 return false; |
114 | 131 |
115 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); | 132 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); |
116 } | 133 } |
117 | 134 |
118 void BrowserPluginGuest::Destroy() { | 135 void BrowserPluginGuest::Destroy() { |
119 delegate_->Destroy(); | 136 delegate_->Destroy(); |
120 } | 137 } |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 505 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
489 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, | 506 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, |
490 OnImeCancelComposition) | 507 OnImeCancelComposition) |
491 #if defined(OS_MACOSX) || defined(USE_AURA) | 508 #if defined(OS_MACOSX) || defined(USE_AURA) |
492 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, | 509 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, |
493 OnImeCompositionRangeChanged) | 510 OnImeCompositionRangeChanged) |
494 #endif | 511 #endif |
495 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 512 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
496 OnHasTouchEventHandlers) | 513 OnHasTouchEventHandlers) |
497 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 514 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
498 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnSetCursor) | |
499 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) | 515 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowWidget, OnShowWidget) |
500 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) | 516 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) |
501 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, | 517 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, |
502 OnTextInputStateChanged) | 518 OnTextInputStateChanged) |
503 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 519 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
504 IPC_MESSAGE_UNHANDLED(handled = false) | 520 IPC_MESSAGE_UNHANDLED(handled = false) |
505 IPC_END_MESSAGE_MAP() | 521 IPC_END_MESSAGE_MAP() |
506 return handled; | 522 return handled; |
507 } | 523 } |
508 | 524 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 | 711 |
696 // Just resize the WebContents and repaint if needed. | 712 // Just resize the WebContents and repaint if needed. |
697 if (!params.view_size.IsEmpty()) | 713 if (!params.view_size.IsEmpty()) |
698 GetWebContents()->GetView()->SizeContents(params.view_size); | 714 GetWebContents()->GetView()->SizeContents(params.view_size); |
699 if (params.repaint) | 715 if (params.repaint) |
700 Send(new ViewMsg_Repaint(routing_id(), params.view_size)); | 716 Send(new ViewMsg_Repaint(routing_id(), params.view_size)); |
701 } | 717 } |
702 | 718 |
703 void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id, | 719 void BrowserPluginGuest::OnSetFocus(int browser_plugin_instance_id, |
704 bool focused) { | 720 bool focused) { |
705 focused_ = focused; | |
706 Send(new InputMsg_SetFocus(routing_id(), focused)); | |
707 if (!focused && mouse_locked_) | |
708 OnUnlockMouse(); | |
709 | 721 |
710 // Restore the last seen state of text input to the view. | 722 RenderWidgetHost* rwh = web_contents()->GetRenderWidgetHostView()-> |
711 RenderWidgetHostViewBase* rwhv = static_cast<RenderWidgetHostViewBase*>( | 723 GetRenderWidgetHost(); |
712 web_contents()->GetRenderWidgetHostView()); | 724 SetFocus(rwh, focused); |
713 if (rwhv) { | |
714 ViewHostMsg_TextInputState_Params params; | |
715 params.type = last_text_input_type_; | |
716 params.mode = last_input_mode_; | |
717 params.can_compose_inline = last_can_compose_inline_; | |
718 rwhv->TextInputStateChanged(params); | |
719 } | |
720 } | 725 } |
721 | 726 |
722 void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( | 727 void BrowserPluginGuest::OnSetEditCommandsForNextKeyEvent( |
723 int browser_plugin_instance_id, | 728 int browser_plugin_instance_id, |
724 const std::vector<EditCommand>& edit_commands) { | 729 const std::vector<EditCommand>& edit_commands) { |
725 Send(new InputMsg_SetEditCommandsForNextKeyEvent(routing_id(), | 730 Send(new InputMsg_SetEditCommandsForNextKeyEvent(routing_id(), |
726 edit_commands)); | 731 edit_commands)); |
727 } | 732 } |
728 | 733 |
729 void BrowserPluginGuest::OnSetContentsOpaque(int browser_plugin_instance_id, | 734 void BrowserPluginGuest::OnSetContentsOpaque(int browser_plugin_instance_id, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 if (rvh) | 782 if (rvh) |
778 rvh->SendScreenRects(); | 783 rvh->SendScreenRects(); |
779 } | 784 } |
780 | 785 |
781 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { | 786 void BrowserPluginGuest::OnHasTouchEventHandlers(bool accept) { |
782 SendMessageToEmbedder( | 787 SendMessageToEmbedder( |
783 new BrowserPluginMsg_ShouldAcceptTouchEvents( | 788 new BrowserPluginMsg_ShouldAcceptTouchEvents( |
784 browser_plugin_instance_id(), accept)); | 789 browser_plugin_instance_id(), accept)); |
785 } | 790 } |
786 | 791 |
787 void BrowserPluginGuest::OnSetCursor(const WebCursor& cursor) { | |
788 SendMessageToEmbedder( | |
789 new BrowserPluginMsg_SetCursor(browser_plugin_instance_id(), cursor)); | |
790 } | |
791 | |
792 #if defined(OS_MACOSX) | 792 #if defined(OS_MACOSX) |
793 void BrowserPluginGuest::OnShowPopup( | 793 void BrowserPluginGuest::OnShowPopup( |
794 RenderFrameHost* render_frame_host, | 794 RenderFrameHost* render_frame_host, |
795 const FrameHostMsg_ShowPopup_Params& params) { | 795 const FrameHostMsg_ShowPopup_Params& params) { |
796 gfx::Rect translated_bounds(params.bounds); | 796 gfx::Rect translated_bounds(params.bounds); |
797 translated_bounds.Offset(guest_window_rect_.OffsetFromOrigin()); | 797 translated_bounds.Offset(guest_window_rect_.OffsetFromOrigin()); |
798 BrowserPluginPopupMenuHelper popup_menu_helper( | 798 BrowserPluginPopupMenuHelper popup_menu_helper( |
799 embedder_web_contents_->GetRenderViewHost(), render_frame_host); | 799 embedder_web_contents_->GetRenderViewHost(), render_frame_host); |
800 popup_menu_helper.ShowPopupMenu(translated_bounds, | 800 popup_menu_helper.ShowPopupMenu(translated_bounds, |
801 params.item_height, | 801 params.item_height, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 837 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
838 const gfx::Range& range, | 838 const gfx::Range& range, |
839 const std::vector<gfx::Rect>& character_bounds) { | 839 const std::vector<gfx::Rect>& character_bounds) { |
840 static_cast<RenderWidgetHostViewBase*>( | 840 static_cast<RenderWidgetHostViewBase*>( |
841 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 841 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
842 range, character_bounds); | 842 range, character_bounds); |
843 } | 843 } |
844 #endif | 844 #endif |
845 | 845 |
846 } // namespace content | 846 } // namespace content |
OLD | NEW |