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

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: address comments from nasko@ 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/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_contents_frame_tree_node_id_(
301 FrameTreeNode::FRAME_TREE_NODE_ID_NONE),
302 outer_web_contents_(nullptr) {
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 // child WebContents do not manage their own lifetime, then we would leak
318 // them.
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.
nasko 2015/06/15 23:00:13 nit: Is postMessage the only thing that will use t
lazyboy 2015/06/16 17:59:52 We expose this proxy as <webview>.contentWindow, a
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.
nasko 2015/06/15 23:00:13 Is it meant to?
lazyboy 2015/06/16 17:59:52 Yes, we need window.open to work from webview!
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 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
4205 const FrameReplicationState& replicated_frame_state, 4277 const FrameReplicationState& replicated_frame_state,
4206 bool for_main_frame_navigation) { 4278 bool for_main_frame_navigation) {
4207 TRACE_EVENT0("browser,navigation", 4279 TRACE_EVENT0("browser,navigation",
4208 "WebContentsImpl::CreateRenderViewForRenderManager"); 4280 "WebContentsImpl::CreateRenderViewForRenderManager");
4209 // Can be NULL during tests. 4281 // Can be NULL during tests.
4210 RenderWidgetHostViewBase* rwh_view; 4282 RenderWidgetHostViewBase* rwh_view;
4211 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary 4283 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4212 // until RenderWidgetHost is attached to RenderFrameHost. We need to special 4284 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4213 // case this because RWH is still a base class of RenderViewHost, and child 4285 // case this because RWH is still a base class of RenderViewHost, and child
4214 // frame RWHVs are unique in that they do not have their own WebContents. 4286 // frame RWHVs are unique in that they do not have their own WebContents.
4215 if (!for_main_frame_navigation) { 4287 bool is_guest_in_site_per_process =
4288 !!browser_plugin_guest_.get() &&
4289 base::CommandLine::ForCurrentProcess()->HasSwitch(
4290 switches::kSitePerProcess);
4291 if (!for_main_frame_navigation || is_guest_in_site_per_process) {
4216 RenderWidgetHostViewChildFrame* rwh_view_child = 4292 RenderWidgetHostViewChildFrame* rwh_view_child =
4217 new RenderWidgetHostViewChildFrame(render_view_host); 4293 new RenderWidgetHostViewChildFrame(render_view_host);
4218 rwh_view = rwh_view_child; 4294 rwh_view = rwh_view_child;
4219 } else { 4295 } else {
4220 rwh_view = view_->CreateViewForWidget(render_view_host, false); 4296 rwh_view = view_->CreateViewForWidget(render_view_host, false);
4221 } 4297 }
4222 4298
4223 // Now that the RenderView has been created, we need to tell it its size. 4299 // Now that the RenderView has been created, we need to tell it its size.
4224 if (rwh_view) 4300 if (rwh_view)
4225 rwh_view->SetSize(GetSizeForNewRenderView()); 4301 rwh_view->SetSize(GetSizeForNewRenderView());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4349 last_reported_encoding_ = encoding; 4425 last_reported_encoding_ = encoding;
4350 4426
4351 canonical_encoding_ = GetContentClient()->browser()-> 4427 canonical_encoding_ = GetContentClient()->browser()->
4352 GetCanonicalEncodingNameByAliasName(encoding); 4428 GetCanonicalEncodingNameByAliasName(encoding);
4353 } 4429 }
4354 4430
4355 bool WebContentsImpl::IsHidden() { 4431 bool WebContentsImpl::IsHidden() {
4356 return capturer_count_ == 0 && !should_normally_be_visible_; 4432 return capturer_count_ == 0 && !should_normally_be_visible_;
4357 } 4433 }
4358 4434
4435 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4436 if (node_ && node_->outer_web_contents())
4437 return node_->outer_contents_frame_tree_node_id();
4438
4439 return FrameTreeNode::FRAME_TREE_NODE_ID_NONE;
4440 }
4441
4359 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { 4442 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
4360 return frame_tree_.root()->render_manager(); 4443 return frame_tree_.root()->render_manager();
4361 } 4444 }
4362 4445
4363 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { 4446 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
4364 return browser_plugin_guest_.get(); 4447 return browser_plugin_guest_.get();
4365 } 4448 }
4366 4449
4367 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { 4450 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4368 CHECK(!browser_plugin_guest_); 4451 CHECK(!browser_plugin_guest_);
4452 CHECK(guest);
4369 browser_plugin_guest_.reset(guest); 4453 browser_plugin_guest_.reset(guest);
4370 } 4454 }
4371 4455
4372 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { 4456 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
4373 return browser_plugin_embedder_.get(); 4457 return browser_plugin_embedder_.get();
4374 } 4458 }
4375 4459
4376 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { 4460 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4377 if (browser_plugin_embedder_) 4461 if (browser_plugin_embedder_)
4378 return; 4462 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4460 player_map->erase(it); 4544 player_map->erase(it);
4461 } 4545 }
4462 4546
4463 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4547 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4464 force_disable_overscroll_content_ = force_disable; 4548 force_disable_overscroll_content_ = force_disable;
4465 if (view_) 4549 if (view_)
4466 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4550 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4467 } 4551 }
4468 4552
4469 } // namespace content 4553 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698