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* 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(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* context = |
| 350 delegate_->GetControllerForRenderManager().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(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(context, new_entry->url())) |
354 return true; | 355 return true; |
355 } else { | 356 } else { |
356 // Force swap if it's a Web UI URL. | 357 // Force swap if it's a Web UI URL. |
357 if (web_ui_factory->UseWebUIForURL(profile, new_entry->url())) | 358 if (web_ui_factory->UseWebUIForURL(context, new_entry->url())) |
358 return true; | 359 return true; |
359 } | 360 } |
360 | 361 |
361 if (!cur_entry) { | 362 if (!cur_entry) { |
362 // Always choose a new process when navigating to extension URLs. The | 363 // Always choose a new process when navigating to extension URLs. The |
363 // process grouping logic will combine all of a given extension's pages | 364 // process grouping logic will combine all of a given extension's pages |
364 // into the same process. | 365 // into the same process. |
365 if (new_entry->url().SchemeIs(chrome::kExtensionScheme)) | 366 if (new_entry->url().SchemeIs(chrome::kExtensionScheme)) |
366 return true; | 367 return true; |
367 | 368 |
(...skipping 18 matching lines...) Expand all Loading... |
386 return false; | 387 return false; |
387 } | 388 } |
388 | 389 |
389 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( | 390 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( |
390 const NavigationEntry& entry, | 391 const NavigationEntry& entry, |
391 SiteInstance* curr_instance) { | 392 SiteInstance* curr_instance) { |
392 // NOTE: This is only called when ShouldTransitionCrossSite is true. | 393 // NOTE: This is only called when ShouldTransitionCrossSite is true. |
393 | 394 |
394 const GURL& dest_url = entry.url(); | 395 const GURL& dest_url = entry.url(); |
395 NavigationController& controller = delegate_->GetControllerForRenderManager(); | 396 NavigationController& controller = delegate_->GetControllerForRenderManager(); |
396 Profile* profile = controller.profile(); | 397 content::BrowserContext* context = controller.context(); |
397 | 398 |
398 // If the entry has an instance already we should use it, unless the URL | 399 // 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 | 400 // is part of an app that has been installed or uninstalled since the last |
400 // visit. | 401 // visit. |
401 if (entry.site_instance()) { | 402 if (entry.site_instance()) { |
402 if (entry.site_instance()->HasWrongProcessForURL(dest_url)) | 403 if (entry.site_instance()->HasWrongProcessForURL(dest_url)) |
403 return curr_instance->GetRelatedSiteInstance(dest_url); | 404 return curr_instance->GetRelatedSiteInstance(dest_url); |
404 else | 405 else |
405 return entry.site_instance(); | 406 return entry.site_instance(); |
406 } | 407 } |
(...skipping 23 matching lines...) Expand all Loading... |
430 // to compare against the current URL and not the SiteInstance's site. In | 431 // 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. | 432 // this case, there is no current URL, so comparing against the site is ok. |
432 // See additional comments below.) | 433 // See additional comments below.) |
433 if (curr_instance->HasRelatedSiteInstance(dest_url)) | 434 if (curr_instance->HasRelatedSiteInstance(dest_url)) |
434 return curr_instance->GetRelatedSiteInstance(dest_url); | 435 return curr_instance->GetRelatedSiteInstance(dest_url); |
435 | 436 |
436 // For extensions and Web UI URLs (such as the new tab page), we do not | 437 // 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 | 438 // 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 | 439 // RenderProcessHost of TYPE_NORMAL. Create a new SiteInstance for this |
439 // URL instead (with the correct process type). | 440 // URL instead (with the correct process type). |
440 if (content::WebUIFactory::Get()->UseWebUIForURL(profile, dest_url)) { | 441 if (content::WebUIFactory::Get()->UseWebUIForURL(context, dest_url)) { |
441 return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); | 442 return SiteInstance::CreateSiteInstanceForURL(context, dest_url); |
442 } | 443 } |
443 | 444 |
444 // Normally the "site" on the SiteInstance is set lazily when the load | 445 // Normally the "site" on the SiteInstance is set lazily when the load |
445 // actually commits. This is to support better process sharing in case | 446 // 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 | 447 // the site redirects to some other site: we want to use the destination |
447 // site in the site instance. | 448 // site in the site instance. |
448 // | 449 // |
449 // In the case of session restore, as it loads all the pages immediately | 450 // 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 | 451 // we need to set the site first, otherwise after a restore none of the |
451 // pages would share renderers in process-per-site. | 452 // 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 | 481 // 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 | 482 // 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 | 483 // the page to a different same-site URL. (This seems very unlikely in |
483 // practice.) | 484 // practice.) |
484 const GURL& current_url = (curr_entry) ? curr_entry->url() : | 485 const GURL& current_url = (curr_entry) ? curr_entry->url() : |
485 curr_instance->site(); | 486 curr_instance->site(); |
486 | 487 |
487 // Use the current SiteInstance for same site navigations, as long as the | 488 // 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 | 489 // process type is correct. (The URL may have been installed as an app since |
489 // the last time we visited it.) | 490 // the last time we visited it.) |
490 if (SiteInstance::IsSameWebSite(profile, current_url, dest_url) && | 491 if (SiteInstance::IsSameWebSite(context, current_url, dest_url) && |
491 !curr_instance->HasWrongProcessForURL(dest_url)) { | 492 !curr_instance->HasWrongProcessForURL(dest_url)) { |
492 return curr_instance; | 493 return curr_instance; |
493 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { | 494 } else if (ShouldSwapProcessesForNavigation(curr_entry, &entry)) { |
494 // When we're swapping, we need to force the site instance AND browsing | 495 // 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 | 496 // 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 | 497 // 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 | 498 // Pages), keeping them in the same process. When you navigate away from |
498 // that page, we want to explicity ignore that BrowsingInstance and group | 499 // that page, we want to explicity ignore that BrowsingInstance and group |
499 // this page into the appropriate SiteInstance for its URL. | 500 // this page into the appropriate SiteInstance for its URL. |
500 return SiteInstance::CreateSiteInstanceForURL(profile, dest_url); | 501 return SiteInstance::CreateSiteInstanceForURL(context, dest_url); |
501 } else { | 502 } else { |
502 // Start the new renderer in a new SiteInstance, but in the current | 503 // Start the new renderer in a new SiteInstance, but in the current |
503 // BrowsingInstance. It is important to immediately give this new | 504 // BrowsingInstance. It is important to immediately give this new |
504 // SiteInstance to a RenderViewHost (if it is different than our current | 505 // SiteInstance to a RenderViewHost (if it is different than our current |
505 // SiteInstance), so that it is ref counted. This will happen in | 506 // SiteInstance), so that it is ref counted. This will happen in |
506 // CreatePendingRenderView. | 507 // CreatePendingRenderView. |
507 return curr_instance->GetRelatedSiteInstance(dest_url); | 508 return curr_instance->GetRelatedSiteInstance(dest_url); |
508 } | 509 } |
509 } | 510 } |
510 | 511 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 delegate_->NotifySwappedFromRenderManager(); | 865 delegate_->NotifySwappedFromRenderManager(); |
865 } | 866 } |
866 | 867 |
867 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { | 868 bool RenderViewHostManager::IsSwappedOut(RenderViewHost* rvh) { |
868 if (!rvh->site_instance()) | 869 if (!rvh->site_instance()) |
869 return false; | 870 return false; |
870 | 871 |
871 return swapped_out_hosts_.find(rvh->site_instance()->id()) != | 872 return swapped_out_hosts_.find(rvh->site_instance()->id()) != |
872 swapped_out_hosts_.end(); | 873 swapped_out_hosts_.end(); |
873 } | 874 } |
OLD | NEW |