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

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

Issue 972313002: Make <webview> use out-of-process iframe architecture. (Closed) Base URL: ssh://saopaulo.wat/mnt/dev/shared/src@testoopif2z-better-chrome
Patch Set: address comments from nasko@ + git cl format Created 5 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/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
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
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 directly use the proxy to send postMessage in
Charlie Reis 2015/06/18 00:13:18 nit: Drop first "directly"
lazyboy 2015/06/18 22:45:12 Done.
114 // --site-per-process, since we use the contentWindow directly from
115 // the frame element instead.
116 return MSG_ROUTING_NONE;
117 }
118
109 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) 119 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE)
110 return guest_proxy_routing_id_; 120 return guest_proxy_routing_id_;
111 121
112 // Create a swapped out RenderView for the guest in the embedder renderer 122 // 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. 123 // process, so that the embedder can access the guest's window object.
114 // On reattachment, we can reuse the same swapped out RenderView because 124 // On reattachment, we can reuse the same swapped out RenderView because
115 // the embedder process will always be the same even if the embedder 125 // the embedder process will always be the same even if the embedder
116 // WebContents changes. 126 // WebContents changes.
117 // 127 //
118 // TODO(fsamuel): Make sure this works for transferring guests across 128 // TODO(fsamuel): Make sure this works for transferring guests across
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 focused_, 270 focused_,
261 blink::WebFocusTypeNone); 271 blink::WebFocusTypeNone);
262 272
263 guest_visible_ = params.visible; 273 guest_visible_ = params.visible;
264 UpdateVisibility(); 274 UpdateVisibility();
265 275
266 is_full_page_plugin_ = params.is_full_page_plugin; 276 is_full_page_plugin_ = params.is_full_page_plugin;
267 guest_window_rect_ = params.view_rect; 277 guest_window_rect_ = params.view_rect;
268 278
269 if (owner_web_contents_ != owner_web_contents) { 279 if (owner_web_contents_ != owner_web_contents) {
270 WebContentsViewGuest* new_view = 280 WebContentsViewGuest* new_view = nullptr;
271 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 281 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
272 if (owner_web_contents_) 282 switches::kSitePerProcess)) {
283 new_view =
284 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
285 }
286
287 if (owner_web_contents_ && new_view)
273 new_view->OnGuestDetached(owner_web_contents_->GetView()); 288 new_view->OnGuestDetached(owner_web_contents_->GetView());
274 289
275 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to 290 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
276 // be attached. 291 // be attached.
277 owner_web_contents_ = owner_web_contents; 292 owner_web_contents_ = owner_web_contents;
278 new_view->OnGuestAttached(owner_web_contents_->GetView()); 293 if (new_view)
294 new_view->OnGuestAttached(owner_web_contents_->GetView());
279 } 295 }
280 296
281 RendererPreferences* renderer_prefs = 297 RendererPreferences* renderer_prefs =
282 GetWebContents()->GetMutableRendererPrefs(); 298 GetWebContents()->GetMutableRendererPrefs();
283 std::string guest_user_agent_override = renderer_prefs->user_agent_override; 299 std::string guest_user_agent_override = renderer_prefs->user_agent_override;
284 // Copy renderer preferences (and nothing else) from the embedder's 300 // Copy renderer preferences (and nothing else) from the embedder's
285 // WebContents to the guest. 301 // WebContents to the guest.
286 // 302 //
287 // For GTK and Aura this is necessary to get proper renderer configuration 303 // For GTK and Aura this is necessary to get proper renderer configuration
288 // values for caret blinking interval, colors related to selection and 304 // values for caret blinking interval, colors related to selection and
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 622
607 // static 623 // static
608 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest( 624 bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(
609 const IPC::Message& message) { 625 const IPC::Message& message) {
610 return (message.type() != BrowserPluginHostMsg_Attach::ID) && 626 return (message.type() != BrowserPluginHostMsg_Attach::ID) &&
611 (IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart); 627 (IPC_MESSAGE_CLASS(message) == BrowserPluginMsgStart);
612 } 628 }
613 629
614 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) { 630 bool BrowserPluginGuest::OnMessageReceived(const IPC::Message& message) {
615 bool handled = true; 631 bool handled = true;
632 // In --site-per-process, we do not need most of BrowserPluginGuest to drive
633 // inner WebContents.
634 // Right now InputHostMsg_ImeCompositionRangeChanged hits NOTREACHED() in
635 // RWHVChildFrame, so we're disabling message handling entirely here.
636 // TODO(lazyboy): Fix this as part of http://crbug.com/330264. The required
637 // parts of code from this class should be exctracted to a separate class for
Charlie Reis 2015/06/18 00:13:18 nit: extracted
lazyboy 2015/06/18 22:45:12 Done.
638 // --site-per-process.
639 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
640 switches::kSitePerProcess)) {
641 return false;
642 }
643
616 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 644 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
617 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition, 645 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCancelComposition,
618 OnImeCancelComposition) 646 OnImeCancelComposition)
619 #if defined(OS_MACOSX) || defined(USE_AURA) 647 #if defined(OS_MACOSX) || defined(USE_AURA)
620 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged, 648 IPC_MESSAGE_HANDLER(InputHostMsg_ImeCompositionRangeChanged,
621 OnImeCompositionRangeChanged) 649 OnImeCompositionRangeChanged)
622 #endif 650 #endif
623 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers, 651 IPC_MESSAGE_HANDLER(ViewHostMsg_HasTouchEventHandlers,
624 OnHasTouchEventHandlers) 652 OnHasTouchEventHandlers)
625 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) 653 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, 714 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
687 params.is_full_page_plugin, 715 params.is_full_page_plugin,
688 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, 716 base::Bind(&BrowserPluginGuest::OnWillAttachComplete,
689 weak_ptr_factory_.GetWeakPtr(), 717 weak_ptr_factory_.GetWeakPtr(),
690 embedder_web_contents, params)); 718 embedder_web_contents, params));
691 } 719 }
692 720
693 void BrowserPluginGuest::OnWillAttachComplete( 721 void BrowserPluginGuest::OnWillAttachComplete(
694 WebContentsImpl* embedder_web_contents, 722 WebContentsImpl* embedder_web_contents,
695 const BrowserPluginHostMsg_Attach_Params& params) { 723 const BrowserPluginHostMsg_Attach_Params& params) {
724 bool use_site_per_process = base::CommandLine::ForCurrentProcess()->HasSwitch(
725 switches::kSitePerProcess);
696 // If a RenderView has already been created for this new window, then we need 726 // 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 727 // to initialize the browser-side state now so that the RenderFrameHostManager
698 // does not create a new RenderView on navigation. 728 // does not create a new RenderView on navigation.
699 if (has_render_view_) { 729 if (!use_site_per_process && has_render_view_) {
700 // This will trigger a callback to RenderViewReady after a round-trip IPC. 730 // This will trigger a callback to RenderViewReady after a round-trip IPC.
701 static_cast<RenderViewHostImpl*>( 731 static_cast<RenderViewHostImpl*>(
702 GetWebContents()->GetRenderViewHost())->Init(); 732 GetWebContents()->GetRenderViewHost())->Init();
703 WebContentsViewGuest* web_contents_view = 733 WebContentsViewGuest* web_contents_view =
704 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 734 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
705 if (!web_contents()->GetRenderViewHost()->GetView()) { 735 if (!web_contents()->GetRenderViewHost()->GetView()) {
706 web_contents_view->CreateViewForWidget( 736 web_contents_view->CreateViewForWidget(
707 web_contents()->GetRenderViewHost(), true); 737 web_contents()->GetRenderViewHost(), true);
708 } 738 }
709 } 739 }
710 740
711 InitInternal(params, embedder_web_contents); 741 InitInternal(params, embedder_web_contents);
712 742
713 attached_ = true; 743 attached_ = true;
714 SendQueuedMessages(); 744 SendQueuedMessages();
715 745
716 delegate_->DidAttach(GetGuestProxyRoutingID()); 746 delegate_->DidAttach(GetGuestProxyRoutingID());
717 747
718 has_render_view_ = true; 748 if (!use_site_per_process) {
749 has_render_view_ = true;
719 750
720 // Enable input method for guest if it's enabled for the embedder. 751 // Enable input method for guest if it's enabled for the embedder.
721 if (static_cast<RenderViewHostImpl*>( 752 if (static_cast<RenderViewHostImpl*>(
722 owner_web_contents_->GetRenderViewHost())->input_method_active()) { 753 owner_web_contents_->GetRenderViewHost())->input_method_active()) {
723 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 754 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
724 GetWebContents()->GetRenderViewHost()); 755 GetWebContents()->GetRenderViewHost());
725 guest_rvh->SetInputMethodActive(true); 756 guest_rvh->SetInputMethodActive(true);
757 }
726 } 758 }
727 759
728 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); 760 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached"));
729 } 761 }
730 762
731 void BrowserPluginGuest::OnCompositorFrameSwappedACK( 763 void BrowserPluginGuest::OnCompositorFrameSwappedACK(
732 int browser_plugin_instance_id, 764 int browser_plugin_instance_id,
733 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { 765 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
734 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, 766 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
735 params.output_surface_id, 767 params.output_surface_id,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 void BrowserPluginGuest::OnImeCompositionRangeChanged( 1001 void BrowserPluginGuest::OnImeCompositionRangeChanged(
970 const gfx::Range& range, 1002 const gfx::Range& range,
971 const std::vector<gfx::Rect>& character_bounds) { 1003 const std::vector<gfx::Rect>& character_bounds) {
972 static_cast<RenderWidgetHostViewBase*>( 1004 static_cast<RenderWidgetHostViewBase*>(
973 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 1005 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
974 range, character_bounds); 1006 range, character_bounds);
975 } 1007 }
976 #endif 1008 #endif
977 1009
978 } // namespace content 1010 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698