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

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: Rebase after swapped out changes major rework with RFP 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 int identifier) 283 int identifier)
284 : render_process_id(render_process_id), 284 : render_process_id(render_process_id),
285 render_frame_id(render_frame_id), 285 render_frame_id(render_frame_id),
286 chooser(chooser), 286 chooser(chooser),
287 identifier(identifier) { 287 identifier(identifier) {
288 } 288 }
289 289
290 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { 290 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
291 } 291 }
292 292
293 // WebContentsImpl::WebContentsTreeNode ----------------------------------------
294 WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
295 : outer_contents_frame_tree_node_id_(-1), outer_web_contents_(nullptr) {
296 }
297
298 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
299 // Remove child pointer from our parent.
300 if (outer_web_contents_) {
301 ChildrenSet& child_ptrs_in_parent =
302 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
303 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
304 DCHECK(iter != child_ptrs_in_parent.end());
305 child_ptrs_in_parent.erase(this);
306 }
307
308 // Remove parent pointers from our children.
309 // TODO(lazyboy): We should destroy the children WebContentses too. If the
310 // child WebContents do not manage their own lifetime, then we would leak
311 // them.
312 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
313 child->outer_web_contents_ = nullptr;
314 }
315
316 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
317 WebContentsImpl* outer_web_contents,
318 RenderFrameHostImpl* outer_contents_frame) {
319 outer_web_contents_ = outer_web_contents;
320 outer_contents_frame_tree_node_id_ =
321 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
322
323 if (!outer_web_contents_->node_)
324 outer_web_contents_->node_.reset(new WebContentsTreeNode());
325
326 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
327 }
328
293 // WebContentsImpl ------------------------------------------------------------- 329 // WebContentsImpl -------------------------------------------------------------
294 330
295 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, 331 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
296 WebContentsImpl* opener) 332 WebContentsImpl* opener)
297 : delegate_(NULL), 333 : delegate_(NULL),
298 controller_(this, browser_context), 334 controller_(this, browser_context),
299 render_view_host_delegate_view_(NULL), 335 render_view_host_delegate_view_(NULL),
300 opener_(opener), 336 opener_(opener),
301 created_with_opener_(!!opener), 337 created_with_opener_(!!opener),
302 #if defined(OS_WIN) 338 #if defined(OS_WIN)
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 bool WebContentsImpl::NeedToFireBeforeUnload() { 1196 bool WebContentsImpl::NeedToFireBeforeUnload() {
1161 // TODO(creis): Should we fire even for interstitial pages? 1197 // TODO(creis): Should we fire even for interstitial pages?
1162 return WillNotifyDisconnection() && !ShowingInterstitialPage() && 1198 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1163 !GetRenderViewHost()->SuddenTerminationAllowed(); 1199 !GetRenderViewHost()->SuddenTerminationAllowed();
1164 } 1200 }
1165 1201
1166 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 1202 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1167 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); 1203 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1168 } 1204 }
1169 1205
1206 void WebContentsImpl::AttachToOuterWebContentsFrame(
1207 WebContents* outer_web_contents,
1208 RenderFrameHost* outer_contents_frame) {
1209 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1210 switches::kSitePerProcess));
1211 // Create a link to our outer WebContents.
1212 node_.reset(new WebContentsTreeNode());
1213 node_->ConnectToOuterWebContents(
1214 static_cast<WebContentsImpl*>(outer_web_contents),
1215 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1216
1217 DCHECK(outer_contents_frame);
1218
1219 // Create a proxy in our render manager, pointing to the SiteInstance of the
nasko 2015/06/11 00:21:28 nit: s/render manager/top-level RenderFrameHostMan
lazyboy 2015/06/11 22:20:29 Done.
1220 // outer WebContents. The proxy will be used to send postMessage to the inner
1221 // WebContents.
1222 GetRenderManager()->CreateOuterDelegateProxy(
1223 outer_contents_frame->GetSiteInstance(),
1224 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1225
1226 GetRenderManager()->SetRWHViewForInnerContents(
1227 GetRenderManager()->GetRenderWidgetHostView());
1228 }
1229
1170 void WebContentsImpl::Stop() { 1230 void WebContentsImpl::Stop() {
1171 GetRenderManager()->Stop(); 1231 GetRenderManager()->Stop();
1172 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1232 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1173 } 1233 }
1174 1234
1175 WebContents* WebContentsImpl::Clone() { 1235 WebContents* WebContentsImpl::Clone() {
1176 // We use our current SiteInstance since the cloned entry will use it anyway. 1236 // We use our current SiteInstance since the cloned entry will use it anyway.
1177 // We pass our own opener so that the cloned page can access it if it was 1237 // We pass our own opener so that the cloned page can access it if it was
1178 // before. 1238 // before.
1179 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); 1239 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 (params.routing_id != MSG_ROUTING_NONE && 1292 (params.routing_id != MSG_ROUTING_NONE &&
1233 params.main_frame_routing_id != MSG_ROUTING_NONE)); 1293 params.main_frame_routing_id != MSG_ROUTING_NONE));
1234 GetRenderManager()->Init( 1294 GetRenderManager()->Init(
1235 params.browser_context, params.site_instance, params.routing_id, 1295 params.browser_context, params.site_instance, params.routing_id,
1236 params.main_frame_routing_id); 1296 params.main_frame_routing_id);
1237 frame_tree_.root()->SetFrameName(params.main_frame_name); 1297 frame_tree_.root()->SetFrameName(params.main_frame_name);
1238 1298
1239 WebContentsViewDelegate* delegate = 1299 WebContentsViewDelegate* delegate =
1240 GetContentClient()->browser()->GetWebContentsViewDelegate(this); 1300 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1241 1301
1242 if (browser_plugin_guest_) { 1302 if (browser_plugin_guest_ &&
1303 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1304 switches::kSitePerProcess)) {
1243 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( 1305 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1244 this, delegate, &render_view_host_delegate_view_)); 1306 this, delegate, &render_view_host_delegate_view_));
1245 1307
1246 WebContentsViewGuest* rv = new WebContentsViewGuest( 1308 WebContentsViewGuest* rv = new WebContentsViewGuest(
1247 this, browser_plugin_guest_.get(), platform_view.Pass(), 1309 this, browser_plugin_guest_.get(), platform_view.Pass(),
1248 render_view_host_delegate_view_); 1310 render_view_host_delegate_view_);
1249 render_view_host_delegate_view_ = rv; 1311 render_view_host_delegate_view_ = rv;
1250 view_.reset(rv); 1312 view_.reset(rv);
1251 } else { 1313 } else {
1252 // Regular WebContentsView. 1314 // Regular WebContentsView.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 int route_id, 1604 int route_id,
1543 int main_frame_route_id, 1605 int main_frame_route_id,
1544 const ViewHostMsg_CreateWindow_Params& params, 1606 const ViewHostMsg_CreateWindow_Params& params,
1545 SessionStorageNamespace* session_storage_namespace) { 1607 SessionStorageNamespace* session_storage_namespace) {
1546 // We usually create the new window in the same BrowsingInstance (group of 1608 // We usually create the new window in the same BrowsingInstance (group of
1547 // script-related windows), by passing in the current SiteInstance. However, 1609 // script-related windows), by passing in the current SiteInstance. However,
1548 // if the opener is being suppressed (in a non-guest), we create a new 1610 // if the opener is being suppressed (in a non-guest), we create a new
1549 // SiteInstance in its own BrowsingInstance. 1611 // SiteInstance in its own BrowsingInstance.
1550 bool is_guest = BrowserPluginGuest::IsGuest(this); 1612 bool is_guest = BrowserPluginGuest::IsGuest(this);
1551 1613
1614 if (is_guest &&
1615 base::CommandLine::ForCurrentProcess()->HasSwitch(
1616 switches::kSitePerProcess)) {
1617 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1618 // yet.
1619 NOTREACHED();
1620 }
1621
1552 // If the opener is to be suppressed, the new window can be in any process. 1622 // If the opener is to be suppressed, the new window can be in any process.
1553 // Since routing ids are process specific, we must not have one passed in 1623 // Since routing ids are process specific, we must not have one passed in
1554 // as argument here. 1624 // as argument here.
1555 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); 1625 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1556 1626
1557 scoped_refptr<SiteInstance> site_instance = 1627 scoped_refptr<SiteInstance> site_instance =
1558 params.opener_suppressed && !is_guest ? 1628 params.opener_suppressed && !is_guest ?
1559 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : 1629 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
1560 GetSiteInstance(); 1630 GetSiteInstance();
1561 1631
(...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after
4209 const FrameReplicationState& replicated_frame_state, 4279 const FrameReplicationState& replicated_frame_state,
4210 bool for_main_frame_navigation) { 4280 bool for_main_frame_navigation) {
4211 TRACE_EVENT0("browser,navigation", 4281 TRACE_EVENT0("browser,navigation",
4212 "WebContentsImpl::CreateRenderViewForRenderManager"); 4282 "WebContentsImpl::CreateRenderViewForRenderManager");
4213 // Can be NULL during tests. 4283 // Can be NULL during tests.
4214 RenderWidgetHostViewBase* rwh_view; 4284 RenderWidgetHostViewBase* rwh_view;
4215 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary 4285 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4216 // until RenderWidgetHost is attached to RenderFrameHost. We need to special 4286 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4217 // case this because RWH is still a base class of RenderViewHost, and child 4287 // case this because RWH is still a base class of RenderViewHost, and child
4218 // frame RWHVs are unique in that they do not have their own WebContents. 4288 // frame RWHVs are unique in that they do not have their own WebContents.
4219 if (!for_main_frame_navigation) { 4289 bool is_guest_in_site_per_process =
4290 !!browser_plugin_guest_.get() &&
4291 base::CommandLine::ForCurrentProcess()->HasSwitch(
4292 switches::kSitePerProcess);
4293 if (!for_main_frame_navigation || is_guest_in_site_per_process) {
4220 RenderWidgetHostViewChildFrame* rwh_view_child = 4294 RenderWidgetHostViewChildFrame* rwh_view_child =
4221 new RenderWidgetHostViewChildFrame(render_view_host); 4295 new RenderWidgetHostViewChildFrame(render_view_host);
4222 rwh_view = rwh_view_child; 4296 rwh_view = rwh_view_child;
4223 } else { 4297 } else {
4224 rwh_view = view_->CreateViewForWidget(render_view_host, false); 4298 rwh_view = view_->CreateViewForWidget(render_view_host, false);
4225 } 4299 }
4226 4300
4227 // Now that the RenderView has been created, we need to tell it its size. 4301 // Now that the RenderView has been created, we need to tell it its size.
4228 if (rwh_view) 4302 if (rwh_view)
4229 rwh_view->SetSize(GetSizeForNewRenderView()); 4303 rwh_view->SetSize(GetSizeForNewRenderView());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4353 last_reported_encoding_ = encoding; 4427 last_reported_encoding_ = encoding;
4354 4428
4355 canonical_encoding_ = GetContentClient()->browser()-> 4429 canonical_encoding_ = GetContentClient()->browser()->
4356 GetCanonicalEncodingNameByAliasName(encoding); 4430 GetCanonicalEncodingNameByAliasName(encoding);
4357 } 4431 }
4358 4432
4359 bool WebContentsImpl::IsHidden() { 4433 bool WebContentsImpl::IsHidden() {
4360 return capturer_count_ == 0 && !should_normally_be_visible_; 4434 return capturer_count_ == 0 && !should_normally_be_visible_;
4361 } 4435 }
4362 4436
4437 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4438 if (node_ && node_->outer_web_contents())
4439 return node_->outer_contents_frame_tree_node_id();
4440
4441 return -1;
nasko 2015/06/11 00:21:28 nit: Let's add a symbolic constant in FrameTreeNod
lazyboy 2015/06/11 22:20:29 Done.
4442 }
4443
4363 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { 4444 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
4364 return frame_tree_.root()->render_manager(); 4445 return frame_tree_.root()->render_manager();
4365 } 4446 }
4366 4447
4367 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { 4448 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
4368 return browser_plugin_guest_.get(); 4449 return browser_plugin_guest_.get();
4369 } 4450 }
4370 4451
4371 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { 4452 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4372 CHECK(!browser_plugin_guest_); 4453 CHECK(!browser_plugin_guest_);
4454 CHECK(guest);
4373 browser_plugin_guest_.reset(guest); 4455 browser_plugin_guest_.reset(guest);
4374 } 4456 }
4375 4457
4376 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { 4458 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
4377 return browser_plugin_embedder_.get(); 4459 return browser_plugin_embedder_.get();
4378 } 4460 }
4379 4461
4380 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { 4462 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4381 if (browser_plugin_embedder_) 4463 if (browser_plugin_embedder_)
4382 return; 4464 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4464 player_map->erase(it); 4546 player_map->erase(it);
4465 } 4547 }
4466 4548
4467 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4549 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4468 force_disable_overscroll_content_ = force_disable; 4550 force_disable_overscroll_content_ = force_disable;
4469 if (view_) 4551 if (view_)
4470 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4552 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4471 } 4553 }
4472 4554
4473 } // namespace content 4555 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698