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 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1126 bool WebContentsImpl::NeedToFireBeforeUnload() { | 1137 bool WebContentsImpl::NeedToFireBeforeUnload() { |
1127 // TODO(creis): Should we fire even for interstitial pages? | 1138 // TODO(creis): Should we fire even for interstitial pages? |
1128 return WillNotifyDisconnection() && !ShowingInterstitialPage() && | 1139 return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
1129 !GetRenderViewHost()->SuddenTerminationAllowed(); | 1140 !GetRenderViewHost()->SuddenTerminationAllowed(); |
1130 } | 1141 } |
1131 | 1142 |
1132 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { | 1143 void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
1133 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); | 1144 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); |
1134 } | 1145 } |
1135 | 1146 |
1147 void WebContentsImpl::AttachToEmbedderFrame(WebContents* embedder_web_contents, | |
1148 RenderFrameHost* embedder_frame) { | |
1149 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1150 switches::kSitePerProcess)); | |
1151 // 1. Create a link to our parent WebContents. | |
nasko
2015/05/05 21:34:50
nit: I don't know if the numbering of the comments
lazyboy
2015/05/05 22:33:53
Removed numbers.
| |
1152 node_.set_parent_web_contents( | |
1153 static_cast<WebContentsImpl*>(embedder_web_contents)); | |
1154 | |
1155 DCHECK(embedder_frame); | |
1156 | |
1157 // 2. Create a swapped out RVH and a proxy in our render manager, pointing | |
1158 // to the embedder's SiteInstance. The swapped out RVH will be used to send | |
1159 // postMessage to guest. | |
1160 int proxy_to_embedder_routing_id = GetRenderManager()->CreateEmbedderProxy( | |
1161 embedder_frame->GetSiteInstance()); | |
1162 | |
1163 // 3. Swap the embedder's initial frame for the guest with the proxy | |
1164 // we've created above. | |
1165 // The proxy has a CPFC and it uses the swapped out RV as its RenderWidget, | |
1166 // which gives us input and rendering. | |
1167 static_cast<RenderFrameHostImpl*>(embedder_frame) | |
1168 ->frame_tree_node() | |
1169 ->render_manager() | |
1170 ->ReplaceWithGuestProxy(proxy_to_embedder_routing_id); | |
1171 } | |
1172 | |
1136 void WebContentsImpl::Stop() { | 1173 void WebContentsImpl::Stop() { |
1137 GetRenderManager()->Stop(); | 1174 GetRenderManager()->Stop(); |
1138 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); | 1175 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); |
1139 } | 1176 } |
1140 | 1177 |
1141 WebContents* WebContentsImpl::Clone() { | 1178 WebContents* WebContentsImpl::Clone() { |
1142 // We use our current SiteInstance since the cloned entry will use it anyway. | 1179 // We use our current SiteInstance since the cloned entry will use it anyway. |
1143 // We pass our own opener so that the cloned page can access it if it was | 1180 // We pass our own opener so that the cloned page can access it if it was |
1144 // before. | 1181 // before. |
1145 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); | 1182 CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 params.main_frame_routing_id == MSG_ROUTING_NONE) || | 1234 params.main_frame_routing_id == MSG_ROUTING_NONE) || |
1198 (params.routing_id != MSG_ROUTING_NONE && | 1235 (params.routing_id != MSG_ROUTING_NONE && |
1199 params.main_frame_routing_id != MSG_ROUTING_NONE)); | 1236 params.main_frame_routing_id != MSG_ROUTING_NONE)); |
1200 GetRenderManager()->Init( | 1237 GetRenderManager()->Init( |
1201 params.browser_context, params.site_instance, params.routing_id, | 1238 params.browser_context, params.site_instance, params.routing_id, |
1202 params.main_frame_routing_id); | 1239 params.main_frame_routing_id); |
1203 | 1240 |
1204 WebContentsViewDelegate* delegate = | 1241 WebContentsViewDelegate* delegate = |
1205 GetContentClient()->browser()->GetWebContentsViewDelegate(this); | 1242 GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
1206 | 1243 |
1207 if (browser_plugin_guest_) { | 1244 if (browser_plugin_guest_ && |
1245 !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1246 switches::kSitePerProcess)) { | |
1208 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( | 1247 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView( |
1209 this, delegate, &render_view_host_delegate_view_)); | 1248 this, delegate, &render_view_host_delegate_view_)); |
1210 | 1249 |
1211 WebContentsViewGuest* rv = new WebContentsViewGuest( | 1250 WebContentsViewGuest* rv = new WebContentsViewGuest( |
1212 this, browser_plugin_guest_.get(), platform_view.Pass(), | 1251 this, browser_plugin_guest_.get(), platform_view.Pass(), |
1213 render_view_host_delegate_view_); | 1252 render_view_host_delegate_view_); |
1214 render_view_host_delegate_view_ = rv; | 1253 render_view_host_delegate_view_ = rv; |
1215 view_.reset(rv); | 1254 view_.reset(rv); |
1216 } else { | 1255 } else { |
1217 // Regular WebContentsView. | 1256 // Regular WebContentsView. |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1506 int route_id, | 1545 int route_id, |
1507 int main_frame_route_id, | 1546 int main_frame_route_id, |
1508 const ViewHostMsg_CreateWindow_Params& params, | 1547 const ViewHostMsg_CreateWindow_Params& params, |
1509 SessionStorageNamespace* session_storage_namespace) { | 1548 SessionStorageNamespace* session_storage_namespace) { |
1510 // We usually create the new window in the same BrowsingInstance (group of | 1549 // We usually create the new window in the same BrowsingInstance (group of |
1511 // script-related windows), by passing in the current SiteInstance. However, | 1550 // script-related windows), by passing in the current SiteInstance. However, |
1512 // if the opener is being suppressed (in a non-guest), we create a new | 1551 // if the opener is being suppressed (in a non-guest), we create a new |
1513 // SiteInstance in its own BrowsingInstance. | 1552 // SiteInstance in its own BrowsingInstance. |
1514 bool is_guest = BrowserPluginGuest::IsGuest(this); | 1553 bool is_guest = BrowserPluginGuest::IsGuest(this); |
1515 | 1554 |
1555 if (is_guest && | |
1556 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1557 switches::kSitePerProcess)) { | |
1558 // TODO(lazyboy): CreateNewWindow doesn't work for <webview> yet. | |
1559 NOTREACHED(); | |
1560 } | |
1561 | |
1516 // If the opener is to be suppressed, the new window can be in any process. | 1562 // If the opener is to be suppressed, the new window can be in any process. |
1517 // Since routing ids are process specific, we must not have one passed in | 1563 // Since routing ids are process specific, we must not have one passed in |
1518 // as argument here. | 1564 // as argument here. |
1519 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); | 1565 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); |
1520 | 1566 |
1521 scoped_refptr<SiteInstance> site_instance = | 1567 scoped_refptr<SiteInstance> site_instance = |
1522 params.opener_suppressed && !is_guest ? | 1568 params.opener_suppressed && !is_guest ? |
1523 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : | 1569 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) : |
1524 GetSiteInstance(); | 1570 GetSiteInstance(); |
1525 | 1571 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1724 void WebContentsImpl::ShowCreatedWidget(int route_id, | 1770 void WebContentsImpl::ShowCreatedWidget(int route_id, |
1725 bool is_fullscreen, | 1771 bool is_fullscreen, |
1726 const gfx::Rect& initial_rect) { | 1772 const gfx::Rect& initial_rect) { |
1727 RenderWidgetHostViewBase* widget_host_view = | 1773 RenderWidgetHostViewBase* widget_host_view = |
1728 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id)); | 1774 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id)); |
1729 if (!widget_host_view) | 1775 if (!widget_host_view) |
1730 return; | 1776 return; |
1731 | 1777 |
1732 RenderWidgetHostView* view = NULL; | 1778 RenderWidgetHostView* view = NULL; |
1733 BrowserPluginGuest* guest = GetBrowserPluginGuest(); | 1779 BrowserPluginGuest* guest = GetBrowserPluginGuest(); |
1734 if (guest && guest->embedder_web_contents()) { | 1780 if (guest && guest->embedder_web_contents() && |
1781 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1782 switches::kSitePerProcess)) { | |
1735 view = guest->embedder_web_contents()->GetRenderWidgetHostView(); | 1783 view = guest->embedder_web_contents()->GetRenderWidgetHostView(); |
1736 } else { | 1784 } else { |
1737 view = GetRenderWidgetHostView(); | 1785 view = GetRenderWidgetHostView(); |
1738 } | 1786 } |
1739 | 1787 |
1740 if (is_fullscreen) { | 1788 if (is_fullscreen) { |
1741 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); | 1789 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
1742 view_->StoreFocus(); | 1790 view_->StoreFocus(); |
1743 fullscreen_widget_routing_id_ = route_id; | 1791 fullscreen_widget_routing_id_ = route_id; |
1744 if (delegate_ && delegate_->EmbedsFullscreenWidget()) { | 1792 if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
(...skipping 2424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4169 int proxy_routing_id, | 4217 int proxy_routing_id, |
4170 bool for_main_frame_navigation) { | 4218 bool for_main_frame_navigation) { |
4171 TRACE_EVENT0("browser,navigation", | 4219 TRACE_EVENT0("browser,navigation", |
4172 "WebContentsImpl::CreateRenderViewForRenderManager"); | 4220 "WebContentsImpl::CreateRenderViewForRenderManager"); |
4173 // Can be NULL during tests. | 4221 // Can be NULL during tests. |
4174 RenderWidgetHostViewBase* rwh_view; | 4222 RenderWidgetHostViewBase* rwh_view; |
4175 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary | 4223 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary |
4176 // until RenderWidgetHost is attached to RenderFrameHost. We need to special | 4224 // until RenderWidgetHost is attached to RenderFrameHost. We need to special |
4177 // 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 |
4178 // 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. |
4179 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) { | |
4180 RenderWidgetHostViewChildFrame* rwh_view_child = | 4232 RenderWidgetHostViewChildFrame* rwh_view_child = |
4181 new RenderWidgetHostViewChildFrame(render_view_host); | 4233 new RenderWidgetHostViewChildFrame(render_view_host); |
4182 rwh_view = rwh_view_child; | 4234 rwh_view = rwh_view_child; |
4235 if (is_guest_in_site_per_process) | |
4236 GetRenderManager()->SetGuestRWHView(rwh_view_child); | |
4183 } else { | 4237 } else { |
4184 rwh_view = view_->CreateViewForWidget(render_view_host, false); | 4238 rwh_view = view_->CreateViewForWidget(render_view_host, false); |
4185 } | 4239 } |
4186 | 4240 |
4187 // Now that the RenderView has been created, we need to tell it its size. | 4241 // Now that the RenderView has been created, we need to tell it its size. |
4188 if (rwh_view) | 4242 if (rwh_view) |
4189 rwh_view->SetSize(GetSizeForNewRenderView()); | 4243 rwh_view->SetSize(GetSizeForNewRenderView()); |
4190 | 4244 |
4191 // Make sure we use the correct starting page_id in the new RenderView. | 4245 // Make sure we use the correct starting page_id in the new RenderView. |
4192 UpdateMaxPageIDIfNecessary(render_view_host); | 4246 UpdateMaxPageIDIfNecessary(render_view_host); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4311 last_reported_encoding_ = encoding; | 4365 last_reported_encoding_ = encoding; |
4312 | 4366 |
4313 canonical_encoding_ = GetContentClient()->browser()-> | 4367 canonical_encoding_ = GetContentClient()->browser()-> |
4314 GetCanonicalEncodingNameByAliasName(encoding); | 4368 GetCanonicalEncodingNameByAliasName(encoding); |
4315 } | 4369 } |
4316 | 4370 |
4317 bool WebContentsImpl::IsHidden() { | 4371 bool WebContentsImpl::IsHidden() { |
4318 return capturer_count_ == 0 && !should_normally_be_visible_; | 4372 return capturer_count_ == 0 && !should_normally_be_visible_; |
4319 } | 4373 } |
4320 | 4374 |
4375 int64 WebContentsImpl::GetEmbedderFrameTreeNodeID() { | |
4376 if (node_.parent_web_contents()) { | |
4377 return node_.parent_web_contents() | |
4378 ->GetFrameTree() | |
4379 ->root() | |
4380 ->frame_tree_node_id(); | |
4381 } | |
4382 return -1; | |
4383 } | |
4384 | |
4321 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { | 4385 RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
4322 return frame_tree_.root()->render_manager(); | 4386 return frame_tree_.root()->render_manager(); |
4323 } | 4387 } |
4324 | 4388 |
4325 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { | 4389 BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
4326 return browser_plugin_guest_.get(); | 4390 return browser_plugin_guest_.get(); |
4327 } | 4391 } |
4328 | 4392 |
4329 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { | 4393 void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
4330 CHECK(!browser_plugin_guest_); | 4394 CHECK(!browser_plugin_guest_); |
4395 CHECK(guest); | |
4331 browser_plugin_guest_.reset(guest); | 4396 browser_plugin_guest_.reset(guest); |
4332 } | 4397 } |
4333 | 4398 |
4334 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { | 4399 BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
4335 return browser_plugin_embedder_.get(); | 4400 return browser_plugin_embedder_.get(); |
4336 } | 4401 } |
4337 | 4402 |
4338 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { | 4403 void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
4339 if (browser_plugin_embedder_) | 4404 if (browser_plugin_embedder_) |
4340 return; | 4405 return; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4427 node->render_manager()->ResumeResponseDeferredAtStart(); | 4492 node->render_manager()->ResumeResponseDeferredAtStart(); |
4428 } | 4493 } |
4429 | 4494 |
4430 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4495 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4431 force_disable_overscroll_content_ = force_disable; | 4496 force_disable_overscroll_content_ = force_disable; |
4432 if (view_) | 4497 if (view_) |
4433 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4498 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4434 } | 4499 } |
4435 | 4500 |
4436 } // namespace content | 4501 } // namespace content |
OLD | NEW |