| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/render_view_host_manager.h" | 5 #include "content/browser/tab_contents/render_view_host_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 386 } |
| 387 | 387 |
| 388 return false; | 388 return false; |
| 389 } | 389 } |
| 390 | 390 |
| 391 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( | 391 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( |
| 392 const NavigationEntry& entry, | 392 const NavigationEntry& entry, |
| 393 SiteInstance* curr_instance) { | 393 SiteInstance* curr_instance) { |
| 394 // NOTE: This is only called when ShouldTransitionCrossSite is true. | 394 // NOTE: This is only called when ShouldTransitionCrossSite is true. |
| 395 | 395 |
| 396 // If the entry has an instance already, we should use it. | 396 const GURL& dest_url = entry.url(); |
| 397 if (entry.site_instance()) | 397 NavigationController& controller = delegate_->GetControllerForRenderManager(); |
| 398 return entry.site_instance(); | 398 Profile* profile = controller.profile(); |
| 399 |
| 400 // If the entry has an instance already we should use it, unless the URL |
| 401 // is part of an app that has been installed or uninstalled since the last |
| 402 // visit. |
| 403 if (entry.site_instance()) { |
| 404 if (entry.site_instance()->HasWrongProcessForURL(dest_url)) |
| 405 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 406 else |
| 407 return entry.site_instance(); |
| 408 } |
| 399 | 409 |
| 400 // (UGLY) HEURISTIC, process-per-site only: | 410 // (UGLY) HEURISTIC, process-per-site only: |
| 401 // | 411 // |
| 402 // If this navigation is generated, then it probably corresponds to a search | 412 // If this navigation is generated, then it probably corresponds to a search |
| 403 // query. Given that search results typically lead to users navigating to | 413 // query. Given that search results typically lead to users navigating to |
| 404 // other sites, we don't really want to use the search engine hostname to | 414 // other sites, we don't really want to use the search engine hostname to |
| 405 // determine the site instance for this navigation. | 415 // determine the site instance for this navigation. |
| 406 // | 416 // |
| 407 // NOTE: This can be removed once we have a way to transition between | 417 // NOTE: This can be removed once we have a way to transition between |
| 408 // RenderViews in response to a link click. | 418 // RenderViews in response to a link click. |
| 409 // | 419 // |
| 410 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerSite) && | 420 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessPerSite) && |
| 411 entry.transition_type() == PageTransition::GENERATED) | 421 entry.transition_type() == PageTransition::GENERATED) |
| 412 return curr_instance; | 422 return curr_instance; |
| 413 | 423 |
| 414 const GURL& dest_url = entry.url(); | |
| 415 NavigationController& controller = delegate_->GetControllerForRenderManager(); | |
| 416 Profile* profile = controller.profile(); | |
| 417 | |
| 418 // If we haven't used our SiteInstance (and thus RVH) yet, then we can use it | 424 // If we haven't used our SiteInstance (and thus RVH) yet, then we can use it |
| 419 // for this entry. We won't commit the SiteInstance to this site until the | 425 // for this entry. We won't commit the SiteInstance to this site until the |
| 420 // navigation commits (in DidNavigate), unless the navigation entry was | 426 // navigation commits (in DidNavigate), unless the navigation entry was |
| 421 // restored or it's a Web UI as described below. | 427 // restored or it's a Web UI as described below. |
| 422 if (!curr_instance->has_site()) { | 428 if (!curr_instance->has_site()) { |
| 423 // If we've already created a SiteInstance for our destination, we don't | 429 // If we've already created a SiteInstance for our destination, we don't |
| 424 // want to use this unused SiteInstance; use the existing one. (We don't | 430 // want to use this unused SiteInstance; use the existing one. (We don't |
| 425 // do this check if the curr_instance has a site, because for now, we want | 431 // do this check if the curr_instance has a site, because for now, we want |
| 426 // to compare against the current URL and not the SiteInstance's site. In | 432 // to compare against the current URL and not the SiteInstance's site. In |
| 427 // this case, there is no current URL, so comparing against the site is ok. | 433 // this case, there is no current URL, so comparing against the site is ok. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // get to it directly. The best we can do is check against the site of | 479 // get to it directly. The best we can do is check against the site of |
| 474 // the SiteInstance. This will be correct when we intercept links and | 480 // the SiteInstance. This will be correct when we intercept links and |
| 475 // script-based navigations, but for now, it could place some pages in a | 481 // script-based navigations, but for now, it could place some pages in a |
| 476 // new process unnecessarily. We should only hit this case if a page tries | 482 // new process unnecessarily. We should only hit this case if a page tries |
| 477 // to open a new tab to an interstitial-inducing URL, and then navigates | 483 // to open a new tab to an interstitial-inducing URL, and then navigates |
| 478 // the page to a different same-site URL. (This seems very unlikely in | 484 // the page to a different same-site URL. (This seems very unlikely in |
| 479 // practice.) | 485 // practice.) |
| 480 const GURL& current_url = (curr_entry) ? curr_entry->url() : | 486 const GURL& current_url = (curr_entry) ? curr_entry->url() : |
| 481 curr_instance->site(); | 487 curr_instance->site(); |
| 482 | 488 |
| 483 if (SiteInstance::IsSameWebSite(profile, current_url, dest_url)) { | 489 // Use the current SiteInstance for same site navigations, as long as the |
| 490 // process type is correct. (The URL may have been installed as an app since |
| 491 // the last time we visited it.) |
| 492 if (SiteInstance::IsSameWebSite(profile, current_url, dest_url) && |
| 493 !curr_instance->HasWrongProcessForURL(dest_url)) { |
| 484 return curr_instance; | 494 return curr_instance; |
| 485 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { | 495 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { |
| 486 // When we're swapping, we need to force the site instance AND browsing | 496 // When we're swapping, we need to force the site instance AND browsing |
| 487 // instance to be different ones. This addresses special cases where we use | 497 // instance to be different ones. This addresses special cases where we use |
| 488 // a single BrowsingInstance for all pages of a certain type (e.g., New Tab | 498 // a single BrowsingInstance for all pages of a certain type (e.g., New Tab |
| 489 // Pages), keeping them in the same process. When you navigate away from | 499 // Pages), keeping them in the same process. When you navigate away from |
| 490 // that page, we want to explicity ignore that BrowsingInstance and group | 500 // that page, we want to explicity ignore that BrowsingInstance and group |
| 491 // this page into the appropriate SiteInstance for its URL. | 501 // this page into the appropriate SiteInstance for its URL. |
| 492 return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); | 502 return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); |
| 493 } else { | 503 } else { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 delegate_->NotifySwappedFromRenderManager(); | 866 delegate_->NotifySwappedFromRenderManager(); |
| 857 } | 867 } |
| 858 | 868 |
| 859 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 869 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
| 860 if (!rvh->site_instance()) | 870 if (!rvh->site_instance()) |
| 861 return false; | 871 return false; |
| 862 | 872 |
| 863 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 873 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
| 864 swapped_out_hosts_.end(); | 874 swapped_out_hosts_.end(); |
| 865 } | 875 } |
| OLD | NEW |