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" |
11 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 11 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_factory.h" | 13 #include "content/browser/renderer_host/render_view_host_factory.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
16 #include "content/browser/web_contents/interstitial_page_impl.h" | 16 #include "content/browser/web_contents/interstitial_page_impl.h" |
17 #include "content/browser/web_contents/navigation_controller_impl.h" | 17 #include "content/browser/web_contents/navigation_controller_impl.h" |
18 #include "content/browser/web_contents/navigation_entry_impl.h" | 18 #include "content/browser/web_contents/navigation_entry_impl.h" |
19 #include "content/browser/webui/web_ui_controller_factory_registry.h" | |
20 #include "content/browser/webui/web_ui_impl.h" | 19 #include "content/browser/webui/web_ui_impl.h" |
21 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
22 #include "content/port/browser/render_widget_host_view_port.h" | 21 #include "content/port/browser/render_widget_host_view_port.h" |
23 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
26 #include "content/public/browser/web_contents_view.h" | 25 #include "content/public/browser/web_contents_view.h" |
27 #include "content/public/browser/web_ui_controller.h" | 26 #include "content/public/browser/web_ui_controller.h" |
| 27 #include "content/public/browser/web_ui_controller_factory.h" |
28 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
29 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 RenderViewHostManager::RenderViewHostManager( | 33 RenderViewHostManager::RenderViewHostManager( |
34 RenderViewHostDelegate* render_view_delegate, | 34 RenderViewHostDelegate* render_view_delegate, |
35 RenderWidgetHostDelegate* render_widget_delegate, | 35 RenderWidgetHostDelegate* render_widget_delegate, |
36 Delegate* delegate) | 36 Delegate* delegate) |
37 : delegate_(delegate), | 37 : delegate_(delegate), |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 // Check for reasons to swap processes even if we are in a process model that | 407 // Check for reasons to swap processes even if we are in a process model that |
408 // doesn't usually swap (e.g., process-per-tab). | 408 // doesn't usually swap (e.g., process-per-tab). |
409 | 409 |
410 // For security, we should transition between processes when one is a Web UI | 410 // For security, we should transition between processes when one is a Web UI |
411 // page and one isn't. If there's no curr_entry, check the current RVH's | 411 // page and one isn't. If there's no curr_entry, check the current RVH's |
412 // site, which might already be committed to a Web UI URL (such as the NTP). | 412 // site, which might already be committed to a Web UI URL (such as the NTP). |
413 const GURL& current_url = (curr_entry) ? curr_entry->GetURL() : | 413 const GURL& current_url = (curr_entry) ? curr_entry->GetURL() : |
414 render_view_host_->GetSiteInstance()->GetSiteURL(); | 414 render_view_host_->GetSiteInstance()->GetSiteURL(); |
415 BrowserContext* browser_context = | 415 BrowserContext* browser_context = |
416 delegate_->GetControllerForRenderManager().GetBrowserContext(); | 416 delegate_->GetControllerForRenderManager().GetBrowserContext(); |
417 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 417 const WebUIControllerFactory* web_ui_factory = |
418 browser_context, current_url)) { | 418 GetContentClient()->browser()->GetWebUIControllerFactory(); |
419 // Force swap if it's not an acceptable URL for Web UI. | 419 if (web_ui_factory) { |
420 // Here, data URLs are never allowed. | 420 if (web_ui_factory->UseWebUIForURL(browser_context, current_url)) { |
421 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( | 421 // Force swap if it's not an acceptable URL for Web UI. |
422 browser_context, new_entry->GetURL(), false)) { | 422 // Here, data URLs are never allowed. |
423 return true; | 423 if (!web_ui_factory->IsURLAcceptableForWebUI(browser_context, |
424 } | 424 new_entry->GetURL(), false)) |
425 } else { | 425 return true; |
426 // Force swap if it's a Web UI URL. | 426 } else { |
427 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 427 // Force swap if it's a Web UI URL. |
428 browser_context, new_entry->GetURL())) { | 428 if (web_ui_factory->UseWebUIForURL(browser_context, new_entry->GetURL())) |
429 return true; | 429 return true; |
430 } | 430 } |
431 } | 431 } |
432 | 432 |
433 if (GetContentClient()->browser()->ShouldSwapProcessesForNavigation( | 433 if (GetContentClient()->browser()->ShouldSwapProcessesForNavigation( |
434 curr_entry ? curr_entry->GetURL() : GURL(), new_entry->GetURL())) { | 434 curr_entry ? curr_entry->GetURL() : GURL(), new_entry->GetURL())) { |
435 return true; | 435 return true; |
436 } | 436 } |
437 | 437 |
438 if (!curr_entry) | 438 if (!curr_entry) |
439 return false; | 439 return false; |
440 | 440 |
441 // We can't switch a RenderView between view source and non-view source mode | 441 // We can't switch a RenderView between view source and non-view source mode |
442 // without screwing up the session history sometimes (when navigating between | 442 // without screwing up the session history sometimes (when navigating between |
443 // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat | 443 // "view-source:http://foo.com/" and "http://foo.com/", WebKit doesn't treat |
444 // it as a new navigation). So require a view switch. | 444 // it as a new navigation). So require a view switch. |
445 if (curr_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) | 445 if (curr_entry->IsViewSourceMode() != new_entry->IsViewSourceMode()) |
446 return true; | 446 return true; |
447 | 447 |
448 return false; | 448 return false; |
449 } | 449 } |
450 | 450 |
451 bool RenderViewHostManager::ShouldReuseWebUI( | 451 bool RenderViewHostManager::ShouldReuseWebUI( |
452 const NavigationEntry* curr_entry, | 452 const NavigationEntry* curr_entry, |
453 const NavigationEntryImpl* new_entry) const { | 453 const NavigationEntryImpl* new_entry) const { |
454 NavigationControllerImpl& controller = | 454 NavigationControllerImpl& controller = |
455 delegate_->GetControllerForRenderManager(); | 455 delegate_->GetControllerForRenderManager(); |
| 456 WebUIControllerFactory* factory = |
| 457 GetContentClient()->browser()->GetWebUIControllerFactory(); |
456 return curr_entry && web_ui_.get() && | 458 return curr_entry && web_ui_.get() && |
457 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 459 (factory->GetWebUIType(controller.GetBrowserContext(), |
458 controller.GetBrowserContext(), curr_entry->GetURL()) == | 460 curr_entry->GetURL()) == |
459 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( | 461 factory->GetWebUIType(controller.GetBrowserContext(), |
460 controller.GetBrowserContext(), new_entry->GetURL())); | 462 new_entry->GetURL())); |
461 } | 463 } |
462 | 464 |
463 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( | 465 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( |
464 const NavigationEntryImpl& entry, | 466 const NavigationEntryImpl& entry, |
465 SiteInstance* curr_instance) { | 467 SiteInstance* curr_instance) { |
466 // NOTE: This is only called when ShouldTransitionCrossSite is true. | 468 // NOTE: This is only called when ShouldTransitionCrossSite is true. |
467 | 469 |
468 const GURL& dest_url = entry.GetURL(); | 470 const GURL& dest_url = entry.GetURL(); |
469 NavigationControllerImpl& controller = | 471 NavigationControllerImpl& controller = |
470 delegate_->GetControllerForRenderManager(); | 472 delegate_->GetControllerForRenderManager(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 527 |
526 // View-source URLs must use a new SiteInstance and BrowsingInstance. | 528 // View-source URLs must use a new SiteInstance and BrowsingInstance. |
527 // TODO(nasko): This is the same condition as later in the function. This | 529 // TODO(nasko): This is the same condition as later in the function. This |
528 // should be taken into account when refactoring this method as part of | 530 // should be taken into account when refactoring this method as part of |
529 // http://crbug.com/123007. | 531 // http://crbug.com/123007. |
530 if (entry.IsViewSourceMode()) | 532 if (entry.IsViewSourceMode()) |
531 return SiteInstance::CreateForURL(browser_context, dest_url); | 533 return SiteInstance::CreateForURL(browser_context, dest_url); |
532 | 534 |
533 // If we are navigating from a blank SiteInstance to a WebUI, make sure we | 535 // If we are navigating from a blank SiteInstance to a WebUI, make sure we |
534 // create a new SiteInstance. | 536 // create a new SiteInstance. |
535 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL( | 537 const WebUIControllerFactory* web_ui_factory = |
536 browser_context, dest_url)) { | 538 GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 539 if (web_ui_factory && |
| 540 web_ui_factory->UseWebUIForURL(browser_context, dest_url)) { |
537 return SiteInstance::CreateForURL(browser_context, dest_url); | 541 return SiteInstance::CreateForURL(browser_context, dest_url); |
538 } | 542 } |
539 | 543 |
540 // Normally the "site" on the SiteInstance is set lazily when the load | 544 // Normally the "site" on the SiteInstance is set lazily when the load |
541 // actually commits. This is to support better process sharing in case | 545 // actually commits. This is to support better process sharing in case |
542 // the site redirects to some other site: we want to use the destination | 546 // the site redirects to some other site: we want to use the destination |
543 // site in the site instance. | 547 // site in the site instance. |
544 // | 548 // |
545 // In the case of session restore, as it loads all the pages immediately | 549 // In the case of session restore, as it loads all the pages immediately |
546 // we need to set the site first, otherwise after a restore none of the | 550 // we need to set the site first, otherwise after a restore none of the |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( | 973 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
970 SiteInstance* instance) { | 974 SiteInstance* instance) { |
971 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 975 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
972 if (iter != swapped_out_hosts_.end()) | 976 if (iter != swapped_out_hosts_.end()) |
973 return iter->second; | 977 return iter->second; |
974 | 978 |
975 return NULL; | 979 return NULL; |
976 } | 980 } |
977 | 981 |
978 } // namespace content | 982 } // namespace content |
OLD | NEW |