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

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 after components/ refactor 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 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.
Charlie Reis 2015/06/02 18:19:14 nit: pointer
lazyboy 2015/06/02 20:15:21 Done.
296 if (outer_web_contents_) {
297 ChildrenList& child_ptrs_in_parent =
298 outer_web_contents_->node_.inner_web_contents_tree_nodes_;
299 ChildrenList::iterator iter = child_ptrs_in_parent.find(this);
300 DCHECK(iter != child_ptrs_in_parent.end());
301 child_ptrs_in_parent.erase(this);
302 }
303
304 // Remove parent pointers from our children.
Charlie Reis 2015/06/02 18:19:14 Wouldn't this leak all the children? Seems like w
lazyboy 2015/06/02 20:15:21 Right now in <webview> use case, children WebConte
305 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
306 child->outer_web_contents_ = nullptr;
307 }
308
309 void WebContentsImpl::WebContentsTreeNode::SetOuterWebContents(
310 WebContentsImpl* outer_web_contents) {
311 outer_web_contents_ = outer_web_contents;
312 outer_web_contents_->node_.inner_web_contents_tree_nodes_.insert(this);
313 }
314
289 // WebContentsImpl ------------------------------------------------------------- 315 // WebContentsImpl -------------------------------------------------------------
290 316
291 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, 317 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context,
292 WebContentsImpl* opener) 318 WebContentsImpl* opener)
293 : delegate_(NULL), 319 : delegate_(NULL),
294 controller_(this, browser_context), 320 controller_(this, browser_context),
295 render_view_host_delegate_view_(NULL), 321 render_view_host_delegate_view_(NULL),
296 opener_(opener), 322 opener_(opener),
297 created_with_opener_(!!opener), 323 created_with_opener_(!!opener),
298 #if defined(OS_WIN) 324 #if defined(OS_WIN)
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 bool WebContentsImpl::NeedToFireBeforeUnload() { 1176 bool WebContentsImpl::NeedToFireBeforeUnload() {
1151 // TODO(creis): Should we fire even for interstitial pages? 1177 // TODO(creis): Should we fire even for interstitial pages?
1152 return WillNotifyDisconnection() && !ShowingInterstitialPage() && 1178 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1153 !GetRenderViewHost()->SuddenTerminationAllowed(); 1179 !GetRenderViewHost()->SuddenTerminationAllowed();
1154 } 1180 }
1155 1181
1156 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 1182 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1157 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); 1183 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
1158 } 1184 }
1159 1185
1186 void WebContentsImpl::AttachToOuterWebContentsFrame(
1187 WebContents* outer_web_contents,
1188 RenderFrameHost* outer_contents_frame) {
1189 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1190 switches::kSitePerProcess));
1191 // Create a link to our outer WebContents.
1192 node_.SetOuterWebContents(static_cast<WebContentsImpl*>(outer_web_contents));
1193
1194 DCHECK(outer_contents_frame);
1195
1196 // Create a swapped out RVH and a proxy in our render manager, pointing
1197 // to the SiteInstance of the outer WebContents. The swapped out RVH will be
1198 // used to send postMessage to the inner WebContents.
1199 // TODO(lazyboy): Use RenderFrameHostManager::CreateRenderFrameProxy() once
1200 // we can a proxy without swapped out RF.
Charlie Reis 2015/06/02 18:19:14 nit: can what?
lazyboy 2015/06/02 20:15:21 Create. Done.
1201 int proxy_to_outer_web_contents_routing_id =
1202 GetRenderManager()->CreateOuterDelegateProxy(
1203 outer_contents_frame->GetSiteInstance());
1204
1205 // Swap the outer WebContents's initial frame for the inner WebContents with
1206 // the proxy we've created above.
1207 // The proxy has a CPFC and it uses the swapped out RV as its RenderWidget,
1208 // which gives us input and rendering.
1209 static_cast<RenderFrameHostImpl*>(outer_contents_frame)
1210 ->frame_tree_node()
1211 ->render_manager()
1212 ->SwapFrameWithProxy(proxy_to_outer_web_contents_routing_id);
1213
1214 GetRenderManager()->SetRWHViewForInnerContents(
1215 GetRenderManager()->GetRenderWidgetHostView());
1216 }
1217
1160 void WebContentsImpl::Stop() { 1218 void WebContentsImpl::Stop() {
1161 GetRenderManager()->Stop(); 1219 GetRenderManager()->Stop();
1162 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); 1220 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
1163 } 1221 }
1164 1222
1165 WebContents* WebContentsImpl::Clone() { 1223 WebContents* WebContentsImpl::Clone() {
1166 // We use our current SiteInstance since the cloned entry will use it anyway. 1224 // We use our current SiteInstance since the cloned entry will use it anyway.
1167 // We pass our own opener so that the cloned page can access it if it was 1225 // We pass our own opener so that the cloned page can access it if it was
1168 // before. 1226 // before.
1169 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); 1227 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 (params.routing_id != MSG_ROUTING_NONE && 1280 (params.routing_id != MSG_ROUTING_NONE &&
1223 params.main_frame_routing_id != MSG_ROUTING_NONE)); 1281 params.main_frame_routing_id != MSG_ROUTING_NONE));
1224 GetRenderManager()->Init( 1282 GetRenderManager()->Init(
1225 params.browser_context, params.site_instance, params.routing_id, 1283 params.browser_context, params.site_instance, params.routing_id,
1226 params.main_frame_routing_id); 1284 params.main_frame_routing_id);
1227 frame_tree_.root()->SetFrameName(params.main_frame_name); 1285 frame_tree_.root()->SetFrameName(params.main_frame_name);
1228 1286
1229 WebContentsViewDelegate* delegate = 1287 WebContentsViewDelegate* delegate =
1230 GetContentClient()->browser()->GetWebContentsViewDelegate(this); 1288 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1231 1289
1232 if (browser_plugin_guest_) { 1290 if (browser_plugin_guest_ &&
1291 !base::CommandLine::ForCurrentProcess()->HasSwitch(
1292 switches::kSitePerProcess)) {
1233 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( 1293 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1234 this, delegate, &render_view_host_delegate_view_)); 1294 this, delegate, &render_view_host_delegate_view_));
1235 1295
1236 WebContentsViewGuest* rv = new WebContentsViewGuest( 1296 WebContentsViewGuest* rv = new WebContentsViewGuest(
1237 this, browser_plugin_guest_.get(), platform_view.Pass(), 1297 this, browser_plugin_guest_.get(), platform_view.Pass(),
1238 render_view_host_delegate_view_); 1298 render_view_host_delegate_view_);
1239 render_view_host_delegate_view_ = rv; 1299 render_view_host_delegate_view_ = rv;
1240 view_.reset(rv); 1300 view_.reset(rv);
1241 } else { 1301 } else {
1242 // Regular WebContentsView. 1302 // Regular WebContentsView.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 int route_id, 1591 int route_id,
1532 int main_frame_route_id, 1592 int main_frame_route_id,
1533 const ViewHostMsg_CreateWindow_Params& params, 1593 const ViewHostMsg_CreateWindow_Params& params,
1534 SessionStorageNamespace* session_storage_namespace) { 1594 SessionStorageNamespace* session_storage_namespace) {
1535 // We usually create the new window in the same BrowsingInstance (group of 1595 // We usually create the new window in the same BrowsingInstance (group of
1536 // script-related windows), by passing in the current SiteInstance. However, 1596 // script-related windows), by passing in the current SiteInstance. However,
1537 // if the opener is being suppressed (in a non-guest), we create a new 1597 // if the opener is being suppressed (in a non-guest), we create a new
1538 // SiteInstance in its own BrowsingInstance. 1598 // SiteInstance in its own BrowsingInstance.
1539 bool is_guest = BrowserPluginGuest::IsGuest(this); 1599 bool is_guest = BrowserPluginGuest::IsGuest(this);
1540 1600
1601 if (is_guest &&
1602 base::CommandLine::ForCurrentProcess()->HasSwitch(
1603 switches::kSitePerProcess)) {
1604 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview>
1605 // yet.
1606 NOTREACHED();
1607 }
1608
1541 // If the opener is to be suppressed, the new window can be in any process. 1609 // If the opener is to be suppressed, the new window can be in any process.
1542 // Since routing ids are process specific, we must not have one passed in 1610 // Since routing ids are process specific, we must not have one passed in
1543 // as argument here. 1611 // as argument here.
1544 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); 1612 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1545 1613
1546 scoped_refptr<SiteInstance> site_instance = 1614 scoped_refptr<SiteInstance> site_instance =
1547 params.opener_suppressed && !is_guest ? 1615 params.opener_suppressed && !is_guest ?
1548 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : 1616 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
1549 GetSiteInstance(); 1617 GetSiteInstance();
1550 1618
(...skipping 2617 matching lines...) Expand 10 before | Expand all | Expand 10 after
4168 int proxy_routing_id, 4236 int proxy_routing_id,
4169 bool for_main_frame_navigation) { 4237 bool for_main_frame_navigation) {
4170 TRACE_EVENT0("browser,navigation", 4238 TRACE_EVENT0("browser,navigation",
4171 "WebContentsImpl::CreateRenderViewForRenderManager"); 4239 "WebContentsImpl::CreateRenderViewForRenderManager");
4172 // Can be NULL during tests. 4240 // Can be NULL during tests.
4173 RenderWidgetHostViewBase* rwh_view; 4241 RenderWidgetHostViewBase* rwh_view;
4174 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary 4242 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
4175 // until RenderWidgetHost is attached to RenderFrameHost. We need to special 4243 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
4176 // case this because RWH is still a base class of RenderViewHost, and child 4244 // case this because RWH is still a base class of RenderViewHost, and child
4177 // frame RWHVs are unique in that they do not have their own WebContents. 4245 // frame RWHVs are unique in that they do not have their own WebContents.
4178 if (!for_main_frame_navigation) { 4246 bool is_guest_in_site_per_process =
4247 !!browser_plugin_guest_.get() &&
4248 base::CommandLine::ForCurrentProcess()->HasSwitch(
4249 switches::kSitePerProcess);
4250 if (!for_main_frame_navigation || is_guest_in_site_per_process) {
4179 RenderWidgetHostViewChildFrame* rwh_view_child = 4251 RenderWidgetHostViewChildFrame* rwh_view_child =
4180 new RenderWidgetHostViewChildFrame(render_view_host); 4252 new RenderWidgetHostViewChildFrame(render_view_host);
4181 rwh_view = rwh_view_child; 4253 rwh_view = rwh_view_child;
4182 } else { 4254 } else {
4183 rwh_view = view_->CreateViewForWidget(render_view_host, false); 4255 rwh_view = view_->CreateViewForWidget(render_view_host, false);
4184 } 4256 }
4185 4257
4186 // Now that the RenderView has been created, we need to tell it its size. 4258 // Now that the RenderView has been created, we need to tell it its size.
4187 if (rwh_view) 4259 if (rwh_view)
4188 rwh_view->SetSize(GetSizeForNewRenderView()); 4260 rwh_view->SetSize(GetSizeForNewRenderView());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
4312 last_reported_encoding_ = encoding; 4384 last_reported_encoding_ = encoding;
4313 4385
4314 canonical_encoding_ = GetContentClient()->browser()-> 4386 canonical_encoding_ = GetContentClient()->browser()->
4315 GetCanonicalEncodingNameByAliasName(encoding); 4387 GetCanonicalEncodingNameByAliasName(encoding);
4316 } 4388 }
4317 4389
4318 bool WebContentsImpl::IsHidden() { 4390 bool WebContentsImpl::IsHidden() {
4319 return capturer_count_ == 0 && !should_normally_be_visible_; 4391 return capturer_count_ == 0 && !should_normally_be_visible_;
4320 } 4392 }
4321 4393
4394 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() {
4395 if (node_.outer_web_contents()) {
4396 return node_.outer_web_contents()
4397 ->GetFrameTree()
4398 ->root()
4399 ->frame_tree_node_id();
4400 }
4401 return -1;
4402 }
4403
4322 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { 4404 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
4323 return frame_tree_.root()->render_manager(); 4405 return frame_tree_.root()->render_manager();
4324 } 4406 }
4325 4407
4326 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { 4408 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
4327 return browser_plugin_guest_.get(); 4409 return browser_plugin_guest_.get();
4328 } 4410 }
4329 4411
4330 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { 4412 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4331 CHECK(!browser_plugin_guest_); 4413 CHECK(!browser_plugin_guest_);
4414 CHECK(guest);
4332 browser_plugin_guest_.reset(guest); 4415 browser_plugin_guest_.reset(guest);
4333 } 4416 }
4334 4417
4335 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { 4418 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
4336 return browser_plugin_embedder_.get(); 4419 return browser_plugin_embedder_.get();
4337 } 4420 }
4338 4421
4339 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { 4422 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4340 if (browser_plugin_embedder_) 4423 if (browser_plugin_embedder_)
4341 return; 4424 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
4423 player_map->erase(it); 4506 player_map->erase(it);
4424 } 4507 }
4425 4508
4426 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { 4509 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4427 force_disable_overscroll_content_ = force_disable; 4510 force_disable_overscroll_content_ = force_disable;
4428 if (view_) 4511 if (view_)
4429 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); 4512 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4430 } 4513 }
4431 4514
4432 } // namespace content 4515 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698