Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: content/browser/frame_host/render_frame_host_manager.cc

Issue 257083002: Check BrowsingInstance before swapping prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 RenderFrameHostManager::~RenderFrameHostManager() { 85 RenderFrameHostManager::~RenderFrameHostManager() {
86 if (pending_render_frame_host_) 86 if (pending_render_frame_host_)
87 CancelPending(); 87 CancelPending();
88 88
89 if (cross_process_frame_connector_) 89 if (cross_process_frame_connector_)
90 delete cross_process_frame_connector_; 90 delete cross_process_frame_connector_;
91 91
92 // We should always have a current RenderFrameHost except in some tests. 92 // We should always have a current RenderFrameHost except in some tests.
93 render_frame_host_.reset(); 93 SetRenderFrameHost(scoped_ptr<RenderFrameHostImpl>());
94 94
95 // Delete any swapped out RenderFrameHosts. 95 // Delete any swapped out RenderFrameHosts.
96 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin(); 96 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin();
97 iter != proxy_hosts_.end(); 97 iter != proxy_hosts_.end();
98 ++iter) { 98 ++iter) {
99 delete iter->second; 99 delete iter->second;
100 } 100 }
101 } 101 }
102 102
103 void RenderFrameHostManager::Init(BrowserContext* browser_context, 103 void RenderFrameHostManager::Init(BrowserContext* browser_context,
104 SiteInstance* site_instance, 104 SiteInstance* site_instance,
105 int view_routing_id, 105 int view_routing_id,
106 int frame_routing_id) { 106 int frame_routing_id) {
107 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It 107 // Create a RenderViewHost and RenderFrameHost, once we have an instance. It
108 // is important to immediately give this SiteInstance to a RenderViewHost so 108 // is important to immediately give this SiteInstance to a RenderViewHost so
109 // that the SiteInstance is ref counted. 109 // that the SiteInstance is ref counted.
110 if (!site_instance) 110 if (!site_instance)
111 site_instance = SiteInstance::Create(browser_context); 111 site_instance = SiteInstance::Create(browser_context);
112 112
113 render_frame_host_ = CreateRenderFrameHost(site_instance, 113 SetRenderFrameHost(CreateRenderFrameHost(site_instance,
114 view_routing_id, 114 view_routing_id,
115 frame_routing_id, 115 frame_routing_id,
116 false, 116 false,
117 delegate_->IsHidden()); 117 delegate_->IsHidden()));
118 118
119 // Keep track of renderer processes as they start to shut down or are 119 // Keep track of renderer processes as they start to shut down or are
120 // crashed/killed. 120 // crashed/killed.
121 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, 121 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED,
122 NotificationService::AllSources()); 122 NotificationService::AllSources());
123 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING, 123 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSING,
124 NotificationService::AllSources()); 124 NotificationService::AllSources());
125 } 125 }
126 126
127 RenderViewHostImpl* RenderFrameHostManager::current_host() const { 127 RenderViewHostImpl* RenderFrameHostManager::current_host() const {
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 render_frame_host_->render_view_host()->GetView() && 1020 render_frame_host_->render_view_host()->GetView() &&
1021 render_frame_host_->render_view_host()->GetView()->HasFocus(); 1021 render_frame_host_->render_view_host()->GetView()->HasFocus();
1022 1022
1023 // TODO(creis): As long as show/hide are on RVH, we don't want to do them for 1023 // TODO(creis): As long as show/hide are on RVH, we don't want to do them for
1024 // subframe navigations or they'll interfere with the top-level page. 1024 // subframe navigations or they'll interfere with the top-level page.
1025 bool is_main_frame = frame_tree_node_->IsMainFrame(); 1025 bool is_main_frame = frame_tree_node_->IsMainFrame();
1026 1026
1027 // Swap in the pending frame and make it active. Also ensure the FrameTree 1027 // Swap in the pending frame and make it active. Also ensure the FrameTree
1028 // stays in sync. 1028 // stays in sync.
1029 scoped_ptr<RenderFrameHostImpl> old_render_frame_host = 1029 scoped_ptr<RenderFrameHostImpl> old_render_frame_host =
1030 render_frame_host_.Pass(); 1030 SetRenderFrameHost(pending_render_frame_host_.Pass());
1031 render_frame_host_ = pending_render_frame_host_.Pass();
1032 if (is_main_frame) 1031 if (is_main_frame)
1033 render_frame_host_->render_view_host()->AttachToFrameTree(); 1032 render_frame_host_->render_view_host()->AttachToFrameTree();
1034 1033
1035 // The process will no longer try to exit, so we can decrement the count. 1034 // The process will no longer try to exit, so we can decrement the count.
1036 render_frame_host_->GetProcess()->RemovePendingView(); 1035 render_frame_host_->GetProcess()->RemovePendingView();
1037 1036
1038 // If the view is gone, then this RenderViewHost died while it was hidden. 1037 // If the view is gone, then this RenderViewHost died while it was hidden.
1039 // We ignored the RenderProcessGone call at the time, so we should send it now 1038 // We ignored the RenderProcessGone call at the time, so we should send it now
1040 // to make sure the sad tab shows up, etc. 1039 // to make sure the sad tab shows up, etc.
1041 if (!render_frame_host_->render_view_host()->GetView()) { 1040 if (!render_frame_host_->render_view_host()->GetView()) {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1352 pending_render_frame_host.Pass()); 1351 pending_render_frame_host.Pass());
1353 } else { 1352 } else {
1354 // We won't be coming back, so delete this one. 1353 // We won't be coming back, so delete this one.
1355 pending_render_frame_host.reset(); 1354 pending_render_frame_host.reset();
1356 } 1355 }
1357 1356
1358 pending_web_ui_.reset(); 1357 pending_web_ui_.reset();
1359 pending_and_current_web_ui_.reset(); 1358 pending_and_current_web_ui_.reset();
1360 } 1359 }
1361 1360
1361 scoped_ptr<RenderFrameHostImpl> RenderFrameHostManager::SetRenderFrameHost(
1362 scoped_ptr<RenderFrameHostImpl> render_frame_host) {
1363 // Swap the two.
1364 scoped_ptr<RenderFrameHostImpl> old_render_frame_host =
1365 render_frame_host_.Pass();
1366 render_frame_host_ = render_frame_host.Pass();
1367
1368 if (frame_tree_node_->IsMainFrame()) {
1369 // Update the count of top-level frames using this SiteInstance. All
1370 // subframes are in the same BrowsingInstance as the main frame, so we only
1371 // count top-level ones. This makes the value easier for consumers to
1372 // interpret.
1373 if (render_frame_host_) {
1374 static_cast<SiteInstanceImpl*>(render_frame_host_->GetSiteInstance())->
1375 IncrementRelatedActiveContentsCount();
1376 }
1377 if (old_render_frame_host) {
1378 static_cast<SiteInstanceImpl*>(old_render_frame_host->GetSiteInstance())->
1379 DecrementRelatedActiveContentsCount();
1380 }
1381 }
1382
1383 return old_render_frame_host.Pass();
1384 }
1385
1362 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) { 1386 void RenderFrameHostManager::RenderViewDeleted(RenderViewHost* rvh) {
1363 // We are doing this in order to work around and to track a crasher 1387 // We are doing this in order to work around and to track a crasher
1364 // (http://crbug.com/23411) where it seems that pending_render_frame_host_ is 1388 // (http://crbug.com/23411) where it seems that pending_render_frame_host_ is
1365 // deleted (not sure from where) but not NULLed. 1389 // deleted (not sure from where) but not NULLed.
1366 if (pending_render_frame_host_ && 1390 if (pending_render_frame_host_ &&
1367 rvh == pending_render_frame_host_->render_view_host()) { 1391 rvh == pending_render_frame_host_->render_view_host()) {
1368 // If you hit this NOTREACHED, please report it in the following bug 1392 // If you hit this NOTREACHED, please report it in the following bug
1369 // http://crbug.com/23411 Make sure to include what you were doing when it 1393 // http://crbug.com/23411 Make sure to include what you were doing when it
1370 // happened (navigating to a new page, closing a tab...) and if you can 1394 // happened (navigating to a new page, closing a tab...) and if you can
1371 // reproduce. 1395 // reproduce.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 SiteInstance* instance) const { 1447 SiteInstance* instance) const {
1424 RenderFrameProxyHostMap::const_iterator iter = 1448 RenderFrameProxyHostMap::const_iterator iter =
1425 proxy_hosts_.find(instance->GetId()); 1449 proxy_hosts_.find(instance->GetId());
1426 if (iter != proxy_hosts_.end()) 1450 if (iter != proxy_hosts_.end())
1427 return iter->second; 1451 return iter->second;
1428 1452
1429 return NULL; 1453 return NULL;
1430 } 1454 }
1431 1455
1432 } // namespace content 1456 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698