| 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 "content/browser/content_browser_client.h" | 9 #include "content/browser/content_browser_client.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 render_view_host->Shutdown(); | 49 render_view_host->Shutdown(); |
| 50 | 50 |
| 51 // Shut down any swapped out RenderViewHosts. | 51 // Shut down any swapped out RenderViewHosts. |
| 52 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); | 52 for (RenderViewHostMap::iterator iter = swapped_out_hosts_.begin(); |
| 53 iter != swapped_out_hosts_.end(); | 53 iter != swapped_out_hosts_.end(); |
| 54 ++iter) { | 54 ++iter) { |
| 55 iter->second->Shutdown(); | 55 iter->second->Shutdown(); |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 void RenderViewHostManager::Init(Profile* profile, | 59 void RenderViewHostManager::Init(content::BrowserContext* browser_context, |
| 60 SiteInstance* site_instance, | 60 SiteInstance* site_instance, |
| 61 int routing_id) { | 61 int routing_id) { |
| 62 // Create a RenderViewHost, once we have an instance. It is important to | 62 // Create a RenderViewHost, once we have an instance. It is important to |
| 63 // immediately give this SiteInstance to a RenderViewHost so that it is | 63 // immediately give this SiteInstance to a RenderViewHost so that it is |
| 64 // ref counted. | 64 // ref counted. |
| 65 if (!site_instance) | 65 if (!site_instance) |
| 66 site_instance = SiteInstance::CreateSiteInstance(profile); | 66 site_instance = SiteInstance::CreateSiteInstance(browser_context); |
| 67 render_view_host_ = RenderViewHostFactory::Create( | 67 render_view_host_ = RenderViewHostFactory::Create( |
| 68 site_instance, render_view_delegate_, routing_id, delegate_-> | 68 site_instance, render_view_delegate_, routing_id, delegate_-> |
| 69 GetControllerForRenderManager().session_storage_namespace()); | 69 GetControllerForRenderManager().session_storage_namespace()); |
| 70 | 70 |
| 71 // Keep track of renderer processes as they start to shut down. | 71 // Keep track of renderer processes as they start to shut down. |
| 72 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSING, | 72 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSING, |
| 73 NotificationService::AllSources()); | 73 NotificationService::AllSources()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 RenderWidgetHostView* RenderViewHostManager::GetRenderWidgetHostView() const { | 76 RenderWidgetHostView* RenderViewHostManager::GetRenderWidgetHostView() const { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 DCHECK(new_entry); | 339 DCHECK(new_entry); |
| 340 | 340 |
| 341 // Check for reasons to swap processes even if we are in a process model that | 341 // Check for reasons to swap processes even if we are in a process model that |
| 342 // doesn't usually swap (e.g., process-per-tab). | 342 // doesn't usually swap (e.g., process-per-tab). |
| 343 | 343 |
| 344 // For security, we should transition between processes when one is a Web UI | 344 // For security, we should transition between processes when one is a Web UI |
| 345 // page and one isn't. If there's no cur_entry, check the current RVH's | 345 // page and one isn't. If there's no cur_entry, check the current RVH's |
| 346 // site, which might already be committed to a Web UI URL (such as the NTP). | 346 // site, which might already be committed to a Web UI URL (such as the NTP). |
| 347 const GURL& current_url = (cur_entry) ? cur_entry->url() : | 347 const GURL& current_url = (cur_entry) ? cur_entry->url() : |
| 348 render_view_host_->site_instance()->site(); | 348 render_view_host_->site_instance()->site(); |
| 349 Profile* profile = delegate_->GetControllerForRenderManager().profile(); | 349 content::BrowserContext* browser_context = |
| 350 delegate_->GetControllerForRenderManager().browser_context(); |
| 350 const content::WebUIFactory* web_ui_factory = content::WebUIFactory::Get(); | 351 const content::WebUIFactory* web_ui_factory = content::WebUIFactory::Get(); |
| 351 if (web_ui_factory->UseWebUIForURL(profile, current_url)) { | 352 if (web_ui_factory->UseWebUIForURL(browser_context, current_url)) { |
| 352 // Force swap if it's not an acceptable URL for Web UI. | 353 // Force swap if it's not an acceptable URL for Web UI. |
| 353 if (!web_ui_factory->IsURLAcceptableForWebUI(profile, new_entry->url())) | 354 if (!web_ui_factory->IsURLAcceptableForWebUI(browser_context, |
| 355 new_entry->url())) |
| 354 return true; | 356 return true; |
| 355 } else { | 357 } else { |
| 356 // Force swap if it's a Web UI URL. | 358 // Force swap if it's a Web UI URL. |
| 357 if (web_ui_factory->UseWebUIForURL(profile, new_entry->url())) | 359 if (web_ui_factory->UseWebUIForURL(browser_context, new_entry->url())) |
| 358 return true; | 360 return true; |
| 359 } | 361 } |
| 360 | 362 |
| 361 if (!cur_entry) { | 363 if (!cur_entry) { |
| 362 // Always choose a new process when navigating to extension URLs. The | 364 // Always choose a new process when navigating to extension URLs. The |
| 363 // process grouping logic will combine all of a given extension's pages | 365 // process grouping logic will combine all of a given extension's pages |
| 364 // into the same process. | 366 // into the same process. |
| 365 if (new_entry->url().SchemeIs(chrome::kExtensionScheme)) | 367 if (new_entry->url().SchemeIs(chrome::kExtensionScheme)) |
| 366 return true; | 368 return true; |
| 367 | 369 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 386 return false; | 388 return false; |
| 387 } | 389 } |
| 388 | 390 |
| 389 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( | 391 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( |
| 390 const NavigationEntry& entry, | 392 const NavigationEntry& entry, |
| 391 SiteInstance* curr_instance) { | 393 SiteInstance* curr_instance) { |
| 392 // NOTE: This is only called when ShouldTransitionCrossSite is true. | 394 // NOTE: This is only called when ShouldTransitionCrossSite is true. |
| 393 | 395 |
| 394 const GURL& dest_url = entry.url(); | 396 const GURL& dest_url = entry.url(); |
| 395 NavigationController& controller = delegate_->GetControllerForRenderManager(); | 397 NavigationController& controller = delegate_->GetControllerForRenderManager(); |
| 396 Profile* profile = controller.profile(); | 398 content::BrowserContext* browser_context = controller.browser_context(); |
| 397 | 399 |
| 398 // If the entry has an instance already we should use it, unless the URL | 400 // If the entry has an instance already we should use it, unless the URL |
| 399 // is part of an app that has been installed or uninstalled since the last | 401 // is part of an app that has been installed or uninstalled since the last |
| 400 // visit. | 402 // visit. |
| 401 if (entry.site_instance()) { | 403 if (entry.site_instance()) { |
| 402 if (entry.site_instance()->HasWrongProcessForURL(dest_url)) | 404 if (entry.site_instance()->HasWrongProcessForURL(dest_url)) |
| 403 return curr_instance->GetRelatedSiteInstance(dest_url); | 405 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 404 else | 406 else |
| 405 return entry.site_instance(); | 407 return entry.site_instance(); |
| 406 } | 408 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 430 // 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 |
| 431 // 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. |
| 432 // See additional comments below.) | 434 // See additional comments below.) |
| 433 if (curr_instance->HasRelatedSiteInstance(dest_url)) | 435 if (curr_instance->HasRelatedSiteInstance(dest_url)) |
| 434 return curr_instance->GetRelatedSiteInstance(dest_url); | 436 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 435 | 437 |
| 436 // For extensions and Web UI URLs (such as the new tab page), we do not | 438 // For extensions and Web UI URLs (such as the new tab page), we do not |
| 437 // want to use the curr_instance if it has no site, since it will have a | 439 // want to use the curr_instance if it has no site, since it will have a |
| 438 // RenderProcessHost of TYPE_NORMAL. Create a new SiteInstance for this | 440 // RenderProcessHost of TYPE_NORMAL. Create a new SiteInstance for this |
| 439 // URL instead (with the correct process type). | 441 // URL instead (with the correct process type). |
| 440 if (content::WebUIFactory::Get()->UseWebUIForURL(profile, dest_url)) { | 442 if (content::WebUIFactory::Get()->UseWebUIForURL(browser_context, |
| 441 return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); | 443 dest_url)) { |
| 444 return SiteInstance::CreateSiteInstanceForURL(browser_context, dest_url); |
| 442 } | 445 } |
| 443 | 446 |
| 444 // Normally the "site" on the SiteInstance is set lazily when the load | 447 // Normally the "site" on the SiteInstance is set lazily when the load |
| 445 // actually commits. This is to support better process sharing in case | 448 // actually commits. This is to support better process sharing in case |
| 446 // the site redirects to some other site: we want to use the destination | 449 // the site redirects to some other site: we want to use the destination |
| 447 // site in the site instance. | 450 // site in the site instance. |
| 448 // | 451 // |
| 449 // In the case of session restore, as it loads all the pages immediately | 452 // In the case of session restore, as it loads all the pages immediately |
| 450 // we need to set the site first, otherwise after a restore none of the | 453 // we need to set the site first, otherwise after a restore none of the |
| 451 // pages would share renderers in process-per-site. | 454 // pages would share renderers in process-per-site. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 480 // new process unnecessarily. We should only hit this case if a page tries | 483 // new process unnecessarily. We should only hit this case if a page tries |
| 481 // to open a new tab to an interstitial-inducing URL, and then navigates | 484 // to open a new tab to an interstitial-inducing URL, and then navigates |
| 482 // the page to a different same-site URL. (This seems very unlikely in | 485 // the page to a different same-site URL. (This seems very unlikely in |
| 483 // practice.) | 486 // practice.) |
| 484 const GURL& current_url = (curr_entry) ? curr_entry->url() : | 487 const GURL& current_url = (curr_entry) ? curr_entry->url() : |
| 485 curr_instance->site(); | 488 curr_instance->site(); |
| 486 | 489 |
| 487 // Use the current SiteInstance for same site navigations, as long as the | 490 // Use the current SiteInstance for same site navigations, as long as the |
| 488 // process type is correct. (The URL may have been installed as an app since | 491 // process type is correct. (The URL may have been installed as an app since |
| 489 // the last time we visited it.) | 492 // the last time we visited it.) |
| 490 if (SiteInstance::IsSameWebSite(profile, current_url, dest_url) && | 493 if (SiteInstance::IsSameWebSite(browser_context, current_url, dest_url) && |
| 491 !curr_instance->HasWrongProcessForURL(dest_url)) { | 494 !curr_instance->HasWrongProcessForURL(dest_url)) { |
| 492 return curr_instance; | 495 return curr_instance; |
| 493 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { | 496 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { |
| 494 // When we're swapping, we need to force the site instance AND browsing | 497 // When we're swapping, we need to force the site instance AND browsing |
| 495 // instance to be different ones. This addresses special cases where we use | 498 // instance to be different ones. This addresses special cases where we use |
| 496 // a single BrowsingInstance for all pages of a certain type (e.g., New Tab | 499 // a single BrowsingInstance for all pages of a certain type (e.g., New Tab |
| 497 // Pages), keeping them in the same process. When you navigate away from | 500 // Pages), keeping them in the same process. When you navigate away from |
| 498 // that page, we want to explicity ignore that BrowsingInstance and group | 501 // that page, we want to explicity ignore that BrowsingInstance and group |
| 499 // this page into the appropriate SiteInstance for its URL. | 502 // this page into the appropriate SiteInstance for its URL. |
| 500 return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); | 503 return SiteInstance::CreateSiteInstanceForURL(browser_context, dest_url); |
| 501 } else { | 504 } else { |
| 502 // Start the new renderer in a new SiteInstance, but in the current | 505 // Start the new renderer in a new SiteInstance, but in the current |
| 503 // BrowsingInstance. It is important to immediately give this new | 506 // BrowsingInstance. It is important to immediately give this new |
| 504 // SiteInstance to a RenderViewHost (if it is different than our current | 507 // SiteInstance to a RenderViewHost (if it is different than our current |
| 505 // SiteInstance), so that it is ref counted. This will happen in | 508 // SiteInstance), so that it is ref counted. This will happen in |
| 506 // CreatePendingRenderView. | 509 // CreatePendingRenderView. |
| 507 return curr_instance->GetRelatedSiteInstance(dest_url); | 510 return curr_instance->GetRelatedSiteInstance(dest_url); |
| 508 } | 511 } |
| 509 } | 512 } |
| 510 | 513 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 delegate_->NotifySwappedFromRenderManager(); | 866 delegate_->NotifySwappedFromRenderManager(); |
| 864 } | 867 } |
| 865 | 868 |
| 866 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 869 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
| 867 if (!rvh->site_instance()) | 870 if (!rvh->site_instance()) |
| 868 return false; | 871 return false; |
| 869 | 872 |
| 870 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 873 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
| 871 swapped_out_hosts_.end(); | 874 swapped_out_hosts_.end(); |
| 872 } | 875 } |
| OLD | NEW |