| 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 "chrome/browser/ui/webui/chrome_web_ui_factory.h" | 5 #include "chrome/browser/ui/webui/chrome_web_ui_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/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_web_ui.h" | 10 #include "chrome/browser/extensions/extension_web_ui.h" |
| 11 #include "chrome/browser/extensions/extensions_ui.h" | 11 #include "chrome/browser/extensions/extensions_ui.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/webui/bookmarks_ui.h" | 13 #include "chrome/browser/ui/webui/bookmarks_ui.h" |
| 14 #include "chrome/browser/ui/webui/bug_report_ui.h" | 14 #include "chrome/browser/ui/webui/bug_report_ui.h" |
| 15 #include "chrome/browser/ui/webui/constrained_html_ui.h" | 15 #include "chrome/browser/ui/webui/constrained_html_ui.h" |
| 16 #include "chrome/browser/ui/webui/crashes_ui.h" | 16 #include "chrome/browser/ui/webui/crashes_ui.h" |
| 17 #include "chrome/browser/ui/webui/devtools_ui.h" | 17 #include "chrome/browser/ui/webui/devtools_ui.h" |
| 18 #include "chrome/browser/ui/webui/downloads_ui.h" | 18 #include "chrome/browser/ui/webui/downloads_ui.h" |
| 19 #include "chrome/browser/ui/webui/flags_ui.h" | 19 #include "chrome/browser/ui/webui/flags_ui.h" |
| 20 #include "chrome/browser/ui/webui/gpu_internals_ui.h" | 20 #include "chrome/browser/ui/webui/gpu_internals_ui.h" |
| 21 #include "chrome/browser/ui/webui/history2_ui.h" | 21 #include "chrome/browser/ui/webui/history2_ui.h" |
| 22 #include "chrome/browser/ui/webui/history_ui.h" | 22 #include "chrome/browser/ui/webui/history_ui.h" |
| 23 #include "chrome/browser/ui/webui/html_dialog_ui.h" | 23 #include "chrome/browser/ui/webui/html_dialog_ui.h" |
| 24 #include "chrome/browser/ui/webui/net_internals_ui.h" | 24 #include "chrome/browser/ui/webui/net_internals_ui.h" |
| 25 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 25 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 26 #include "chrome/browser/ui/webui/options/options_ui.h" | 26 #include "chrome/browser/ui/webui/options/options_ui.h" |
| 27 #include "chrome/browser/ui/webui/plugins_ui.h" | 27 #include "chrome/browser/ui/webui/plugins_ui.h" |
| 28 #include "chrome/browser/ui/webui/print_preview_ui.h" | 28 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 29 #include "chrome/browser/ui/webui/sync_internals_ui.h" | 29 #include "chrome/browser/ui/webui/sync_internals_ui.h" |
| 30 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
| 30 #include "chrome/browser/ui/webui/textfields_ui.h" | 31 #include "chrome/browser/ui/webui/textfields_ui.h" |
| 31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/extensions/extension_constants.h" | 33 #include "chrome/common/extensions/extension_constants.h" |
| 33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 34 #include "content/browser/tab_contents/tab_contents.h" | 35 #include "content/browser/tab_contents/tab_contents.h" |
| 35 #include "content/browser/webui/web_ui.h" | 36 #include "content/browser/webui/web_ui.h" |
| 36 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
| 37 | 38 |
| 38 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
| 39 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h" | 40 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 if (url.host() == chrome::kChromeUILoginHost) | 211 if (url.host() == chrome::kChromeUILoginHost) |
| 211 return &NewWebUI<chromeos::LoginUI>; | 212 return &NewWebUI<chromeos::LoginUI>; |
| 212 #endif | 213 #endif |
| 213 | 214 |
| 214 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL) | 215 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL) |
| 215 return &NewWebUI<ConstrainedHtmlUI>; | 216 return &NewWebUI<ConstrainedHtmlUI>; |
| 216 | 217 |
| 217 return NULL; | 218 return NULL; |
| 218 } | 219 } |
| 219 | 220 |
| 221 // When the test-type switch is set, return a TestType object, which should be a |
| 222 // subclass of Type. The logic is provided here in the traits class, rather than |
| 223 // in GetInstance() so that the choice is made only once, when the Singleton is |
| 224 // first instantiated, rather than every time GetInstance() is called. |
| 225 template<typename Type, typename TestType> |
| 226 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { |
| 227 static Type* New() { |
| 228 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) |
| 229 return DefaultSingletonTraits<TestType>::New(); |
| 230 else |
| 231 return DefaultSingletonTraits<Type>::New(); |
| 232 } |
| 233 }; |
| 234 |
| 220 } // namespace | 235 } // namespace |
| 221 | 236 |
| 222 WebUI::TypeID ChromeWebUIFactory::GetWebUIType(Profile* profile, | 237 WebUI::TypeID ChromeWebUIFactory::GetWebUIType(Profile* profile, |
| 223 const GURL& url) const { | 238 const GURL& url) const { |
| 224 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); | 239 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); |
| 225 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; | 240 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; |
| 226 } | 241 } |
| 227 | 242 |
| 228 bool ChromeWebUIFactory::UseWebUIForURL(Profile* profile, | 243 bool ChromeWebUIFactory::UseWebUIForURL(Profile* profile, |
| 229 const GURL& url) const { | 244 const GURL& url) const { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 favicon.known_icon = favicon.image_data.get() != NULL && | 294 favicon.known_icon = favicon.image_data.get() != NULL && |
| 280 favicon.image_data->size() > 0; | 295 favicon.image_data->size() > 0; |
| 281 request->ForwardResultAsync( | 296 request->ForwardResultAsync( |
| 282 FaviconService::FaviconDataCallback::TupleType(request->handle(), | 297 FaviconService::FaviconDataCallback::TupleType(request->handle(), |
| 283 favicon)); | 298 favicon)); |
| 284 } | 299 } |
| 285 } | 300 } |
| 286 | 301 |
| 287 // static | 302 // static |
| 288 ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() { | 303 ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() { |
| 289 return Singleton<ChromeWebUIFactory>::get(); | 304 return Singleton<ChromeWebUIFactory, PossibleTestSingletonTraits< |
| 305 ChromeWebUIFactory, TestChromeWebUIFactory> >::get(); |
| 290 } | 306 } |
| 291 | 307 |
| 292 ChromeWebUIFactory::ChromeWebUIFactory() { | 308 ChromeWebUIFactory::ChromeWebUIFactory() { |
| 293 } | 309 } |
| 294 | 310 |
| 295 ChromeWebUIFactory::~ChromeWebUIFactory() { | 311 ChromeWebUIFactory::~ChromeWebUIFactory() { |
| 296 } | 312 } |
| 297 | 313 |
| 298 RefCountedMemory* ChromeWebUIFactory::GetFaviconResourceBytes( | 314 RefCountedMemory* ChromeWebUIFactory::GetFaviconResourceBytes( |
| 299 const GURL& page_url) const { | 315 const GURL& page_url) const { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 return FlagsUI::GetFaviconResourceBytes(); | 351 return FlagsUI::GetFaviconResourceBytes(); |
| 336 | 352 |
| 337 if (page_url.host() == chrome::kChromeUISettingsHost) | 353 if (page_url.host() == chrome::kChromeUISettingsHost) |
| 338 return OptionsUI::GetFaviconResourceBytes(); | 354 return OptionsUI::GetFaviconResourceBytes(); |
| 339 | 355 |
| 340 if (page_url.host() == chrome::kChromeUIPluginsHost) | 356 if (page_url.host() == chrome::kChromeUIPluginsHost) |
| 341 return PluginsUI::GetFaviconResourceBytes(); | 357 return PluginsUI::GetFaviconResourceBytes(); |
| 342 | 358 |
| 343 return NULL; | 359 return NULL; |
| 344 } | 360 } |
| OLD | NEW |