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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 pending_render_frame_host_->DisownOpener(); | 496 pending_render_frame_host_->DisownOpener(); |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
500 void RenderFrameHostManager::RendererProcessClosing( | 500 void RenderFrameHostManager::RendererProcessClosing( |
501 RenderProcessHost* render_process_host) { | 501 RenderProcessHost* render_process_host) { |
502 // Remove any swapped out RVHs from this process, so that we don't try to | 502 // Remove any swapped out RVHs from this process, so that we don't try to |
503 // swap them back in while the process is exiting. Start by finding them, | 503 // swap them back in while the process is exiting. Start by finding them, |
504 // since there could be more than one. | 504 // since there could be more than one. |
505 std::list<int> ids_to_remove; | 505 std::list<int> ids_to_remove; |
506 // Do not remove proxies in the dead process that still have active frame | |
507 // count though, we just reset them to be uninitialized. | |
508 std::list<int> ids_to_keep; | |
506 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin(); | 509 for (RenderFrameProxyHostMap::iterator iter = proxy_hosts_.begin(); |
507 iter != proxy_hosts_.end(); | 510 iter != proxy_hosts_.end(); |
508 ++iter) { | 511 ++iter) { |
509 if (iter->second->GetProcess() == render_process_host) | 512 RenderFrameProxyHost* proxy = iter->second; |
513 if (proxy->GetProcess() != render_process_host) | |
514 continue; | |
515 | |
516 if (static_cast<SiteInstanceImpl*>(proxy->GetSiteInstance()) | |
517 ->active_frame_count() >= 1U) { | |
518 ids_to_keep.push_back(iter->first); | |
519 } else { | |
510 ids_to_remove.push_back(iter->first); | 520 ids_to_remove.push_back(iter->first); |
521 } | |
511 } | 522 } |
512 | 523 |
513 // Now delete them. | 524 // Now delete them. |
514 while (!ids_to_remove.empty()) { | 525 while (!ids_to_remove.empty()) { |
515 delete proxy_hosts_[ids_to_remove.back()]; | 526 delete proxy_hosts_[ids_to_remove.back()]; |
516 proxy_hosts_.erase(ids_to_remove.back()); | 527 proxy_hosts_.erase(ids_to_remove.back()); |
517 ids_to_remove.pop_back(); | 528 ids_to_remove.pop_back(); |
518 } | 529 } |
530 | |
531 while (!ids_to_keep.empty()) { | |
532 frame_tree_node_->frame_tree()->ForEach( | |
533 base::Bind( | |
534 &RenderFrameHostManager::ResetProxiesInSiteInstance, | |
535 ids_to_keep.back())); | |
536 ids_to_keep.pop_back(); | |
537 } | |
519 } | 538 } |
520 | 539 |
521 void RenderFrameHostManager::SwapOutOldFrame( | 540 void RenderFrameHostManager::SwapOutOldFrame( |
522 scoped_ptr<RenderFrameHostImpl> old_render_frame_host) { | 541 scoped_ptr<RenderFrameHostImpl> old_render_frame_host) { |
523 TRACE_EVENT1("navigation", "RenderFrameHostManager::SwapOutOldFrame", | 542 TRACE_EVENT1("navigation", "RenderFrameHostManager::SwapOutOldFrame", |
524 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); | 543 "FrameTreeNode id", frame_tree_node_->frame_tree_node_id()); |
525 | 544 |
526 // Tell the renderer to suppress any further modal dialogs so that we can swap | 545 // Tell the renderer to suppress any further modal dialogs so that we can swap |
527 // it out. This must be done before canceling any current dialog, in case | 546 // it out. This must be done before canceling any current dialog, in case |
528 // there is a loop creating additional dialogs. | 547 // there is a loop creating additional dialogs. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 // Otherwise there are active views and we need a proxy for the old RFH. | 582 // Otherwise there are active views and we need a proxy for the old RFH. |
564 // (There should not be one yet.) | 583 // (There should not be one yet.) |
565 CHECK(!GetRenderFrameProxyHost(old_render_frame_host->GetSiteInstance())); | 584 CHECK(!GetRenderFrameProxyHost(old_render_frame_host->GetSiteInstance())); |
566 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( | 585 RenderFrameProxyHost* proxy = new RenderFrameProxyHost( |
567 old_render_frame_host->GetSiteInstance(), frame_tree_node_); | 586 old_render_frame_host->GetSiteInstance(), frame_tree_node_); |
568 CHECK(proxy_hosts_.insert(std::make_pair(old_site_instance_id, proxy)).second) | 587 CHECK(proxy_hosts_.insert(std::make_pair(old_site_instance_id, proxy)).second) |
569 << "Inserting a duplicate item."; | 588 << "Inserting a duplicate item."; |
570 | 589 |
571 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. | 590 // Tell the old RenderFrameHost to swap out and be replaced by the proxy. |
572 old_render_frame_host->SwapOut(proxy, true); | 591 old_render_frame_host->SwapOut(proxy, true); |
592 // SwapOut creates a RenderFrameProxy, so set the proxy to be initialized. | |
nasko
2015/02/02 22:47:09
nit: empty line before comment
lazyboy
2015/02/03 00:22:42
Done.
| |
593 proxy->set_render_frame_proxy_created(true); | |
573 | 594 |
574 bool is_main_frame = frame_tree_node_->IsMainFrame(); | 595 bool is_main_frame = frame_tree_node_->IsMainFrame(); |
575 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 596 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
576 switches::kSitePerProcess) && | 597 switches::kSitePerProcess) && |
577 !is_main_frame) { | 598 !is_main_frame) { |
578 // In --site-per-process, subframes delete their RFH rather than storing it | 599 // In --site-per-process, subframes delete their RFH rather than storing it |
579 // in the proxy. Schedule it for deletion once the SwapOutACK comes in. | 600 // in the proxy. Schedule it for deletion once the SwapOutACK comes in. |
580 // TODO(creis): This will be the default when we remove swappedout://. | 601 // TODO(creis): This will be the default when we remove swappedout://. |
581 MoveToPendingDeleteHosts(old_render_frame_host.Pass()); | 602 MoveToPendingDeleteHosts(old_render_frame_host.Pass()); |
582 } else { | 603 } else { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 proxy->PassFrameHostOwnership(); | 825 proxy->PassFrameHostOwnership(); |
805 node->render_manager()->MoveToPendingDeleteHosts(swapped_out_rfh.Pass()); | 826 node->render_manager()->MoveToPendingDeleteHosts(swapped_out_rfh.Pass()); |
806 } | 827 } |
807 delete proxy; | 828 delete proxy; |
808 node->render_manager()->proxy_hosts_.erase(site_instance_id); | 829 node->render_manager()->proxy_hosts_.erase(site_instance_id); |
809 } | 830 } |
810 | 831 |
811 return true; | 832 return true; |
812 } | 833 } |
813 | 834 |
835 // static. | |
836 bool RenderFrameHostManager::ResetProxiesInSiteInstance(int32 site_instance_id, | |
837 FrameTreeNode* node) { | |
838 RenderFrameProxyHostMap::iterator iter = | |
839 node->render_manager()->proxy_hosts_.find(site_instance_id); | |
840 if (iter != node->render_manager()->proxy_hosts_.end()) | |
841 iter->second->set_render_frame_proxy_created(false); | |
842 | |
843 return true; | |
844 } | |
845 | |
814 bool RenderFrameHostManager::ShouldTransitionCrossSite() { | 846 bool RenderFrameHostManager::ShouldTransitionCrossSite() { |
815 // False in the single-process mode, as it makes RVHs to accumulate | 847 // False in the single-process mode, as it makes RVHs to accumulate |
816 // in swapped_out_hosts_. | 848 // in swapped_out_hosts_. |
817 // True if we are using process-per-site-instance (default) or | 849 // True if we are using process-per-site-instance (default) or |
818 // process-per-site (kProcessPerSite). | 850 // process-per-site (kProcessPerSite). |
819 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 851 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
820 switches::kSingleProcess) && | 852 switches::kSingleProcess) && |
821 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 853 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
822 switches::kProcessPerTab); | 854 switches::kProcessPerTab); |
823 } | 855 } |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1371 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | 1403 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); |
1372 if (proxy) | 1404 if (proxy) |
1373 return proxy->GetRoutingID(); | 1405 return proxy->GetRoutingID(); |
1374 | 1406 |
1375 proxy = new RenderFrameProxyHost(instance, frame_tree_node_); | 1407 proxy = new RenderFrameProxyHost(instance, frame_tree_node_); |
1376 proxy_hosts_[instance->GetId()] = proxy; | 1408 proxy_hosts_[instance->GetId()] = proxy; |
1377 proxy->InitRenderFrameProxy(); | 1409 proxy->InitRenderFrameProxy(); |
1378 return proxy->GetRoutingID(); | 1410 return proxy->GetRoutingID(); |
1379 } | 1411 } |
1380 | 1412 |
1413 void RenderFrameHostManager::EnsureRenderViewInitialized( | |
1414 FrameTreeNode* source, | |
1415 RenderViewHostImpl* render_view_host, | |
1416 SiteInstance* instance) { | |
1417 DCHECK(frame_tree_node_->IsMainFrame()); | |
1418 | |
1419 if (render_view_host->IsRenderViewLive()) | |
1420 return; | |
1421 | |
1422 // Recreate the opener chain. | |
1423 int opener_route_id = | |
1424 delegate_->CreateOpenerRenderViewsForRenderManager(instance); | |
1425 RenderFrameProxyHost* proxy = GetRenderFrameProxyHost(instance); | |
1426 InitRenderView(render_view_host, opener_route_id, proxy->GetRoutingID(), | |
1427 source->IsMainFrame()); | |
1428 } | |
1429 | |
1381 bool RenderFrameHostManager::InitRenderView( | 1430 bool RenderFrameHostManager::InitRenderView( |
1382 RenderViewHostImpl* render_view_host, | 1431 RenderViewHostImpl* render_view_host, |
1383 int opener_route_id, | 1432 int opener_route_id, |
1384 int proxy_routing_id, | 1433 int proxy_routing_id, |
1385 bool for_main_frame_navigation) { | 1434 bool for_main_frame_navigation) { |
1386 // We may have initialized this RenderViewHost for another RenderFrameHost. | 1435 // We may have initialized this RenderViewHost for another RenderFrameHost. |
1387 if (render_view_host->IsRenderViewLive()) | 1436 if (render_view_host->IsRenderViewLive()) |
1388 return true; | 1437 return true; |
1389 | 1438 |
1390 // If the ongoing navigation is to a WebUI and the RenderView is not in a | 1439 // If the ongoing navigation is to a WebUI and the RenderView is not in a |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1432 // the proxy it is replacing, so that it can fully initialize itself. | 1481 // the proxy it is replacing, so that it can fully initialize itself. |
1433 // NOTE: This is the only time that a RenderFrameProxyHost can be in the same | 1482 // NOTE: This is the only time that a RenderFrameProxyHost can be in the same |
1434 // SiteInstance as its RenderFrameHost. This is only the case until the | 1483 // SiteInstance as its RenderFrameHost. This is only the case until the |
1435 // RenderFrameHost commits, at which point it will replace and delete the | 1484 // RenderFrameHost commits, at which point it will replace and delete the |
1436 // RenderFrameProxyHost. | 1485 // RenderFrameProxyHost. |
1437 RenderFrameProxyHost* existing_proxy = | 1486 RenderFrameProxyHost* existing_proxy = |
1438 GetRenderFrameProxyHost(render_frame_host->GetSiteInstance()); | 1487 GetRenderFrameProxyHost(render_frame_host->GetSiteInstance()); |
1439 if (existing_proxy) { | 1488 if (existing_proxy) { |
1440 proxy_routing_id = existing_proxy->GetRoutingID(); | 1489 proxy_routing_id = existing_proxy->GetRoutingID(); |
1441 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE); | 1490 CHECK_NE(proxy_routing_id, MSG_ROUTING_NONE); |
1491 if (!existing_proxy->is_render_frame_proxy_live()) | |
1492 existing_proxy->InitRenderFrameProxy(); | |
1442 } | 1493 } |
1443 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, | 1494 return delegate_->CreateRenderFrameForRenderManager(render_frame_host, |
1444 parent_routing_id, | 1495 parent_routing_id, |
1445 proxy_routing_id); | 1496 proxy_routing_id); |
1446 } | 1497 } |
1447 | 1498 |
1448 int RenderFrameHostManager::GetRoutingIdForSiteInstance( | 1499 int RenderFrameHostManager::GetRoutingIdForSiteInstance( |
1449 SiteInstance* site_instance) { | 1500 SiteInstance* site_instance) { |
1450 if (render_frame_host_->GetSiteInstance() == site_instance) | 1501 if (render_frame_host_->GetSiteInstance() == site_instance) |
1451 return render_frame_host_->GetRoutingID(); | 1502 return render_frame_host_->GetRoutingID(); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1868 void RenderFrameHostManager::DeleteRenderFrameProxyHost( | 1919 void RenderFrameHostManager::DeleteRenderFrameProxyHost( |
1869 SiteInstance* instance) { | 1920 SiteInstance* instance) { |
1870 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); | 1921 RenderFrameProxyHostMap::iterator iter = proxy_hosts_.find(instance->GetId()); |
1871 if (iter != proxy_hosts_.end()) { | 1922 if (iter != proxy_hosts_.end()) { |
1872 delete iter->second; | 1923 delete iter->second; |
1873 proxy_hosts_.erase(iter); | 1924 proxy_hosts_.erase(iter); |
1874 } | 1925 } |
1875 } | 1926 } |
1876 | 1927 |
1877 } // namespace content | 1928 } // namespace content |
OLD | NEW |