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_controller_factory.h" | 5 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h" | 41 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h" |
42 #include "chrome/browser/ui/webui/options/options_ui.h" | 42 #include "chrome/browser/ui/webui/options/options_ui.h" |
43 #include "chrome/browser/ui/webui/performance_monitor/performance_monitor_ui.h" | 43 #include "chrome/browser/ui/webui/performance_monitor/performance_monitor_ui.h" |
44 #include "chrome/browser/ui/webui/plugins_ui.h" | 44 #include "chrome/browser/ui/webui/plugins_ui.h" |
45 #include "chrome/browser/ui/webui/predictors/predictors_ui.h" | 45 #include "chrome/browser/ui/webui/predictors/predictors_ui.h" |
46 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 46 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
47 #include "chrome/browser/ui/webui/profiler_ui.h" | 47 #include "chrome/browser/ui/webui/profiler_ui.h" |
48 #include "chrome/browser/ui/webui/quota_internals_ui.h" | 48 #include "chrome/browser/ui/webui/quota_internals_ui.h" |
49 #include "chrome/browser/ui/webui/signin_internals_ui.h" | 49 #include "chrome/browser/ui/webui/signin_internals_ui.h" |
50 #include "chrome/browser/ui/webui/sync_internals_ui.h" | 50 #include "chrome/browser/ui/webui/sync_internals_ui.h" |
51 #include "chrome/browser/ui/webui/test_chrome_web_ui_controller_factory.h" | |
52 #include "chrome/browser/ui/webui/tracing_ui.h" | 51 #include "chrome/browser/ui/webui/tracing_ui.h" |
53 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" | 52 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" |
54 #include "chrome/browser/ui/webui/version_ui.h" | 53 #include "chrome/browser/ui/webui/version_ui.h" |
55 #include "chrome/common/chrome_switches.h" | 54 #include "chrome/common/chrome_switches.h" |
56 #include "chrome/common/extensions/extension_constants.h" | 55 #include "chrome/common/extensions/extension_constants.h" |
57 #include "chrome/common/extensions/feature_switch.h" | 56 #include "chrome/common/extensions/feature_switch.h" |
58 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
59 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
60 #include "content/public/browser/web_contents.h" | 59 #include "content/public/browser/web_contents.h" |
61 #include "content/public/browser/web_ui.h" | 60 #include "content/public/browser/web_ui.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 #include "chrome/browser/ui/webui/certificate_viewer_ui.h" | 112 #include "chrome/browser/ui/webui/certificate_viewer_ui.h" |
114 #endif | 113 #endif |
115 | 114 |
116 using content::WebUI; | 115 using content::WebUI; |
117 using content::WebUIController; | 116 using content::WebUIController; |
118 using ui::ExternalWebDialogUI; | 117 using ui::ExternalWebDialogUI; |
119 using ui::WebDialogUI; | 118 using ui::WebDialogUI; |
120 | 119 |
121 namespace { | 120 namespace { |
122 | 121 |
123 static bool g_use_test_factory = false; | |
124 | |
125 // A function for creating a new WebUI. The caller owns the return value, which | 122 // A function for creating a new WebUI. The caller owns the return value, which |
126 // may be NULL (for example, if the URL refers to an non-existent extension). | 123 // may be NULL (for example, if the URL refers to an non-existent extension). |
127 typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui, | 124 typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui, |
128 const GURL& url); | 125 const GURL& url); |
129 | 126 |
130 // Template for defining WebUIFactoryFunction. | 127 // Template for defining WebUIFactoryFunction. |
131 template<class T> | 128 template<class T> |
132 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { | 129 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { |
133 return new T(web_ui); | 130 return new T(web_ui); |
134 } | 131 } |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 #endif | 400 #endif |
404 #if defined(ENABLE_PRINTING) | 401 #if defined(ENABLE_PRINTING) |
405 if (url.host() == chrome::kChromeUIPrintHost && | 402 if (url.host() == chrome::kChromeUIPrintHost && |
406 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) | 403 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) |
407 return &NewWebUI<PrintPreviewUI>; | 404 return &NewWebUI<PrintPreviewUI>; |
408 #endif | 405 #endif |
409 | 406 |
410 return NULL; | 407 return NULL; |
411 } | 408 } |
412 | 409 |
413 // When the test-type switch is set, return a TestType object, which should be a | |
414 // subclass of Type. The logic is provided here in the traits class, rather than | |
415 // in GetInstance() so that the choice is made only once, when the Singleton is | |
416 // first instantiated, rather than every time GetInstance() is called. | |
417 template<typename Type, typename TestType> | |
418 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { | |
419 static Type* New() { | |
420 if (g_use_test_factory) | |
421 return DefaultSingletonTraits<TestType>::New(); | |
422 else | |
423 return DefaultSingletonTraits<Type>::New(); | |
424 } | |
425 }; | |
426 | |
427 void RunFaviconCallbackAsync( | 410 void RunFaviconCallbackAsync( |
428 const FaviconService::FaviconResultsCallback& callback, | 411 const FaviconService::FaviconResultsCallback& callback, |
429 const std::vector<history::FaviconBitmapResult>* results) { | 412 const std::vector<history::FaviconBitmapResult>* results) { |
430 base::MessageLoopProxy::current()->PostTask( | 413 base::MessageLoopProxy::current()->PostTask( |
431 FROM_HERE, | 414 FROM_HERE, |
432 base::Bind(&FaviconService::FaviconResultsCallbackRunner, | 415 base::Bind(&FaviconService::FaviconResultsCallbackRunner, |
433 callback, base::Owned(results))); | 416 callback, base::Owned(results))); |
434 } | 417 } |
435 | 418 |
436 } // namespace | 419 } // namespace |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); | 518 static_cast<int>(gfx::kFaviconSize * scale + 0.5f); |
536 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); | 519 bitmap_result.pixel_size = gfx::Size(edge_pixel_size, edge_pixel_size); |
537 } | 520 } |
538 } | 521 } |
539 | 522 |
540 RunFaviconCallbackAsync(callback, favicon_bitmap_results); | 523 RunFaviconCallbackAsync(callback, favicon_bitmap_results); |
541 } | 524 } |
542 | 525 |
543 // static | 526 // static |
544 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { | 527 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { |
545 return Singleton< ChromeWebUIControllerFactory, PossibleTestSingletonTraits< | 528 return Singleton<ChromeWebUIControllerFactory>::get(); |
546 ChromeWebUIControllerFactory, TestChromeWebUIControllerFactory> >::get(); | |
547 } | |
548 | |
549 // static | |
550 void ChromeWebUIControllerFactory::UseTestFactoryForTesting() { | |
551 g_use_test_factory = true; | |
552 } | 529 } |
553 | 530 |
554 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { | 531 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() { |
555 } | 532 } |
556 | 533 |
557 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() { | 534 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() { |
558 } | 535 } |
559 | 536 |
560 base::RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes( | 537 base::RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes( |
561 const GURL& page_url, ui::ScaleFactor scale_factor) const { | 538 const GURL& page_url, ui::ScaleFactor scale_factor) const { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 if (page_url.host() == chrome::kChromeUISettingsFrameHost) | 579 if (page_url.host() == chrome::kChromeUISettingsFrameHost) |
603 return options::OptionsUI::GetFaviconResourceBytes(scale_factor); | 580 return options::OptionsUI::GetFaviconResourceBytes(scale_factor); |
604 | 581 |
605 // Android doesn't use the plugins pages. | 582 // Android doesn't use the plugins pages. |
606 if (page_url.host() == chrome::kChromeUIPluginsHost) | 583 if (page_url.host() == chrome::kChromeUIPluginsHost) |
607 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 584 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
608 #endif | 585 #endif |
609 | 586 |
610 return NULL; | 587 return NULL; |
611 } | 588 } |
OLD | NEW |