| 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 "content/browser/webui/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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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/remoting_ui.h" | 29 #include "chrome/browser/ui/webui/remoting_ui.h" |
| 30 #include "chrome/browser/ui/webui/slideshow_ui.h" | 30 #include "chrome/browser/ui/webui/slideshow_ui.h" |
| 31 #include "chrome/browser/ui/webui/sync_internals_ui.h" | 31 #include "chrome/browser/ui/webui/sync_internals_ui.h" |
| 32 #include "chrome/browser/ui/webui/textfields_ui.h" | 32 #include "chrome/browser/ui/webui/textfields_ui.h" |
| 33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
| 35 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 36 #include "content/browser/tab_contents/tab_contents.h" | 36 #include "content/browser/tab_contents/tab_contents.h" |
| 37 #include "content/browser/webui/web_ui.h" |
| 37 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
| 38 | 39 |
| 39 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
| 40 #include "chrome/browser/ui/webui/chromeos/imageburner_ui.h" | 41 #include "chrome/browser/ui/webui/chromeos/imageburner_ui.h" |
| 41 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h" | 42 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h" |
| 42 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h" | 43 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h" |
| 43 #include "chrome/browser/ui/webui/chromeos/proxy_settings_ui.h" | 44 #include "chrome/browser/ui/webui/chromeos/proxy_settings_ui.h" |
| 44 #include "chrome/browser/ui/webui/chromeos/register_page_ui.h" | 45 #include "chrome/browser/ui/webui/chromeos/register_page_ui.h" |
| 45 #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h" | 46 #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h" |
| 46 #include "chrome/browser/ui/webui/chromeos/system_info_ui.h" | 47 #include "chrome/browser/ui/webui/chromeos/system_info_ui.h" |
| 47 #include "chrome/browser/ui/webui/filebrowse_ui.h" | 48 #include "chrome/browser/ui/webui/filebrowse_ui.h" |
| 48 #include "chrome/browser/ui/webui/mediaplayer_ui.h" | 49 #include "chrome/browser/ui/webui/mediaplayer_ui.h" |
| 49 #endif | 50 #endif |
| 50 | 51 |
| 51 #if defined(TOUCH_UI) | 52 #if defined(TOUCH_UI) |
| 52 #include "chrome/browser/ui/webui/keyboard_ui.h" | 53 #include "chrome/browser/ui/webui/keyboard_ui.h" |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 55 #if defined(TOUCH_UI) && defined(OS_CHROMEOS) | 56 #if defined(TOUCH_UI) && defined(OS_CHROMEOS) |
| 56 #include "chrome/browser/chromeos/webui/login/login_container_ui.h" | 57 #include "chrome/browser/chromeos/webui/login/login_container_ui.h" |
| 57 #include "chrome/browser/chromeos/webui/login/login_ui.h" | 58 #include "chrome/browser/chromeos/webui/login/login_ui.h" |
| 58 #endif | 59 #endif |
| 59 | 60 |
| 60 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
| 61 #include "chrome/browser/ui/webui/conflicts_ui.h" | 62 #include "chrome/browser/ui/webui/conflicts_ui.h" |
| 62 #endif | 63 #endif |
| 63 | 64 |
| 64 const WebUITypeID WebUIFactory::kNoWebUI = NULL; | 65 namespace { |
| 65 | 66 |
| 66 // A function for creating a new WebUI. The caller owns the return value, which | 67 // A function for creating a new WebUI. The caller owns the return value, which |
| 67 // may be NULL (for example, if the URL refers to an non-existent extension). | 68 // may be NULL (for example, if the URL refers to an non-existent extension). |
| 68 typedef WebUI* (*WebUIFactoryFunction)(TabContents* tab_contents, | 69 typedef WebUI* (*WebUIFactoryFunction)(TabContents* tab_contents, |
| 69 const GURL& url); | 70 const GURL& url); |
| 70 | 71 |
| 71 // Template for defining WebUIFactoryFunction. | 72 // Template for defining WebUIFactoryFunction. |
| 72 template<class T> | 73 template<class T> |
| 73 WebUI* NewWebUI(TabContents* contents, const GURL& url) { | 74 WebUI* NewWebUI(TabContents* contents, const GURL& url) { |
| 74 return new T(contents); | 75 return new T(contents); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 return new ExtensionWebUI(contents, url); | 86 return new ExtensionWebUI(contents, url); |
| 86 } | 87 } |
| 87 return NULL; | 88 return NULL; |
| 88 } | 89 } |
| 89 | 90 |
| 90 // Returns a function that can be used to create the right type of WebUI for a | 91 // Returns a function that can be used to create the right type of WebUI for a |
| 91 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 92 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
| 92 // with it. Even if the factory function is valid, it may yield a NULL WebUI | 93 // with it. Even if the factory function is valid, it may yield a NULL WebUI |
| 93 // when invoked for a particular tab - see NewWebUI<ExtensionWebUI>. | 94 // when invoked for a particular tab - see NewWebUI<ExtensionWebUI>. |
| 94 static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, | 95 static WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, |
| 95 const GURL& url) { | 96 const GURL& url) { |
| 96 if (url.host() == chrome::kChromeUIDialogHost) | 97 if (url.host() == chrome::kChromeUIDialogHost) |
| 97 return &NewWebUI<ConstrainedHtmlUI>; | 98 return &NewWebUI<ConstrainedHtmlUI>; |
| 98 | 99 |
| 99 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; | 100 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; |
| 100 if (service && service->ExtensionBindingsAllowed(url)) | 101 if (service && service->ExtensionBindingsAllowed(url)) |
| 101 return &NewWebUI<ExtensionWebUI>; | 102 return &NewWebUI<ExtensionWebUI>; |
| 102 | 103 |
| 103 // All platform builds of Chrome will need to have a cloud printing | 104 // All platform builds of Chrome will need to have a cloud printing |
| 104 // dialog as backup. It's just that on Chrome OS, it's the only | 105 // dialog as backup. It's just that on Chrome OS, it's the only |
| 105 // print dialog. | 106 // print dialog. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 if (url.host() == chrome::kChromeUILoginContainerHost) | 220 if (url.host() == chrome::kChromeUILoginContainerHost) |
| 220 return &NewWebUI<chromeos::LoginContainerUI>; | 221 return &NewWebUI<chromeos::LoginContainerUI>; |
| 221 #endif | 222 #endif |
| 222 | 223 |
| 223 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL) | 224 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL) |
| 224 return &NewWebUI<ConstrainedHtmlUI>; | 225 return &NewWebUI<ConstrainedHtmlUI>; |
| 225 | 226 |
| 226 return NULL; | 227 return NULL; |
| 227 } | 228 } |
| 228 | 229 |
| 229 // static | 230 } // namespace |
| 230 WebUITypeID WebUIFactory::GetWebUIType(Profile* profile, const GURL& url) { | 231 |
| 232 WebUI::WebUITypeID ChromeWebUIFactory::GetWebUIType(Profile* profile, |
| 233 const GURL& url) const { |
| 231 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); | 234 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); |
| 232 return function ? reinterpret_cast<WebUITypeID>(function) : kNoWebUI; | 235 return function ? reinterpret_cast<WebUI::WebUITypeID>(function) : |
| 236 WebUI::kNoWebUI; |
| 233 } | 237 } |
| 234 | 238 |
| 235 // static | 239 bool ChromeWebUIFactory::UseWebUIForURL(Profile* profile, |
| 236 bool WebUIFactory::HasWebUIScheme(const GURL& url) { | 240 const GURL& url) const { |
| 241 return GetWebUIType(profile, url) != WebUI::kNoWebUI; |
| 242 } |
| 243 |
| 244 bool ChromeWebUIFactory::HasWebUIScheme(const GURL& url) const { |
| 237 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 245 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
| 238 url.SchemeIs(chrome::kChromeInternalScheme) || | 246 url.SchemeIs(chrome::kChromeInternalScheme) || |
| 239 url.SchemeIs(chrome::kChromeUIScheme) || | 247 url.SchemeIs(chrome::kChromeUIScheme) || |
| 240 url.SchemeIs(chrome::kExtensionScheme); | 248 url.SchemeIs(chrome::kExtensionScheme); |
| 241 } | 249 } |
| 242 | 250 |
| 243 // static | 251 bool ChromeWebUIFactory::IsURLAcceptableForWebUI(Profile* profile, |
| 244 bool WebUIFactory::UseWebUIForURL(Profile* profile, const GURL& url) { | 252 const GURL& url) const { |
| 245 return GetWebUIFactoryFunction(profile, url) != NULL; | |
| 246 } | |
| 247 | |
| 248 // static | |
| 249 bool WebUIFactory::IsURLAcceptableForWebUI(Profile* profile, const GURL& url) { | |
| 250 return UseWebUIForURL(profile, url) || | 253 return UseWebUIForURL(profile, url) || |
| 251 // javacsript: URLs are allowed to run in Web UI pages | 254 // javacsript: URLs are allowed to run in Web UI pages |
| 252 url.SchemeIs(chrome::kJavaScriptScheme) || | 255 url.SchemeIs(chrome::kJavaScriptScheme) || |
| 253 // It's possible to load about:blank in a Web UI renderer. | 256 // It's possible to load about:blank in a Web UI renderer. |
| 254 // See http://crbug.com/42547 | 257 // See http://crbug.com/42547 |
| 255 url.spec() == chrome::kAboutBlankURL || | 258 url.spec() == chrome::kAboutBlankURL || |
| 256 // about:crash, about:kill, about:hang, and about:shorthang are allowed. | 259 // about:crash, about:kill, about:hang, and about:shorthang are allowed. |
| 257 url.spec() == chrome::kAboutCrashURL || | 260 url.spec() == chrome::kAboutCrashURL || |
| 258 url.spec() == chrome::kAboutKillURL || | 261 url.spec() == chrome::kAboutKillURL || |
| 259 url.spec() == chrome::kAboutHangURL || | 262 url.spec() == chrome::kAboutHangURL || |
| 260 url.spec() == chrome::kAboutShorthangURL; | 263 url.spec() == chrome::kAboutShorthangURL; |
| 261 } | 264 } |
| 262 | 265 |
| 263 // static | 266 WebUI* ChromeWebUIFactory::CreateWebUIForURL(TabContents* tab_contents, |
| 264 WebUI* WebUIFactory::CreateWebUIForURL(TabContents* tab_contents, | 267 const GURL& url) const { |
| 265 const GURL& url) { | |
| 266 WebUIFactoryFunction function = GetWebUIFactoryFunction( | 268 WebUIFactoryFunction function = GetWebUIFactoryFunction( |
| 267 tab_contents->profile(), url); | 269 tab_contents->profile(), url); |
| 268 if (!function) | 270 if (!function) |
| 269 return NULL; | 271 return NULL; |
| 270 return (*function)(tab_contents, url); | 272 return (*function)(tab_contents, url); |
| 271 } | 273 } |
| 272 | 274 |
| 273 // static | 275 void ChromeWebUIFactory::GetFaviconForURL(Profile* profile, |
| 274 void WebUIFactory::GetFaviconForURL(Profile* profile, | |
| 275 FaviconService::GetFaviconRequest* request, | 276 FaviconService::GetFaviconRequest* request, |
| 276 const GURL& page_url) { | 277 const GURL& page_url) const { |
| 277 // All extensions but the bookmark manager get their favicon from the icons | 278 // All extensions but the bookmark manager get their favicon from the icons |
| 278 // part of the manifest. | 279 // part of the manifest. |
| 279 if (page_url.SchemeIs(chrome::kExtensionScheme) && | 280 if (page_url.SchemeIs(chrome::kExtensionScheme) && |
| 280 page_url.host() != extension_misc::kBookmarkManagerId) { | 281 page_url.host() != extension_misc::kBookmarkManagerId) { |
| 281 ExtensionWebUI::GetFaviconForURL(profile, request, page_url); | 282 ExtensionWebUI::GetFaviconForURL(profile, request, page_url); |
| 282 } else { | 283 } else { |
| 283 history::FaviconData favicon; | 284 history::FaviconData favicon; |
| 284 favicon.image_data = scoped_refptr<RefCountedMemory>( | 285 favicon.image_data = scoped_refptr<RefCountedMemory>( |
| 285 WebUIFactory::GetFaviconResourceBytes(profile, page_url)); | 286 GetFaviconResourceBytes(profile, page_url)); |
| 286 favicon.known_icon = favicon.image_data.get() != NULL && | 287 favicon.known_icon = favicon.image_data.get() != NULL && |
| 287 favicon.image_data->size() > 0; | 288 favicon.image_data->size() > 0; |
| 288 request->ForwardResultAsync( | 289 request->ForwardResultAsync( |
| 289 FaviconService::FaviconDataCallback::TupleType(request->handle(), | 290 FaviconService::FaviconDataCallback::TupleType(request->handle(), |
| 290 favicon)); | 291 favicon)); |
| 291 } | 292 } |
| 292 } | 293 } |
| 293 | 294 |
| 294 // static | 295 // static |
| 295 RefCountedMemory* WebUIFactory::GetFaviconResourceBytes(Profile* profile, | 296 ChromeWebUIFactory* ChromeWebUIFactory::GetInstance() { |
| 296 const GURL& page_url) { | 297 return Singleton<ChromeWebUIFactory>::get(); |
| 298 } |
| 299 |
| 300 ChromeWebUIFactory::ChromeWebUIFactory() { |
| 301 } |
| 302 |
| 303 ChromeWebUIFactory::~ChromeWebUIFactory() { |
| 304 } |
| 305 |
| 306 RefCountedMemory* ChromeWebUIFactory::GetFaviconResourceBytes( |
| 307 Profile* profile, |
| 308 const GURL& page_url) const { |
| 297 // The bookmark manager is a chrome extension, so we have to check for it | 309 // The bookmark manager is a chrome extension, so we have to check for it |
| 298 // before we check for extension scheme. | 310 // before we check for extension scheme. |
| 299 if (page_url.host() == extension_misc::kBookmarkManagerId) | 311 if (page_url.host() == extension_misc::kBookmarkManagerId) |
| 300 return BookmarksUI::GetFaviconResourceBytes(); | 312 return BookmarksUI::GetFaviconResourceBytes(); |
| 301 | 313 |
| 302 // The extension scheme is handled in GetFaviconForURL. | 314 // The extension scheme is handled in GetFaviconForURL. |
| 303 if (page_url.SchemeIs(chrome::kExtensionScheme)) { | 315 if (page_url.SchemeIs(chrome::kExtensionScheme)) { |
| 304 NOTREACHED(); | 316 NOTREACHED(); |
| 305 return NULL; | 317 return NULL; |
| 306 } | 318 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 337 if (page_url.host() == chrome::kChromeUIPluginsHost) | 349 if (page_url.host() == chrome::kChromeUIPluginsHost) |
| 338 return PluginsUI::GetFaviconResourceBytes(); | 350 return PluginsUI::GetFaviconResourceBytes(); |
| 339 | 351 |
| 340 #if defined(ENABLE_REMOTING) | 352 #if defined(ENABLE_REMOTING) |
| 341 if (page_url.host() == chrome::kChromeUIRemotingHost) | 353 if (page_url.host() == chrome::kChromeUIRemotingHost) |
| 342 return RemotingUI::GetFaviconResourceBytes(); | 354 return RemotingUI::GetFaviconResourceBytes(); |
| 343 #endif | 355 #endif |
| 344 | 356 |
| 345 return NULL; | 357 return NULL; |
| 346 } | 358 } |
| OLD | NEW |