Chromium Code Reviews| 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 : parent_web_contents_(nullptr) { | |
| 292 } | |
| 293 | |
| 294 WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { | |
| 295 // TODO(lazyboy): Enforce that a child WebContentsTreeNode gets deleted | |
| 296 // before its parent. Otherwise the child could have a stale pointer to its | |
| 297 // parent WebContents, risking a use-after-free. | |
| 298 } | |
| 299 | |
| 289 // WebContentsImpl ------------------------------------------------------------- | 300 // WebContentsImpl ------------------------------------------------------------- |
| 290 | 301 |
| 291 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, | 302 WebContentsImpl::WebContentsImpl(BrowserContext* browser_context, |
| 292 WebContentsImpl* opener) | 303 WebContentsImpl* opener) |
| 293 : delegate_(NULL), | 304 : delegate_(NULL), |
| 294 controller_(this, browser_context), | 305 controller_(this, browser_context), |
| 295 render_view_host_delegate_view_(NULL), | 306 render_view_host_delegate_view_(NULL), |
| 296 opener_(opener), | 307 opener_(opener), |
| 297 created_with_opener_(!!opener), | 308 created_with_opener_(!!opener), |
| 298 #if defined(OS_WIN) | 309 #if defined(OS_WIN) |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1130 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1141 bool WebContentsImpl::NeedToFireBeforeUnload() { |
| 1131 // TODO(creis): Should we fire even for interstitial pages? | 1142 // TODO(creis): Should we fire even for interstitial pages? |
| 1132 return WillNotifyDisconnection() && !ShowingInterstitialPage() && | 1143 return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
| 1133 !GetRenderViewHost()->SuddenTerminationAllowed(); | 1144 !GetRenderViewHost()->SuddenTerminationAllowed(); |
| 1134 } | 1145 } |
| 1135 | 1146 |
| 1136 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1147 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
| 1137 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); | 1148 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); |
| 1138 } | 1149 } |
| 1139 | 1150 |
| 1151 void WebContentsImpl::AttachToEmbedderFrame(WebContents* embedder_web_contents, | |
| 1152 RenderFrameHost* embedder_frame) { | |
| 1153 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1154 switches::kSitePerProcess)); | |
| 1155 // Create a link to our parent WebContents. | |
| 1156 node_.set_parent_web_contents( | |
| 1157 static_cast<WebContentsImpl*>(embedder_web_contents)); | |
| 1158 | |
| 1159 DCHECK(embedder_frame); | |
| 1160 | |
| 1161 // Create a swapped out RVH and a proxy in our render manager, pointing | |
| 1162 // to the embedder's SiteInstance. The swapped out RVH will be used to send | |
| 1163 // postMessage to guest. | |
| 1164 int proxy_to_embedder_routing_id = GetRenderManager()->CreateEmbedderProxy( | |
| 1165 embedder_frame->GetSiteInstance()); | |
| 1166 | |
| 1167 // Swap the embedder's initial frame for the guest with the proxy | |
| 1168 // we've created above. | |
| 1169 // The proxy has a CPFC and it uses the swapped out RV as its RenderWidget, | |
| 1170 // which gives us input and rendering. | |
| 1171 static_cast<RenderFrameHostImpl*>(embedder_frame) | |
| 1172 ->frame_tree_node() | |
| 1173 ->render_manager() | |
| 1174 ->ReplaceWithGuestProxy(proxy_to_embedder_routing_id); | |
| 1175 } | |
| 1176 | |
| 1140 void WebContentsImpl::Stop() { | 1177 void WebContentsImpl::Stop() { |
| 1141 GetRenderManager()->Stop(); | 1178 GetRenderManager()->Stop(); |
| 1142 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); | 1179 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); |
| 1143 } | 1180 } |
| 1144 | 1181 |
| 1145 WebContents* WebContentsImpl::Clone() { | 1182 WebContents* WebContentsImpl::Clone() { |
| 1146 // We use our current SiteInstance since the cloned entry will use it anyway. | 1183 // We use our current SiteInstance since the cloned entry will use it anyway. |
| 1147 // We pass our own opener so that the cloned page can access it if it was | 1184 // We pass our own opener so that the cloned page can access it if it was |
| 1148 // before. | 1185 // before. |
| 1149 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); | 1186 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1202 (params.routing_id != MSG_ROUTING_NONE && | 1239 (params.routing_id != MSG_ROUTING_NONE && |
| 1203 params.main_frame_routing_id != MSG_ROUTING_NONE)); | 1240 params.main_frame_routing_id != MSG_ROUTING_NONE)); |
| 1204 GetRenderManager()->Init( | 1241 GetRenderManager()->Init( |
| 1205 params.browser_context, params.site_instance, params.routing_id, | 1242 params.browser_context, params.site_instance, params.routing_id, |
| 1206 params.main_frame_routing_id); | 1243 params.main_frame_routing_id); |
| 1207 frame_tree_.root()->SetFrameName(params.main_frame_name); | 1244 frame_tree_.root()->SetFrameName(params.main_frame_name); |
| 1208 | 1245 |
| 1209 WebContentsViewDelegate* delegate = | 1246 WebContentsViewDelegate* delegate = |
| 1210 GetContentClient()->browser()->GetWebContentsViewDelegate(this); | 1247 GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 1211 | 1248 |
| 1212 if (browser_plugin_guest_) { | 1249 if (browser_plugin_guest_ && |
| 1250 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1251 switches::kSitePerProcess)) { | |
| 1213 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( | 1252 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( |
| 1214 this, delegate, &render_view_host_delegate_view_)); | 1253 this, delegate, &render_view_host_delegate_view_)); |
| 1215 | 1254 |
| 1216 WebContentsViewGuest* rv = new WebContentsViewGuest( | 1255 WebContentsViewGuest* rv = new WebContentsViewGuest( |
| 1217 this, browser_plugin_guest_.get(), platform_view.Pass(), | 1256 this, browser_plugin_guest_.get(), platform_view.Pass(), |
| 1218 render_view_host_delegate_view_); | 1257 render_view_host_delegate_view_); |
| 1219 render_view_host_delegate_view_ = rv; | 1258 render_view_host_delegate_view_ = rv; |
| 1220 view_.reset(rv); | 1259 view_.reset(rv); |
| 1221 } else { | 1260 } else { |
| 1222 // Regular WebContentsView. | 1261 // Regular WebContentsView. |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1511 int route_id, | 1550 int route_id, |
| 1512 int main_frame_route_id, | 1551 int main_frame_route_id, |
| 1513 const ViewHostMsg_CreateWindow_Params& params, | 1552 const ViewHostMsg_CreateWindow_Params& params, |
| 1514 SessionStorageNamespace* session_storage_namespace) { | 1553 SessionStorageNamespace* session_storage_namespace) { |
| 1515 // We usually create the new window in the same BrowsingInstance (group of | 1554 // We usually create the new window in the same BrowsingInstance (group of |
| 1516 // script-related windows), by passing in the current SiteInstance. However, | 1555 // script-related windows), by passing in the current SiteInstance. However, |
| 1517 // if the opener is being suppressed (in a non-guest), we create a new | 1556 // if the opener is being suppressed (in a non-guest), we create a new |
| 1518 // SiteInstance in its own BrowsingInstance. | 1557 // SiteInstance in its own BrowsingInstance. |
| 1519 bool is_guest = BrowserPluginGuest::IsGuest(this); | 1558 bool is_guest = BrowserPluginGuest::IsGuest(this); |
| 1520 | 1559 |
| 1560 if (is_guest && | |
| 1561 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1562 switches::kSitePerProcess)) { | |
| 1563 // TODO(lazyboy): CreateNewWindow doesn't work for <webview> yet. | |
|
Charlie Reis
2015/05/19 07:12:31
for OOPIF-based <webview> yet
lazyboy
2015/05/21 23:23:47
Done.
| |
| 1564 NOTREACHED(); | |
| 1565 } | |
| 1566 | |
| 1521 // If the opener is to be suppressed, the new window can be in any process. | 1567 // If the opener is to be suppressed, the new window can be in any process. |
| 1522 // Since routing ids are process specific, we must not have one passed in | 1568 // Since routing ids are process specific, we must not have one passed in |
| 1523 // as argument here. | 1569 // as argument here. |
| 1524 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); | 1570 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); |
| 1525 | 1571 |
| 1526 scoped_refptr<SiteInstance> site_instance = | 1572 scoped_refptr<SiteInstance> site_instance = |
| 1527 params.opener_suppressed && !is_guest ? | 1573 params.opener_suppressed && !is_guest ? |
| 1528 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : | 1574 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : |
| 1529 GetSiteInstance(); | 1575 GetSiteInstance(); |
| 1530 | 1576 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1730 void WebContentsImpl::ShowCreatedWidget(int route_id, | 1776 void WebContentsImpl::ShowCreatedWidget(int route_id, |
| 1731 bool is_fullscreen, | 1777 bool is_fullscreen, |
| 1732 const gfx::Rect& initial_rect) { | 1778 const gfx::Rect& initial_rect) { |
| 1733 RenderWidgetHostViewBase* widget_host_view = | 1779 RenderWidgetHostViewBase* widget_host_view = |
| 1734 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id)); | 1780 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id)); |
| 1735 if (!widget_host_view) | 1781 if (!widget_host_view) |
| 1736 return; | 1782 return; |
| 1737 | 1783 |
| 1738 RenderWidgetHostView* view = NULL; | 1784 RenderWidgetHostView* view = NULL; |
| 1739 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | 1785 BrowserPluginGuest* guest = GetBrowserPluginGuest(); |
| 1740 if (guest && guest->embedder_web_contents()) { | 1786 if (guest && guest->embedder_web_contents() && |
| 1787 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1788 switches::kSitePerProcess)) { | |
| 1741 view = guest->embedder_web_contents()->GetRenderWidgetHostView(); | 1789 view = guest->embedder_web_contents()->GetRenderWidgetHostView(); |
| 1742 } else { | 1790 } else { |
| 1743 view = GetRenderWidgetHostView(); | 1791 view = GetRenderWidgetHostView(); |
| 1744 } | 1792 } |
| 1745 | 1793 |
| 1746 if (is_fullscreen) { | 1794 if (is_fullscreen) { |
| 1747 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); | 1795 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
| 1748 view_->StoreFocus(); | 1796 view_->StoreFocus(); |
| 1749 fullscreen_widget_routing_id_ = route_id; | 1797 fullscreen_widget_routing_id_ = route_id; |
| 1750 if (delegate_ && delegate_->EmbedsFullscreenWidget()) { | 1798 if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
| (...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4163 int proxy_routing_id, | 4211 int proxy_routing_id, |
| 4164 bool for_main_frame_navigation) { | 4212 bool for_main_frame_navigation) { |
| 4165 TRACE_EVENT0("browser,navigation", | 4213 TRACE_EVENT0("browser,navigation", |
| 4166 "WebContentsImpl::CreateRenderViewForRenderManager"); | 4214 "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 4167 // Can be NULL during tests. | 4215 // Can be NULL during tests. |
| 4168 RenderWidgetHostViewBase* rwh_view; | 4216 RenderWidgetHostViewBase* rwh_view; |
| 4169 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary | 4217 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary |
| 4170 // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 4218 // until RenderWidgetHost is attached to RenderFrameHost. We need to special |
| 4171 // case this because RWH is still a base class of RenderViewHost, and child | 4219 // case this because RWH is still a base class of RenderViewHost, and child |
| 4172 // frame RWHVs are unique in that they do not have their own WebContents. | 4220 // frame RWHVs are unique in that they do not have their own WebContents. |
| 4173 if (!for_main_frame_navigation) { | 4221 bool is_guest_in_site_per_process = |
| 4222 !!browser_plugin_guest_.get() && | |
| 4223 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 4224 switches::kSitePerProcess); | |
| 4225 if (!for_main_frame_navigation || is_guest_in_site_per_process) { | |
| 4174 RenderWidgetHostViewChildFrame* rwh_view_child = | 4226 RenderWidgetHostViewChildFrame* rwh_view_child = |
| 4175 new RenderWidgetHostViewChildFrame(render_view_host); | 4227 new RenderWidgetHostViewChildFrame(render_view_host); |
| 4176 rwh_view = rwh_view_child; | 4228 rwh_view = rwh_view_child; |
| 4229 if (is_guest_in_site_per_process) | |
| 4230 GetRenderManager()->SetGuestRWHView(rwh_view_child); | |
| 4177 } else { | 4231 } else { |
| 4178 rwh_view = view_->CreateViewForWidget(render_view_host, false); | 4232 rwh_view = view_->CreateViewForWidget(render_view_host, false); |
| 4179 } | 4233 } |
| 4180 | 4234 |
| 4181 // Now that the RenderView has been created, we need to tell it its size. | 4235 // Now that the RenderView has been created, we need to tell it its size. |
| 4182 if (rwh_view) | 4236 if (rwh_view) |
| 4183 rwh_view->SetSize(GetSizeForNewRenderView()); | 4237 rwh_view->SetSize(GetSizeForNewRenderView()); |
| 4184 | 4238 |
| 4185 // Make sure we use the correct starting page_id in the new RenderView. | 4239 // Make sure we use the correct starting page_id in the new RenderView. |
| 4186 UpdateMaxPageIDIfNecessary(render_view_host); | 4240 UpdateMaxPageIDIfNecessary(render_view_host); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4307 last_reported_encoding_ = encoding; | 4361 last_reported_encoding_ = encoding; |
| 4308 | 4362 |
| 4309 canonical_encoding_ = GetContentClient()->browser()-> | 4363 canonical_encoding_ = GetContentClient()->browser()-> |
| 4310 GetCanonicalEncodingNameByAliasName(encoding); | 4364 GetCanonicalEncodingNameByAliasName(encoding); |
| 4311 } | 4365 } |
| 4312 | 4366 |
| 4313 bool WebContentsImpl::IsHidden() { | 4367 bool WebContentsImpl::IsHidden() { |
| 4314 return capturer_count_ == 0 && !should_normally_be_visible_; | 4368 return capturer_count_ == 0 && !should_normally_be_visible_; |
| 4315 } | 4369 } |
| 4316 | 4370 |
| 4371 int64 WebContentsImpl::GetEmbedderFrameTreeNodeID() { | |
| 4372 if (node_.parent_web_contents()) { | |
| 4373 return node_.parent_web_contents() | |
| 4374 ->GetFrameTree() | |
| 4375 ->root() | |
| 4376 ->frame_tree_node_id(); | |
| 4377 } | |
| 4378 return -1; | |
| 4379 } | |
| 4380 | |
| 4317 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4381 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
| 4318 return frame_tree_.root()->render_manager(); | 4382 return frame_tree_.root()->render_manager(); |
| 4319 } | 4383 } |
| 4320 | 4384 |
| 4321 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4385 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
| 4322 return browser_plugin_guest_.get(); | 4386 return browser_plugin_guest_.get(); |
| 4323 } | 4387 } |
| 4324 | 4388 |
| 4325 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4389 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 4326 CHECK(!browser_plugin_guest_); | 4390 CHECK(!browser_plugin_guest_); |
| 4391 CHECK(guest); | |
| 4327 browser_plugin_guest_.reset(guest); | 4392 browser_plugin_guest_.reset(guest); |
| 4328 } | 4393 } |
| 4329 | 4394 |
| 4330 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4395 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
| 4331 return browser_plugin_embedder_.get(); | 4396 return browser_plugin_embedder_.get(); |
| 4332 } | 4397 } |
| 4333 | 4398 |
| 4334 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4399 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 4335 if (browser_plugin_embedder_) | 4400 if (browser_plugin_embedder_) |
| 4336 return; | 4401 return; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4423 node->render_manager()->ResumeResponseDeferredAtStart(); | 4488 node->render_manager()->ResumeResponseDeferredAtStart(); |
| 4424 } | 4489 } |
| 4425 | 4490 |
| 4426 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4491 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4427 force_disable_overscroll_content_ = force_disable; | 4492 force_disable_overscroll_content_ = force_disable; |
| 4428 if (view_) | 4493 if (view_) |
| 4429 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4494 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4430 } | 4495 } |
| 4431 | 4496 |
| 4432 } // namespace content | 4497 } // namespace content |
| OLD | NEW |