| 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/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 WebUIFactory::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 WebUIFactory::UseWebUIForURL(Profile* profile, const GURL& url) const { |
| 236 bool WebUIFactory::HasWebUIScheme(const GURL& url) { | 240 return GetWebUIType(profile, url) != WebUI::kNoWebUI; |
| 241 } |
| 242 |
| 243 bool WebUIFactory::HasWebUIScheme(const GURL& url) const { |
| 237 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 244 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
| 238 url.SchemeIs(chrome::kChromeInternalScheme) || | 245 url.SchemeIs(chrome::kChromeInternalScheme) || |
| 239 url.SchemeIs(chrome::kChromeUIScheme) || | 246 url.SchemeIs(chrome::kChromeUIScheme) || |
| 240 url.SchemeIs(chrome::kExtensionScheme); | 247 url.SchemeIs(chrome::kExtensionScheme); |
| 241 } | 248 } |
| 242 | 249 |
| 243 // static | 250 bool WebUIFactory::IsURLAcceptableForWebUI(Profile* profile, |
| 244 bool WebUIFactory::UseWebUIForURL(Profile* profile, const GURL& url) { | 251 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) || | 252 return UseWebUIForURL(profile, url) || |
| 251 // javacsript: URLs are allowed to run in Web UI pages | 253 // javacsript: URLs are allowed to run in Web UI pages |
| 252 url.SchemeIs(chrome::kJavaScriptScheme) || | 254 url.SchemeIs(chrome::kJavaScriptScheme) || |
| 253 // It's possible to load about:blank in a Web UI renderer. | 255 // It's possible to load about:blank in a Web UI renderer. |
| 254 // See http://crbug.com/42547 | 256 // See http://crbug.com/42547 |
| 255 url.spec() == chrome::kAboutBlankURL || | 257 url.spec() == chrome::kAboutBlankURL || |
| 256 // about:crash, about:kill, about:hang, and about:shorthang are allowed. | 258 // about:crash, about:kill, about:hang, and about:shorthang are allowed. |
| 257 url.spec() == chrome::kAboutCrashURL || | 259 url.spec() == chrome::kAboutCrashURL || |
| 258 url.spec() == chrome::kAboutKillURL || | 260 url.spec() == chrome::kAboutKillURL || |
| 259 url.spec() == chrome::kAboutHangURL || | 261 url.spec() == chrome::kAboutHangURL || |
| 260 url.spec() == chrome::kAboutShorthangURL; | 262 url.spec() == chrome::kAboutShorthangURL; |
| 261 } | 263 } |
| 262 | 264 |
| 263 // static | |
| 264 WebUI* WebUIFactory::CreateWebUIForURL(TabContents* tab_contents, | 265 WebUI* WebUIFactory::CreateWebUIForURL(TabContents* tab_contents, |
| 265 const GURL& url) { | 266 const GURL& url) const { |
| 266 WebUIFactoryFunction function = GetWebUIFactoryFunction( | 267 WebUIFactoryFunction function = GetWebUIFactoryFunction( |
| 267 tab_contents->profile(), url); | 268 tab_contents->profile(), url); |
| 268 if (!function) | 269 if (!function) |
| 269 return NULL; | 270 return NULL; |
| 270 return (*function)(tab_contents, url); | 271 return (*function)(tab_contents, url); |
| 271 } | 272 } |
| 272 | 273 |
| 273 // static | |
| 274 void WebUIFactory::GetFaviconForURL(Profile* profile, | 274 void WebUIFactory::GetFaviconForURL(Profile* profile, |
| 275 FaviconService::GetFaviconRequest* request, | 275 FaviconService::GetFaviconRequest* request, |
| 276 const GURL& page_url) { | 276 const GURL& page_url) const { |
| 277 // All extensions but the bookmark manager get their favicon from the icons | 277 // All extensions but the bookmark manager get their favicon from the icons |
| 278 // part of the manifest. | 278 // part of the manifest. |
| 279 if (page_url.SchemeIs(chrome::kExtensionScheme) && | 279 if (page_url.SchemeIs(chrome::kExtensionScheme) && |
| 280 page_url.host() != extension_misc::kBookmarkManagerId) { | 280 page_url.host() != extension_misc::kBookmarkManagerId) { |
| 281 ExtensionWebUI::GetFaviconForURL(profile, request, page_url); | 281 ExtensionWebUI::GetFaviconForURL(profile, request, page_url); |
| 282 } else { | 282 } else { |
| 283 history::FaviconData favicon; | 283 history::FaviconData favicon; |
| 284 favicon.image_data = scoped_refptr<RefCountedMemory>( | 284 favicon.image_data = scoped_refptr<RefCountedMemory>( |
| 285 WebUIFactory::GetFaviconResourceBytes(profile, page_url)); | 285 GetFaviconResourceBytes(profile, page_url)); |
| 286 favicon.known_icon = favicon.image_data.get() != NULL && | 286 favicon.known_icon = favicon.image_data.get() != NULL && |
| 287 favicon.image_data->size() > 0; | 287 favicon.image_data->size() > 0; |
| 288 request->ForwardResultAsync( | 288 request->ForwardResultAsync( |
| 289 FaviconService::FaviconDataCallback::TupleType(request->handle(), | 289 FaviconService::FaviconDataCallback::TupleType(request->handle(), |
| 290 favicon)); | 290 favicon)); |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 | 293 |
| 294 // static | 294 // static |
| 295 RefCountedMemory* WebUIFactory::GetFaviconResourceBytes(Profile* profile, | 295 WebUIFactory* WebUIFactory::GetInstance() { |
| 296 const GURL& page_url) { | 296 return Singleton<WebUIFactory>::get(); |
| 297 } |
| 298 |
| 299 WebUIFactory::WebUIFactory() { |
| 300 } |
| 301 |
| 302 WebUIFactory::~WebUIFactory() { |
| 303 } |
| 304 |
| 305 RefCountedMemory* WebUIFactory::GetFaviconResourceBytes( |
| 306 Profile* profile, |
| 307 const GURL& page_url) const { |
| 297 // The bookmark manager is a chrome extension, so we have to check for it | 308 // The bookmark manager is a chrome extension, so we have to check for it |
| 298 // before we check for extension scheme. | 309 // before we check for extension scheme. |
| 299 if (page_url.host() == extension_misc::kBookmarkManagerId) | 310 if (page_url.host() == extension_misc::kBookmarkManagerId) |
| 300 return BookmarksUI::GetFaviconResourceBytes(); | 311 return BookmarksUI::GetFaviconResourceBytes(); |
| 301 | 312 |
| 302 // The extension scheme is handled in GetFaviconForURL. | 313 // The extension scheme is handled in GetFaviconForURL. |
| 303 if (page_url.SchemeIs(chrome::kExtensionScheme)) { | 314 if (page_url.SchemeIs(chrome::kExtensionScheme)) { |
| 304 NOTREACHED(); | 315 NOTREACHED(); |
| 305 return NULL; | 316 return NULL; |
| 306 } | 317 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 337 if (page_url.host() == chrome::kChromeUIPluginsHost) | 348 if (page_url.host() == chrome::kChromeUIPluginsHost) |
| 338 return PluginsUI::GetFaviconResourceBytes(); | 349 return PluginsUI::GetFaviconResourceBytes(); |
| 339 | 350 |
| 340 #if defined(ENABLE_REMOTING) | 351 #if defined(ENABLE_REMOTING) |
| 341 if (page_url.host() == chrome::kChromeUIRemotingHost) | 352 if (page_url.host() == chrome::kChromeUIRemotingHost) |
| 342 return RemotingUI::GetFaviconResourceBytes(); | 353 return RemotingUI::GetFaviconResourceBytes(); |
| 343 #endif | 354 #endif |
| 344 | 355 |
| 345 return NULL; | 356 return NULL; |
| 346 } | 357 } |
| OLD | NEW |