| 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 "content/browser/browser_plugin/browser_plugin_embedder.h" | 13 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" | 15 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 16 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 17 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
| 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 20 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 21 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 21 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
| 22 #include "content/browser/web_contents/web_contents_view_guest.h" | 23 #include "content/browser/web_contents/web_contents_view_guest.h" |
| 23 #include "content/common/browser_plugin/browser_plugin_constants.h" | 24 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 24 #include "content/common/browser_plugin/browser_plugin_messages.h" | 25 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 25 #include "content/common/content_constants_internal.h" | 26 #include "content/common/content_constants_internal.h" |
| 26 #include "content/common/drag_messages.h" | 27 #include "content/common/drag_messages.h" |
| 27 #include "content/common/frame_messages.h" | 28 #include "content/common/frame_messages.h" |
| 28 #include "content/common/host_shared_bitmap_manager.h" | 29 #include "content/common/host_shared_bitmap_manager.h" |
| 29 #include "content/common/input_messages.h" | 30 #include "content/common/input_messages.h" |
| 30 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
| 31 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
| 32 #include "content/public/browser/browser_plugin_guest_manager.h" | 33 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 33 #include "content/public/browser/content_browser_client.h" | 34 #include "content/public/browser/content_browser_client.h" |
| 34 #include "content/public/browser/guest_host.h" | 35 #include "content/public/browser/guest_host.h" |
| 35 #include "content/public/browser/render_widget_host_view.h" | 36 #include "content/public/browser/render_widget_host_view.h" |
| 36 #include "content/public/browser/user_metrics.h" | 37 #include "content/public/browser/user_metrics.h" |
| 37 #include "content/public/browser/web_contents_observer.h" | 38 #include "content/public/browser/web_contents_observer.h" |
| 39 #include "content/public/common/content_switches.h" |
| 38 #include "content/public/common/drop_data.h" | 40 #include "content/public/common/drop_data.h" |
| 39 #include "ui/gfx/geometry/size_conversions.h" | 41 #include "ui/gfx/geometry/size_conversions.h" |
| 40 | 42 |
| 41 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
| 42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" | 44 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" |
| 43 #endif | 45 #endif |
| 44 | 46 |
| 45 namespace content { | 47 namespace content { |
| 46 | 48 |
| 47 class BrowserPluginGuest::EmbedderVisibilityObserver | 49 class BrowserPluginGuest::EmbedderVisibilityObserver |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 delegate_(delegate), | 98 delegate_(delegate), |
| 97 weak_ptr_factory_(this) { | 99 weak_ptr_factory_(this) { |
| 98 DCHECK(web_contents); | 100 DCHECK(web_contents); |
| 99 DCHECK(delegate); | 101 DCHECK(delegate); |
| 100 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 102 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
| 101 web_contents->SetBrowserPluginGuest(this); | 103 web_contents->SetBrowserPluginGuest(this); |
| 102 delegate->SetGuestHost(this); | 104 delegate->SetGuestHost(this); |
| 103 } | 105 } |
| 104 | 106 |
| 105 int BrowserPluginGuest::GetGuestProxyRoutingID() { | 107 int BrowserPluginGuest::GetGuestProxyRoutingID() { |
| 108 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 109 switches::kSitePerProcess)) { |
| 110 // We don't directly use the proxy to send postMessage in |
| 111 // --site-per-process, since we use the contentWindow directly from |
| 112 // the frame element instead. |
| 113 return MSG_ROUTING_NONE; |
| 114 } |
| 115 |
| 106 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) | 116 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) |
| 107 return guest_proxy_routing_id_; | 117 return guest_proxy_routing_id_; |
| 108 | 118 |
| 109 // Create a swapped out RenderView for the guest in the embedder renderer | 119 // Create a swapped out RenderView for the guest in the embedder renderer |
| 110 // process, so that the embedder can access the guest's window object. | 120 // process, so that the embedder can access the guest's window object. |
| 111 // On reattachment, we can reuse the same swapped out RenderView because | 121 // On reattachment, we can reuse the same swapped out RenderView because |
| 112 // the embedder process will always be the same even if the embedder | 122 // the embedder process will always be the same even if the embedder |
| 113 // WebContents changes. | 123 // WebContents changes. |
| 114 // | 124 // |
| 115 // TODO(fsamuel): Make sure this works for transferring guests across | 125 // TODO(fsamuel): Make sure this works for transferring guests across |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 focused_, | 265 focused_, |
| 256 blink::WebFocusTypeNone); | 266 blink::WebFocusTypeNone); |
| 257 | 267 |
| 258 guest_visible_ = params.visible; | 268 guest_visible_ = params.visible; |
| 259 UpdateVisibility(); | 269 UpdateVisibility(); |
| 260 | 270 |
| 261 is_full_page_plugin_ = params.is_full_page_plugin; | 271 is_full_page_plugin_ = params.is_full_page_plugin; |
| 262 guest_window_rect_ = params.view_rect; | 272 guest_window_rect_ = params.view_rect; |
| 263 | 273 |
| 264 if (owner_web_contents_ != owner_web_contents) { | 274 if (owner_web_contents_ != owner_web_contents) { |
| 265 WebContentsViewGuest* new_view = | 275 WebContentsViewGuest* new_view = nullptr; |
| 266 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 276 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 267 if (owner_web_contents_) | 277 switches::kSitePerProcess)) { |
| 278 new_view = |
| 279 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
| 280 } |
| 281 |
| 282 if (owner_web_contents_ && new_view) |
| 268 new_view->OnGuestDetached(owner_web_contents_->GetView()); | 283 new_view->OnGuestDetached(owner_web_contents_->GetView()); |
| 269 | 284 |
| 270 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 285 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
| 271 // be attached. | 286 // be attached. |
| 272 owner_web_contents_ = owner_web_contents; | 287 owner_web_contents_ = owner_web_contents; |
| 273 new_view->OnGuestAttached(owner_web_contents_->GetView()); | 288 if (new_view) |
| 289 new_view->OnGuestAttached(owner_web_contents_->GetView()); |
| 274 } | 290 } |
| 275 | 291 |
| 276 RendererPreferences* renderer_prefs = | 292 RendererPreferences* renderer_prefs = |
| 277 GetWebContents()->GetMutableRendererPrefs(); | 293 GetWebContents()->GetMutableRendererPrefs(); |
| 278 std::string guest_user_agent_override = renderer_prefs->user_agent_override; | 294 std::string guest_user_agent_override = renderer_prefs->user_agent_override; |
| 279 // Copy renderer preferences (and nothing else) from the embedder's | 295 // Copy renderer preferences (and nothing else) from the embedder's |
| 280 // WebContents to the guest. | 296 // WebContents to the guest. |
| 281 // | 297 // |
| 282 // For GTK and Aura this is necessary to get proper renderer configuration | 298 // For GTK and Aura this is necessary to get proper renderer configuration |
| 283 // values for caret blinking interval, colors related to selection and | 299 // values for caret blinking interval, colors related to selection and |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 575 |
| 560 // static | 576 // static |
| 561 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( | 577 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( |
| 562 const IPC::Message& message) { | 578 const IPC::Message& message) { |
| 563 return (message.type() != BrowserPluginHostMsg_Attach::ID) && | 579 return (message.type() != BrowserPluginHostMsg_Attach::ID) && |
| 564 (IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart); | 580 (IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart); |
| 565 } | 581 } |
| 566 | 582 |
| 567 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { | 583 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { |
| 568 bool handled = true; | 584 bool handled = true; |
| 585 // In --site-per-process, we do not need most of BrowserPluginGuest to drive |
| 586 // inner WebContents. |
| 587 // Right now InputHostMsg_ImeCompositionRangeChanged hits NOTREACHED() in |
| 588 // RWHVChildFrame, so we're disabling message handling entirely here. |
| 589 // TODO(lazyboy): Fix this as part of http://crbug.com/330264. The required |
| 590 // parts of code from this class should be exctracted to a separate class for |
| 591 // --site-per-process. |
| 592 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 593 switches::kSitePerProcess)) { |
| 594 return false; |
| 595 } |
| 596 |
| 569 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 597 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
| 570 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, | 598 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, |
| 571 OnImeCancelComposition) | 599 OnImeCancelComposition) |
| 572 #if defined(OS_MACOSX) || defined(USE_AURA) | 600 #if defined(OS_MACOSX) || defined(USE_AURA) |
| 573 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, | 601 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, |
| 574 OnImeCompositionRangeChanged) | 602 OnImeCompositionRangeChanged) |
| 575 #endif | 603 #endif |
| 576 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, | 604 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, |
| 577 OnHasTouchEventHandlers) | 605 OnHasTouchEventHandlers) |
| 578 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 606 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, | 667 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, |
| 640 params.is_full_page_plugin, | 668 params.is_full_page_plugin, |
| 641 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, | 669 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, |
| 642 weak_ptr_factory_.GetWeakPtr(), | 670 weak_ptr_factory_.GetWeakPtr(), |
| 643 embedder_web_contents, params)); | 671 embedder_web_contents, params)); |
| 644 } | 672 } |
| 645 | 673 |
| 646 void BrowserPluginGuest::OnWillAttachComplete( | 674 void BrowserPluginGuest::OnWillAttachComplete( |
| 647 WebContentsImpl* embedder_web_contents, | 675 WebContentsImpl* embedder_web_contents, |
| 648 const BrowserPluginHostMsg_Attach_Params& params) { | 676 const BrowserPluginHostMsg_Attach_Params& params) { |
| 677 bool use_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 678 switches::kSitePerProcess); |
| 649 // If a RenderView has already been created for this new window, then we need | 679 // If a RenderView has already been created for this new window, then we need |
| 650 // to initialize the browser-side state now so that the RenderFrameHostManager | 680 // to initialize the browser-side state now so that the RenderFrameHostManager |
| 651 // does not create a new RenderView on navigation. | 681 // does not create a new RenderView on navigation. |
| 652 if (has_render_view_) { | 682 if (!use_site_per_process && has_render_view_) { |
| 653 // This will trigger a callback to RenderViewReady after a round-trip IPC. | 683 // This will trigger a callback to RenderViewReady after a round-trip IPC. |
| 654 static_cast<RenderViewHostImpl*>( | 684 static_cast<RenderViewHostImpl*>( |
| 655 GetWebContents()->GetRenderViewHost())->Init(); | 685 GetWebContents()->GetRenderViewHost())->Init(); |
| 656 WebContentsViewGuest* web_contents_view = | 686 WebContentsViewGuest* web_contents_view = |
| 657 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 687 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
| 658 if (!web_contents()->GetRenderViewHost()->GetView()) { | 688 if (!web_contents()->GetRenderViewHost()->GetView()) { |
| 659 web_contents_view->CreateViewForWidget( | 689 web_contents_view->CreateViewForWidget( |
| 660 web_contents()->GetRenderViewHost(), true); | 690 web_contents()->GetRenderViewHost(), true); |
| 661 } | 691 } |
| 662 } | 692 } |
| 663 | 693 |
| 664 InitInternal(params, embedder_web_contents); | 694 InitInternal(params, embedder_web_contents); |
| 665 | 695 |
| 666 attached_ = true; | 696 attached_ = true; |
| 667 SendQueuedMessages(); | 697 SendQueuedMessages(); |
| 668 | 698 |
| 669 delegate_->DidAttach(GetGuestProxyRoutingID()); | 699 delegate_->DidAttach(GetGuestProxyRoutingID()); |
| 670 | 700 |
| 671 has_render_view_ = true; | 701 if (!use_site_per_process) { |
| 702 has_render_view_ = true; |
| 672 | 703 |
| 673 // Enable input method for guest if it's enabled for the embedder. | 704 // Enable input method for guest if it's enabled for the embedder. |
| 674 if (static_cast<RenderViewHostImpl*>( | 705 if (static_cast<RenderViewHostImpl*>( |
| 675 owner_web_contents_->GetRenderViewHost())->input_method_active()) { | 706 owner_web_contents_->GetRenderViewHost())->input_method_active()) { |
| 676 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 707 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 677 GetWebContents()->GetRenderViewHost()); | 708 GetWebContents()->GetRenderViewHost()); |
| 678 guest_rvh->SetInputMethodActive(true); | 709 guest_rvh->SetInputMethodActive(true); |
| 710 } |
| 679 } | 711 } |
| 680 | 712 |
| 681 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 713 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
| 682 } | 714 } |
| 683 | 715 |
| 684 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 716 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
| 685 int browser_plugin_instance_id, | 717 int browser_plugin_instance_id, |
| 686 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { | 718 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
| 687 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, | 719 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, |
| 688 params.output_surface_id, | 720 params.output_surface_id, |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 954 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
| 923 const gfx::Range& range, | 955 const gfx::Range& range, |
| 924 const std::vector<gfx::Rect>& character_bounds) { | 956 const std::vector<gfx::Rect>& character_bounds) { |
| 925 static_cast<RenderWidgetHostViewBase*>( | 957 static_cast<RenderWidgetHostViewBase*>( |
| 926 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 958 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
| 927 range, character_bounds); | 959 range, character_bounds); |
| 928 } | 960 } |
| 929 #endif | 961 #endif |
| 930 | 962 |
| 931 } // namespace content | 963 } // namespace content |
| OLD | NEW |