Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 336283002: Remove GuestWebContentsCreated (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_creation
Patch Set: Fix diff Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 241
231 BrowserPluginGuest::~BrowserPluginGuest() { 242 BrowserPluginGuest::~BrowserPluginGuest() {
232 } 243 }
233 244
234 // static 245 // static
235 BrowserPluginGuest* BrowserPluginGuest::Create( 246 BrowserPluginGuest* BrowserPluginGuest::Create(
236 int instance_id, 247 int instance_id,
237 SiteInstance* guest_site_instance,
238 WebContentsImpl* web_contents, 248 WebContentsImpl* web_contents,
239 scoped_ptr<base::DictionaryValue> extra_params, 249 BrowserPluginGuestDelegate* delegate) {
240 BrowserPluginGuest* opener) { 250 return new BrowserPluginGuest(
241 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 251 instance_id, web_contents->opener() != NULL, web_contents, delegate);
242 BrowserPluginGuest* guest = new BrowserPluginGuest(
243 instance_id, web_contents->opener() != NULL, web_contents);
244 web_contents->SetBrowserPluginGuest(guest);
245 WebContents* opener_web_contents = NULL;
246 if (opener) {
247 opener_web_contents = opener->GetWebContents();
248 guest_site_instance = opener_web_contents->GetSiteInstance();
249 }
250 BrowserPluginGuestDelegate* delegate = NULL;
251 GetContentClient()->browser()->GuestWebContentsCreated(
252 instance_id,
253 guest_site_instance,
254 web_contents,
255 opener_web_contents,
256 &delegate,
257 extra_params.Pass());
258 if (delegate) {
259 delegate->RegisterDestructionCallback(
260 base::Bind(&BrowserPluginGuest::WillDestroy,
261 base::Unretained(guest)));
262 guest->set_delegate(delegate);
263 }
264 return guest;
265 } 252 }
266 253
267 // static 254 // static
268 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) { 255 bool BrowserPluginGuest::IsGuest(WebContentsImpl* web_contents) {
269 return web_contents && web_contents->GetBrowserPluginGuest(); 256 return web_contents && web_contents->GetBrowserPluginGuest();
270 } 257 }
271 258
272 // static 259 // static
273 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { 260 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
274 return render_view_host && IsGuest( 261 return render_view_host && IsGuest(
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 void BrowserPluginGuest::OnLockMouse(bool user_gesture, 633 void BrowserPluginGuest::OnLockMouse(bool user_gesture,
647 bool last_unlocked_by_target, 634 bool last_unlocked_by_target,
648 bool privileged) { 635 bool privileged) {
649 if (pending_lock_request_) { 636 if (pending_lock_request_) {
650 // Immediately reject the lock because only one pointerLock may be active 637 // Immediately reject the lock because only one pointerLock may be active
651 // at a time. 638 // at a time.
652 Send(new ViewMsg_LockMouse_ACK(routing_id(), false)); 639 Send(new ViewMsg_LockMouse_ACK(routing_id(), false));
653 return; 640 return;
654 } 641 }
655 642
656 if (!delegate_)
657 return;
658
659 pending_lock_request_ = true; 643 pending_lock_request_ = true;
660 644
661 delegate_->RequestPointerLockPermission( 645 delegate_->RequestPointerLockPermission(
662 user_gesture, 646 user_gesture,
663 last_unlocked_by_target, 647 last_unlocked_by_target,
664 base::Bind(&BrowserPluginGuest::PointerLockPermissionResponse, 648 base::Bind(&BrowserPluginGuest::PointerLockPermissionResponse,
665 weak_ptr_factory_.GetWeakPtr())); 649 weak_ptr_factory_.GetWeakPtr()));
666 } 650 }
667 651
668 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) { 652 void BrowserPluginGuest::OnLockMouseAck(int instance_id, bool succeeded) {
(...skipping 22 matching lines...) Expand all
691 render_widget_host->ResetSizeAndRepaintPendingFlags(); 675 render_widget_host->ResetSizeAndRepaintPendingFlags();
692 676
693 if (guest_device_scale_factor_ != params.scale_factor) { 677 if (guest_device_scale_factor_ != params.scale_factor) {
694 guest_device_scale_factor_ = params.scale_factor; 678 guest_device_scale_factor_ = params.scale_factor;
695 render_widget_host->NotifyScreenInfoChanged(); 679 render_widget_host->NotifyScreenInfoChanged();
696 } 680 }
697 } 681 }
698 // When autosize is turned off and as a result there is a layout change, we 682 // When autosize is turned off and as a result there is a layout change, we
699 // send a sizechanged event. 683 // send a sizechanged event.
700 if (!auto_size_enabled_ && last_seen_auto_size_enabled_ && 684 if (!auto_size_enabled_ && last_seen_auto_size_enabled_ &&
701 !params.view_size.IsEmpty() && delegate_) { 685 !params.view_size.IsEmpty()) {
702 delegate_->SizeChanged(last_seen_view_size_, params.view_size); 686 delegate_->SizeChanged(last_seen_view_size_, params.view_size);
703 last_seen_auto_size_enabled_ = false; 687 last_seen_auto_size_enabled_ = false;
704 } 688 }
705 // Just resize the WebContents and repaint if needed. 689 // Just resize the WebContents and repaint if needed.
706 full_size_ = params.view_size; 690 full_size_ = params.view_size;
707 if (!params.view_size.IsEmpty()) 691 if (!params.view_size.IsEmpty())
708 GetWebContents()->GetView()->SizeContents(params.view_size); 692 GetWebContents()->GetView()->SizeContents(params.view_size);
709 if (params.repaint) 693 if (params.repaint)
710 Send(new ViewMsg_Repaint(routing_id(), params.view_size)); 694 Send(new ViewMsg_Repaint(routing_id(), params.view_size));
711 } 695 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 relay_params.view_size = params.view_size; 843 relay_params.view_size = params.view_size;
860 relay_params.scale_factor = params.scale_factor; 844 relay_params.scale_factor = params.scale_factor;
861 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack( 845 relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
862 params.flags); 846 params.flags);
863 847
864 bool size_changed = last_seen_view_size_ != params.view_size; 848 bool size_changed = last_seen_view_size_ != params.view_size;
865 gfx::Size old_size = last_seen_view_size_; 849 gfx::Size old_size = last_seen_view_size_;
866 last_seen_view_size_ = params.view_size; 850 last_seen_view_size_ = params.view_size;
867 851
868 if ((auto_size_enabled_ || last_seen_auto_size_enabled_) && 852 if ((auto_size_enabled_ || last_seen_auto_size_enabled_) &&
869 size_changed && delegate_) { 853 size_changed) {
870 delegate_->SizeChanged(old_size, last_seen_view_size_); 854 delegate_->SizeChanged(old_size, last_seen_view_size_);
871 } 855 }
872 last_seen_auto_size_enabled_ = auto_size_enabled_; 856 last_seen_auto_size_enabled_ = auto_size_enabled_;
873 857
874 SendMessageToEmbedder( 858 SendMessageToEmbedder(
875 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params)); 859 new BrowserPluginMsg_UpdateRect(instance_id(), relay_params));
876 } 860 }
877 861
878 void BrowserPluginGuest::OnTextInputStateChanged( 862 void BrowserPluginGuest::OnTextInputStateChanged(
879 const ViewHostMsg_TextInputState_Params& params) { 863 const ViewHostMsg_TextInputState_Params& params) {
(...skipping 15 matching lines...) Expand all
895 void BrowserPluginGuest::OnImeCompositionRangeChanged( 879 void BrowserPluginGuest::OnImeCompositionRangeChanged(
896 const gfx::Range& range, 880 const gfx::Range& range,
897 const std::vector<gfx::Rect>& character_bounds) { 881 const std::vector<gfx::Rect>& character_bounds) {
898 static_cast<RenderWidgetHostViewBase*>( 882 static_cast<RenderWidgetHostViewBase*>(
899 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 883 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
900 range, character_bounds); 884 range, character_bounds);
901 } 885 }
902 #endif 886 #endif
903 887
904 } // namespace content 888 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698