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

Side by Side Diff: content/browser/web_contents/web_contents_impl.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: sync Created 5 years, 5 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
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/web_contents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 int identifier) 288 int identifier)
289 : render_process_id(render_process_id), 289 : render_process_id(render_process_id),
290 render_frame_id(render_frame_id), 290 render_frame_id(render_frame_id),
291 chooser(chooser), 291 chooser(chooser),
292 identifier(identifier) { 292 identifier(identifier) {
293 } 293 }
294 294
295 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { 295 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
296 } 296 }
297 297
298 // WebContentsImpl::WebContentsTreeNode ----------------------------------------
299 WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
300 : outer_web_contents_(nullptr),
301 outer_contents_frame_tree_node_id_(
302 FrameTreeNode::kFrameTreeNodeInvalidID) {
303 }
304
305 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
306 // Remove child pointer from our parent.
307 if (outer_web_contents_) {
308 ChildrenSet& child_ptrs_in_parent =
309 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
310 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
311 DCHECK(iter != child_ptrs_in_parent.end());
312 child_ptrs_in_parent.erase(this);
313 }
314
315 // Remove parent pointers from our children.
316 // TODO(lazyboy): We should destroy the children WebContentses too. If the
317 // children do not manage their own lifetime, then we would leak their
318 // WebContentses.
319 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
320 child->outer_web_contents_ = nullptr;
321 }
322
323 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
324 WebContentsImpl* outer_web_contents,
325 RenderFrameHostImpl* outer_contents_frame) {
326 outer_web_contents_ = outer_web_contents;
327 outer_contents_frame_tree_node_id_ =
328 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
329
330 if (!outer_web_contents_->node_)
331 outer_web_contents_->node_.reset(new WebContentsTreeNode());
332
333 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
334 }
335
298 // WebContentsImpl ------------------------------------------------------------- 336 // WebContentsImpl -------------------------------------------------------------
299 337
300 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) 338 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
301 : delegate_(NULL), 339 : delegate_(NULL),
302 controller_(this, browser_context), 340 controller_(this, browser_context),
303 render_view_host_delegate_view_(NULL), 341 render_view_host_delegate_view_(NULL),
304 created_with_opener_(false), 342 created_with_opener_(false),
305 #if defined(OS_WIN) 343 #if defined(OS_WIN)
306 accessible_parent_(NULL), 344 accessible_parent_(NULL),
307 #endif 345 #endif
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 bool WebContentsImpl::NeedToFireBeforeUnload() { 1207 bool WebContentsImpl::NeedToFireBeforeUnload() {
1170 // TODO(creis): Should we fire even for interstitial pages? 1208 // TODO(creis): Should we fire even for interstitial pages?
1171 return WillNotifyDisconnection() && !ShowingInterstitialPage() && 1209 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1172 !GetRenderViewHost()->SuddenTerminationAllowed(); 1210 !GetRenderViewHost()->SuddenTerminationAllowed();
1173 } 1211 }
1174 1212
1175 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 1213 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1176 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); 1214 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1177 } 1215 }
1178 1216
1217 void WebContentsImpl::AttachToOuterWebContentsFrame(
1218 WebContents* outer_web_contents,
1219 RenderFrameHost* outer_contents_frame) {
1220 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1221 switches::kSitePerProcess));
1222 // Create a link to our outer WebContents.
1223 node_.reset(new WebContentsTreeNode());
1224 node_->ConnectToOuterWebContents(
1225 static_cast<WebContentsImpl*>(outer_web_contents),
1226 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1227
1228 DCHECK(outer_contents_frame);
1229
1230 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1231 // SiteInstance of the outer WebContents. The proxy will be used to send
1232 // postMessage to the inner WebContents.
1233 GetRenderManager()->CreateOuterDelegateProxy(
1234 outer_contents_frame->GetSiteInstance(),
1235 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1236
1237 GetRenderManager()->SetRWHViewForInnerContents(
1238 GetRenderManager()->GetRenderWidgetHostView());
1239 }
1240
1179 void WebContentsImpl::Stop() { 1241 void WebContentsImpl::Stop() {
1180 GetRenderManager()->Stop(); 1242 GetRenderManager()->Stop();
1181 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1243 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1182 } 1244 }
1183 1245
1184 WebContents* WebContentsImpl::Clone() { 1246 WebContents* WebContentsImpl::Clone() {
1185 // We use our current SiteInstance since the cloned entry will use it anyway. 1247 // We use our current SiteInstance since the cloned entry will use it anyway.
1186 // We pass our own opener so that the cloned page can access it if it was set 1248 // We pass our own opener so that the cloned page can access it if it was set
1187 // before. 1249 // before.
1188 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); 1250 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 (params.routing_id != MSG_ROUTING_NONE && 1304 (params.routing_id != MSG_ROUTING_NONE &&
1243 params.main_frame_routing_id != MSG_ROUTING_NONE)); 1305 params.main_frame_routing_id != MSG_ROUTING_NONE));
1244 GetRenderManager()->Init( 1306 GetRenderManager()->Init(
1245 params.browser_context, params.site_instance, params.routing_id, 1307 params.browser_context, params.site_instance, params.routing_id,
1246 params.main_frame_routing_id); 1308 params.main_frame_routing_id);
1247 frame_tree_.root()->SetFrameName(params.main_frame_name); 1309 frame_tree_.root()->SetFrameName(params.main_frame_name);
1248 1310
1249 WebContentsViewDelegate* delegate = 1311 WebContentsViewDelegate* delegate =
1250 GetContentClient()->browser()->GetWebContentsViewDelegate(this); 1312 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1251 1313
1252 if (browser_plugin_guest_) { 1314 if (browser_plugin_guest_ &&
1315 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1316 switches::kSitePerProcess)) {
1253 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( 1317 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1254 this, delegate, &render_view_host_delegate_view_)); 1318 this, delegate, &render_view_host_delegate_view_));
1255 1319
1256 WebContentsViewGuest* rv = new WebContentsViewGuest( 1320 WebContentsViewGuest* rv = new WebContentsViewGuest(
1257 this, browser_plugin_guest_.get(), platform_view.Pass(), 1321 this, browser_plugin_guest_.get(), platform_view.Pass(),
1258 render_view_host_delegate_view_); 1322 render_view_host_delegate_view_);
1259 render_view_host_delegate_view_ = rv; 1323 render_view_host_delegate_view_ = rv;
1260 view_.reset(rv); 1324 view_.reset(rv);
1261 } else { 1325 } else {
1262 // Regular WebContentsView. 1326 // Regular WebContentsView.
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 int route_id, 1607 int route_id,
1544 int main_frame_route_id, 1608 int main_frame_route_id,
1545 const ViewHostMsg_CreateWindow_Params& params, 1609 const ViewHostMsg_CreateWindow_Params& params,
1546 SessionStorageNamespace* session_storage_namespace) { 1610 SessionStorageNamespace* session_storage_namespace) {
1547 // We usually create the new window in the same BrowsingInstance (group of 1611 // We usually create the new window in the same BrowsingInstance (group of
1548 // script-related windows), by passing in the current SiteInstance. However, 1612 // script-related windows), by passing in the current SiteInstance. However,
1549 // if the opener is being suppressed (in a non-guest), we create a new 1613 // if the opener is being suppressed (in a non-guest), we create a new
1550 // SiteInstance in its own BrowsingInstance. 1614 // SiteInstance in its own BrowsingInstance.
1551 bool is_guest = BrowserPluginGuest::IsGuest(this); 1615 bool is_guest = BrowserPluginGuest::IsGuest(this);
1552 1616
1617 if (is_guest &&
1618 base::CommandLine::ForCurrentProcess()->HasSwitch(
1619 switches::kSitePerProcess)) {
1620 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1621 // yet.
1622 NOTREACHED();
1623 }
1624
1553 // If the opener is to be suppressed, the new window can be in any process. 1625 // If the opener is to be suppressed, the new window can be in any process.
1554 // Since routing ids are process specific, we must not have one passed in 1626 // Since routing ids are process specific, we must not have one passed in
1555 // as argument here. 1627 // as argument here.
1556 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); 1628 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1557 1629
1558 scoped_refptr<SiteInstance> site_instance = 1630 scoped_refptr<SiteInstance> site_instance =
1559 params.opener_suppressed && !is_guest ? 1631 params.opener_suppressed && !is_guest ?
1560 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : 1632 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
1561 GetSiteInstance(); 1633 GetSiteInstance();
1562 1634
(...skipping 2355 matching lines...) Expand 10 before | Expand all | Expand 10 after
3918 // probably not a risk for apps since other pages won't have references 3990 // probably not a risk for apps since other pages won't have references
3919 // to App windows. 3991 // to App windows.
3920 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); 3992 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
3921 } 3993 }
3922 3994
3923 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { 3995 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
3924 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( 3996 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
3925 WebContents::FromRenderFrameHost(source_rfh)); 3997 WebContents::FromRenderFrameHost(source_rfh));
3926 3998
3927 if (source_web_contents) { 3999 if (source_web_contents) {
4000 // If this message is going to outer WebContents from inner WebContents,
4001 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4002 // already created a RenderFrameProxyHost for that purpose.
4003 if (GetBrowserPluginEmbedder() &&
4004 base::CommandLine::ForCurrentProcess()->HasSwitch(
4005 switches::kSitePerProcess)) {
4006 return;
4007 }
4008
3928 if (GetBrowserPluginGuest()) { 4009 if (GetBrowserPluginGuest()) {
3929 // We create a swapped out RenderView for the embedder in the guest's 4010 // We create a swapped out RenderView for the embedder in the guest's
3930 // render process but we intentionally do not expose the embedder's 4011 // render process but we intentionally do not expose the embedder's
3931 // opener chain to it. 4012 // opener chain to it.
3932 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); 4013 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance());
3933 } else { 4014 } else {
3934 RenderFrameHostImpl* source_rfhi = 4015 RenderFrameHostImpl* source_rfhi =
3935 static_cast<RenderFrameHostImpl*>(source_rfh); 4016 static_cast<RenderFrameHostImpl*>(source_rfh);
3936 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( 4017 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
3937 GetSiteInstance()); 4018 GetSiteInstance());
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
4137 const FrameReplicationState& replicated_frame_state, 4218 const FrameReplicationState& replicated_frame_state,
4138 bool for_main_frame_navigation) { 4219 bool for_main_frame_navigation) {
4139 TRACE_EVENT0("browser,navigation", 4220 TRACE_EVENT0("browser,navigation",
4140 "WebContentsImpl::CreateRenderViewForRenderManager"); 4221 "WebContentsImpl::CreateRenderViewForRenderManager");
4141 // Can be NULL during tests. 4222 // Can be NULL during tests.
4142 RenderWidgetHostViewBase* rwh_view; 4223 RenderWidgetHostViewBase* rwh_view;
4143 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary 4224 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4144 // until RenderWidgetHost is attached to RenderFrameHost. We need to special 4225 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4145 // case this because RWH is still a base class of RenderViewHost, and child 4226 // case this because RWH is still a base class of RenderViewHost, and child
4146 // frame RWHVs are unique in that they do not have their own WebContents. 4227 // frame RWHVs are unique in that they do not have their own WebContents.
4147 if (!for_main_frame_navigation) { 4228 bool is_guest_in_site_per_process =
4229 !!browser_plugin_guest_.get() &&
4230 base::CommandLine::ForCurrentProcess()->HasSwitch(
4231 switches::kSitePerProcess);
4232 if (!for_main_frame_navigation || is_guest_in_site_per_process) {
4148 RenderWidgetHostViewChildFrame* rwh_view_child = 4233 RenderWidgetHostViewChildFrame* rwh_view_child =
4149 new RenderWidgetHostViewChildFrame(render_view_host); 4234 new RenderWidgetHostViewChildFrame(render_view_host);
4150 rwh_view = rwh_view_child; 4235 rwh_view = rwh_view_child;
4151 } else { 4236 } else {
4152 rwh_view = view_->CreateViewForWidget(render_view_host, false); 4237 rwh_view = view_->CreateViewForWidget(render_view_host, false);
4153 } 4238 }
4154 4239
4155 // Now that the RenderView has been created, we need to tell it its size. 4240 // Now that the RenderView has been created, we need to tell it its size.
4156 if (rwh_view) 4241 if (rwh_view)
4157 rwh_view->SetSize(GetSizeForNewRenderView()); 4242 rwh_view->SetSize(GetSizeForNewRenderView());
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
4280 last_reported_encoding_ = encoding; 4365 last_reported_encoding_ = encoding;
4281 4366
4282 canonical_encoding_ = GetContentClient()->browser()-> 4367 canonical_encoding_ = GetContentClient()->browser()->
4283 GetCanonicalEncodingNameByAliasName(encoding); 4368 GetCanonicalEncodingNameByAliasName(encoding);
4284 } 4369 }
4285 4370
4286 bool WebContentsImpl::IsHidden() { 4371 bool WebContentsImpl::IsHidden() {
4287 return capturer_count_ == 0 && !should_normally_be_visible_; 4372 return capturer_count_ == 0 && !should_normally_be_visible_;
4288 } 4373 }
4289 4374
4375 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4376 if (node_ && node_->outer_web_contents())
4377 return node_->outer_contents_frame_tree_node_id();
4378
4379 return FrameTreeNode::kFrameTreeNodeInvalidID;
4380 }
4381
4290 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { 4382 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
4291 return frame_tree_.root()->render_manager(); 4383 return frame_tree_.root()->render_manager();
4292 } 4384 }
4293 4385
4294 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { 4386 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
4295 return browser_plugin_guest_.get(); 4387 return browser_plugin_guest_.get();
4296 } 4388 }
4297 4389
4298 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { 4390 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4299 CHECK(!browser_plugin_guest_); 4391 CHECK(!browser_plugin_guest_);
4392 CHECK(guest);
4300 browser_plugin_guest_.reset(guest); 4393 browser_plugin_guest_.reset(guest);
4301 } 4394 }
4302 4395
4303 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { 4396 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
4304 return browser_plugin_embedder_.get(); 4397 return browser_plugin_embedder_.get();
4305 } 4398 }
4306 4399
4307 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { 4400 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4308 if (browser_plugin_embedder_) 4401 if (browser_plugin_embedder_)
4309 return; 4402 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4391 player_map->erase(it); 4484 player_map->erase(it);
4392 } 4485 }
4393 4486
4394 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4487 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4395 force_disable_overscroll_content_ = force_disable; 4488 force_disable_overscroll_content_ = force_disable;
4396 if (view_) 4489 if (view_)
4397 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4490 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4398 } 4491 }
4399 4492
4400 } // namespace content 4493 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | content/public/browser/web_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698