Chromium Code Reviews| 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/render_view_host_manager.h" | 5 #include "content/browser/web_contents/render_view_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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 // A navigation in the original page has taken place. Cancel the pending | 232 // A navigation in the original page has taken place. Cancel the pending |
| 233 // one. | 233 // one. |
| 234 CancelPending(); | 234 CancelPending(); |
| 235 cross_navigation_pending_ = false; | 235 cross_navigation_pending_ = false; |
| 236 } else { | 236 } else { |
| 237 // No one else should be sending us DidNavigate in this state. | 237 // No one else should be sending us DidNavigate in this state. |
| 238 DCHECK(false); | 238 DCHECK(false); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 void RenderViewHostManager::DidUpdateFrameTree( | |
| 243 RenderViewHost* render_view_host) { | |
| 244 DCHECK_EQ(render_view_host, current_host()); | |
|
Charlie Reis
2012/08/22 22:08:34
Are there any races that could cause this to be ca
nasko
2012/08/23 21:55:53
Based on the cross-site transition timeline, it sh
| |
| 245 | |
| 246 RenderViewHostImpl* render_view_host_impl = static_cast<RenderViewHostImpl*>( | |
| 247 render_view_host); | |
| 248 | |
| 249 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | |
| 250 iter != swapped_out_hosts_.end(); | |
| 251 ++iter) { | |
| 252 DCHECK_NE(iter->second->GetSiteInstance(), | |
| 253 current_host()->GetSiteInstance()); | |
| 254 | |
| 255 iter->second->UpdateFrameTree( | |
| 256 render_view_host_impl->GetProcess()->GetID(), | |
|
Charlie Reis
2012/08/22 22:08:34
Interesting... I wonder what happens if one of th
nasko
2012/08/23 21:55:53
GetProcess() returns the RenderProcessHost, which
Charlie Reis
2012/08/24 23:26:07
Ah, right you are! I was thinking of SiteInstance
| |
| 257 render_view_host_impl->GetRoutingID(), | |
| 258 render_view_host_impl->frame_tree()); | |
| 259 } | |
| 260 } | |
| 261 | |
| 242 void RenderViewHostManager::SetWebUIPostCommit(WebUIImpl* web_ui) { | 262 void RenderViewHostManager::SetWebUIPostCommit(WebUIImpl* web_ui) { |
| 243 DCHECK(!web_ui_.get()); | 263 DCHECK(!web_ui_.get()); |
| 244 web_ui_.reset(web_ui); | 264 web_ui_.reset(web_ui); |
| 245 } | 265 } |
| 246 | 266 |
| 247 void RenderViewHostManager::RendererAbortedProvisionalLoad( | 267 void RenderViewHostManager::RendererAbortedProvisionalLoad( |
| 248 RenderViewHost* render_view_host) { | 268 RenderViewHost* render_view_host) { |
| 249 // We used to cancel the pending renderer here for cross-site downloads. | 269 // We used to cancel the pending renderer here for cross-site downloads. |
| 250 // However, it's not safe to do that because the download logic repeatedly | 270 // However, it's not safe to do that because the download logic repeatedly |
| 251 // looks for this WebContents based on a render view ID. Instead, we just | 271 // looks for this WebContents based on a render view ID. Instead, we just |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 if (curr_site_instance->HasWrongProcessForURL(dest_url)) | 508 if (curr_site_instance->HasWrongProcessForURL(dest_url)) |
| 489 return curr_site_instance->GetRelatedSiteInstance(dest_url); | 509 return curr_site_instance->GetRelatedSiteInstance(dest_url); |
| 490 | 510 |
| 491 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 511 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
| 492 // TODO(nasko): This is the same condition as later in the function. This | 512 // TODO(nasko): This is the same condition as later in the function. This |
| 493 // should be taken into account when refactoring this method as part of | 513 // should be taken into account when refactoring this method as part of |
| 494 // http://crbug.com/123007. | 514 // http://crbug.com/123007. |
| 495 if (entry.IsViewSourceMode()) | 515 if (entry.IsViewSourceMode()) |
| 496 return SiteInstance::CreateForURL(browser_context, dest_url); | 516 return SiteInstance::CreateForURL(browser_context, dest_url); |
| 497 | 517 |
| 518 // If we are navigating from a blank SiteInstance to a WebUI, make sure we | |
| 519 // create a new SiteInstance. | |
|
Charlie Reis
2012/08/22 22:08:34
Wait, shouldn't HasWrongProcessForURL have caught
nasko
2012/08/23 21:55:53
The first thing HasWrongProcessForURL checks is wh
Charlie Reis
2012/08/24 23:26:07
:(
Good catch. This is fine, then, and I'll clea
| |
| 520 const WebUIControllerFactory* web_ui_factory = | |
| 521 content::GetContentClient()->browser()->GetWebUIControllerFactory(); | |
| 522 if (web_ui_factory && | |
| 523 web_ui_factory->UseWebUIForURL(browser_context, dest_url)) { | |
| 524 return SiteInstance::CreateForURL(browser_context, dest_url); | |
| 525 } | |
| 526 | |
| 498 // Normally the "site" on the SiteInstance is set lazily when the load | 527 // Normally the "site" on the SiteInstance is set lazily when the load |
| 499 // actually commits. This is to support better process sharing in case | 528 // actually commits. This is to support better process sharing in case |
| 500 // the site redirects to some other site: we want to use the destination | 529 // the site redirects to some other site: we want to use the destination |
| 501 // site in the site instance. | 530 // site in the site instance. |
| 502 // | 531 // |
| 503 // In the case of session restore, as it loads all the pages immediately | 532 // In the case of session restore, as it loads all the pages immediately |
| 504 // we need to set the site first, otherwise after a restore none of the | 533 // we need to set the site first, otherwise after a restore none of the |
| 505 // pages would share renderers in process-per-site. | 534 // pages would share renderers in process-per-site. |
| 506 if (entry.restore_type() != NavigationEntryImpl::RESTORE_NONE) | 535 if (entry.restore_type() != NavigationEntryImpl::RESTORE_NONE) |
| 507 curr_site_instance->SetSite(dest_url); | 536 curr_site_instance->SetSite(dest_url); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 return curr_instance->GetRelatedSiteInstance(dest_url); | 599 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 571 } | 600 } |
| 572 } | 601 } |
| 573 | 602 |
| 574 int RenderViewHostManager::CreateRenderView( | 603 int RenderViewHostManager::CreateRenderView( |
| 575 SiteInstance* instance, | 604 SiteInstance* instance, |
| 576 int opener_route_id, | 605 int opener_route_id, |
| 577 bool swapped_out) { | 606 bool swapped_out) { |
| 578 CHECK(instance); | 607 CHECK(instance); |
| 579 | 608 |
| 609 // If the current host is already in the site instance we are looking for | |
|
Charlie Reis
2012/08/22 22:08:34
nit: site instance -> SiteInstance
nasko
2012/08/23 21:55:53
Done.
| |
| 610 // and we are creating a swapped out renderer, just return the routing id. | |
| 611 if (current_host()->GetSiteInstance() == instance) { | |
| 612 // TODO(nasko): Convert this if statement to a DCHECK once all causes | |
| 613 // of creating a new non-swapped out RVH for the same SiteInstance as the | |
| 614 // active one are tracked down and resolved. | |
|
Charlie Reis
2012/08/22 22:08:34
Nice. Please mention http://crbug.com/123007 here
nasko
2012/08/23 21:55:53
Done.
| |
| 615 if (swapped_out) | |
|
Charlie Reis
2012/08/22 22:08:34
This is actually a little confusing. The caller i
nasko
2012/08/23 21:55:53
Yes, changing the caller makes a bit more sense. I
Charlie Reis
2012/08/24 23:26:07
Great. Please CC me on the bug.
| |
| 616 return current_host()->GetRoutingID(); | |
| 617 } | |
| 618 | |
| 580 // Check if we've already created an RVH for this SiteInstance. If so, try | 619 // Check if we've already created an RVH for this SiteInstance. If so, try |
| 581 // to re-use the existing one, which has already been initialized. We'll | 620 // to re-use the existing one, which has already been initialized. We'll |
| 582 // remove it from the list of swapped out hosts if it commits. | 621 // remove it from the list of swapped out hosts if it commits. |
| 583 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( | 622 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( |
| 584 GetSwappedOutRenderViewHost(instance)); | 623 GetSwappedOutRenderViewHost(instance)); |
| 585 if (new_render_view_host) { | 624 if (new_render_view_host) { |
| 586 // Prevent the process from exiting while we're trying to use it. | 625 // Prevent the process from exiting while we're trying to use it. |
| 587 if (!swapped_out) | 626 if (!swapped_out) |
| 588 new_render_view_host->GetProcess()->AddPendingView(); | 627 new_render_view_host->GetProcess()->AddPendingView(); |
| 589 } else { | 628 } else { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 600 if (swapped_out) { | 639 if (swapped_out) { |
| 601 swapped_out_hosts_[instance->GetId()] = new_render_view_host; | 640 swapped_out_hosts_[instance->GetId()] = new_render_view_host; |
| 602 } else { | 641 } else { |
| 603 new_render_view_host->GetProcess()->AddPendingView(); | 642 new_render_view_host->GetProcess()->AddPendingView(); |
| 604 } | 643 } |
| 605 | 644 |
| 606 bool success = InitRenderView(new_render_view_host, opener_route_id); | 645 bool success = InitRenderView(new_render_view_host, opener_route_id); |
| 607 if (success) { | 646 if (success) { |
| 608 // Don't show the view until we get a DidNavigate from it. | 647 // Don't show the view until we get a DidNavigate from it. |
| 609 new_render_view_host->GetView()->Hide(); | 648 new_render_view_host->GetView()->Hide(); |
| 649 | |
| 650 // If we are creating a swapped out RVH, send a message to update the | |
|
Charlie Reis
2012/08/22 22:08:34
nit: the -> its
nasko
2012/08/23 21:55:53
Done.
| |
| 651 // frame tree based on the active RVH for this RenderViewHostManager. | |
| 652 if (swapped_out) { | |
| 653 new_render_view_host->UpdateFrameTree( | |
| 654 current_host()->GetProcess()->GetID(), | |
| 655 current_host()->GetRoutingID(), | |
| 656 current_host()->frame_tree()); | |
| 657 } | |
| 610 } else if (!swapped_out) { | 658 } else if (!swapped_out) { |
| 611 CancelPending(); | 659 CancelPending(); |
| 612 } | 660 } |
| 613 } | 661 } |
| 614 | 662 |
| 615 // Use this as our new pending RVH if it isn't swapped out. | 663 // Use this as our new pending RVH if it isn't swapped out. |
| 616 if (!swapped_out) | 664 if (!swapped_out) |
| 617 pending_render_view_host_ = new_render_view_host; | 665 pending_render_view_host_ = new_render_view_host; |
| 618 | 666 |
| 619 return new_render_view_host->GetRoutingID(); | 667 return new_render_view_host->GetRoutingID(); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 } | 961 } |
| 914 | 962 |
| 915 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 963 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
| 916 if (!rvh->GetSiteInstance()) | 964 if (!rvh->GetSiteInstance()) |
| 917 return false; | 965 return false; |
| 918 | 966 |
| 919 return swapped_out_hosts_.find(rvh->GetSiteInstance()->GetId()) != | 967 return swapped_out_hosts_.find(rvh->GetSiteInstance()->GetId()) != |
| 920 swapped_out_hosts_.end(); | 968 swapped_out_hosts_.end(); |
| 921 } | 969 } |
| 922 | 970 |
| 923 RenderViewHost* RenderViewHostManager::GetSwappedOutRenderViewHost( | 971 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
| 924 SiteInstance* instance) { | 972 SiteInstance* instance) { |
| 925 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 973 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
| 926 if (iter != swapped_out_hosts_.end()) | 974 if (iter != swapped_out_hosts_.end()) |
| 927 return iter->second; | 975 return iter->second; |
| 928 | 976 |
| 929 return NULL; | 977 return NULL; |
| 930 } | 978 } |
| OLD | NEW |