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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 : WebContentsObserver(web_contents), | 74 : WebContentsObserver(web_contents), |
75 embedder_web_contents_(NULL), | 75 embedder_web_contents_(NULL), |
76 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), | 76 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
77 guest_device_scale_factor_(1.0f), | 77 guest_device_scale_factor_(1.0f), |
78 focused_(false), | 78 focused_(false), |
79 mouse_locked_(false), | 79 mouse_locked_(false), |
80 pending_lock_request_(false), | 80 pending_lock_request_(false), |
81 guest_visible_(false), | 81 guest_visible_(false), |
82 embedder_visible_(true), | 82 embedder_visible_(true), |
83 is_full_page_plugin_(false), | 83 is_full_page_plugin_(false), |
84 copy_request_id_(0), | |
85 has_render_view_(has_render_view), | 84 has_render_view_(has_render_view), |
86 is_in_destruction_(false), | 85 is_in_destruction_(false), |
87 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 86 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
88 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 87 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
89 last_input_flags_(0), | 88 last_input_flags_(0), |
90 last_can_compose_inline_(true), | 89 last_can_compose_inline_(true), |
91 guest_proxy_routing_id_(MSG_ROUTING_NONE), | 90 guest_proxy_routing_id_(MSG_ROUTING_NONE), |
92 delegate_(delegate), | 91 delegate_(delegate), |
93 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
94 DCHECK(web_contents); | 93 DCHECK(web_contents); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 message, | 158 message, |
160 static_cast<RenderViewHostImpl*>( | 159 static_cast<RenderViewHostImpl*>( |
161 embedder_web_contents()->GetRenderViewHost()))) { | 160 embedder_web_contents()->GetRenderViewHost()))) { |
162 return true; | 161 return true; |
163 } | 162 } |
164 | 163 |
165 bool handled = true; | 164 bool handled = true; |
166 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 165 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
167 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, | 166 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, |
168 OnCompositorFrameSwappedACK) | 167 OnCompositorFrameSwappedACK) |
169 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck, | |
170 OnCopyFromCompositingSurfaceAck) | |
171 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 168 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
172 OnDragStatusUpdate) | 169 OnDragStatusUpdate) |
173 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, | 170 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, |
174 OnExecuteEditCommand) | 171 OnExecuteEditCommand) |
175 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, | 172 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, |
176 OnExtendSelectionAndDelete) | 173 OnExtendSelectionAndDelete) |
177 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, | 174 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, |
178 OnImeConfirmComposition) | 175 OnImeConfirmComposition) |
179 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, | 176 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, |
180 OnImeSetComposition) | 177 OnImeSetComposition) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { | 283 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { |
287 if (!attached()) | 284 if (!attached()) |
288 return NULL; | 285 return NULL; |
289 return embedder_web_contents_->GetRenderWidgetHostView(); | 286 return embedder_web_contents_->GetRenderWidgetHostView(); |
290 } | 287 } |
291 | 288 |
292 void BrowserPluginGuest::UpdateVisibility() { | 289 void BrowserPluginGuest::UpdateVisibility() { |
293 OnSetVisibility(browser_plugin_instance_id(), visible()); | 290 OnSetVisibility(browser_plugin_instance_id(), visible()); |
294 } | 291 } |
295 | 292 |
296 void BrowserPluginGuest::CopyFromCompositingSurface( | |
297 gfx::Rect src_subrect, | |
298 gfx::Size dst_size, | |
299 const base::Callback<void(bool, const SkBitmap&)>& callback) { | |
300 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); | |
301 SendMessageToEmbedder( | |
302 new BrowserPluginMsg_CopyFromCompositingSurface( | |
303 browser_plugin_instance_id(), | |
304 copy_request_id_, | |
305 src_subrect, | |
306 dst_size)); | |
307 } | |
308 | |
309 BrowserPluginGuestManager* | 293 BrowserPluginGuestManager* |
310 BrowserPluginGuest::GetBrowserPluginGuestManager() const { | 294 BrowserPluginGuest::GetBrowserPluginGuestManager() const { |
311 return GetWebContents()->GetBrowserContext()->GetGuestManager(); | 295 return GetWebContents()->GetBrowserContext()->GetGuestManager(); |
312 } | 296 } |
313 | 297 |
314 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { | 298 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
315 embedder_visible_ = visible; | 299 embedder_visible_ = visible; |
316 UpdateVisibility(); | 300 UpdateVisibility(); |
317 } | 301 } |
318 | 302 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 default: | 435 default: |
452 break; | 436 break; |
453 } | 437 } |
454 } | 438 } |
455 | 439 |
456 // static | 440 // static |
457 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( | 441 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( |
458 const IPC::Message& message) { | 442 const IPC::Message& message) { |
459 switch (message.type()) { | 443 switch (message.type()) { |
460 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: | 444 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: |
461 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID: | |
462 case BrowserPluginHostMsg_DragStatusUpdate::ID: | 445 case BrowserPluginHostMsg_DragStatusUpdate::ID: |
463 case BrowserPluginHostMsg_ExecuteEditCommand::ID: | 446 case BrowserPluginHostMsg_ExecuteEditCommand::ID: |
464 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: | 447 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: |
465 case BrowserPluginHostMsg_HandleInputEvent::ID: | 448 case BrowserPluginHostMsg_HandleInputEvent::ID: |
466 case BrowserPluginHostMsg_ImeConfirmComposition::ID: | 449 case BrowserPluginHostMsg_ImeConfirmComposition::ID: |
467 case BrowserPluginHostMsg_ImeSetComposition::ID: | 450 case BrowserPluginHostMsg_ImeSetComposition::ID: |
468 case BrowserPluginHostMsg_LockMouse_ACK::ID: | 451 case BrowserPluginHostMsg_LockMouse_ACK::ID: |
469 case BrowserPluginHostMsg_ReclaimCompositorResources::ID: | 452 case BrowserPluginHostMsg_ReclaimCompositorResources::ID: |
470 case BrowserPluginHostMsg_ResizeGuest::ID: | 453 case BrowserPluginHostMsg_ResizeGuest::ID: |
471 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: | 454 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 | 718 |
736 void BrowserPluginGuest::OnUnlockMouseAck(int browser_plugin_instance_id) { | 719 void BrowserPluginGuest::OnUnlockMouseAck(int browser_plugin_instance_id) { |
737 // mouse_locked_ could be false here if the lock attempt was cancelled due | 720 // mouse_locked_ could be false here if the lock attempt was cancelled due |
738 // to window focus, or for various other reasons before the guest was informed | 721 // to window focus, or for various other reasons before the guest was informed |
739 // of the lock's success. | 722 // of the lock's success. |
740 if (mouse_locked_) | 723 if (mouse_locked_) |
741 Send(new ViewMsg_MouseLockLost(routing_id())); | 724 Send(new ViewMsg_MouseLockLost(routing_id())); |
742 mouse_locked_ = false; | 725 mouse_locked_ = false; |
743 } | 726 } |
744 | 727 |
745 void BrowserPluginGuest::OnCopyFromCompositingSurfaceAck( | |
746 int browser_plugin_instance_id, | |
747 int request_id, | |
748 const SkBitmap& bitmap) { | |
749 CHECK(copy_request_callbacks_.count(request_id)); | |
750 if (!copy_request_callbacks_.count(request_id)) | |
751 return; | |
752 const CopyRequestCallback& callback = copy_request_callbacks_[request_id]; | |
753 callback.Run(!bitmap.empty() && !bitmap.isNull(), bitmap); | |
754 copy_request_callbacks_.erase(request_id); | |
755 } | |
756 | |
757 void BrowserPluginGuest::OnUpdateGeometry(int browser_plugin_instance_id, | 728 void BrowserPluginGuest::OnUpdateGeometry(int browser_plugin_instance_id, |
758 const gfx::Rect& view_rect) { | 729 const gfx::Rect& view_rect) { |
759 // The plugin has moved within the embedder without resizing or the | 730 // The plugin has moved within the embedder without resizing or the |
760 // embedder/container's view rect changing. | 731 // embedder/container's view rect changing. |
761 guest_window_rect_ = view_rect; | 732 guest_window_rect_ = view_rect; |
762 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 733 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
763 GetWebContents()->GetRenderViewHost()); | 734 GetWebContents()->GetRenderViewHost()); |
764 if (rvh) | 735 if (rvh) |
765 rvh->SendScreenRects(); | 736 rvh->SendScreenRects(); |
766 } | 737 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 794 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
824 const gfx::Range& range, | 795 const gfx::Range& range, |
825 const std::vector<gfx::Rect>& character_bounds) { | 796 const std::vector<gfx::Rect>& character_bounds) { |
826 static_cast<RenderWidgetHostViewBase*>( | 797 static_cast<RenderWidgetHostViewBase*>( |
827 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 798 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
828 range, character_bounds); | 799 range, character_bounds); |
829 } | 800 } |
830 #endif | 801 #endif |
831 | 802 |
832 } // namespace content | 803 } // namespace content |
OLD | NEW |