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 | |
Charlie Reis
2015/06/18 00:13:18
nit: Let's be consistent about how we pluralize We
lazyboy
2015/06/18 22:45:12
Done.
| |
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 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4206 const FrameReplicationState& replicated_frame_state, | 4278 const FrameReplicationState& replicated_frame_state, |
4207 bool for_main_frame_navigation) { | 4279 bool for_main_frame_navigation) { |
4208 TRACE_EVENT0("browser,navigation", | 4280 TRACE_EVENT0("browser,navigation", |
4209 "WebContentsImpl::CreateRenderViewForRenderManager"); | 4281 "WebContentsImpl::CreateRenderViewForRenderManager"); |
4210 // Can be NULL during tests. | 4282 // Can be NULL during tests. |
4211 RenderWidgetHostViewBase* rwh_view; | 4283 RenderWidgetHostViewBase* rwh_view; |
4212 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary | 4284 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary |
4213 // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 4285 // until RenderWidgetHost is attached to RenderFrameHost. We need to special |
4214 // case this because RWH is still a base class of RenderViewHost, and child | 4286 // 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. | 4287 // frame RWHVs are unique in that they do not have their own WebContents. |
4216 if (!for_main_frame_navigation) { | 4288 bool is_guest_in_site_per_process = |
4289 !!browser_plugin_guest_.get() && | |
4290 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
4291 switches::kSitePerProcess); | |
4292 if (!for_main_frame_navigation || is_guest_in_site_per_process) { | |
4217 RenderWidgetHostViewChildFrame* rwh_view_child = | 4293 RenderWidgetHostViewChildFrame* rwh_view_child = |
4218 new RenderWidgetHostViewChildFrame(render_view_host); | 4294 new RenderWidgetHostViewChildFrame(render_view_host); |
4219 rwh_view = rwh_view_child; | 4295 rwh_view = rwh_view_child; |
4220 } else { | 4296 } else { |
4221 rwh_view = view_->CreateViewForWidget(render_view_host, false); | 4297 rwh_view = view_->CreateViewForWidget(render_view_host, false); |
4222 } | 4298 } |
4223 | 4299 |
4224 // Now that the RenderView has been created, we need to tell it its size. | 4300 // Now that the RenderView has been created, we need to tell it its size. |
4225 if (rwh_view) | 4301 if (rwh_view) |
4226 rwh_view->SetSize(GetSizeForNewRenderView()); | 4302 rwh_view->SetSize(GetSizeForNewRenderView()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4350 last_reported_encoding_ = encoding; | 4426 last_reported_encoding_ = encoding; |
4351 | 4427 |
4352 canonical_encoding_ = GetContentClient()->browser()-> | 4428 canonical_encoding_ = GetContentClient()->browser()-> |
4353 GetCanonicalEncodingNameByAliasName(encoding); | 4429 GetCanonicalEncodingNameByAliasName(encoding); |
4354 } | 4430 } |
4355 | 4431 |
4356 bool WebContentsImpl::IsHidden() { | 4432 bool WebContentsImpl::IsHidden() { |
4357 return capturer_count_ == 0 && !should_normally_be_visible_; | 4433 return capturer_count_ == 0 && !should_normally_be_visible_; |
4358 } | 4434 } |
4359 | 4435 |
4436 int WebContentsImpl::GetOuterDelegateFrameTreeNodeID() { | |
4437 if (node_ && node_->outer_web_contents()) | |
4438 return node_->outer_contents_frame_tree_node_id(); | |
4439 | |
4440 return FrameTreeNode::kFrameTreeNodeInvalidID; | |
4441 } | |
4442 | |
4360 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4443 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
4361 return frame_tree_.root()->render_manager(); | 4444 return frame_tree_.root()->render_manager(); |
4362 } | 4445 } |
4363 | 4446 |
4364 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4447 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
4365 return browser_plugin_guest_.get(); | 4448 return browser_plugin_guest_.get(); |
4366 } | 4449 } |
4367 | 4450 |
4368 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4451 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
4369 CHECK(!browser_plugin_guest_); | 4452 CHECK(!browser_plugin_guest_); |
4453 CHECK(guest); | |
4370 browser_plugin_guest_.reset(guest); | 4454 browser_plugin_guest_.reset(guest); |
4371 } | 4455 } |
4372 | 4456 |
4373 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4457 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
4374 return browser_plugin_embedder_.get(); | 4458 return browser_plugin_embedder_.get(); |
4375 } | 4459 } |
4376 | 4460 |
4377 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4461 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
4378 if (browser_plugin_embedder_) | 4462 if (browser_plugin_embedder_) |
4379 return; | 4463 return; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4461 player_map->erase(it); | 4545 player_map->erase(it); |
4462 } | 4546 } |
4463 | 4547 |
4464 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4548 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4465 force_disable_overscroll_content_ = force_disable; | 4549 force_disable_overscroll_content_ = force_disable; |
4466 if (view_) | 4550 if (view_) |
4467 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4551 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4468 } | 4552 } |
4469 | 4553 |
4470 } // namespace content | 4554 } // namespace content |
OLD | NEW |