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/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/pickle.h" | 11 #include "base/pickle.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "cc/surfaces/surface.h" | 13 #include "cc/surfaces/surface.h" |
13 #include "cc/surfaces/surface_manager.h" | 14 #include "cc/surfaces/surface_manager.h" |
14 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 15 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
15 #include "content/browser/browser_thread_impl.h" | 16 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/child_process_security_policy_impl.h" | 17 #include "content/browser/child_process_security_policy_impl.h" |
17 #include "content/browser/compositor/surface_utils.h" | 18 #include "content/browser/compositor/surface_utils.h" |
18 #include "content/browser/frame_host/render_frame_host_impl.h" | 19 #include "content/browser/frame_host/render_frame_host_impl.h" |
(...skipping 11 matching lines...) Expand all Loading... |
30 #include "content/common/host_shared_bitmap_manager.h" | 31 #include "content/common/host_shared_bitmap_manager.h" |
31 #include "content/common/input_messages.h" | 32 #include "content/common/input_messages.h" |
32 #include "content/common/view_messages.h" | 33 #include "content/common/view_messages.h" |
33 #include "content/public/browser/browser_context.h" | 34 #include "content/public/browser/browser_context.h" |
34 #include "content/public/browser/browser_plugin_guest_manager.h" | 35 #include "content/public/browser/browser_plugin_guest_manager.h" |
35 #include "content/public/browser/content_browser_client.h" | 36 #include "content/public/browser/content_browser_client.h" |
36 #include "content/public/browser/guest_host.h" | 37 #include "content/public/browser/guest_host.h" |
37 #include "content/public/browser/render_widget_host_view.h" | 38 #include "content/public/browser/render_widget_host_view.h" |
38 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
39 #include "content/public/browser/web_contents_observer.h" | 40 #include "content/public/browser/web_contents_observer.h" |
| 41 #include "content/public/common/content_switches.h" |
40 #include "content/public/common/drop_data.h" | 42 #include "content/public/common/drop_data.h" |
41 #include "ui/gfx/geometry/size_conversions.h" | 43 #include "ui/gfx/geometry/size_conversions.h" |
42 | 44 |
43 #if defined(OS_MACOSX) | 45 #if defined(OS_MACOSX) |
44 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 46 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
45 #include "content/common/frame_messages.h" | 47 #include "content/common/frame_messages.h" |
46 #endif | 48 #endif |
47 | 49 |
48 namespace content { | 50 namespace content { |
49 | 51 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 delegate_(delegate), | 101 delegate_(delegate), |
100 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
101 DCHECK(web_contents); | 103 DCHECK(web_contents); |
102 DCHECK(delegate); | 104 DCHECK(delegate); |
103 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 105 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
104 web_contents->SetBrowserPluginGuest(this); | 106 web_contents->SetBrowserPluginGuest(this); |
105 delegate->SetGuestHost(this); | 107 delegate->SetGuestHost(this); |
106 } | 108 } |
107 | 109 |
108 int BrowserPluginGuest::GetGuestProxyRoutingID() { | 110 int BrowserPluginGuest::GetGuestProxyRoutingID() { |
| 111 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 switches::kSitePerProcess)) { |
| 113 // We don't use the proxy to send postMessage in --site-per-process, since |
| 114 // we use the contentWindow directly from the frame element instead. |
| 115 return MSG_ROUTING_NONE; |
| 116 } |
| 117 |
109 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) | 118 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) |
110 return guest_proxy_routing_id_; | 119 return guest_proxy_routing_id_; |
111 | 120 |
112 // Create a swapped out RenderView for the guest in the embedder renderer | 121 // Create a swapped out RenderView for the guest in the embedder renderer |
113 // process, so that the embedder can access the guest's window object. | 122 // process, so that the embedder can access the guest's window object. |
114 // On reattachment, we can reuse the same swapped out RenderView because | 123 // On reattachment, we can reuse the same swapped out RenderView because |
115 // the embedder process will always be the same even if the embedder | 124 // the embedder process will always be the same even if the embedder |
116 // WebContents changes. | 125 // WebContents changes. |
117 // | 126 // |
118 // TODO(fsamuel): Make sure this works for transferring guests across | 127 // TODO(fsamuel): Make sure this works for transferring guests across |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 focused_, | 269 focused_, |
261 blink::WebFocusTypeNone); | 270 blink::WebFocusTypeNone); |
262 | 271 |
263 guest_visible_ = params.visible; | 272 guest_visible_ = params.visible; |
264 UpdateVisibility(); | 273 UpdateVisibility(); |
265 | 274 |
266 is_full_page_plugin_ = params.is_full_page_plugin; | 275 is_full_page_plugin_ = params.is_full_page_plugin; |
267 guest_window_rect_ = params.view_rect; | 276 guest_window_rect_ = params.view_rect; |
268 | 277 |
269 if (owner_web_contents_ != owner_web_contents) { | 278 if (owner_web_contents_ != owner_web_contents) { |
270 WebContentsViewGuest* new_view = | 279 WebContentsViewGuest* new_view = nullptr; |
271 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 280 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
272 if (owner_web_contents_) | 281 switches::kSitePerProcess)) { |
| 282 new_view = |
| 283 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
| 284 } |
| 285 |
| 286 if (owner_web_contents_ && new_view) |
273 new_view->OnGuestDetached(owner_web_contents_->GetView()); | 287 new_view->OnGuestDetached(owner_web_contents_->GetView()); |
274 | 288 |
275 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 289 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
276 // be attached. | 290 // be attached. |
277 owner_web_contents_ = owner_web_contents; | 291 owner_web_contents_ = owner_web_contents; |
278 new_view->OnGuestAttached(owner_web_contents_->GetView()); | 292 if (new_view) |
| 293 new_view->OnGuestAttached(owner_web_contents_->GetView()); |
279 } | 294 } |
280 | 295 |
281 RendererPreferences* renderer_prefs = | 296 RendererPreferences* renderer_prefs = |
282 GetWebContents()->GetMutableRendererPrefs(); | 297 GetWebContents()->GetMutableRendererPrefs(); |
283 std::string guest_user_agent_override = renderer_prefs->user_agent_override; | 298 std::string guest_user_agent_override = renderer_prefs->user_agent_override; |
284 // Copy renderer preferences (and nothing else) from the embedder's | 299 // Copy renderer preferences (and nothing else) from the embedder's |
285 // WebContents to the guest. | 300 // WebContents to the guest. |
286 // | 301 // |
287 // For GTK and Aura this is necessary to get proper renderer configuration | 302 // For GTK and Aura this is necessary to get proper renderer configuration |
288 // values for caret blinking interval, colors related to selection and | 303 // values for caret blinking interval, colors related to selection and |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 621 |
607 // static | 622 // static |
608 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( | 623 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( |
609 const IPC::Message& message) { | 624 const IPC::Message& message) { |
610 return (message.type() != BrowserPluginHostMsg_Attach::ID) && | 625 return (message.type() != BrowserPluginHostMsg_Attach::ID) && |
611 (IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart); | 626 (IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart); |
612 } | 627 } |
613 | 628 |
614 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 629 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
615 bool handled = true; | 630 bool handled = true; |
| 631 // In --site-per-process, we do not need most of BrowserPluginGuest to drive |
| 632 // inner WebContents. |
| 633 // Right now InputHostMsg_ImeCompositionRangeChanged hits NOTREACHED() in |
| 634 // RWHVChildFrame, so we're disabling message handling entirely here. |
| 635 // TODO(lazyboy): Fix this as part of http://crbug.com/330264. The required |
| 636 // parts of code from this class should be extracted to a separate class for |
| 637 // --site-per-process. |
| 638 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 639 switches::kSitePerProcess)) { |
| 640 return false; |
| 641 } |
| 642 |
616 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 643 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
617 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, | 644 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, |
618 OnImeCancelComposition) | 645 OnImeCancelComposition) |
619 #if defined(OS_MACOSX) || defined(USE_AURA) | 646 #if defined(OS_MACOSX) || defined(USE_AURA) |
620 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, | 647 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, |
621 OnImeCompositionRangeChanged) | 648 OnImeCompositionRangeChanged) |
622 #endif | 649 #endif |
623 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 650 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
624 OnHasTouchEventHandlers) | 651 OnHasTouchEventHandlers) |
625 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 652 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, | 713 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, |
687 params.is_full_page_plugin, | 714 params.is_full_page_plugin, |
688 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, | 715 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, |
689 weak_ptr_factory_.GetWeakPtr(), | 716 weak_ptr_factory_.GetWeakPtr(), |
690 embedder_web_contents, params)); | 717 embedder_web_contents, params)); |
691 } | 718 } |
692 | 719 |
693 void BrowserPluginGuest::OnWillAttachComplete( | 720 void BrowserPluginGuest::OnWillAttachComplete( |
694 WebContentsImpl* embedder_web_contents, | 721 WebContentsImpl* embedder_web_contents, |
695 const BrowserPluginHostMsg_Attach_Params& params) { | 722 const BrowserPluginHostMsg_Attach_Params& params) { |
| 723 bool use_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 724 switches::kSitePerProcess); |
696 // If a RenderView has already been created for this new window, then we need | 725 // If a RenderView has already been created for this new window, then we need |
697 // to initialize the browser-side state now so that the RenderFrameHostManager | 726 // to initialize the browser-side state now so that the RenderFrameHostManager |
698 // does not create a new RenderView on navigation. | 727 // does not create a new RenderView on navigation. |
699 if (has_render_view_) { | 728 if (!use_site_per_process && has_render_view_) { |
700 // This will trigger a callback to RenderViewReady after a round-trip IPC. | 729 // This will trigger a callback to RenderViewReady after a round-trip IPC. |
701 static_cast<RenderViewHostImpl*>( | 730 static_cast<RenderViewHostImpl*>( |
702 GetWebContents()->GetRenderViewHost())->Init(); | 731 GetWebContents()->GetRenderViewHost())->Init(); |
703 WebContentsViewGuest* web_contents_view = | 732 WebContentsViewGuest* web_contents_view = |
704 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 733 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
705 if (!web_contents()->GetRenderViewHost()->GetView()) { | 734 if (!web_contents()->GetRenderViewHost()->GetView()) { |
706 web_contents_view->CreateViewForWidget( | 735 web_contents_view->CreateViewForWidget( |
707 web_contents()->GetRenderViewHost(), true); | 736 web_contents()->GetRenderViewHost(), true); |
708 } | 737 } |
709 } | 738 } |
710 | 739 |
711 InitInternal(params, embedder_web_contents); | 740 InitInternal(params, embedder_web_contents); |
712 | 741 |
713 attached_ = true; | 742 attached_ = true; |
714 SendQueuedMessages(); | 743 SendQueuedMessages(); |
715 | 744 |
716 delegate_->DidAttach(GetGuestProxyRoutingID()); | 745 delegate_->DidAttach(GetGuestProxyRoutingID()); |
717 | 746 |
718 has_render_view_ = true; | 747 if (!use_site_per_process) { |
| 748 has_render_view_ = true; |
719 | 749 |
720 // Enable input method for guest if it's enabled for the embedder. | 750 // Enable input method for guest if it's enabled for the embedder. |
721 if (static_cast<RenderViewHostImpl*>( | 751 if (static_cast<RenderViewHostImpl*>( |
722 owner_web_contents_->GetRenderViewHost())->input_method_active()) { | 752 owner_web_contents_->GetRenderViewHost())->input_method_active()) { |
723 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 753 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
724 GetWebContents()->GetRenderViewHost()); | 754 GetWebContents()->GetRenderViewHost()); |
725 guest_rvh->SetInputMethodActive(true); | 755 guest_rvh->SetInputMethodActive(true); |
| 756 } |
726 } | 757 } |
727 | 758 |
728 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 759 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
729 } | 760 } |
730 | 761 |
731 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 762 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
732 int browser_plugin_instance_id, | 763 int browser_plugin_instance_id, |
733 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { | 764 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
734 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, | 765 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, |
735 params.output_surface_id, | 766 params.output_surface_id, |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 1000 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
970 const gfx::Range& range, | 1001 const gfx::Range& range, |
971 const std::vector<gfx::Rect>& character_bounds) { | 1002 const std::vector<gfx::Rect>& character_bounds) { |
972 static_cast<RenderWidgetHostViewBase*>( | 1003 static_cast<RenderWidgetHostViewBase*>( |
973 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 1004 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
974 range, character_bounds); | 1005 range, character_bounds); |
975 } | 1006 } |
976 #endif | 1007 #endif |
977 | 1008 |
978 } // namespace content | 1009 } // namespace content |
OLD | NEW |