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

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

Powered by Google App Engine
This is Rietveld 408576698