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/history/history_types.h" | 11 #include "chrome/browser/history/history_types.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/webui/about_ui.h" |
14 #include "chrome/browser/ui/webui/bookmarks_ui.h" | 15 #include "chrome/browser/ui/webui/bookmarks_ui.h" |
15 #include "chrome/browser/ui/webui/bug_report_ui.h" | 16 #include "chrome/browser/ui/webui/bug_report_ui.h" |
16 #include "chrome/browser/ui/webui/constrained_html_ui.h" | 17 #include "chrome/browser/ui/webui/constrained_html_ui.h" |
17 #include "chrome/browser/ui/webui/crashes_ui.h" | 18 #include "chrome/browser/ui/webui/crashes_ui.h" |
18 #include "chrome/browser/ui/webui/devtools_ui.h" | 19 #include "chrome/browser/ui/webui/devtools_ui.h" |
19 #include "chrome/browser/ui/webui/downloads_ui.h" | 20 #include "chrome/browser/ui/webui/downloads_ui.h" |
20 #include "chrome/browser/ui/webui/edit_search_engine_dialog_ui_webui.h" | 21 #include "chrome/browser/ui/webui/edit_search_engine_dialog_ui_webui.h" |
21 #include "chrome/browser/ui/webui/task_manager_ui.h" | 22 #include "chrome/browser/ui/webui/task_manager_ui.h" |
22 #include "chrome/browser/ui/webui/flags_ui.h" | 23 #include "chrome/browser/ui/webui/flags_ui.h" |
23 #include "chrome/browser/ui/webui/flash_ui.h" | 24 #include "chrome/browser/ui/webui/flash_ui.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ChromeWebUI* NewWebUI<ExtensionWebUI>(TabContents* contents, const GURL& url) { | 97 ChromeWebUI* NewWebUI<ExtensionWebUI>(TabContents* contents, const GURL& url) { |
97 // Don't use a WebUI for incognito tabs because we require extensions to run | 98 // Don't use a WebUI for incognito tabs because we require extensions to run |
98 // within a single process. | 99 // within a single process. |
99 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | 100 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); |
100 ExtensionService* service = profile->GetExtensionService(); | 101 ExtensionService* service = profile->GetExtensionService(); |
101 if (service && service->ExtensionBindingsAllowed(url)) | 102 if (service && service->ExtensionBindingsAllowed(url)) |
102 return new ExtensionWebUI(contents, url); | 103 return new ExtensionWebUI(contents, url); |
103 return NULL; | 104 return NULL; |
104 } | 105 } |
105 | 106 |
| 107 // Special case for older about: handlers. |
| 108 template<> |
| 109 ChromeWebUI* NewWebUI<AboutUI>(TabContents* contents, const GURL& url) { |
| 110 return new AboutUI(contents, url.host()); |
| 111 } |
| 112 |
106 // Returns a function that can be used to create the right type of WebUI for a | 113 // Returns a function that can be used to create the right type of WebUI for a |
107 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 114 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
108 // with it. Even if the factory function is valid, it may yield a NULL WebUI | 115 // with it. Even if the factory function is valid, it may yield a NULL WebUI |
109 // when invoked for a particular tab - see NewWebUI<ExtensionWebUI>. | 116 // when invoked for a particular tab - see NewWebUI<ExtensionWebUI>. |
110 static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, | 117 WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, |
111 const GURL& url) { | 118 const GURL& url) { |
112 if (url.host() == chrome::kChromeUIDialogHost) | 119 if (url.host() == chrome::kChromeUIDialogHost) |
113 return &NewWebUI<ConstrainedHtmlUI>; | 120 return &NewWebUI<ConstrainedHtmlUI>; |
114 | 121 |
115 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; | 122 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; |
116 if (service && service->ExtensionBindingsAllowed(url)) | 123 if (service && service->ExtensionBindingsAllowed(url)) |
117 return &NewWebUI<ExtensionWebUI>; | 124 return &NewWebUI<ExtensionWebUI>; |
118 | 125 |
119 // All platform builds of Chrome will need to have a cloud printing | 126 // All platform builds of Chrome will need to have a cloud printing |
120 // dialog as backup. It's just that on Chrome OS, it's the only | 127 // dialog as backup. It's just that on Chrome OS, it's the only |
121 // print dialog. | 128 // print dialog. |
(...skipping 12 matching lines...) Expand all Loading... |
134 return &NewWebUI<HtmlDialogUI>; | 141 return &NewWebUI<HtmlDialogUI>; |
135 | 142 |
136 // Special case the new tab page. In older versions of Chrome, the new tab | 143 // Special case the new tab page. In older versions of Chrome, the new tab |
137 // page was hosted at chrome-internal:<blah>. This might be in people's saved | 144 // page was hosted at chrome-internal:<blah>. This might be in people's saved |
138 // sessions or bookmarks, so we say any URL with that scheme triggers the new | 145 // sessions or bookmarks, so we say any URL with that scheme triggers the new |
139 // tab page. | 146 // tab page. |
140 if (url.host() == chrome::kChromeUINewTabHost || | 147 if (url.host() == chrome::kChromeUINewTabHost || |
141 url.SchemeIs(chrome::kChromeInternalScheme)) | 148 url.SchemeIs(chrome::kChromeInternalScheme)) |
142 return &NewWebUI<NewTabUI>; | 149 return &NewWebUI<NewTabUI>; |
143 | 150 |
144 // Return a generic Web UI so chrome:chrome-urls can navigate to Web UI pages. | |
145 if (url.host() == chrome::kChromeUIAboutHost || | |
146 url.host() == chrome::kChromeUIChromeURLsHost) | |
147 return &NewWebUI<ChromeWebUI>; | |
148 | |
149 // We must compare hosts only since some of the Web UIs append extra stuff | 151 // We must compare hosts only since some of the Web UIs append extra stuff |
150 // after the host name. | 152 // after the host name. |
151 if (url.host() == chrome::kChromeUIBookmarksHost) | 153 if (url.host() == chrome::kChromeUIBookmarksHost) |
152 return &NewWebUI<BookmarksUI>; | 154 return &NewWebUI<BookmarksUI>; |
153 if (url.host() == chrome::kChromeUIBugReportHost) | 155 if (url.host() == chrome::kChromeUIBugReportHost) |
154 return &NewWebUI<BugReportUI>; | 156 return &NewWebUI<BugReportUI>; |
155 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 157 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
156 if (url.host() == chrome::kChromeUICertificateViewerHost) | 158 if (url.host() == chrome::kChromeUICertificateViewerHost) |
157 return &NewWebUI<CertificateViewerUI>; | 159 return &NewWebUI<CertificateViewerUI>; |
158 #endif | 160 #endif |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 // If the sync promo page is enabled then use the sync promo WebUI otherwise | 264 // If the sync promo page is enabled then use the sync promo WebUI otherwise |
263 // use the NTP WebUI. We don't want to return NULL if the sync promo page | 265 // use the NTP WebUI. We don't want to return NULL if the sync promo page |
264 // is disabled because the page can be disabled mid-flight (for example, | 266 // is disabled because the page can be disabled mid-flight (for example, |
265 // if sync login finishes). | 267 // if sync login finishes). |
266 if (SyncPromoUI::ShouldShowSyncPromo(profile)) | 268 if (SyncPromoUI::ShouldShowSyncPromo(profile)) |
267 return &NewWebUI<SyncPromoUI>; | 269 return &NewWebUI<SyncPromoUI>; |
268 else | 270 else |
269 return &NewWebUI<NewTabUI>; | 271 return &NewWebUI<NewTabUI>; |
270 } | 272 } |
271 #endif | 273 #endif |
| 274 |
| 275 if (url.host() == chrome::kChromeUIChromeURLsHost || |
| 276 url.host() == chrome::kChromeUICreditsHost || |
| 277 url.host() == chrome::kChromeUIDNSHost || |
| 278 url.host() == chrome::kChromeUIHistogramsHost || |
| 279 url.host() == chrome::kChromeUIMemoryHost || |
| 280 url.host() == chrome::kChromeUIMemoryRedirectHost || |
| 281 url.host() == chrome::kChromeUIStatsHost || |
| 282 url.host() == chrome::kChromeUITaskManagerHost || |
| 283 url.host() == chrome::kChromeUITermsHost || |
| 284 url.host() == chrome::kChromeUIVersionHost |
| 285 #if defined(USE_TCMALLOC) |
| 286 || url.host() == chrome::kChromeUITCMallocHost |
| 287 #endif |
| 288 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
| 289 || url.host() == chrome::kChromeUILinuxProxyConfigHost |
| 290 || url.host() == chrome::kChromeUISandboxHost |
| 291 #endif |
| 292 #if defined(OS_CHROMEOS) |
| 293 || url.host() == chrome::kChromeUICryptohomeHost |
| 294 || url.host() == chrome::kChromeUIDiscardsHost |
| 295 || url.host() == chrome::kChromeUINetworkHost |
| 296 || url.host() == chrome::kChromeUIOSCreditsHost |
| 297 #endif |
| 298 ) { |
| 299 return &NewWebUI<AboutUI>; |
| 300 } |
| 301 |
272 DLOG(WARNING) << "Unknown WebUI:" << url; | 302 DLOG(WARNING) << "Unknown WebUI:" << url; |
273 return NULL; | 303 return NULL; |
274 } | 304 } |
275 | 305 |
276 // When the test-type switch is set, return a TestType object, which should be a | 306 // When the test-type switch is set, return a TestType object, which should be a |
277 // subclass of Type. The logic is provided here in the traits class, rather than | 307 // subclass of Type. The logic is provided here in the traits class, rather than |
278 // in GetInstance() so that the choice is made only once, when the Singleton is | 308 // in GetInstance() so that the choice is made only once, when the Singleton is |
279 // first instantiated, rather than every time GetInstance() is called. | 309 // first instantiated, rather than every time GetInstance() is called. |
280 template<typename Type, typename TestType> | 310 template<typename Type, typename TestType> |
281 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { | 311 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 return FlashUI::GetFaviconResourceBytes(); | 436 return FlashUI::GetFaviconResourceBytes(); |
407 | 437 |
408 if (page_url.host() == chrome::kChromeUISettingsHost) | 438 if (page_url.host() == chrome::kChromeUISettingsHost) |
409 return OptionsUI::GetFaviconResourceBytes(); | 439 return OptionsUI::GetFaviconResourceBytes(); |
410 | 440 |
411 if (page_url.host() == chrome::kChromeUIPluginsHost) | 441 if (page_url.host() == chrome::kChromeUIPluginsHost) |
412 return PluginsUI::GetFaviconResourceBytes(); | 442 return PluginsUI::GetFaviconResourceBytes(); |
413 | 443 |
414 return NULL; | 444 return NULL; |
415 } | 445 } |
OLD | NEW |