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_web_contents_(nullptr), |
| 301 outer_contents_frame_tree_node_id_( |
| 302 FrameTreeNode::kFrameTreeNodeInvalidID) { |
| 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 // children do not manage their own lifetime, then we would leak their |
| 318 // WebContentses. |
| 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 2352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3915 // probably not a risk for apps since other pages won't have references | 3987 // probably not a risk for apps since other pages won't have references |
3916 // to App windows. | 3988 // to App windows. |
3917 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); | 3989 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
3918 } | 3990 } |
3919 | 3991 |
3920 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { | 3992 void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
3921 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( | 3993 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
3922 WebContents::FromRenderFrameHost(source_rfh)); | 3994 WebContents::FromRenderFrameHost(source_rfh)); |
3923 | 3995 |
3924 if (source_web_contents) { | 3996 if (source_web_contents) { |
| 3997 // If this message is going to outer WebContents from inner WebContents, |
| 3998 // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 3999 // already created a RenderFrameProxyHost for that purpose. |
| 4000 if (GetBrowserPluginEmbedder() && |
| 4001 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4002 switches::kSitePerProcess)) { |
| 4003 return; |
| 4004 } |
| 4005 |
3925 if (GetBrowserPluginGuest()) { | 4006 if (GetBrowserPluginGuest()) { |
3926 // We create a swapped out RenderView for the embedder in the guest's | 4007 // We create a swapped out RenderView for the embedder in the guest's |
3927 // render process but we intentionally do not expose the embedder's | 4008 // render process but we intentionally do not expose the embedder's |
3928 // opener chain to it. | 4009 // opener chain to it. |
3929 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); | 4010 source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
3930 } else { | 4011 } else { |
3931 RenderFrameHostImpl* source_rfhi = | 4012 RenderFrameHostImpl* source_rfhi = |
3932 static_cast<RenderFrameHostImpl*>(source_rfh); | 4013 static_cast<RenderFrameHostImpl*>(source_rfh); |
3933 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( | 4014 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
3934 GetSiteInstance()); | 4015 GetSiteInstance()); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4135 const FrameReplicationState& replicated_frame_state, | 4216 const FrameReplicationState& replicated_frame_state, |
4136 bool for_main_frame_navigation) { | 4217 bool for_main_frame_navigation) { |
4137 TRACE_EVENT0("browser,navigation", | 4218 TRACE_EVENT0("browser,navigation", |
4138 "WebContentsImpl::CreateRenderViewForRenderManager"); | 4219 "WebContentsImpl::CreateRenderViewForRenderManager"); |
4139 // Can be NULL during tests. | 4220 // Can be NULL during tests. |
4140 RenderWidgetHostViewBase* rwh_view; | 4221 RenderWidgetHostViewBase* rwh_view; |
4141 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary | 4222 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary |
4142 // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 4223 // until RenderWidgetHost is attached to RenderFrameHost. We need to special |
4143 // case this because RWH is still a base class of RenderViewHost, and child | 4224 // case this because RWH is still a base class of RenderViewHost, and child |
4144 // frame RWHVs are unique in that they do not have their own WebContents. | 4225 // frame RWHVs are unique in that they do not have their own WebContents. |
4145 if (!for_main_frame_navigation) { | 4226 bool is_guest_in_site_per_process = |
| 4227 !!browser_plugin_guest_.get() && |
| 4228 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4229 switches::kSitePerProcess); |
| 4230 if (!for_main_frame_navigation || is_guest_in_site_per_process) { |
4146 RenderWidgetHostViewChildFrame* rwh_view_child = | 4231 RenderWidgetHostViewChildFrame* rwh_view_child = |
4147 new RenderWidgetHostViewChildFrame(render_view_host); | 4232 new RenderWidgetHostViewChildFrame(render_view_host); |
4148 rwh_view = rwh_view_child; | 4233 rwh_view = rwh_view_child; |
4149 } else { | 4234 } else { |
4150 rwh_view = view_->CreateViewForWidget(render_view_host, false); | 4235 rwh_view = view_->CreateViewForWidget(render_view_host, false); |
4151 } | 4236 } |
4152 | 4237 |
4153 // Now that the RenderView has been created, we need to tell it its size. | 4238 // Now that the RenderView has been created, we need to tell it its size. |
4154 if (rwh_view) | 4239 if (rwh_view) |
4155 rwh_view->SetSize(GetSizeForNewRenderView()); | 4240 rwh_view->SetSize(GetSizeForNewRenderView()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4279 last_reported_encoding_ = encoding; | 4364 last_reported_encoding_ = encoding; |
4280 | 4365 |
4281 canonical_encoding_ = GetContentClient()->browser()-> | 4366 canonical_encoding_ = GetContentClient()->browser()-> |
4282 GetCanonicalEncodingNameByAliasName(encoding); | 4367 GetCanonicalEncodingNameByAliasName(encoding); |
4283 } | 4368 } |
4284 | 4369 |
4285 bool WebContentsImpl::IsHidden() { | 4370 bool WebContentsImpl::IsHidden() { |
4286 return capturer_count_ == 0 && !should_normally_be_visible_; | 4371 return capturer_count_ == 0 && !should_normally_be_visible_; |
4287 } | 4372 } |
4288 | 4373 |
| 4374 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() { |
| 4375 if (node_ && node_->outer_web_contents()) |
| 4376 return node_->outer_contents_frame_tree_node_id(); |
| 4377 |
| 4378 return FrameTreeNode::kFrameTreeNodeInvalidID; |
| 4379 } |
| 4380 |
4289 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4381 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
4290 return frame_tree_.root()->render_manager(); | 4382 return frame_tree_.root()->render_manager(); |
4291 } | 4383 } |
4292 | 4384 |
4293 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4385 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
4294 return browser_plugin_guest_.get(); | 4386 return browser_plugin_guest_.get(); |
4295 } | 4387 } |
4296 | 4388 |
4297 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4389 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
4298 CHECK(!browser_plugin_guest_); | 4390 CHECK(!browser_plugin_guest_); |
| 4391 CHECK(guest); |
4299 browser_plugin_guest_.reset(guest); | 4392 browser_plugin_guest_.reset(guest); |
4300 } | 4393 } |
4301 | 4394 |
4302 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4395 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
4303 return browser_plugin_embedder_.get(); | 4396 return browser_plugin_embedder_.get(); |
4304 } | 4397 } |
4305 | 4398 |
4306 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4399 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
4307 if (browser_plugin_embedder_) | 4400 if (browser_plugin_embedder_) |
4308 return; | 4401 return; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4390 player_map->erase(it); | 4483 player_map->erase(it); |
4391 } | 4484 } |
4392 | 4485 |
4393 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4486 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4394 force_disable_overscroll_content_ = force_disable; | 4487 force_disable_overscroll_content_ = force_disable; |
4395 if (view_) | 4488 if (view_) |
4396 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4489 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4397 } | 4490 } |
4398 | 4491 |
4399 } // namespace content | 4492 } // namespace content |
OLD | NEW |