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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 int identifier) | 289 int identifier) |
290 : render_process_id(render_process_id), | 290 : render_process_id(render_process_id), |
291 render_frame_id(render_frame_id), | 291 render_frame_id(render_frame_id), |
292 chooser(chooser), | 292 chooser(chooser), |
293 identifier(identifier) { | 293 identifier(identifier) { |
294 } | 294 } |
295 | 295 |
296 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { | 296 WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { |
297 } | 297 } |
298 | 298 |
| 299 // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
| 300 WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode() |
| 301 : outer_web_contents_(nullptr), |
| 302 outer_contents_frame_tree_node_id_( |
| 303 FrameTreeNode::kFrameTreeNodeInvalidID) { |
| 304 } |
| 305 |
| 306 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { |
| 307 // Remove child pointer from our parent. |
| 308 if (outer_web_contents_) { |
| 309 ChildrenSet& child_ptrs_in_parent = |
| 310 outer_web_contents_->node_->inner_web_contents_tree_nodes_; |
| 311 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this); |
| 312 DCHECK(iter != child_ptrs_in_parent.end()); |
| 313 child_ptrs_in_parent.erase(this); |
| 314 } |
| 315 |
| 316 // Remove parent pointers from our children. |
| 317 // TODO(lazyboy): We should destroy the children WebContentses too. If the |
| 318 // children do not manage their own lifetime, then we would leak their |
| 319 // WebContentses. |
| 320 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_) |
| 321 child->outer_web_contents_ = nullptr; |
| 322 } |
| 323 |
| 324 void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( |
| 325 WebContentsImpl* outer_web_contents, |
| 326 RenderFrameHostImpl* outer_contents_frame) { |
| 327 outer_web_contents_ = outer_web_contents; |
| 328 outer_contents_frame_tree_node_id_ = |
| 329 outer_contents_frame->frame_tree_node()->frame_tree_node_id(); |
| 330 |
| 331 if (!outer_web_contents_->node_) |
| 332 outer_web_contents_->node_.reset(new WebContentsTreeNode()); |
| 333 |
| 334 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this); |
| 335 } |
| 336 |
299 // WebContentsImpl ------------------------------------------------------------- | 337 // WebContentsImpl ------------------------------------------------------------- |
300 | 338 |
301 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) | 339 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
302 : delegate_(NULL), | 340 : delegate_(NULL), |
303 controller_(this, browser_context), | 341 controller_(this, browser_context), |
304 render_view_host_delegate_view_(NULL), | 342 render_view_host_delegate_view_(NULL), |
305 created_with_opener_(false), | 343 created_with_opener_(false), |
306 #if defined(OS_WIN) | 344 #if defined(OS_WIN) |
307 accessible_parent_(NULL), | 345 accessible_parent_(NULL), |
308 #endif | 346 #endif |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1208 bool WebContentsImpl::NeedToFireBeforeUnload() { |
1171 // TODO(creis): Should we fire even for interstitial pages? | 1209 // TODO(creis): Should we fire even for interstitial pages? |
1172 return WillNotifyDisconnection() && !ShowingInterstitialPage() && | 1210 return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
1173 !GetRenderViewHost()->SuddenTerminationAllowed(); | 1211 !GetRenderViewHost()->SuddenTerminationAllowed(); |
1174 } | 1212 } |
1175 | 1213 |
1176 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1214 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
1177 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); | 1215 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); |
1178 } | 1216 } |
1179 | 1217 |
| 1218 void WebContentsImpl::AttachToOuterWebContentsFrame( |
| 1219 WebContents* outer_web_contents, |
| 1220 RenderFrameHost* outer_contents_frame) { |
| 1221 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1222 switches::kSitePerProcess)); |
| 1223 // Create a link to our outer WebContents. |
| 1224 node_.reset(new WebContentsTreeNode()); |
| 1225 node_->ConnectToOuterWebContents( |
| 1226 static_cast<WebContentsImpl*>(outer_web_contents), |
| 1227 static_cast<RenderFrameHostImpl*>(outer_contents_frame)); |
| 1228 |
| 1229 DCHECK(outer_contents_frame); |
| 1230 |
| 1231 // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 1232 // SiteInstance of the outer WebContents. The proxy will be used to send |
| 1233 // postMessage to the inner WebContents. |
| 1234 GetRenderManager()->CreateOuterDelegateProxy( |
| 1235 outer_contents_frame->GetSiteInstance(), |
| 1236 static_cast<RenderFrameHostImpl*>(outer_contents_frame)); |
| 1237 |
| 1238 GetRenderManager()->SetRWHViewForInnerContents( |
| 1239 GetRenderManager()->GetRenderWidgetHostView()); |
| 1240 } |
| 1241 |
1180 void WebContentsImpl::Stop() { | 1242 void WebContentsImpl::Stop() { |
1181 GetRenderManager()->Stop(); | 1243 GetRenderManager()->Stop(); |
1182 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); | 1244 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); |
1183 } | 1245 } |
1184 | 1246 |
1185 WebContents* WebContentsImpl::Clone() { | 1247 WebContents* WebContentsImpl::Clone() { |
1186 // We use our current SiteInstance since the cloned entry will use it anyway. | 1248 // We use our current SiteInstance since the cloned entry will use it anyway. |
1187 // We pass our own opener so that the cloned page can access it if it was set | 1249 // We pass our own opener so that the cloned page can access it if it was set |
1188 // before. | 1250 // before. |
1189 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); | 1251 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 (params.routing_id != MSG_ROUTING_NONE && | 1305 (params.routing_id != MSG_ROUTING_NONE && |
1244 params.main_frame_routing_id != MSG_ROUTING_NONE)); | 1306 params.main_frame_routing_id != MSG_ROUTING_NONE)); |
1245 GetRenderManager()->Init( | 1307 GetRenderManager()->Init( |
1246 params.browser_context, params.site_instance, params.routing_id, | 1308 params.browser_context, params.site_instance, params.routing_id, |
1247 params.main_frame_routing_id); | 1309 params.main_frame_routing_id); |
1248 frame_tree_.root()->SetFrameName(params.main_frame_name); | 1310 frame_tree_.root()->SetFrameName(params.main_frame_name); |
1249 | 1311 |
1250 WebContentsViewDelegate* delegate = | 1312 WebContentsViewDelegate* delegate = |
1251 GetContentClient()->browser()->GetWebContentsViewDelegate(this); | 1313 GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
1252 | 1314 |
1253 if (browser_plugin_guest_) { | 1315 if (browser_plugin_guest_ && |
| 1316 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1317 switches::kSitePerProcess)) { |
1254 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( | 1318 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( |
1255 this, delegate, &render_view_host_delegate_view_)); | 1319 this, delegate, &render_view_host_delegate_view_)); |
1256 | 1320 |
1257 WebContentsViewGuest* rv = new WebContentsViewGuest( | 1321 WebContentsViewGuest* rv = new WebContentsViewGuest( |
1258 this, browser_plugin_guest_.get(), platform_view.Pass(), | 1322 this, browser_plugin_guest_.get(), platform_view.Pass(), |
1259 render_view_host_delegate_view_); | 1323 render_view_host_delegate_view_); |
1260 render_view_host_delegate_view_ = rv; | 1324 render_view_host_delegate_view_ = rv; |
1261 view_.reset(rv); | 1325 view_.reset(rv); |
1262 } else { | 1326 } else { |
1263 // Regular WebContentsView. | 1327 // Regular WebContentsView. |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 int route_id, | 1608 int route_id, |
1545 int main_frame_route_id, | 1609 int main_frame_route_id, |
1546 const ViewHostMsg_CreateWindow_Params& params, | 1610 const ViewHostMsg_CreateWindow_Params& params, |
1547 SessionStorageNamespace* session_storage_namespace) { | 1611 SessionStorageNamespace* session_storage_namespace) { |
1548 // We usually create the new window in the same BrowsingInstance (group of | 1612 // We usually create the new window in the same BrowsingInstance (group of |
1549 // script-related windows), by passing in the current SiteInstance. However, | 1613 // script-related windows), by passing in the current SiteInstance. However, |
1550 // if the opener is being suppressed (in a non-guest), we create a new | 1614 // if the opener is being suppressed (in a non-guest), we create a new |
1551 // SiteInstance in its own BrowsingInstance. | 1615 // SiteInstance in its own BrowsingInstance. |
1552 bool is_guest = BrowserPluginGuest::IsGuest(this); | 1616 bool is_guest = BrowserPluginGuest::IsGuest(this); |
1553 | 1617 |
| 1618 if (is_guest && |
| 1619 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1620 switches::kSitePerProcess)) { |
| 1621 // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview> |
| 1622 // yet. |
| 1623 NOTREACHED(); |
| 1624 } |
| 1625 |
1554 // If the opener is to be suppressed, the new window can be in any process. | 1626 // If the opener is to be suppressed, the new window can be in any process. |
1555 // Since routing ids are process specific, we must not have one passed in | 1627 // Since routing ids are process specific, we must not have one passed in |
1556 // as argument here. | 1628 // as argument here. |
1557 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); | 1629 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); |
1558 | 1630 |
1559 scoped_refptr<SiteInstance> site_instance = | 1631 scoped_refptr<SiteInstance> site_instance = |
1560 params.opener_suppressed && !is_guest ? | 1632 params.opener_suppressed && !is_guest ? |
1561 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : | 1633 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : |
1562 GetSiteInstance(); | 1634 GetSiteInstance(); |
1563 | 1635 |
(...skipping 2352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3916 // probably not a risk for apps since other pages won't have references | 3988 // probably not a risk for apps since other pages won't have references |
3917 // to App windows. | 3989 // to App windows. |
3918 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); | 3990 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
3919 } | 3991 } |
3920 | 3992 |
3921 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { | 3993 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
3922 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( | 3994 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
3923 WebContents::FromRenderFrameHost(source_rfh)); | 3995 WebContents::FromRenderFrameHost(source_rfh)); |
3924 | 3996 |
3925 if (source_web_contents) { | 3997 if (source_web_contents) { |
| 3998 // If this message is going to outer WebContents from inner WebContents, |
| 3999 // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 4000 // already created a RenderFrameProxyHost for that purpose. |
| 4001 if (GetBrowserPluginEmbedder() && |
| 4002 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4003 switches::kSitePerProcess)) { |
| 4004 return; |
| 4005 } |
| 4006 |
3926 if (GetBrowserPluginGuest()) { | 4007 if (GetBrowserPluginGuest()) { |
3927 // We create a swapped out RenderView for the embedder in the guest's | 4008 // We create a swapped out RenderView for the embedder in the guest's |
3928 // render process but we intentionally do not expose the embedder's | 4009 // render process but we intentionally do not expose the embedder's |
3929 // opener chain to it. | 4010 // opener chain to it. |
3930 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); | 4011 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
3931 } else { | 4012 } else { |
3932 RenderFrameHostImpl* source_rfhi = | 4013 RenderFrameHostImpl* source_rfhi = |
3933 static_cast<RenderFrameHostImpl*>(source_rfh); | 4014 static_cast<RenderFrameHostImpl*>(source_rfh); |
3934 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( | 4015 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
3935 GetSiteInstance()); | 4016 GetSiteInstance()); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4136 const FrameReplicationState& replicated_frame_state, | 4217 const FrameReplicationState& replicated_frame_state, |
4137 bool for_main_frame_navigation) { | 4218 bool for_main_frame_navigation) { |
4138 TRACE_EVENT0("browser,navigation", | 4219 TRACE_EVENT0("browser,navigation", |
4139 "WebContentsImpl::CreateRenderViewForRenderManager"); | 4220 "WebContentsImpl::CreateRenderViewForRenderManager"); |
4140 // Can be NULL during tests. | 4221 // Can be NULL during tests. |
4141 RenderWidgetHostViewBase* rwh_view; | 4222 RenderWidgetHostViewBase* rwh_view; |
4142 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary | 4223 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary |
4143 // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 4224 // until RenderWidgetHost is attached to RenderFrameHost. We need to special |
4144 // case this because RWH is still a base class of RenderViewHost, and child | 4225 // case this because RWH is still a base class of RenderViewHost, and child |
4145 // frame RWHVs are unique in that they do not have their own WebContents. | 4226 // frame RWHVs are unique in that they do not have their own WebContents. |
4146 if (!for_main_frame_navigation) { | 4227 bool is_guest_in_site_per_process = |
| 4228 !!browser_plugin_guest_.get() && |
| 4229 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4230 switches::kSitePerProcess); |
| 4231 if (!for_main_frame_navigation || is_guest_in_site_per_process) { |
4147 RenderWidgetHostViewChildFrame* rwh_view_child = | 4232 RenderWidgetHostViewChildFrame* rwh_view_child = |
4148 new RenderWidgetHostViewChildFrame(render_view_host); | 4233 new RenderWidgetHostViewChildFrame(render_view_host); |
4149 rwh_view = rwh_view_child; | 4234 rwh_view = rwh_view_child; |
4150 } else { | 4235 } else { |
4151 rwh_view = view_->CreateViewForWidget(render_view_host, false); | 4236 rwh_view = view_->CreateViewForWidget(render_view_host, false); |
4152 } | 4237 } |
4153 | 4238 |
4154 // Now that the RenderView has been created, we need to tell it its size. | 4239 // Now that the RenderView has been created, we need to tell it its size. |
4155 if (rwh_view) | 4240 if (rwh_view) |
4156 rwh_view->SetSize(GetSizeForNewRenderView()); | 4241 rwh_view->SetSize(GetSizeForNewRenderView()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4280 last_reported_encoding_ = encoding; | 4365 last_reported_encoding_ = encoding; |
4281 | 4366 |
4282 canonical_encoding_ = GetContentClient()->browser()-> | 4367 canonical_encoding_ = GetContentClient()->browser()-> |
4283 GetCanonicalEncodingNameByAliasName(encoding); | 4368 GetCanonicalEncodingNameByAliasName(encoding); |
4284 } | 4369 } |
4285 | 4370 |
4286 bool WebContentsImpl::IsHidden() { | 4371 bool WebContentsImpl::IsHidden() { |
4287 return capturer_count_ == 0 && !should_normally_be_visible_; | 4372 return capturer_count_ == 0 && !should_normally_be_visible_; |
4288 } | 4373 } |
4289 | 4374 |
| 4375 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() { |
| 4376 if (node_ && node_->outer_web_contents()) |
| 4377 return node_->outer_contents_frame_tree_node_id(); |
| 4378 |
| 4379 return FrameTreeNode::kFrameTreeNodeInvalidID; |
| 4380 } |
| 4381 |
4290 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4382 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
4291 return frame_tree_.root()->render_manager(); | 4383 return frame_tree_.root()->render_manager(); |
4292 } | 4384 } |
4293 | 4385 |
4294 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4386 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
4295 return browser_plugin_guest_.get(); | 4387 return browser_plugin_guest_.get(); |
4296 } | 4388 } |
4297 | 4389 |
4298 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4390 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
4299 CHECK(!browser_plugin_guest_); | 4391 CHECK(!browser_plugin_guest_); |
| 4392 CHECK(guest); |
4300 browser_plugin_guest_.reset(guest); | 4393 browser_plugin_guest_.reset(guest); |
4301 } | 4394 } |
4302 | 4395 |
4303 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4396 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
4304 return browser_plugin_embedder_.get(); | 4397 return browser_plugin_embedder_.get(); |
4305 } | 4398 } |
4306 | 4399 |
4307 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4400 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
4308 if (browser_plugin_embedder_) | 4401 if (browser_plugin_embedder_) |
4309 return; | 4402 return; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4391 player_map->erase(it); | 4484 player_map->erase(it); |
4392 } | 4485 } |
4393 | 4486 |
4394 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4487 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4395 force_disable_overscroll_content_ = force_disable; | 4488 force_disable_overscroll_content_ = force_disable; |
4396 if (view_) | 4489 if (view_) |
4397 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4490 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4398 } | 4491 } |
4399 | 4492 |
4400 } // namespace content | 4493 } // namespace content |
OLD | NEW |