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" | |
10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
11 #include "base/pickle.h" | 10 #include "base/pickle.h" |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "cc/surfaces/surface.h" | 12 #include "cc/surfaces/surface.h" |
14 #include "cc/surfaces/surface_manager.h" | 13 #include "cc/surfaces/surface_manager.h" |
15 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 14 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
16 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
17 #include "content/browser/child_process_security_policy_impl.h" | 16 #include "content/browser/child_process_security_policy_impl.h" |
18 #include "content/browser/compositor/surface_utils.h" | 17 #include "content/browser/compositor/surface_utils.h" |
19 #include "content/browser/frame_host/render_frame_host_impl.h" | 18 #include "content/browser/frame_host/render_frame_host_impl.h" |
(...skipping 11 matching lines...) Expand all Loading... |
31 #include "content/common/host_shared_bitmap_manager.h" | 30 #include "content/common/host_shared_bitmap_manager.h" |
32 #include "content/common/input_messages.h" | 31 #include "content/common/input_messages.h" |
33 #include "content/common/view_messages.h" | 32 #include "content/common/view_messages.h" |
34 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
35 #include "content/public/browser/browser_plugin_guest_manager.h" | 34 #include "content/public/browser/browser_plugin_guest_manager.h" |
36 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
37 #include "content/public/browser/guest_host.h" | 36 #include "content/public/browser/guest_host.h" |
38 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
39 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
40 #include "content/public/browser/web_contents_observer.h" | 39 #include "content/public/browser/web_contents_observer.h" |
41 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/browser_plugin_guest_mode.h" |
42 #include "content/public/common/drop_data.h" | 41 #include "content/public/common/drop_data.h" |
43 #include "ui/gfx/geometry/size_conversions.h" | 42 #include "ui/gfx/geometry/size_conversions.h" |
44 | 43 |
45 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
46 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 45 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
47 #include "content/common/frame_messages.h" | 46 #include "content/common/frame_messages.h" |
48 #endif | 47 #endif |
49 | 48 |
50 namespace content { | 49 namespace content { |
51 | 50 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 delegate_(delegate), | 101 delegate_(delegate), |
103 weak_ptr_factory_(this) { | 102 weak_ptr_factory_(this) { |
104 DCHECK(web_contents); | 103 DCHECK(web_contents); |
105 DCHECK(delegate); | 104 DCHECK(delegate); |
106 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 105 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
107 web_contents->SetBrowserPluginGuest(this); | 106 web_contents->SetBrowserPluginGuest(this); |
108 delegate->SetGuestHost(this); | 107 delegate->SetGuestHost(this); |
109 } | 108 } |
110 | 109 |
111 int BrowserPluginGuest::GetGuestProxyRoutingID() { | 110 int BrowserPluginGuest::GetGuestProxyRoutingID() { |
112 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 111 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
113 switches::kSitePerProcess)) { | |
114 // We don't use the proxy to send postMessage in --site-per-process, since | 112 // We don't use the proxy to send postMessage in --site-per-process, since |
115 // we use the contentWindow directly from the frame element instead. | 113 // we use the contentWindow directly from the frame element instead. |
116 return MSG_ROUTING_NONE; | 114 return MSG_ROUTING_NONE; |
117 } | 115 } |
118 | 116 |
119 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) | 117 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) |
120 return guest_proxy_routing_id_; | 118 return guest_proxy_routing_id_; |
121 | 119 |
122 // Create a swapped out RenderView for the guest in the embedder renderer | 120 // Create a swapped out RenderView for the guest in the embedder renderer |
123 // process, so that the embedder can access the guest's window object. | 121 // process, so that the embedder can access the guest's window object. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 blink::WebFocusTypeNone); | 269 blink::WebFocusTypeNone); |
272 | 270 |
273 guest_visible_ = params.visible; | 271 guest_visible_ = params.visible; |
274 UpdateVisibility(); | 272 UpdateVisibility(); |
275 | 273 |
276 is_full_page_plugin_ = params.is_full_page_plugin; | 274 is_full_page_plugin_ = params.is_full_page_plugin; |
277 guest_window_rect_ = params.view_rect; | 275 guest_window_rect_ = params.view_rect; |
278 | 276 |
279 if (owner_web_contents_ != owner_web_contents) { | 277 if (owner_web_contents_ != owner_web_contents) { |
280 WebContentsViewGuest* new_view = nullptr; | 278 WebContentsViewGuest* new_view = nullptr; |
281 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 279 if (!BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
282 switches::kSitePerProcess)) { | |
283 new_view = | 280 new_view = |
284 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 281 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
285 } | 282 } |
286 | 283 |
287 if (owner_web_contents_ && new_view) | 284 if (owner_web_contents_ && new_view) |
288 new_view->OnGuestDetached(owner_web_contents_->GetView()); | 285 new_view->OnGuestDetached(owner_web_contents_->GetView()); |
289 | 286 |
290 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 287 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
291 // be attached. | 288 // be attached. |
292 owner_web_contents_ = owner_web_contents; | 289 owner_web_contents_ = owner_web_contents; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 621 |
625 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 622 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
626 bool handled = true; | 623 bool handled = true; |
627 // In --site-per-process, we do not need most of BrowserPluginGuest to drive | 624 // In --site-per-process, we do not need most of BrowserPluginGuest to drive |
628 // inner WebContents. | 625 // inner WebContents. |
629 // Right now InputHostMsg_ImeCompositionRangeChanged hits NOTREACHED() in | 626 // Right now InputHostMsg_ImeCompositionRangeChanged hits NOTREACHED() in |
630 // RWHVChildFrame, so we're disabling message handling entirely here. | 627 // RWHVChildFrame, so we're disabling message handling entirely here. |
631 // TODO(lazyboy): Fix this as part of http://crbug.com/330264. The required | 628 // TODO(lazyboy): Fix this as part of http://crbug.com/330264. The required |
632 // parts of code from this class should be extracted to a separate class for | 629 // parts of code from this class should be extracted to a separate class for |
633 // --site-per-process. | 630 // --site-per-process. |
634 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 631 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
635 switches::kSitePerProcess)) { | |
636 return false; | 632 return false; |
637 } | 633 } |
638 | 634 |
639 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 635 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
640 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, | 636 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, |
641 OnImeCancelComposition) | 637 OnImeCancelComposition) |
642 #if defined(OS_MACOSX) || defined(USE_AURA) | 638 #if defined(OS_MACOSX) || defined(USE_AURA) |
643 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, | 639 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, |
644 OnImeCompositionRangeChanged) | 640 OnImeCompositionRangeChanged) |
645 #endif | 641 #endif |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, | 705 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, |
710 params.is_full_page_plugin, | 706 params.is_full_page_plugin, |
711 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, | 707 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, |
712 weak_ptr_factory_.GetWeakPtr(), | 708 weak_ptr_factory_.GetWeakPtr(), |
713 embedder_web_contents, params)); | 709 embedder_web_contents, params)); |
714 } | 710 } |
715 | 711 |
716 void BrowserPluginGuest::OnWillAttachComplete( | 712 void BrowserPluginGuest::OnWillAttachComplete( |
717 WebContentsImpl* embedder_web_contents, | 713 WebContentsImpl* embedder_web_contents, |
718 const BrowserPluginHostMsg_Attach_Params& params) { | 714 const BrowserPluginHostMsg_Attach_Params& params) { |
719 bool use_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch( | 715 bool use_cross_process_frames = |
720 switches::kSitePerProcess); | 716 BrowserPluginGuestMode::UseCrossProcessFramesForGuests(); |
721 // If a RenderView has already been created for this new window, then we need | 717 // If a RenderView has already been created for this new window, then we need |
722 // to initialize the browser-side state now so that the RenderFrameHostManager | 718 // to initialize the browser-side state now so that the RenderFrameHostManager |
723 // does not create a new RenderView on navigation. | 719 // does not create a new RenderView on navigation. |
724 if (!use_site_per_process && has_render_view_) { | 720 if (!use_cross_process_frames && has_render_view_) { |
725 // This will trigger a callback to RenderViewReady after a round-trip IPC. | 721 // This will trigger a callback to RenderViewReady after a round-trip IPC. |
726 static_cast<RenderViewHostImpl*>( | 722 static_cast<RenderViewHostImpl*>( |
727 GetWebContents()->GetRenderViewHost())->Init(); | 723 GetWebContents()->GetRenderViewHost())->Init(); |
728 WebContentsViewGuest* web_contents_view = | 724 WebContentsViewGuest* web_contents_view = |
729 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 725 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
730 if (!web_contents()->GetRenderViewHost()->GetView()) { | 726 if (!web_contents()->GetRenderViewHost()->GetView()) { |
731 web_contents_view->CreateViewForWidget( | 727 web_contents_view->CreateViewForWidget( |
732 web_contents()->GetRenderViewHost(), true); | 728 web_contents()->GetRenderViewHost(), true); |
733 } | 729 } |
734 } | 730 } |
735 | 731 |
736 InitInternal(params, embedder_web_contents); | 732 InitInternal(params, embedder_web_contents); |
737 | 733 |
738 attached_ = true; | 734 attached_ = true; |
739 has_attached_since_surface_set_ = true; | 735 has_attached_since_surface_set_ = true; |
740 SendQueuedMessages(); | 736 SendQueuedMessages(); |
741 | 737 |
742 delegate_->DidAttach(GetGuestProxyRoutingID()); | 738 delegate_->DidAttach(GetGuestProxyRoutingID()); |
743 | 739 |
744 if (!use_site_per_process) | 740 if (!use_cross_process_frames) |
745 has_render_view_ = true; | 741 has_render_view_ = true; |
746 | 742 |
747 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 743 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
748 } | 744 } |
749 | 745 |
750 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 746 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
751 int browser_plugin_instance_id, | 747 int browser_plugin_instance_id, |
752 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { | 748 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
753 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, | 749 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, |
754 params.output_surface_id, | 750 params.output_surface_id, |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 984 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
989 const gfx::Range& range, | 985 const gfx::Range& range, |
990 const std::vector<gfx::Rect>& character_bounds) { | 986 const std::vector<gfx::Rect>& character_bounds) { |
991 static_cast<RenderWidgetHostViewBase*>( | 987 static_cast<RenderWidgetHostViewBase*>( |
992 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 988 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
993 range, character_bounds); | 989 range, character_bounds); |
994 } | 990 } |
995 #endif | 991 #endif |
996 | 992 |
997 } // namespace content | 993 } // namespace content |
OLD | NEW |