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

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 all comments from Nasko and Charlie, minus is_loading Created 5 years, 7 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 int identifier) 279 int identifier)
280 : render_process_id(render_process_id), 280 : render_process_id(render_process_id),
281 render_frame_id(render_frame_id), 281 render_frame_id(render_frame_id),
282 chooser(chooser), 282 chooser(chooser),
283 identifier(identifier) { 283 identifier(identifier) {
284 } 284 }
285 285
286 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { 286 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
287 } 287 }
288 288
289 // WebContentsImpl::WebContentsTreeNode ----------------------------------------
290 WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
291 : outer_web_contents_(nullptr) {
292 }
293
294 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
295 // Remove child pointers from our parent.
lfg 2015/05/26 19:18:15 Maybe we should have the outer WebContents own the
nasko 2015/05/28 22:13:46 This does seem a bit hacky. Can't we manage the li
lazyboy 2015/05/29 00:02:24 Right now <webview>s WebContents's lifetime depend
296 if (outer_web_contents_) {
297 std::set<WebContentsTreeNode*>& child_ptrs_in_parent =
nasko 2015/05/28 22:13:46 nit: Why not typedef std::set<WebContentsTreeNode*
lazyboy 2015/05/29 00:02:24 Done.
298 outer_web_contents_->node_.inner_web_contents_tree_nodes_;
299 std::set<WebContentsTreeNode*>::iterator iter =
300 child_ptrs_in_parent.find(this);
301 DCHECK(iter != child_ptrs_in_parent.end());
302 child_ptrs_in_parent.erase(this);
303 }
304
305 // Remove parent pointers from our children.
306 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
307 child->outer_web_contents_ = nullptr;
308 }
309
310 void WebContentsImpl::WebContentsTreeNode::SetOuterWebContents(
311 WebContentsImpl* outer_web_contents) {
312 outer_web_contents_ = outer_web_contents;
313 outer_web_contents_->node_.inner_web_contents_tree_nodes_.insert(this);
314 }
315
289 // WebContentsImpl ------------------------------------------------------------- 316 // WebContentsImpl -------------------------------------------------------------
290 317
291 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, 318 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
292 WebContentsImpl* opener) 319 WebContentsImpl* opener)
293 : delegate_(NULL), 320 : delegate_(NULL),
294 controller_(this, browser_context), 321 controller_(this, browser_context),
295 render_view_host_delegate_view_(NULL), 322 render_view_host_delegate_view_(NULL),
296 opener_(opener), 323 opener_(opener),
297 created_with_opener_(!!opener), 324 created_with_opener_(!!opener),
298 #if defined(OS_WIN) 325 #if defined(OS_WIN)
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 bool WebContentsImpl::NeedToFireBeforeUnload() { 1156 bool WebContentsImpl::NeedToFireBeforeUnload() {
1130 // TODO(creis): Should we fire even for interstitial pages? 1157 // TODO(creis): Should we fire even for interstitial pages?
1131 return WillNotifyDisconnection() && !ShowingInterstitialPage() && 1158 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1132 !GetRenderViewHost()->SuddenTerminationAllowed(); 1159 !GetRenderViewHost()->SuddenTerminationAllowed();
1133 } 1160 }
1134 1161
1135 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 1162 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1136 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); 1163 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1137 } 1164 }
1138 1165
1166 void WebContentsImpl::AttachToOuterWebContentsFrame(
1167 WebContents* outer_web_contents,
1168 RenderFrameHost* outer_contents_frame) {
1169 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1170 switches::kSitePerProcess));
1171 // Create a link to our outer WebContents.
1172 node_.SetOuterWebContents(static_cast<WebContentsImpl*>(outer_web_contents));
1173
1174 DCHECK(outer_contents_frame);
1175
1176 // Create a swapped out RVH and a proxy in our render manager, pointing
1177 // to the SiteInstance of the outer WebContents. The swapped out RVH will be
1178 // used to send postMessage to the inner WebContents.
1179 // TODO(lazyboy): Use RenderFrameHostManager::CreateRenderFrameProxy() once
1180 // we can a proxy without swapped out RV and RF.
nasko 2015/05/28 22:13:46 nit: RenderView will stick around a bit longer, bu
lazyboy 2015/05/29 00:02:24 So remove the RV from the comment? Done.
1181 int proxy_to_outer_web_contents_routing_id =
1182 GetRenderManager()->CreateOuterDelegateProxy(
1183 outer_contents_frame->GetSiteInstance());
1184
1185 // Swap the outer WebContents's initial frame for the inner WebContents with
1186 // the proxy we've created above.
1187 // The proxy has a CPFC and it uses the swapped out RV as its RenderWidget,
1188 // which gives us input and rendering.
1189 static_cast<RenderFrameHostImpl*>(outer_contents_frame)
1190 ->frame_tree_node()
1191 ->render_manager()
1192 ->SwapFrameWithProxy(proxy_to_outer_web_contents_routing_id);
1193
1194 GetRenderManager()->SetRWHViewForInnerContents(
1195 GetRenderManager()->GetRenderWidgetHostView());
1196 }
1197
1139 void WebContentsImpl::Stop() { 1198 void WebContentsImpl::Stop() {
1140 GetRenderManager()->Stop(); 1199 GetRenderManager()->Stop();
1141 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1200 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1142 } 1201 }
1143 1202
1144 WebContents* WebContentsImpl::Clone() { 1203 WebContents* WebContentsImpl::Clone() {
1145 // We use our current SiteInstance since the cloned entry will use it anyway. 1204 // We use our current SiteInstance since the cloned entry will use it anyway.
1146 // We pass our own opener so that the cloned page can access it if it was 1205 // We pass our own opener so that the cloned page can access it if it was
1147 // before. 1206 // before.
1148 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); 1207 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 (params.routing_id != MSG_ROUTING_NONE && 1260 (params.routing_id != MSG_ROUTING_NONE &&
1202 params.main_frame_routing_id != MSG_ROUTING_NONE)); 1261 params.main_frame_routing_id != MSG_ROUTING_NONE));
1203 GetRenderManager()->Init( 1262 GetRenderManager()->Init(
1204 params.browser_context, params.site_instance, params.routing_id, 1263 params.browser_context, params.site_instance, params.routing_id,
1205 params.main_frame_routing_id); 1264 params.main_frame_routing_id);
1206 frame_tree_.root()->SetFrameName(params.main_frame_name); 1265 frame_tree_.root()->SetFrameName(params.main_frame_name);
1207 1266
1208 WebContentsViewDelegate* delegate = 1267 WebContentsViewDelegate* delegate =
1209 GetContentClient()->browser()->GetWebContentsViewDelegate(this); 1268 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1210 1269
1211 if (browser_plugin_guest_) { 1270 if (browser_plugin_guest_ &&
1271 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1272 switches::kSitePerProcess)) {
1212 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( 1273 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1213 this, delegate, &render_view_host_delegate_view_)); 1274 this, delegate, &render_view_host_delegate_view_));
1214 1275
1215 WebContentsViewGuest* rv = new WebContentsViewGuest( 1276 WebContentsViewGuest* rv = new WebContentsViewGuest(
1216 this, browser_plugin_guest_.get(), platform_view.Pass(), 1277 this, browser_plugin_guest_.get(), platform_view.Pass(),
1217 render_view_host_delegate_view_); 1278 render_view_host_delegate_view_);
1218 render_view_host_delegate_view_ = rv; 1279 render_view_host_delegate_view_ = rv;
1219 view_.reset(rv); 1280 view_.reset(rv);
1220 } else { 1281 } else {
1221 // Regular WebContentsView. 1282 // Regular WebContentsView.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 int route_id, 1571 int route_id,
1511 int main_frame_route_id, 1572 int main_frame_route_id,
1512 const ViewHostMsg_CreateWindow_Params& params, 1573 const ViewHostMsg_CreateWindow_Params& params,
1513 SessionStorageNamespace* session_storage_namespace) { 1574 SessionStorageNamespace* session_storage_namespace) {
1514 // We usually create the new window in the same BrowsingInstance (group of 1575 // We usually create the new window in the same BrowsingInstance (group of
1515 // script-related windows), by passing in the current SiteInstance. However, 1576 // script-related windows), by passing in the current SiteInstance. However,
1516 // if the opener is being suppressed (in a non-guest), we create a new 1577 // if the opener is being suppressed (in a non-guest), we create a new
1517 // SiteInstance in its own BrowsingInstance. 1578 // SiteInstance in its own BrowsingInstance.
1518 bool is_guest = BrowserPluginGuest::IsGuest(this); 1579 bool is_guest = BrowserPluginGuest::IsGuest(this);
1519 1580
1581 if (is_guest &&
1582 base::CommandLine::ForCurrentProcess()->HasSwitch(
1583 switches::kSitePerProcess)) {
1584 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1585 // yet.
1586 NOTREACHED();
1587 }
1588
1520 // If the opener is to be suppressed, the new window can be in any process. 1589 // If the opener is to be suppressed, the new window can be in any process.
1521 // Since routing ids are process specific, we must not have one passed in 1590 // Since routing ids are process specific, we must not have one passed in
1522 // as argument here. 1591 // as argument here.
1523 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); 1592 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1524 1593
1525 scoped_refptr<SiteInstance> site_instance = 1594 scoped_refptr<SiteInstance> site_instance =
1526 params.opener_suppressed && !is_guest ? 1595 params.opener_suppressed && !is_guest ?
1527 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : 1596 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
1528 GetSiteInstance(); 1597 GetSiteInstance();
1529 1598
(...skipping 2607 matching lines...) Expand 10 before | Expand all | Expand 10 after
4137 int proxy_routing_id, 4206 int proxy_routing_id,
4138 bool for_main_frame_navigation) { 4207 bool for_main_frame_navigation) {
4139 TRACE_EVENT0("browser,navigation", 4208 TRACE_EVENT0("browser,navigation",
4140 "WebContentsImpl::CreateRenderViewForRenderManager"); 4209 "WebContentsImpl::CreateRenderViewForRenderManager");
4141 // Can be NULL during tests. 4210 // Can be NULL during tests.
4142 RenderWidgetHostViewBase* rwh_view; 4211 RenderWidgetHostViewBase* rwh_view;
4143 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary 4212 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4144 // until RenderWidgetHost is attached to RenderFrameHost. We need to special 4213 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4145 // case this because RWH is still a base class of RenderViewHost, and child 4214 // 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. 4215 // frame RWHVs are unique in that they do not have their own WebContents.
4147 if (!for_main_frame_navigation) { 4216 bool is_guest_in_site_per_process =
4217 !!browser_plugin_guest_.get() &&
4218 base::CommandLine::ForCurrentProcess()->HasSwitch(
4219 switches::kSitePerProcess);
4220 if (!for_main_frame_navigation || is_guest_in_site_per_process) {
4148 RenderWidgetHostViewChildFrame* rwh_view_child = 4221 RenderWidgetHostViewChildFrame* rwh_view_child =
4149 new RenderWidgetHostViewChildFrame(render_view_host); 4222 new RenderWidgetHostViewChildFrame(render_view_host);
4150 rwh_view = rwh_view_child; 4223 rwh_view = rwh_view_child;
4151 } else { 4224 } else {
4152 rwh_view = view_->CreateViewForWidget(render_view_host, false); 4225 rwh_view = view_->CreateViewForWidget(render_view_host, false);
4153 } 4226 }
4154 4227
4155 // Now that the RenderView has been created, we need to tell it its size. 4228 // Now that the RenderView has been created, we need to tell it its size.
4156 if (rwh_view) 4229 if (rwh_view)
4157 rwh_view->SetSize(GetSizeForNewRenderView()); 4230 rwh_view->SetSize(GetSizeForNewRenderView());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4281 last_reported_encoding_ = encoding; 4354 last_reported_encoding_ = encoding;
4282 4355
4283 canonical_encoding_ = GetContentClient()->browser()-> 4356 canonical_encoding_ = GetContentClient()->browser()->
4284 GetCanonicalEncodingNameByAliasName(encoding); 4357 GetCanonicalEncodingNameByAliasName(encoding);
4285 } 4358 }
4286 4359
4287 bool WebContentsImpl::IsHidden() { 4360 bool WebContentsImpl::IsHidden() {
4288 return capturer_count_ == 0 && !should_normally_be_visible_; 4361 return capturer_count_ == 0 && !should_normally_be_visible_;
4289 } 4362 }
4290 4363
4364 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4365 if (node_.outer_web_contents()) {
4366 return node_.outer_web_contents()
4367 ->GetFrameTree()
4368 ->root()
4369 ->frame_tree_node_id();
4370 }
4371 return -1;
4372 }
4373
4291 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { 4374 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
4292 return frame_tree_.root()->render_manager(); 4375 return frame_tree_.root()->render_manager();
4293 } 4376 }
4294 4377
4295 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { 4378 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
4296 return browser_plugin_guest_.get(); 4379 return browser_plugin_guest_.get();
4297 } 4380 }
4298 4381
4299 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { 4382 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4300 CHECK(!browser_plugin_guest_); 4383 CHECK(!browser_plugin_guest_);
4384 CHECK(guest);
4301 browser_plugin_guest_.reset(guest); 4385 browser_plugin_guest_.reset(guest);
4302 } 4386 }
4303 4387
4304 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { 4388 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
4305 return browser_plugin_embedder_.get(); 4389 return browser_plugin_embedder_.get();
4306 } 4390 }
4307 4391
4308 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { 4392 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4309 if (browser_plugin_embedder_) 4393 if (browser_plugin_embedder_)
4310 return; 4394 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4392 player_map->erase(it); 4476 player_map->erase(it);
4393 } 4477 }
4394 4478
4395 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4479 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4396 force_disable_overscroll_content_ = force_disable; 4480 force_disable_overscroll_content_ = force_disable;
4397 if (view_) 4481 if (view_)
4398 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4482 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4399 } 4483 }
4400 4484
4401 } // namespace content 4485 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698