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 return &NewWebUI<AboutUI>; | |
286 } | |
287 | |
288 #if defined(USE_TCMALLOC) | |
289 if (url.host() == chrome::kChromeUITCMallocHost) | |
Evan Stade
2011/11/22 02:27:44
nit: I would place these macro-guarded checks in t
Tom Sepez
2011/11/22 18:34:01
Will do. My personal preference has always been t
| |
290 return &NewWebUI<AboutUI>; | |
291 #endif | |
292 | |
293 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
294 if (url.host() == chrome::kChromeUILinuxProxyConfigHost || | |
295 url.host() == chrome::kChromeUISandboxHost) { | |
296 return &NewWebUI<AboutUI>; | |
297 } | |
298 #endif | |
299 | |
300 #if defined(OS_CHROMEOS) | |
301 if (url.host() == chrome::kChromeUICryptohomeHost || | |
302 url.host() == chrome::kChromeUIDiscardsHost || | |
303 url.host() == chrome::kChromeUINetworkHost || | |
304 url.host() == chrome::kChromeUIOSCreditsHost) { | |
305 return &NewWebUI<AboutUI>; | |
306 } | |
307 #endif | |
308 | |
272 DLOG(WARNING) << "Unknown WebUI:" << url; | 309 DLOG(WARNING) << "Unknown WebUI:" << url; |
273 return NULL; | 310 return NULL; |
274 } | 311 } |
275 | 312 |
276 // When the test-type switch is set, return a TestType object, which should be a | 313 // 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 | 314 // 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 | 315 // in GetInstance() so that the choice is made only once, when the Singleton is |
279 // first instantiated, rather than every time GetInstance() is called. | 316 // first instantiated, rather than every time GetInstance() is called. |
280 template<typename Type, typename TestType> | 317 template<typename Type, typename TestType> |
281 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { | 318 struct PossibleTestSingletonTraits : public DefaultSingletonTraits<Type> { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 return FlashUI::GetFaviconResourceBytes(); | 443 return FlashUI::GetFaviconResourceBytes(); |
407 | 444 |
408 if (page_url.host() == chrome::kChromeUISettingsHost) | 445 if (page_url.host() == chrome::kChromeUISettingsHost) |
409 return OptionsUI::GetFaviconResourceBytes(); | 446 return OptionsUI::GetFaviconResourceBytes(); |
410 | 447 |
411 if (page_url.host() == chrome::kChromeUIPluginsHost) | 448 if (page_url.host() == chrome::kChromeUIPluginsHost) |
412 return PluginsUI::GetFaviconResourceBytes(); | 449 return PluginsUI::GetFaviconResourceBytes(); |
413 | 450 |
414 return NULL; | 451 return NULL; |
415 } | 452 } |
OLD | NEW |