| OLD | NEW |
| 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 Loading... |
| 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::kFrameTreeNodeInvalidID), |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3934 // to App windows. | 4006 // to App windows. |
| 3935 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); | 4007 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 3936 } | 4008 } |
| 3937 | 4009 |
| 3938 int WebContentsImpl::EnsureOpenerRenderViewsExist( | 4010 int WebContentsImpl::EnsureOpenerRenderViewsExist( |
| 3939 RenderFrameHost* source_rfh) { | 4011 RenderFrameHost* source_rfh) { |
| 3940 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( | 4012 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 3941 WebContents::FromRenderFrameHost(source_rfh)); | 4013 WebContents::FromRenderFrameHost(source_rfh)); |
| 3942 | 4014 |
| 3943 if (source_web_contents) { | 4015 if (source_web_contents) { |
| 4016 // If this message is going to outer WebContents from inner WebContents, |
| 4017 // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 4018 // already created a RenderFrameProxyHost for that purpose. |
| 4019 if (GetBrowserPluginEmbedder() && |
| 4020 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4021 switches::kSitePerProcess)) { |
| 4022 return MSG_ROUTING_NONE; |
| 4023 } |
| 4024 |
| 3944 if (GetBrowserPluginGuest()) { | 4025 if (GetBrowserPluginGuest()) { |
| 3945 // We create a swapped out RenderView for the embedder in the guest's | 4026 // We create a swapped out RenderView for the embedder in the guest's |
| 3946 // render process but we intentionally do not expose the embedder's | 4027 // render process but we intentionally do not expose the embedder's |
| 3947 // opener chain to it. | 4028 // opener chain to it. |
| 3948 return | 4029 return |
| 3949 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); | 4030 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
| 3950 } else { | 4031 } else { |
| 3951 return source_web_contents->CreateOpenerRenderViews(GetSiteInstance()); | 4032 return source_web_contents->CreateOpenerRenderViews(GetSiteInstance()); |
| 3952 } | 4033 } |
| 3953 } | 4034 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4206 const FrameReplicationState& replicated_frame_state, | 4287 const FrameReplicationState& replicated_frame_state, |
| 4207 bool for_main_frame_navigation) { | 4288 bool for_main_frame_navigation) { |
| 4208 TRACE_EVENT0("browser,navigation", | 4289 TRACE_EVENT0("browser,navigation", |
| 4209 "WebContentsImpl::CreateRenderViewForRenderManager"); | 4290 "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 4210 // Can be NULL during tests. | 4291 // Can be NULL during tests. |
| 4211 RenderWidgetHostViewBase* rwh_view; | 4292 RenderWidgetHostViewBase* rwh_view; |
| 4212 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary | 4293 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary |
| 4213 // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 4294 // until RenderWidgetHost is attached to RenderFrameHost. We need to special |
| 4214 // case this because RWH is still a base class of RenderViewHost, and child | 4295 // case this because RWH is still a base class of RenderViewHost, and child |
| 4215 // frame RWHVs are unique in that they do not have their own WebContents. | 4296 // frame RWHVs are unique in that they do not have their own WebContents. |
| 4216 if (!for_main_frame_navigation) { | 4297 bool is_guest_in_site_per_process = |
| 4298 !!browser_plugin_guest_.get() && |
| 4299 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4300 switches::kSitePerProcess); |
| 4301 if (!for_main_frame_navigation || is_guest_in_site_per_process) { |
| 4217 RenderWidgetHostViewChildFrame* rwh_view_child = | 4302 RenderWidgetHostViewChildFrame* rwh_view_child = |
| 4218 new RenderWidgetHostViewChildFrame(render_view_host); | 4303 new RenderWidgetHostViewChildFrame(render_view_host); |
| 4219 rwh_view = rwh_view_child; | 4304 rwh_view = rwh_view_child; |
| 4220 } else { | 4305 } else { |
| 4221 rwh_view = view_->CreateViewForWidget(render_view_host, false); | 4306 rwh_view = view_->CreateViewForWidget(render_view_host, false); |
| 4222 } | 4307 } |
| 4223 | 4308 |
| 4224 // Now that the RenderView has been created, we need to tell it its size. | 4309 // Now that the RenderView has been created, we need to tell it its size. |
| 4225 if (rwh_view) | 4310 if (rwh_view) |
| 4226 rwh_view->SetSize(GetSizeForNewRenderView()); | 4311 rwh_view->SetSize(GetSizeForNewRenderView()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4350 last_reported_encoding_ = encoding; | 4435 last_reported_encoding_ = encoding; |
| 4351 | 4436 |
| 4352 canonical_encoding_ = GetContentClient()->browser()-> | 4437 canonical_encoding_ = GetContentClient()->browser()-> |
| 4353 GetCanonicalEncodingNameByAliasName(encoding); | 4438 GetCanonicalEncodingNameByAliasName(encoding); |
| 4354 } | 4439 } |
| 4355 | 4440 |
| 4356 bool WebContentsImpl::IsHidden() { | 4441 bool WebContentsImpl::IsHidden() { |
| 4357 return capturer_count_ == 0 && !should_normally_be_visible_; | 4442 return capturer_count_ == 0 && !should_normally_be_visible_; |
| 4358 } | 4443 } |
| 4359 | 4444 |
| 4445 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() { |
| 4446 if (node_ && node_->outer_web_contents()) |
| 4447 return node_->outer_contents_frame_tree_node_id(); |
| 4448 |
| 4449 return FrameTreeNode::kFrameTreeNodeInvalidID; |
| 4450 } |
| 4451 |
| 4360 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4452 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
| 4361 return frame_tree_.root()->render_manager(); | 4453 return frame_tree_.root()->render_manager(); |
| 4362 } | 4454 } |
| 4363 | 4455 |
| 4364 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4456 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
| 4365 return browser_plugin_guest_.get(); | 4457 return browser_plugin_guest_.get(); |
| 4366 } | 4458 } |
| 4367 | 4459 |
| 4368 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4460 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 4369 CHECK(!browser_plugin_guest_); | 4461 CHECK(!browser_plugin_guest_); |
| 4462 CHECK(guest); |
| 4370 browser_plugin_guest_.reset(guest); | 4463 browser_plugin_guest_.reset(guest); |
| 4371 } | 4464 } |
| 4372 | 4465 |
| 4373 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4466 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
| 4374 return browser_plugin_embedder_.get(); | 4467 return browser_plugin_embedder_.get(); |
| 4375 } | 4468 } |
| 4376 | 4469 |
| 4377 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4470 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 4378 if (browser_plugin_embedder_) | 4471 if (browser_plugin_embedder_) |
| 4379 return; | 4472 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4461 player_map->erase(it); | 4554 player_map->erase(it); |
| 4462 } | 4555 } |
| 4463 | 4556 |
| 4464 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4557 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4465 force_disable_overscroll_content_ = force_disable; | 4558 force_disable_overscroll_content_ = force_disable; |
| 4466 if (view_) | 4559 if (view_) |
| 4467 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4560 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4468 } | 4561 } |
| 4469 | 4562 |
| 4470 } // namespace content | 4563 } // namespace content |
| OLD | NEW |