OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/render_frame_host_manager.h" | 5 #include "content/browser/frame_host/render_frame_host_manager.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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 RenderFrameHostManager::~RenderFrameHostManager() { | 86 RenderFrameHostManager::~RenderFrameHostManager() { |
87 if (pending_render_frame_host_) | 87 if (pending_render_frame_host_) |
88 CancelPending(); | 88 CancelPending(); |
89 | 89 |
90 if (cross_process_frame_connector_) | 90 if (cross_process_frame_connector_) |
91 delete cross_process_frame_connector_; | 91 delete cross_process_frame_connector_; |
92 | 92 |
93 // We should always have a current RenderFrameHost except in some tests. | 93 // We should always have a current RenderFrameHost except in some tests. |
94 render_frame_host_.reset(); | 94 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>()); |
95 | 95 |
96 // Delete any swapped out RenderFrameHosts. | 96 // Delete any swapped out RenderFrameHosts. |
97 STLDeleteValues(&proxy_hosts_); | 97 STLDeleteValues(&proxy_hosts_); |
98 } | 98 } |
99 | 99 |
100 void RenderFrameHostManager::Init(BrowserContext* browser_context, | 100 void RenderFrameHostManager::Init(BrowserContext* browser_context, |
101 SiteInstance* site_instance, | 101 SiteInstance* site_instance, |
102 int view_routing_id, | 102 int view_routing_id, |
103 int frame_routing_id) { | 103 int frame_routing_id) { |
104 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It | 104 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It |
105 // is important to immediately give this SiteInstance to a RenderViewHost so | 105 // is important to immediately give this SiteInstance to a RenderViewHost so |
106 // that the SiteInstance is ref counted. | 106 // that the SiteInstance is ref counted. |
107 if (!site_instance) | 107 if (!site_instance) |
108 site_instance = SiteInstance::Create(browser_context); | 108 site_instance = SiteInstance::Create(browser_context); |
109 | 109 |
110 render_frame_host_ = CreateRenderFrameHost(site_instance, | 110 SetRenderFrameHost(CreateRenderFrameHost(site_instance, |
111 view_routing_id, | 111 view_routing_id, |
112 frame_routing_id, | 112 frame_routing_id, |
113 false, | 113 false, |
114 delegate_->IsHidden()); | 114 delegate_->IsHidden())); |
115 | 115 |
116 // Keep track of renderer processes as they start to shut down or are | 116 // Keep track of renderer processes as they start to shut down or are |
117 // crashed/killed. | 117 // crashed/killed. |
118 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | 118 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
119 NotificationService::AllSources()); | 119 NotificationService::AllSources()); |
120 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, | 120 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, |
121 NotificationService::AllSources()); | 121 NotificationService::AllSources()); |
122 } | 122 } |
123 | 123 |
124 RenderViewHostImpl* RenderFrameHostManager::current_host() const { | 124 RenderViewHostImpl* RenderFrameHostManager::current_host() const { |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 render_frame_host_->render_view_host()->GetView() && | 1017 render_frame_host_->render_view_host()->GetView() && |
1018 render_frame_host_->render_view_host()->GetView()->HasFocus(); | 1018 render_frame_host_->render_view_host()->GetView()->HasFocus(); |
1019 | 1019 |
1020 // TODO(creis): As long as show/hide are on RVH, we don't want to do them for | 1020 // TODO(creis): As long as show/hide are on RVH, we don't want to do them for |
1021 // subframe navigations or they'll interfere with the top-level page. | 1021 // subframe navigations or they'll interfere with the top-level page. |
1022 bool is_main_frame = frame_tree_node_->IsMainFrame(); | 1022 bool is_main_frame = frame_tree_node_->IsMainFrame(); |
1023 | 1023 |
1024 // Swap in the pending frame and make it active. Also ensure the FrameTree | 1024 // Swap in the pending frame and make it active. Also ensure the FrameTree |
1025 // stays in sync. | 1025 // stays in sync. |
1026 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = | 1026 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = |
1027 render_frame_host_.Pass(); | 1027 SetRenderFrameHost(pending_render_frame_host_.Pass()); |
1028 render_frame_host_ = pending_render_frame_host_.Pass(); | |
1029 if (is_main_frame) | 1028 if (is_main_frame) |
1030 render_frame_host_->render_view_host()->AttachToFrameTree(); | 1029 render_frame_host_->render_view_host()->AttachToFrameTree(); |
1031 | 1030 |
1032 // The process will no longer try to exit, so we can decrement the count. | 1031 // The process will no longer try to exit, so we can decrement the count. |
1033 render_frame_host_->GetProcess()->RemovePendingView(); | 1032 render_frame_host_->GetProcess()->RemovePendingView(); |
1034 | 1033 |
1035 // If the view is gone, then this RenderViewHost died while it was hidden. | 1034 // If the view is gone, then this RenderViewHost died while it was hidden. |
1036 // We ignored the RenderProcessGone call at the time, so we should send it now | 1035 // We ignored the RenderProcessGone call at the time, so we should send it now |
1037 // to make sure the sad tab shows up, etc. | 1036 // to make sure the sad tab shows up, etc. |
1038 if (!render_frame_host_->render_view_host()->GetView()) { | 1037 if (!render_frame_host_->render_view_host()->GetView()) { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 pending_render_frame_host.Pass()); | 1348 pending_render_frame_host.Pass()); |
1350 } else { | 1349 } else { |
1351 // We won't be coming back, so delete this one. | 1350 // We won't be coming back, so delete this one. |
1352 pending_render_frame_host.reset(); | 1351 pending_render_frame_host.reset(); |
1353 } | 1352 } |
1354 | 1353 |
1355 pending_web_ui_.reset(); | 1354 pending_web_ui_.reset(); |
1356 pending_and_current_web_ui_.reset(); | 1355 pending_and_current_web_ui_.reset(); |
1357 } | 1356 } |
1358 | 1357 |
| 1358 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost( |
| 1359 scoped_ptr<RenderFrameHostImpl> render_frame_host) { |
| 1360 // Swap the two. |
| 1361 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = |
| 1362 render_frame_host_.Pass(); |
| 1363 render_frame_host_ = render_frame_host.Pass(); |
| 1364 |
| 1365 if (frame_tree_node_->IsMainFrame()) { |
| 1366 // Update the count of top-level frames using this SiteInstance. All |
| 1367 // subframes are in the same BrowsingInstance as the main frame, so we only |
| 1368 // count top-level ones. This makes the value easier for consumers to |
| 1369 // interpret. |
| 1370 if (render_frame_host_) { |
| 1371 static_cast<SiteInstanceImpl*>(render_frame_host_->GetSiteInstance())-> |
| 1372 IncrementRelatedActiveContentsCount(); |
| 1373 } |
| 1374 if (old_render_frame_host) { |
| 1375 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance())-> |
| 1376 DecrementRelatedActiveContentsCount(); |
| 1377 } |
| 1378 } |
| 1379 |
| 1380 return old_render_frame_host.Pass(); |
| 1381 } |
| 1382 |
1359 bool RenderFrameHostManager::IsRVHOnSwappedOutList( | 1383 bool RenderFrameHostManager::IsRVHOnSwappedOutList( |
1360 RenderViewHostImpl* rvh) const { | 1384 RenderViewHostImpl* rvh) const { |
1361 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( | 1385 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost( |
1362 rvh->GetSiteInstance()); | 1386 rvh->GetSiteInstance()); |
1363 if (!proxy) | 1387 if (!proxy) |
1364 return false; | 1388 return false; |
1365 return IsOnSwappedOutList(proxy->render_frame_host()); | 1389 return IsOnSwappedOutList(proxy->render_frame_host()); |
1366 } | 1390 } |
1367 | 1391 |
1368 bool RenderFrameHostManager::IsOnSwappedOutList( | 1392 bool RenderFrameHostManager::IsOnSwappedOutList( |
(...skipping 21 matching lines...) Expand all Loading... |
1390 SiteInstance* instance) const { | 1414 SiteInstance* instance) const { |
1391 RenderFrameProxyHostMap::const_iterator iter = | 1415 RenderFrameProxyHostMap::const_iterator iter = |
1392 proxy_hosts_.find(instance->GetId()); | 1416 proxy_hosts_.find(instance->GetId()); |
1393 if (iter != proxy_hosts_.end()) | 1417 if (iter != proxy_hosts_.end()) |
1394 return iter->second; | 1418 return iter->second; |
1395 | 1419 |
1396 return NULL; | 1420 return NULL; |
1397 } | 1421 } |
1398 | 1422 |
1399 } // namespace content | 1423 } // namespace content |
OLD | NEW |