| 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 422 } |
| 423 | 423 |
| 424 bool RenderViewHostManager::ShouldSwapProcessesForNavigation( | 424 bool RenderViewHostManager::ShouldSwapProcessesForNavigation( |
| 425 const NavigationEntry* curr_entry, | 425 const NavigationEntry* curr_entry, |
| 426 const NavigationEntryImpl* new_entry) const { | 426 const NavigationEntryImpl* new_entry) const { |
| 427 DCHECK(new_entry); | 427 DCHECK(new_entry); |
| 428 | 428 |
| 429 // Check for reasons to swap processes even if we are in a process model that | 429 // Check for reasons to swap processes even if we are in a process model that |
| 430 // doesn't usually swap (e.g., process-per-tab). | 430 // doesn't usually swap (e.g., process-per-tab). |
| 431 | 431 |
| 432 // For security, we should transition between processes when one is a Web UI | 432 // We use the effective URL here, since that's what is used in the |
| 433 // page and one isn't. If there's no curr_entry, check the current RVH's | 433 // SiteInstance's site and when we later call IsSameWebSite. If there's no |
| 434 // site, which might already be committed to a Web UI URL (such as the NTP). | 434 // curr_entry, check the current SiteInstance's site, which might already be |
| 435 const GURL& current_url = (curr_entry) ? curr_entry->GetURL() : | 435 // committed to a Web UI URL (such as the NTP). |
| 436 render_view_host_->GetSiteInstance()->GetSiteURL(); | |
| 437 BrowserContext* browser_context = | 436 BrowserContext* browser_context = |
| 438 delegate_->GetControllerForRenderManager().GetBrowserContext(); | 437 delegate_->GetControllerForRenderManager().GetBrowserContext(); |
| 438 const GURL& current_url = (curr_entry) ? |
| 439 SiteInstanceImpl::GetEffectiveURL(browser_context, curr_entry->GetURL()) : |
| 440 render_view_host_->GetSiteInstance()->GetSiteURL(); |
| 441 const GURL& new_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
| 442 new_entry->GetURL()); |
| 443 |
| 444 // For security, we should transition between processes when one is a Web UI |
| 445 // page and one isn't. |
| 439 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 446 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
| 440 browser_context, current_url)) { | 447 browser_context, current_url)) { |
| 441 // Force swap if it's not an acceptable URL for Web UI. | 448 // Force swap if it's not an acceptable URL for Web UI. |
| 442 // Here, data URLs are never allowed. | 449 // Here, data URLs are never allowed. |
| 443 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 450 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 444 browser_context, new_entry->GetURL(), false)) { | 451 browser_context, new_url, false)) { |
| 445 return true; | 452 return true; |
| 446 } | 453 } |
| 447 } else { | 454 } else { |
| 448 // Force swap if it's a Web UI URL. | 455 // Force swap if it's a Web UI URL. |
| 449 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 456 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( |
| 450 browser_context, new_entry->GetURL())) { | 457 browser_context, new_url)) { |
| 451 return true; | 458 return true; |
| 452 } | 459 } |
| 453 } | 460 } |
| 454 | 461 |
| 462 // Check with the content client as well. Important to pass current_url here, |
| 463 // which uses the SiteInstance's site if there is no curr_entry. |
| 455 if (GetContentClient()->browser()->ShouldSwapProcessesForNavigation( | 464 if (GetContentClient()->browser()->ShouldSwapProcessesForNavigation( |
| 456 render_view_host_->GetSiteInstance(), | 465 render_view_host_->GetSiteInstance(), current_url, new_url)) { |
| 457 curr_entry ? curr_entry->GetURL() : GURL(), | |
| 458 new_entry->GetURL())) { | |
| 459 return true; | 466 return true; |
| 460 } | 467 } |
| 461 | 468 |
| 462 if (!curr_entry) | 469 if (!curr_entry) |
| 463 return false; | 470 return false; |
| 464 | 471 |
| 465 // We can't switch a RenderView between view source and non-view source mode | 472 // We can't switch a RenderView between view source and non-view source mode |
| 466 // without screwing up the session history sometimes (when navigating between | 473 // without screwing up the session history sometimes (when navigating between |
| 467 // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat | 474 // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat |
| 468 // it as a new navigation). So require a view switch. | 475 // it as a new navigation). So require a view switch. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 return curr_instance->GetRelatedSiteInstance(dest_url); | 648 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 642 } | 649 } |
| 643 } | 650 } |
| 644 | 651 |
| 645 int RenderViewHostManager::CreateRenderView( | 652 int RenderViewHostManager::CreateRenderView( |
| 646 SiteInstance* instance, | 653 SiteInstance* instance, |
| 647 int opener_route_id, | 654 int opener_route_id, |
| 648 bool swapped_out) { | 655 bool swapped_out) { |
| 649 CHECK(instance); | 656 CHECK(instance); |
| 650 | 657 |
| 658 // We are creating a pending or swapped out RVH here. We should never create |
| 659 // it in the same SiteInstance as our current RVH. |
| 660 CHECK_NE(render_view_host_->GetSiteInstance(), instance); |
| 661 |
| 651 // Check if we've already created an RVH for this SiteInstance. If so, try | 662 // Check if we've already created an RVH for this SiteInstance. If so, try |
| 652 // to re-use the existing one, which has already been initialized. We'll | 663 // to re-use the existing one, which has already been initialized. We'll |
| 653 // remove it from the list of swapped out hosts if it commits. | 664 // remove it from the list of swapped out hosts if it commits. |
| 654 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( | 665 RenderViewHostImpl* new_render_view_host = static_cast<RenderViewHostImpl*>( |
| 655 GetSwappedOutRenderViewHost(instance)); | 666 GetSwappedOutRenderViewHost(instance)); |
| 656 if (new_render_view_host) { | 667 if (new_render_view_host) { |
| 657 // Prevent the process from exiting while we're trying to use it. | 668 // Prevent the process from exiting while we're trying to use it. |
| 658 if (!swapped_out) | 669 if (!swapped_out) |
| 659 new_render_view_host->GetProcess()->AddPendingView(); | 670 new_render_view_host->GetProcess()->AddPendingView(); |
| 660 } else { | 671 } else { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( | 1019 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
| 1009 SiteInstance* instance) { | 1020 SiteInstance* instance) { |
| 1010 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 1021 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
| 1011 if (iter != swapped_out_hosts_.end()) | 1022 if (iter != swapped_out_hosts_.end()) |
| 1012 return iter->second; | 1023 return iter->second; |
| 1013 | 1024 |
| 1014 return NULL; | 1025 return NULL; |
| 1015 } | 1026 } |
| 1016 | 1027 |
| 1017 } // namespace content | 1028 } // namespace content |
| OLD | NEW |