Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl.cc | 
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc | 
| index 6228fbf1316f1e4295bfe077168b7be7b1e8a708..ee9471abcea7897511379e66a3f41b3b70cc8054 100644 | 
| --- a/content/browser/web_contents/web_contents_impl.cc | 
| +++ b/content/browser/web_contents/web_contents_impl.cc | 
| @@ -286,6 +286,17 @@ WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id, | 
| WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { | 
| } | 
| +// WebContentsImpl::WebContentsTreeNode ---------------------------------------- | 
| +WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode() | 
| + : parent_web_contents_(nullptr) { | 
| +} | 
| + | 
| +WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { | 
| + // TODO(lazyboy): Enforce that a child WebContentsTreeNode gets deleted | 
| + // before its parent. Otherwise the child could have a stale pointer to its | 
| + // parent WebContents, risking a use-after-free. | 
| +} | 
| + | 
| // WebContentsImpl ------------------------------------------------------------- | 
| WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, | 
| @@ -1133,6 +1144,32 @@ void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 
| GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); | 
| } | 
| +void WebContentsImpl::AttachToEmbedderFrame(WebContents* embedder_web_contents, | 
| + RenderFrameHost* embedder_frame) { | 
| + CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| + switches::kSitePerProcess)); | 
| + // 1. Create a link to our parent WebContents. | 
| 
 
nasko
2015/05/05 21:34:50
nit: I don't know if the numbering of the comments
 
lazyboy
2015/05/05 22:33:53
Removed numbers.
 
 | 
| + node_.set_parent_web_contents( | 
| + static_cast<WebContentsImpl*>(embedder_web_contents)); | 
| + | 
| + DCHECK(embedder_frame); | 
| + | 
| + // 2. Create a swapped out RVH and a proxy in our render manager, pointing | 
| + // to the embedder's SiteInstance. The swapped out RVH will be used to send | 
| + // postMessage to guest. | 
| + int proxy_to_embedder_routing_id = GetRenderManager()->CreateEmbedderProxy( | 
| + embedder_frame->GetSiteInstance()); | 
| + | 
| + // 3. Swap the embedder's initial frame for the guest with the proxy | 
| + // we've created above. | 
| + // The proxy has a CPFC and it uses the swapped out RV as its RenderWidget, | 
| + // which gives us input and rendering. | 
| + static_cast<RenderFrameHostImpl*>(embedder_frame) | 
| + ->frame_tree_node() | 
| + ->render_manager() | 
| + ->ReplaceWithGuestProxy(proxy_to_embedder_routing_id); | 
| +} | 
| + | 
| void WebContentsImpl::Stop() { | 
| GetRenderManager()->Stop(); | 
| FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); | 
| @@ -1204,7 +1241,9 @@ void WebContentsImpl::Init(const WebContents::CreateParams& params) { | 
| WebContentsViewDelegate* delegate = | 
| GetContentClient()->browser()->GetWebContentsViewDelegate(this); | 
| - if (browser_plugin_guest_) { | 
| + if (browser_plugin_guest_ && | 
| + !base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| + switches::kSitePerProcess)) { | 
| scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( | 
| this, delegate, &render_view_host_delegate_view_)); | 
| @@ -1513,6 +1552,13 @@ void WebContentsImpl::CreateNewWindow( | 
| // SiteInstance in its own BrowsingInstance. | 
| bool is_guest = BrowserPluginGuest::IsGuest(this); | 
| + if (is_guest && | 
| + base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| + switches::kSitePerProcess)) { | 
| + // TODO(lazyboy): CreateNewWindow doesn't work for <webview> yet. | 
| + NOTREACHED(); | 
| + } | 
| + | 
| // If the opener is to be suppressed, the new window can be in any process. | 
| // Since routing ids are process specific, we must not have one passed in | 
| // as argument here. | 
| @@ -1731,7 +1777,9 @@ void WebContentsImpl::ShowCreatedWidget(int route_id, | 
| RenderWidgetHostView* view = NULL; | 
| BrowserPluginGuest* guest = GetBrowserPluginGuest(); | 
| - if (guest && guest->embedder_web_contents()) { | 
| + if (guest && guest->embedder_web_contents() && | 
| + base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| + switches::kSitePerProcess)) { | 
| view = guest->embedder_web_contents()->GetRenderWidgetHostView(); | 
| } else { | 
| view = GetRenderWidgetHostView(); | 
| @@ -4176,10 +4224,16 @@ bool WebContentsImpl::CreateRenderViewForRenderManager( | 
| // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 
| // case this because RWH is still a base class of RenderViewHost, and child | 
| // frame RWHVs are unique in that they do not have their own WebContents. | 
| - if (!for_main_frame_navigation) { | 
| + bool is_guest_in_site_per_process = | 
| + !!browser_plugin_guest_.get() && | 
| + base::CommandLine::ForCurrentProcess()->HasSwitch( | 
| + switches::kSitePerProcess); | 
| + if (!for_main_frame_navigation || is_guest_in_site_per_process) { | 
| RenderWidgetHostViewChildFrame* rwh_view_child = | 
| new RenderWidgetHostViewChildFrame(render_view_host); | 
| rwh_view = rwh_view_child; | 
| + if (is_guest_in_site_per_process) | 
| + GetRenderManager()->SetGuestRWHView(rwh_view_child); | 
| } else { | 
| rwh_view = view_->CreateViewForWidget(render_view_host, false); | 
| } | 
| @@ -4318,6 +4372,16 @@ bool WebContentsImpl::IsHidden() { | 
| return capturer_count_ == 0 && !should_normally_be_visible_; | 
| } | 
| +int64 WebContentsImpl::GetEmbedderFrameTreeNodeID() { | 
| + if (node_.parent_web_contents()) { | 
| + return node_.parent_web_contents() | 
| + ->GetFrameTree() | 
| + ->root() | 
| + ->frame_tree_node_id(); | 
| + } | 
| + return -1; | 
| +} | 
| + | 
| RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 
| return frame_tree_.root()->render_manager(); | 
| } | 
| @@ -4328,6 +4392,7 @@ BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 
| void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 
| CHECK(!browser_plugin_guest_); | 
| + CHECK(guest); | 
| browser_plugin_guest_.reset(guest); | 
| } |