| 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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 BrowserPluginGuest* browser_plugin_guest_; | 63 BrowserPluginGuest* browser_plugin_guest_; |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); | 65 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 BrowserPluginGuest::BrowserPluginGuest( | 68 BrowserPluginGuest::BrowserPluginGuest( |
| 69 int instance_id, | 69 int instance_id, |
| 70 bool has_render_view, | 70 bool has_render_view, |
| 71 WebContentsImpl* web_contents) | 71 WebContentsImpl* web_contents, |
| 72 BrowserPluginGuestDelegate* delegate) |
| 72 : WebContentsObserver(web_contents), | 73 : WebContentsObserver(web_contents), |
| 73 embedder_web_contents_(NULL), | 74 embedder_web_contents_(NULL), |
| 74 instance_id_(instance_id), | 75 instance_id_(instance_id), |
| 75 guest_device_scale_factor_(1.0f), | 76 guest_device_scale_factor_(1.0f), |
| 76 focused_(false), | 77 focused_(false), |
| 77 mouse_locked_(false), | 78 mouse_locked_(false), |
| 78 pending_lock_request_(false), | 79 pending_lock_request_(false), |
| 79 guest_visible_(false), | 80 guest_visible_(false), |
| 80 guest_opaque_(true), | 81 guest_opaque_(true), |
| 81 embedder_visible_(true), | 82 embedder_visible_(true), |
| 82 auto_size_enabled_(false), | 83 auto_size_enabled_(false), |
| 83 copy_request_id_(0), | 84 copy_request_id_(0), |
| 84 has_render_view_(has_render_view), | 85 has_render_view_(has_render_view), |
| 85 last_seen_auto_size_enabled_(false), | 86 last_seen_auto_size_enabled_(false), |
| 86 is_in_destruction_(false), | 87 is_in_destruction_(false), |
| 87 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 88 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 88 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 89 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
| 89 last_can_compose_inline_(true), | 90 last_can_compose_inline_(true), |
| 90 delegate_(NULL), | 91 delegate_(delegate), |
| 91 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
| 92 DCHECK(web_contents); | 93 DCHECK(web_contents); |
| 94 DCHECK(delegate); |
| 95 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
| 96 web_contents->SetBrowserPluginGuest(this); |
| 97 delegate->RegisterDestructionCallback( |
| 98 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); |
| 93 } | 99 } |
| 94 | 100 |
| 95 void BrowserPluginGuest::WillDestroy() { | 101 void BrowserPluginGuest::WillDestroy() { |
| 96 is_in_destruction_ = true; | 102 is_in_destruction_ = true; |
| 97 embedder_web_contents_ = NULL; | 103 embedder_web_contents_ = NULL; |
| 98 delegate_ = NULL; | |
| 99 } | 104 } |
| 100 | 105 |
| 101 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { | 106 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
| 102 return weak_ptr_factory_.GetWeakPtr(); | 107 return weak_ptr_factory_.GetWeakPtr(); |
| 103 } | 108 } |
| 104 | 109 |
| 105 bool BrowserPluginGuest::LockMouse(bool allowed) { | 110 bool BrowserPluginGuest::LockMouse(bool allowed) { |
| 106 if (!attached() || (mouse_locked_ == allowed)) | 111 if (!attached() || (mouse_locked_ == allowed)) |
| 107 return false; | 112 return false; |
| 108 | 113 |
| 109 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); | 114 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); |
| 110 } | 115 } |
| 111 | 116 |
| 112 void BrowserPluginGuest::Destroy() { | 117 void BrowserPluginGuest::Destroy() { |
| 113 if (!delegate_) | |
| 114 return; | |
| 115 delegate_->Destroy(); | 118 delegate_->Destroy(); |
| 116 } | 119 } |
| 117 | 120 |
| 121 WebContentsImpl* BrowserPluginGuest::CreateNewGuestWindow( |
| 122 const WebContents::CreateParams& params) { |
| 123 WebContentsImpl* new_contents = |
| 124 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); |
| 125 DCHECK(new_contents); |
| 126 return new_contents; |
| 127 } |
| 128 |
| 118 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 129 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
| 119 const IPC::Message& message) { | 130 const IPC::Message& message) { |
| 120 bool handled = true; | 131 bool handled = true; |
| 121 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 132 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 122 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, | 133 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, |
| 123 OnCompositorFrameSwappedACK) | 134 OnCompositorFrameSwappedACK) |
| 124 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck, | 135 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck, |
| 125 OnCopyFromCompositingSurfaceAck) | 136 OnCopyFromCompositingSurfaceAck) |
| 126 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 137 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
| 127 OnDragStatusUpdate) | 138 OnDragStatusUpdate) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 if (static_cast<RenderViewHostImpl*>( | 231 if (static_cast<RenderViewHostImpl*>( |
| 221 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { | 232 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { |
| 222 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 233 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 223 GetWebContents()->GetRenderViewHost()); | 234 GetWebContents()->GetRenderViewHost()); |
| 224 guest_rvh->SetInputMethodActive(true); | 235 guest_rvh->SetInputMethodActive(true); |
| 225 } | 236 } |
| 226 | 237 |
| 227 // Inform the embedder of the guest's attachment. | 238 // Inform the embedder of the guest's attachment. |
| 228 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_)); | 239 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_)); |
| 229 | 240 |
| 230 if (delegate_) { | 241 delegate_->DidAttach(embedder_web_contents, extra_params); |
| 231 delegate_->DidAttach(embedder_web_contents, extra_params); | 242 has_render_view_ = true; |
| 232 has_render_view_ = true; | |
| 233 } | |
| 234 } | 243 } |
| 235 | 244 |
| 236 BrowserPluginGuest::~BrowserPluginGuest() { | 245 BrowserPluginGuest::~BrowserPluginGuest() { |
| 237 } | 246 } |
| 238 | 247 |
| 239 // static | 248 // static |
| 240 BrowserPluginGuest* BrowserPluginGuest::Create( | 249 BrowserPluginGuest* BrowserPluginGuest::Create( |
| 241 int instance_id, | 250 int instance_id, |
| 242 SiteInstance* guest_site_instance, | |
| 243 WebContentsImpl* web_contents, | 251 WebContentsImpl* web_contents, |
| 244 scoped_ptr<base::DictionaryValue> extra_params, | 252 BrowserPluginGuestDelegate* delegate) { |
| 245 BrowserPluginGuest* opener) { | 253 return new BrowserPluginGuest( |
| 246 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 254 instance_id, web_contents->opener() != NULL, web_contents, delegate); |
| 247 BrowserPluginGuest* guest = new BrowserPluginGuest( | |
| 248 instance_id, web_contents->opener() != NULL, web_contents); | |
| 249 web_contents->SetBrowserPluginGuest(guest); | |
| 250 WebContents* opener_web_contents = NULL; | |
| 251 if (opener) { | |
| 252 opener_web_contents = opener->GetWebContents(); | |
| 253 guest_site_instance = opener_web_contents->GetSiteInstance(); | |
| 254 } | |
| 255 BrowserPluginGuestDelegate* delegate = NULL; | |
| 256 GetContentClient()->browser()->GuestWebContentsCreated( | |
| 257 instance_id, | |
| 258 guest_site_instance, | |
| 259 web_contents, | |
| 260 opener_web_contents, | |
| 261 &delegate, | |
| 262 extra_params.Pass()); | |
| 263 if (delegate) { | |
| 264 delegate->RegisterDestructionCallback( | |
| 265 base::Bind(&BrowserPluginGuest::WillDestroy, | |
| 266 base::Unretained(guest))); | |
| 267 guest->set_delegate(delegate); | |
| 268 } | |
| 269 return guest; | |
| 270 } | 255 } |
| 271 | 256 |
| 272 // static | 257 // static |
| 273 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { | 258 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { |
| 274 return web_contents && web_contents->GetBrowserPluginGuest(); | 259 return web_contents && web_contents->GetBrowserPluginGuest(); |
| 275 } | 260 } |
| 276 | 261 |
| 277 // static | 262 // static |
| 278 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { | 263 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { |
| 279 return render_view_host && IsGuest( | 264 return render_view_host && IsGuest( |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 void BrowserPluginGuest::OnLockMouse(bool user_gesture, | 630 void BrowserPluginGuest::OnLockMouse(bool user_gesture, |
| 646 bool last_unlocked_by_target, | 631 bool last_unlocked_by_target, |
| 647 bool privileged) { | 632 bool privileged) { |
| 648 if (pending_lock_request_) { | 633 if (pending_lock_request_) { |
| 649 // Immediately reject the lock because only one pointerLock may be active | 634 // Immediately reject the lock because only one pointerLock may be active |
| 650 // at a time. | 635 // at a time. |
| 651 Send(new ViewMsg_LockMouse_ACK(routing_id(), false)); | 636 Send(new ViewMsg_LockMouse_ACK(routing_id(), false)); |
| 652 return; | 637 return; |
| 653 } | 638 } |
| 654 | 639 |
| 655 if (!delegate_) | |
| 656 return; | |
| 657 | |
| 658 pending_lock_request_ = true; | 640 pending_lock_request_ = true; |
| 659 | 641 |
| 660 delegate_->RequestPointerLockPermission( | 642 delegate_->RequestPointerLockPermission( |
| 661 user_gesture, | 643 user_gesture, |
| 662 last_unlocked_by_target, | 644 last_unlocked_by_target, |
| 663 base::Bind(&BrowserPluginGuest::PointerLockPermissionResponse, | 645 base::Bind(&BrowserPluginGuest::PointerLockPermissionResponse, |
| 664 weak_ptr_factory_.GetWeakPtr())); | 646 weak_ptr_factory_.GetWeakPtr())); |
| 665 } | 647 } |
| 666 | 648 |
| 667 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { | 649 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 690 render_widget_host->ResetSizeAndRepaintPendingFlags(); | 672 render_widget_host->ResetSizeAndRepaintPendingFlags(); |
| 691 | 673 |
| 692 if (guest_device_scale_factor_ != params.scale_factor) { | 674 if (guest_device_scale_factor_ != params.scale_factor) { |
| 693 guest_device_scale_factor_ = params.scale_factor; | 675 guest_device_scale_factor_ = params.scale_factor; |
| 694 render_widget_host->NotifyScreenInfoChanged(); | 676 render_widget_host->NotifyScreenInfoChanged(); |
| 695 } | 677 } |
| 696 } | 678 } |
| 697 // When autosize is turned off and as a result there is a layout change, we | 679 // When autosize is turned off and as a result there is a layout change, we |
| 698 // send a sizechanged event. | 680 // send a sizechanged event. |
| 699 if (!auto_size_enabled_ && last_seen_auto_size_enabled_ && | 681 if (!auto_size_enabled_ && last_seen_auto_size_enabled_ && |
| 700 !params.view_size.IsEmpty() && delegate_) { | 682 !params.view_size.IsEmpty()) { |
| 701 delegate_->SizeChanged(last_seen_view_size_, params.view_size); | 683 delegate_->SizeChanged(last_seen_view_size_, params.view_size); |
| 702 last_seen_auto_size_enabled_ = false; | 684 last_seen_auto_size_enabled_ = false; |
| 703 } | 685 } |
| 704 // Just resize the WebContents and repaint if needed. | 686 // Just resize the WebContents and repaint if needed. |
| 705 full_size_ = params.view_size; | 687 full_size_ = params.view_size; |
| 706 if (!params.view_size.IsEmpty()) | 688 if (!params.view_size.IsEmpty()) |
| 707 GetWebContents()->GetView()->SizeContents(params.view_size); | 689 GetWebContents()->GetView()->SizeContents(params.view_size); |
| 708 if (params.repaint) | 690 if (params.repaint) |
| 709 Send(new ViewMsg_Repaint(routing_id(), params.view_size)); | 691 Send(new ViewMsg_Repaint(routing_id(), params.view_size)); |
| 710 } | 692 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 relay_params.view_size = params.view_size; | 840 relay_params.view_size = params.view_size; |
| 859 relay_params.scale_factor = params.scale_factor; | 841 relay_params.scale_factor = params.scale_factor; |
| 860 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( | 842 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( |
| 861 params.flags); | 843 params.flags); |
| 862 | 844 |
| 863 bool size_changed = last_seen_view_size_ != params.view_size; | 845 bool size_changed = last_seen_view_size_ != params.view_size; |
| 864 gfx::Size old_size = last_seen_view_size_; | 846 gfx::Size old_size = last_seen_view_size_; |
| 865 last_seen_view_size_ = params.view_size; | 847 last_seen_view_size_ = params.view_size; |
| 866 | 848 |
| 867 if ((auto_size_enabled_ || last_seen_auto_size_enabled_) && | 849 if ((auto_size_enabled_ || last_seen_auto_size_enabled_) && |
| 868 size_changed && delegate_) { | 850 size_changed) { |
| 869 delegate_->SizeChanged(old_size, last_seen_view_size_); | 851 delegate_->SizeChanged(old_size, last_seen_view_size_); |
| 870 } | 852 } |
| 871 last_seen_auto_size_enabled_ = auto_size_enabled_; | 853 last_seen_auto_size_enabled_ = auto_size_enabled_; |
| 872 | 854 |
| 873 SendMessageToEmbedder( | 855 SendMessageToEmbedder( |
| 874 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); | 856 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); |
| 875 } | 857 } |
| 876 | 858 |
| 877 void BrowserPluginGuest::OnTextInputStateChanged( | 859 void BrowserPluginGuest::OnTextInputStateChanged( |
| 878 const ViewHostMsg_TextInputState_Params& params) { | 860 const ViewHostMsg_TextInputState_Params& params) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 894 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 876 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
| 895 const gfx::Range& range, | 877 const gfx::Range& range, |
| 896 const std::vector<gfx::Rect>& character_bounds) { | 878 const std::vector<gfx::Rect>& character_bounds) { |
| 897 static_cast<RenderWidgetHostViewBase*>( | 879 static_cast<RenderWidgetHostViewBase*>( |
| 898 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 880 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
| 899 range, character_bounds); | 881 range, character_bounds); |
| 900 } | 882 } |
| 901 #endif | 883 #endif |
| 902 | 884 |
| 903 } // namespace content | 885 } // namespace content |
| OLD | NEW |