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 "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 5 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/about_flags.h" | 8 #include "chrome/browser/about_flags.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/extension_web_ui.h" | 11 #include "chrome/browser/extensions/extension_web_ui.h" |
12 #include "chrome/browser/history/history_types.h" | 12 #include "chrome/browser/history/history_types.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
(...skipping 21 matching lines...) Expand all Loading... |
37 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h" | 37 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h" |
38 #include "chrome/browser/ui/webui/options/options_ui.h" | 38 #include "chrome/browser/ui/webui/options/options_ui.h" |
39 #include "chrome/browser/ui/webui/options2/options_ui2.h" | 39 #include "chrome/browser/ui/webui/options2/options_ui2.h" |
40 #include "chrome/browser/ui/webui/plugins_ui.h" | 40 #include "chrome/browser/ui/webui/plugins_ui.h" |
41 #include "chrome/browser/ui/webui/policy_ui.h" | 41 #include "chrome/browser/ui/webui/policy_ui.h" |
42 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 42 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
43 #include "chrome/browser/ui/webui/profiler_ui.h" | 43 #include "chrome/browser/ui/webui/profiler_ui.h" |
44 #include "chrome/browser/ui/webui/quota_internals_ui.h" | 44 #include "chrome/browser/ui/webui/quota_internals_ui.h" |
45 #include "chrome/browser/ui/webui/sessions_ui.h" | 45 #include "chrome/browser/ui/webui/sessions_ui.h" |
46 #include "chrome/browser/ui/webui/sync_internals_ui.h" | 46 #include "chrome/browser/ui/webui/sync_internals_ui.h" |
47 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | 47 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" |
48 #include "chrome/browser/ui/webui/tracing_ui.h" | 48 #include "chrome/browser/ui/webui/tracing_ui.h" |
49 #include "chrome/browser/ui/webui/uber/uber_ui.h" | 49 #include "chrome/browser/ui/webui/uber/uber_ui.h" |
50 #include "chrome/browser/ui/webui/workers_ui.h" | 50 #include "chrome/browser/ui/webui/workers_ui.h" |
51 #include "chrome/common/chrome_switches.h" | 51 #include "chrome/common/chrome_switches.h" |
52 #include "chrome/common/extensions/extension_constants.h" | 52 #include "chrome/common/extensions/extension_constants.h" |
53 #include "chrome/common/pref_names.h" | 53 #include "chrome/common/pref_names.h" |
54 #include "chrome/common/url_constants.h" | 54 #include "chrome/common/url_constants.h" |
55 #include "content/public/browser/web_contents.h" | 55 #include "content/public/browser/web_contents.h" |
56 #include "content/public/browser/web_ui.h" | 56 #include "content/public/browser/web_ui.h" |
57 #include "googleurl/src/gurl.h" | 57 #include "googleurl/src/gurl.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 static Type* New() { | 356 static Type* New() { |
357 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) | 357 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) |
358 return DefaultSingletonTraits<TestType>::New(); | 358 return DefaultSingletonTraits<TestType>::New(); |
359 else | 359 else |
360 return DefaultSingletonTraits<Type>::New(); | 360 return DefaultSingletonTraits<Type>::New(); |
361 } | 361 } |
362 }; | 362 }; |
363 | 363 |
364 } // namespace | 364 } // namespace |
365 | 365 |
366 WebUI::TypeID ChromeWebUIFactory::GetWebUIType( | 366 WebUI::TypeID ChromeWebUIControllerFactory::GetWebUIType( |
367 content::BrowserContext* browser_context, const GURL& url) const { | 367 content::BrowserContext* browser_context, const GURL& url) const { |
368 Profile* profile = Profile::FromBrowserContext(browser_context); | 368 Profile* profile = Profile::FromBrowserContext(browser_context); |
369 WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, profile, url); | 369 WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, profile, url); |
370 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; | 370 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; |
371 } | 371 } |
372 | 372 |
373 bool ChromeWebUIFactory::UseWebUIForURL( | 373 bool ChromeWebUIControllerFactory::UseWebUIForURL( |
374 content::BrowserContext* browser_context, const GURL& url) const { | 374 content::BrowserContext* browser_context, const GURL& url) const { |
375 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; | 375 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; |
376 } | 376 } |
377 | 377 |
378 bool ChromeWebUIFactory::UseWebUIBindingsForURL( | 378 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( |
379 content::BrowserContext* browser_context, const GURL& url) const { | 379 content::BrowserContext* browser_context, const GURL& url) const { |
380 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI | 380 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI |
381 // bindings (see the ExtensionWebUI constructor). | 381 // bindings (see the ExtensionWebUI constructor). |
382 return !NeedsExtensionWebUI(NULL, | 382 return !NeedsExtensionWebUI(NULL, |
383 Profile::FromBrowserContext(browser_context), | 383 Profile::FromBrowserContext(browser_context), |
384 url) && | 384 url) && |
385 UseWebUIForURL(browser_context, url); | 385 UseWebUIForURL(browser_context, url); |
386 } | 386 } |
387 | 387 |
388 bool ChromeWebUIFactory::HasWebUIScheme(const GURL& url) const { | 388 bool ChromeWebUIControllerFactory::HasWebUIScheme(const GURL& url) const { |
389 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 389 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
390 url.SchemeIs(chrome::kChromeInternalScheme) || | 390 url.SchemeIs(chrome::kChromeInternalScheme) || |
391 url.SchemeIs(chrome::kChromeUIScheme); | 391 url.SchemeIs(chrome::kChromeUIScheme); |
392 } | 392 } |
393 | 393 |
394 bool ChromeWebUIFactory::IsURLAcceptableForWebUI( | 394 bool ChromeWebUIControllerFactory::IsURLAcceptableForWebUI( |
395 content::BrowserContext* browser_context, | 395 content::BrowserContext* browser_context, |
396 const GURL& url) const { | 396 const GURL& url) const { |
397 return UseWebUIForURL(browser_context, url) || | 397 return UseWebUIForURL(browser_context, url) || |
398 // javacsript: URLs are allowed to run in Web UI pages | 398 // javacsript: URLs are allowed to run in Web UI pages |
399 url.SchemeIs(chrome::kJavaScriptScheme) || | 399 url.SchemeIs(chrome::kJavaScriptScheme) || |
400 // It's possible to load about:blank in a Web UI renderer. | 400 // It's possible to load about:blank in a Web UI renderer. |
401 // See http://crbug.com/42547 | 401 // See http://crbug.com/42547 |
402 url.spec() == chrome::kAboutBlankURL || | 402 url.spec() == chrome::kAboutBlankURL || |
403 // Chrome URLs crash, kill, hang, and shorthang are allowed. | 403 // Chrome URLs crash, kill, hang, and shorthang are allowed. |
404 url == GURL(chrome::kChromeUICrashURL) || | 404 url == GURL(chrome::kChromeUICrashURL) || |
405 url == GURL(chrome::kChromeUIKillURL) || | 405 url == GURL(chrome::kChromeUIKillURL) || |
406 url == GURL(chrome::kChromeUIHangURL) || | 406 url == GURL(chrome::kChromeUIHangURL) || |
407 url == GURL(chrome::kChromeUIShorthangURL); | 407 url == GURL(chrome::kChromeUIShorthangURL); |
408 } | 408 } |
409 | 409 |
410 WebUIController* ChromeWebUIFactory::CreateWebUIForURL( | 410 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( |
411 content::WebUI* web_ui, | 411 content::WebUI* web_ui, |
412 const GURL& url) const { | 412 const GURL& url) const { |
413 Profile* profile = Profile::FromWebUI(web_ui); | 413 Profile* profile = Profile::FromWebUI(web_ui); |
414 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, | 414 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, |
415 profile, url); | 415 profile, url); |
416 if (!function) | 416 if (!function) |
417 return NULL; | 417 return NULL; |
418 | 418 |
419 return (*function)(web_ui, url); | 419 return (*function)(web_ui, url); |
420 } | 420 } |
421 | 421 |
422 void ChromeWebUIFactory::GetFaviconForURL( | 422 void ChromeWebUIControllerFactory::GetFaviconForURL( |
423 Profile* profile, | 423 Profile* profile, |
424 FaviconService::GetFaviconRequest* request, | 424 FaviconService::GetFaviconRequest* request, |
425 const GURL& page_url) const { | 425 const GURL& page_url) const { |
426 // All extensions but the bookmark manager get their favicon from the icons | 426 // All extensions but the bookmark manager get their favicon from the icons |
427 // part of the manifest. | 427 // part of the manifest. |
428 if (page_url.SchemeIs(chrome::kExtensionScheme) && | 428 if (page_url.SchemeIs(chrome::kExtensionScheme) && |
429 page_url.host() != extension_misc::kBookmarkManagerId) { | 429 page_url.host() != extension_misc::kBookmarkManagerId) { |
430 ExtensionWebUI::GetFaviconForURL(profile, request, page_url); | 430 ExtensionWebUI::GetFaviconForURL(profile, request, page_url); |
431 } else { | 431 } else { |
432 history::FaviconData favicon; | 432 history::FaviconData favicon; |
433 favicon.image_data = scoped_refptr<RefCountedMemory>( | 433 favicon.image_data = scoped_refptr<RefCountedMemory>( |
434 GetFaviconResourceBytes(page_url)); | 434 GetFaviconResourceBytes(page_url)); |
435 favicon.known_icon = favicon.image_data.get() != NULL && | 435 favicon.known_icon = favicon.image_data.get() != NULL && |
436 favicon.image_data->size() > 0; | 436 favicon.image_data->size() > 0; |
437 favicon.icon_type = history::FAVICON; | 437 favicon.icon_type = history::FAVICON; |
438 request->ForwardResultAsync(request->handle(), favicon); | 438 request->ForwardResultAsync(request->handle(), favicon); |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 // static | 442 // static |
443 ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() { | 443 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { |
444 return Singleton< ChromeWebUIFactory, PossibleTestSingletonTraits< | 444 return Singleton< ChromeWebUIControllerFactory, PossibleTestSingletonTraits< |
445 ChromeWebUIFactory, TestChromeWebUIFactory> >::get(); | 445 ChromeWebUIControllerFactory, TestChromeWebUIControllerFactory> >::get(); |
446 } | 446 } |
447 | 447 |
448 ChromeWebUIFactory::ChromeWebUIFactory() { | 448 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { |
449 } | 449 } |
450 | 450 |
451 ChromeWebUIFactory::~ChromeWebUIFactory() { | 451 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() { |
452 } | 452 } |
453 | 453 |
454 RefCountedMemory* ChromeWebUIFactory::GetFaviconResourceBytes( | 454 RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes( |
455 const GURL& page_url) const { | 455 const GURL& page_url) const { |
456 // The bookmark manager is a chrome extension, so we have to check for it | 456 // The bookmark manager is a chrome extension, so we have to check for it |
457 // before we check for extension scheme. | 457 // before we check for extension scheme. |
458 if (page_url.host() == extension_misc::kBookmarkManagerId) | 458 if (page_url.host() == extension_misc::kBookmarkManagerId) |
459 return BookmarksUI::GetFaviconResourceBytes(); | 459 return BookmarksUI::GetFaviconResourceBytes(); |
460 | 460 |
461 // The extension scheme is handled in GetFaviconForURL. | 461 // The extension scheme is handled in GetFaviconForURL. |
462 if (page_url.SchemeIs(chrome::kExtensionScheme)) { | 462 if (page_url.SchemeIs(chrome::kExtensionScheme)) { |
463 NOTREACHED(); | 463 NOTREACHED(); |
464 return NULL; | 464 return NULL; |
(...skipping 29 matching lines...) Expand all Loading... |
494 return OptionsUI::GetFaviconResourceBytes(); | 494 return OptionsUI::GetFaviconResourceBytes(); |
495 | 495 |
496 if (page_url.host() == chrome::kChromeUISettingsFrameHost) | 496 if (page_url.host() == chrome::kChromeUISettingsFrameHost) |
497 return options2::OptionsUI::GetFaviconResourceBytes(); | 497 return options2::OptionsUI::GetFaviconResourceBytes(); |
498 | 498 |
499 if (page_url.host() == chrome::kChromeUIPluginsHost) | 499 if (page_url.host() == chrome::kChromeUIPluginsHost) |
500 return PluginsUI::GetFaviconResourceBytes(); | 500 return PluginsUI::GetFaviconResourceBytes(); |
501 | 501 |
502 return NULL; | 502 return NULL; |
503 } | 503 } |
OLD | NEW |