Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Side by Side Diff: content/browser/web_contents/render_view_host_manager.cc

Issue 11783038: Allow multiple WebUIControllerFactory objects to be registered. This makes is possible to implement… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: reland after bogus revert of r175971 Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
19 #include "content/browser/webui/web_ui_impl.h" 20 #include "content/browser/webui/web_ui_impl.h"
20 #include "content/common/view_messages.h" 21 #include "content/common/view_messages.h"
21 #include "content/port/browser/render_widget_host_view_port.h" 22 #include "content/port/browser/render_widget_host_view_port.h"
22 #include "content/public/browser/content_browser_client.h" 23 #include "content/public/browser/content_browser_client.h"
23 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 25 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/web_contents_view.h" 26 #include "content/public/browser/web_contents_view.h"
26 #include "content/public/browser/web_ui_controller.h" 27 #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
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 const WebUIControllerFactory* web_ui_factory = 417 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL(
418 GetContentClient()->browser()->GetWebUIControllerFactory(); 418 browser_context, current_url)) {
419 if (web_ui_factory) { 419 // Force swap if it's not an acceptable URL for Web UI.
420 if (web_ui_factory->UseWebUIForURL(browser_context, current_url)) { 420 // Here, data URLs are never allowed.
421 // Force swap if it's not an acceptable URL for Web UI. 421 if (!WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI(
422 // Here, data URLs are never allowed. 422 browser_context, new_entry->GetURL(), false)) {
423 if (!web_ui_factory->IsURLAcceptableForWebUI(browser_context, 423 return true;
424 new_entry->GetURL(), false)) 424 }
425 return true; 425 } else {
426 } else { 426 // Force swap if it's a Web UI URL.
427 // Force swap if it's a Web UI URL. 427 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL(
428 if (web_ui_factory->UseWebUIForURL(browser_context, new_entry->GetURL())) 428 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();
458 return curr_entry && web_ui_.get() && 456 return curr_entry && web_ui_.get() &&
459 (factory->GetWebUIType(controller.GetBrowserContext(), 457 (WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
460 curr_entry->GetURL()) == 458 controller.GetBrowserContext(), curr_entry->GetURL()) ==
461 factory->GetWebUIType(controller.GetBrowserContext(), 459 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType(
462 new_entry->GetURL())); 460 controller.GetBrowserContext(), new_entry->GetURL()));
463 } 461 }
464 462
465 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry( 463 SiteInstance* RenderViewHostManager::GetSiteInstanceForEntry(
466 const NavigationEntryImpl& entry, 464 const NavigationEntryImpl& entry,
467 SiteInstance* curr_instance) { 465 SiteInstance* curr_instance) {
468 // NOTE: This is only called when ShouldTransitionCrossSite is true. 466 // NOTE: This is only called when ShouldTransitionCrossSite is true.
469 467
470 const GURL& dest_url = entry.GetURL(); 468 const GURL& dest_url = entry.GetURL();
471 NavigationControllerImpl& controller = 469 NavigationControllerImpl& controller =
472 delegate_->GetControllerForRenderManager(); 470 delegate_->GetControllerForRenderManager();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 525
528 // View-source URLs must use a new SiteInstance and BrowsingInstance. 526 // View-source URLs must use a new SiteInstance and BrowsingInstance.
529 // TODO(nasko): This is the same condition as later in the function. This 527 // TODO(nasko): This is the same condition as later in the function. This
530 // should be taken into account when refactoring this method as part of 528 // should be taken into account when refactoring this method as part of
531 // http://crbug.com/123007. 529 // http://crbug.com/123007.
532 if (entry.IsViewSourceMode()) 530 if (entry.IsViewSourceMode())
533 return SiteInstance::CreateForURL(browser_context, dest_url); 531 return SiteInstance::CreateForURL(browser_context, dest_url);
534 532
535 // If we are navigating from a blank SiteInstance to a WebUI, make sure we 533 // If we are navigating from a blank SiteInstance to a WebUI, make sure we
536 // create a new SiteInstance. 534 // create a new SiteInstance.
537 const WebUIControllerFactory* web_ui_factory = 535 if (WebUIControllerFactoryRegistry::GetInstance()->UseWebUIForURL(
538 GetContentClient()->browser()->GetWebUIControllerFactory(); 536 browser_context, dest_url)) {
539 if (web_ui_factory &&
540 web_ui_factory->UseWebUIForURL(browser_context, dest_url)) {
541 return SiteInstance::CreateForURL(browser_context, dest_url); 537 return SiteInstance::CreateForURL(browser_context, dest_url);
542 } 538 }
543 539
544 // Normally the "site" on the SiteInstance is set lazily when the load 540 // Normally the "site" on the SiteInstance is set lazily when the load
545 // actually commits. This is to support better process sharing in case 541 // actually commits. This is to support better process sharing in case
546 // the site redirects to some other site: we want to use the destination 542 // the site redirects to some other site: we want to use the destination
547 // site in the site instance. 543 // site in the site instance.
548 // 544 //
549 // In the case of session restore, as it loads all the pages immediately 545 // In the case of session restore, as it loads all the pages immediately
550 // we need to set the site first, otherwise after a restore none of the 546 // 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
973 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( 969 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost(
974 SiteInstance* instance) { 970 SiteInstance* instance) {
975 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); 971 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId());
976 if (iter != swapped_out_hosts_.end()) 972 if (iter != swapped_out_hosts_.end())
977 return iter->second; 973 return iter->second;
978 974
979 return NULL; 975 return NULL;
980 } 976 }
981 977
982 } // namespace content 978 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/site_instance_impl_unittest.cc ('k') | content/browser/web_contents/render_view_host_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698