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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 mouse_locked_(false), | 80 mouse_locked_(false), |
81 pending_lock_request_(false), | 81 pending_lock_request_(false), |
82 guest_visible_(false), | 82 guest_visible_(false), |
83 embedder_visible_(true), | 83 embedder_visible_(true), |
84 copy_request_id_(0), | 84 copy_request_id_(0), |
85 has_render_view_(has_render_view), | 85 has_render_view_(has_render_view), |
86 is_in_destruction_(false), | 86 is_in_destruction_(false), |
87 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 87 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
88 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 88 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
89 last_can_compose_inline_(true), | 89 last_can_compose_inline_(true), |
| 90 guest_proxy_routing_id_(MSG_ROUTING_NONE), |
90 delegate_(delegate), | 91 delegate_(delegate), |
91 weak_ptr_factory_(this) { | 92 weak_ptr_factory_(this) { |
92 DCHECK(web_contents); | 93 DCHECK(web_contents); |
93 DCHECK(delegate); | 94 DCHECK(delegate); |
94 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 95 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
95 web_contents->SetBrowserPluginGuest(this); | 96 web_contents->SetBrowserPluginGuest(this); |
96 delegate->RegisterDestructionCallback( | 97 delegate->RegisterDestructionCallback( |
97 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); | 98 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); |
98 } | 99 } |
99 | 100 |
(...skipping 27 matching lines...) Expand all Loading... |
127 } | 128 } |
128 } | 129 } |
129 | 130 |
130 bool BrowserPluginGuest::LockMouse(bool allowed) { | 131 bool BrowserPluginGuest::LockMouse(bool allowed) { |
131 if (!attached() || (mouse_locked_ == allowed)) | 132 if (!attached() || (mouse_locked_ == allowed)) |
132 return false; | 133 return false; |
133 | 134 |
134 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); | 135 return embedder_web_contents()->GotResponseToLockMouseRequest(allowed); |
135 } | 136 } |
136 | 137 |
137 void BrowserPluginGuest::Destroy() { | |
138 delegate_->Destroy(); | |
139 } | |
140 | |
141 WebContentsImpl* BrowserPluginGuest::CreateNewGuestWindow( | 138 WebContentsImpl* BrowserPluginGuest::CreateNewGuestWindow( |
142 const WebContents::CreateParams& params) { | 139 const WebContents::CreateParams& params) { |
143 WebContentsImpl* new_contents = | 140 WebContentsImpl* new_contents = |
144 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); | 141 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); |
145 DCHECK(new_contents); | 142 DCHECK(new_contents); |
146 return new_contents; | 143 return new_contents; |
147 } | 144 } |
148 | 145 |
149 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 146 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
150 const IPC::Message& message) { | 147 const IPC::Message& message) { |
(...skipping 17 matching lines...) Expand all Loading... |
168 OnDragStatusUpdate) | 165 OnDragStatusUpdate) |
169 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, | 166 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, |
170 OnExecuteEditCommand) | 167 OnExecuteEditCommand) |
171 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, | 168 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExtendSelectionAndDelete, |
172 OnExtendSelectionAndDelete) | 169 OnExtendSelectionAndDelete) |
173 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, | 170 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeConfirmComposition, |
174 OnImeConfirmComposition) | 171 OnImeConfirmComposition) |
175 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, | 172 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ImeSetComposition, |
176 OnImeSetComposition) | 173 OnImeSetComposition) |
177 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) | 174 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_LockMouse_ACK, OnLockMouseAck) |
178 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, OnPluginDestroyed) | |
179 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, | 175 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ReclaimCompositorResources, |
180 OnReclaimCompositorResources) | 176 OnReclaimCompositorResources) |
181 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) | 177 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) |
182 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, | 178 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent, |
183 OnSetEditCommandsForNextKeyEvent) | 179 OnSetEditCommandsForNextKeyEvent) |
184 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) | 180 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) |
185 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 181 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
186 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) | 182 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
187 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) | 183 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
188 IPC_MESSAGE_UNHANDLED(handled = false) | 184 IPC_MESSAGE_UNHANDLED(handled = false) |
189 IPC_END_MESSAGE_MAP() | 185 IPC_END_MESSAGE_MAP() |
190 return handled; | 186 return handled; |
191 } | 187 } |
192 | 188 |
193 void BrowserPluginGuest::Initialize( | 189 void BrowserPluginGuest::Initialize( |
194 int browser_plugin_instance_id, | 190 int browser_plugin_instance_id, |
195 const BrowserPluginHostMsg_Attach_Params& params, | 191 const BrowserPluginHostMsg_Attach_Params& params, |
196 WebContentsImpl* embedder_web_contents) { | 192 WebContentsImpl* embedder_web_contents) { |
197 browser_plugin_instance_id_ = browser_plugin_instance_id; | 193 browser_plugin_instance_id_ = browser_plugin_instance_id; |
198 focused_ = params.focused; | 194 focused_ = params.focused; |
199 guest_visible_ = params.visible; | 195 guest_visible_ = params.visible; |
200 guest_window_rect_ = gfx::Rect(params.origin, | 196 guest_window_rect_ = gfx::Rect(params.origin, |
201 params.resize_guest_params.view_size); | 197 params.resize_guest_params.view_size); |
202 | 198 |
| 199 WebContentsViewGuest* new_view = |
| 200 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
| 201 if (attached()) |
| 202 new_view->OnGuestDetached(embedder_web_contents_->GetView()); |
| 203 |
203 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 204 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
204 // be attached. | 205 // be attached. |
205 embedder_web_contents_ = embedder_web_contents; | 206 embedder_web_contents_ = embedder_web_contents; |
206 | 207 new_view->OnGuestAttached(embedder_web_contents->GetView()); |
207 WebContentsViewGuest* new_view = | |
208 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | |
209 new_view->OnGuestInitialized(embedder_web_contents->GetView()); | |
210 | 208 |
211 RendererPreferences* renderer_prefs = | 209 RendererPreferences* renderer_prefs = |
212 GetWebContents()->GetMutableRendererPrefs(); | 210 GetWebContents()->GetMutableRendererPrefs(); |
213 std::string guest_user_agent_override = renderer_prefs->user_agent_override; | 211 std::string guest_user_agent_override = renderer_prefs->user_agent_override; |
214 // Copy renderer preferences (and nothing else) from the embedder's | 212 // Copy renderer preferences (and nothing else) from the embedder's |
215 // WebContents to the guest. | 213 // WebContents to the guest. |
216 // | 214 // |
217 // For GTK and Aura this is necessary to get proper renderer configuration | 215 // For GTK and Aura this is necessary to get proper renderer configuration |
218 // values for caret blinking interval, colors related to selection and | 216 // values for caret blinking interval, colors related to selection and |
219 // focus. | 217 // focus. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 if (last_seen_view_size_ != view_size) { | 327 if (last_seen_view_size_ != view_size) { |
330 delegate_->GuestSizeChanged(last_seen_view_size_, view_size); | 328 delegate_->GuestSizeChanged(last_seen_view_size_, view_size); |
331 last_seen_view_size_ = view_size; | 329 last_seen_view_size_ = view_size; |
332 } | 330 } |
333 | 331 |
334 FrameMsg_CompositorFrameSwapped_Params guest_params; | 332 FrameMsg_CompositorFrameSwapped_Params guest_params; |
335 frame->AssignTo(&guest_params.frame); | 333 frame->AssignTo(&guest_params.frame); |
336 guest_params.output_surface_id = output_surface_id; | 334 guest_params.output_surface_id = output_surface_id; |
337 guest_params.producing_route_id = host_routing_id; | 335 guest_params.producing_route_id = host_routing_id; |
338 guest_params.producing_host_id = host_process_id; | 336 guest_params.producing_host_id = host_process_id; |
339 | |
340 SendMessageToEmbedder( | 337 SendMessageToEmbedder( |
341 new BrowserPluginMsg_CompositorFrameSwapped( | 338 new BrowserPluginMsg_CompositorFrameSwapped( |
342 browser_plugin_instance_id(), guest_params)); | 339 browser_plugin_instance_id(), guest_params)); |
343 } | 340 } |
344 | 341 |
345 void BrowserPluginGuest::SetContentsOpaque(bool opaque) { | 342 void BrowserPluginGuest::SetContentsOpaque(bool opaque) { |
346 SendMessageToEmbedder( | 343 SendMessageToEmbedder( |
347 new BrowserPluginMsg_SetContentsOpaque( | 344 new BrowserPluginMsg_SetContentsOpaque( |
348 browser_plugin_instance_id(), opaque)); | 345 browser_plugin_instance_id(), opaque)); |
349 } | 346 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 switch (message.type()) { | 444 switch (message.type()) { |
448 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: | 445 case BrowserPluginHostMsg_CompositorFrameSwappedACK::ID: |
449 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID: | 446 case BrowserPluginHostMsg_CopyFromCompositingSurfaceAck::ID: |
450 case BrowserPluginHostMsg_DragStatusUpdate::ID: | 447 case BrowserPluginHostMsg_DragStatusUpdate::ID: |
451 case BrowserPluginHostMsg_ExecuteEditCommand::ID: | 448 case BrowserPluginHostMsg_ExecuteEditCommand::ID: |
452 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: | 449 case BrowserPluginHostMsg_ExtendSelectionAndDelete::ID: |
453 case BrowserPluginHostMsg_HandleInputEvent::ID: | 450 case BrowserPluginHostMsg_HandleInputEvent::ID: |
454 case BrowserPluginHostMsg_ImeConfirmComposition::ID: | 451 case BrowserPluginHostMsg_ImeConfirmComposition::ID: |
455 case BrowserPluginHostMsg_ImeSetComposition::ID: | 452 case BrowserPluginHostMsg_ImeSetComposition::ID: |
456 case BrowserPluginHostMsg_LockMouse_ACK::ID: | 453 case BrowserPluginHostMsg_LockMouse_ACK::ID: |
457 case BrowserPluginHostMsg_PluginDestroyed::ID: | |
458 case BrowserPluginHostMsg_ReclaimCompositorResources::ID: | 454 case BrowserPluginHostMsg_ReclaimCompositorResources::ID: |
459 case BrowserPluginHostMsg_ResizeGuest::ID: | 455 case BrowserPluginHostMsg_ResizeGuest::ID: |
460 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: | 456 case BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent::ID: |
461 case BrowserPluginHostMsg_SetFocus::ID: | 457 case BrowserPluginHostMsg_SetFocus::ID: |
462 case BrowserPluginHostMsg_SetVisibility::ID: | 458 case BrowserPluginHostMsg_SetVisibility::ID: |
463 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: | 459 case BrowserPluginHostMsg_UnlockMouse_ACK::ID: |
464 case BrowserPluginHostMsg_UpdateGeometry::ID: | 460 case BrowserPluginHostMsg_UpdateGeometry::ID: |
465 return true; | 461 return true; |
466 default: | 462 default: |
467 return false; | 463 return false; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 return handled; | 509 return handled; |
514 #else | 510 #else |
515 return false; | 511 return false; |
516 #endif | 512 #endif |
517 } | 513 } |
518 | 514 |
519 void BrowserPluginGuest::Attach( | 515 void BrowserPluginGuest::Attach( |
520 int browser_plugin_instance_id, | 516 int browser_plugin_instance_id, |
521 WebContentsImpl* embedder_web_contents, | 517 WebContentsImpl* embedder_web_contents, |
522 const BrowserPluginHostMsg_Attach_Params& params) { | 518 const BrowserPluginHostMsg_Attach_Params& params) { |
523 if (attached()) | |
524 return; | |
525 | |
526 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id); | 519 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id); |
527 | 520 |
528 // If a RenderView has already been created for this new window, then we need | 521 // If a RenderView has already been created for this new window, then we need |
529 // to initialize the browser-side state now so that the RenderFrameHostManager | 522 // to initialize the browser-side state now so that the RenderFrameHostManager |
530 // does not create a new RenderView on navigation. | 523 // does not create a new RenderView on navigation. |
531 if (has_render_view_) { | 524 if (has_render_view_) { |
| 525 // This will trigger a callback to RenderViewReady after a round-trip IPC. |
532 static_cast<RenderViewHostImpl*>( | 526 static_cast<RenderViewHostImpl*>( |
533 GetWebContents()->GetRenderViewHost())->Init(); | 527 GetWebContents()->GetRenderViewHost())->Init(); |
534 WebContentsViewGuest* new_view = | 528 WebContentsViewGuest* web_contents_view = |
535 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 529 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
536 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 530 if (!web_contents()->GetRenderViewHost()->GetView()) { |
| 531 web_contents_view->CreateViewForWidget( |
| 532 web_contents()->GetRenderViewHost()); |
| 533 } |
537 } | 534 } |
538 | 535 |
539 Initialize(browser_plugin_instance_id, params, embedder_web_contents); | 536 Initialize(browser_plugin_instance_id, params, embedder_web_contents); |
540 | 537 |
541 SendQueuedMessages(); | 538 SendQueuedMessages(); |
542 | 539 |
543 // Create a swapped out RenderView for the guest in the embedder render | 540 // Create a swapped out RenderView for the guest in the embedder render |
544 // process, so that the embedder can access the guest's window object. | 541 // process, so that the embedder can access the guest's window object. |
545 int guest_routing_id = | 542 // On reattachment, we can reuse the same swapped out RenderView because |
546 GetWebContents()->CreateSwappedOutRenderView( | 543 // the embedder process will always be the same even if the embedder |
547 embedder_web_contents_->GetSiteInstance()); | 544 // WebContents changes. |
| 545 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) { |
| 546 guest_proxy_routing_id_ = |
| 547 GetWebContents()->CreateSwappedOutRenderView( |
| 548 embedder_web_contents_->GetSiteInstance()); |
| 549 } |
548 | 550 |
549 delegate_->DidAttach(guest_routing_id); | 551 delegate_->DidAttach(guest_proxy_routing_id_); |
| 552 |
| 553 has_render_view_ = true; |
550 | 554 |
551 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 555 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
552 } | 556 } |
553 | 557 |
554 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 558 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
555 int browser_plugin_instance_id, | 559 int browser_plugin_instance_id, |
556 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { | 560 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
557 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, | 561 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, |
558 params.output_surface_id, | 562 params.output_surface_id, |
559 params.producing_host_id, | 563 params.producing_host_id, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 } | 657 } |
654 | 658 |
655 void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id, | 659 void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id, |
656 bool succeeded) { | 660 bool succeeded) { |
657 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); | 661 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); |
658 pending_lock_request_ = false; | 662 pending_lock_request_ = false; |
659 if (succeeded) | 663 if (succeeded) |
660 mouse_locked_ = true; | 664 mouse_locked_ = true; |
661 } | 665 } |
662 | 666 |
663 void BrowserPluginGuest::OnPluginDestroyed(int browser_plugin_instance_id) { | |
664 Destroy(); | |
665 } | |
666 | |
667 void BrowserPluginGuest::OnResizeGuest( | 667 void BrowserPluginGuest::OnResizeGuest( |
668 int browser_plugin_instance_id, | 668 int browser_plugin_instance_id, |
669 const BrowserPluginHostMsg_ResizeGuest_Params& params) { | 669 const BrowserPluginHostMsg_ResizeGuest_Params& params) { |
670 // If we are setting the size for the first time before navigating then | 670 // If we are setting the size for the first time before navigating then |
671 // BrowserPluginGuest does not yet have a RenderViewHost. | 671 // BrowserPluginGuest does not yet have a RenderViewHost. |
672 if (guest_device_scale_factor_ != params.scale_factor && | 672 if (guest_device_scale_factor_ != params.scale_factor && |
673 GetWebContents()->GetRenderViewHost()) { | 673 GetWebContents()->GetRenderViewHost()) { |
674 RenderWidgetHostImpl* render_widget_host = | 674 RenderWidgetHostImpl* render_widget_host = |
675 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost()); | 675 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost()); |
676 guest_device_scale_factor_ = params.scale_factor; | 676 guest_device_scale_factor_ = params.scale_factor; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 804 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
805 const gfx::Range& range, | 805 const gfx::Range& range, |
806 const std::vector<gfx::Rect>& character_bounds) { | 806 const std::vector<gfx::Rect>& character_bounds) { |
807 static_cast<RenderWidgetHostViewBase*>( | 807 static_cast<RenderWidgetHostViewBase*>( |
808 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 808 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
809 range, character_bounds); | 809 range, character_bounds); |
810 } | 810 } |
811 #endif | 811 #endif |
812 | 812 |
813 } // namespace content | 813 } // namespace content |
OLD | NEW |