| 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/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/browser/ui/webui/about_ui.h" | 15 #include "chrome/browser/ui/webui/about_ui.h" |
| 15 #include "chrome/browser/ui/webui/bookmarks_ui.h" | 16 #include "chrome/browser/ui/webui/bookmarks_ui.h" |
| 16 #include "chrome/browser/ui/webui/bug_report_ui.h" | 17 #include "chrome/browser/ui/webui/bug_report_ui.h" |
| 17 #include "chrome/browser/ui/webui/constrained_html_ui.h" | 18 #include "chrome/browser/ui/webui/constrained_html_ui.h" |
| 18 #include "chrome/browser/ui/webui/crashes_ui.h" | 19 #include "chrome/browser/ui/webui/crashes_ui.h" |
| 19 #include "chrome/browser/ui/webui/devtools_ui.h" | 20 #include "chrome/browser/ui/webui/devtools_ui.h" |
| 20 #include "chrome/browser/ui/webui/downloads_ui.h" | 21 #include "chrome/browser/ui/webui/downloads_ui.h" |
| 21 #include "chrome/browser/ui/webui/edit_search_engine_dialog_ui_webui.h" | 22 #include "chrome/browser/ui/webui/edit_search_engine_dialog_ui_webui.h" |
| 22 #include "chrome/browser/ui/webui/task_manager_ui.h" | 23 #include "chrome/browser/ui/webui/task_manager_ui.h" |
| 23 #include "chrome/browser/ui/webui/flags_ui.h" | 24 #include "chrome/browser/ui/webui/flags_ui.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 89 |
| 89 // Template for defining WebUIFactoryFunction. | 90 // Template for defining WebUIFactoryFunction. |
| 90 template<class T> | 91 template<class T> |
| 91 ChromeWebUI* NewWebUI(TabContents* contents, const GURL& url) { | 92 ChromeWebUI* NewWebUI(TabContents* contents, const GURL& url) { |
| 92 return new T(contents); | 93 return new T(contents); |
| 93 } | 94 } |
| 94 | 95 |
| 95 // Special case for extensions. | 96 // Special case for extensions. |
| 96 template<> | 97 template<> |
| 97 ChromeWebUI* NewWebUI<ExtensionWebUI>(TabContents* contents, const GURL& url) { | 98 ChromeWebUI* NewWebUI<ExtensionWebUI>(TabContents* contents, const GURL& url) { |
| 98 // Don't use a WebUI for incognito tabs because we require extensions to run | 99 return new ExtensionWebUI(contents, url); |
| 99 // within a single process. | |
| 100 Profile* profile = Profile::FromBrowserContext(contents->browser_context()); | |
| 101 ExtensionService* service = profile->GetExtensionService(); | |
| 102 if (service && service->ExtensionBindingsAllowed(url)) | |
| 103 return new ExtensionWebUI(contents, url); | |
| 104 return NULL; | |
| 105 } | 100 } |
| 106 | 101 |
| 107 // Special case for older about: handlers. | 102 // Special case for older about: handlers. |
| 108 template<> | 103 template<> |
| 109 ChromeWebUI* NewWebUI<AboutUI>(TabContents* contents, const GURL& url) { | 104 ChromeWebUI* NewWebUI<AboutUI>(TabContents* contents, const GURL& url) { |
| 110 return new AboutUI(contents, url.host()); | 105 return new AboutUI(contents, url.host()); |
| 111 } | 106 } |
| 112 | 107 |
| 113 // Returns a function that can be used to create the right type of WebUI for a | 108 // Returns a function that can be used to create the right type of WebUI for a |
| 114 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 109 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
| 115 // with it. Even if the factory function is valid, it may yield a NULL WebUI | 110 // with it. |
| 116 // when invoked for a particular tab - see NewWebUI<ExtensionWebUI>. | 111 WebUIFactoryFunction GetWebUIFactoryFunction(TabContents* tab_contents, |
| 117 WebUIFactoryFunction GetWebUIFactoryFunction(Profile* profile, | 112 Profile* profile, |
| 118 const GURL& url) { | 113 const GURL& url) { |
| 119 if (url.host() == chrome::kChromeUIDialogHost) | 114 if (url.host() == chrome::kChromeUIDialogHost) |
| 120 return &NewWebUI<ConstrainedHtmlUI>; | 115 return &NewWebUI<ConstrainedHtmlUI>; |
| 121 | 116 |
| 117 // Only create ExtensionWebUI for URLs that are allowed extension bindings, |
| 118 // hosted by actual tabs. If tab_contents has no wrapper, it likely refers |
| 119 // to another container type, like an extension background page. |
| 122 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; | 120 ExtensionService* service = profile ? profile->GetExtensionService() : NULL; |
| 123 if (service && service->ExtensionBindingsAllowed(url)) | 121 if (service && service->ExtensionBindingsAllowed(url) && |
| 124 return &NewWebUI<ExtensionWebUI>; | 122 (!tab_contents || |
| 123 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents))) |
| 124 return &NewWebUI<ExtensionWebUI>; |
| 125 | 125 |
| 126 // 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 |
| 127 // 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 |
| 128 // print dialog. | 128 // print dialog. |
| 129 if (url.host() == chrome::kChromeUICloudPrintResourcesHost) | 129 if (url.host() == chrome::kChromeUICloudPrintResourcesHost) |
| 130 return &NewWebUI<ExternalHtmlDialogUI>; | 130 return &NewWebUI<ExternalHtmlDialogUI>; |
| 131 | 131 |
| 132 // This will get called a lot to check all URLs, so do a quick check of other | 132 // This will get called a lot to check all URLs, so do a quick check of other |
| 133 // schemes to filter out most URLs. | 133 // schemes to filter out most URLs. |
| 134 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && | 134 if (!url.SchemeIs(chrome::kChromeDevToolsScheme) && |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 else | 315 else |
| 316 return DefaultSingletonTraits<Type>::New(); | 316 return DefaultSingletonTraits<Type>::New(); |
| 317 } | 317 } |
| 318 }; | 318 }; |
| 319 | 319 |
| 320 } // namespace | 320 } // namespace |
| 321 | 321 |
| 322 WebUI::TypeID ChromeWebUIFactory::GetWebUIType( | 322 WebUI::TypeID ChromeWebUIFactory::GetWebUIType( |
| 323 content::BrowserContext* browser_context, const GURL& url) const { | 323 content::BrowserContext* browser_context, const GURL& url) const { |
| 324 Profile* profile = Profile::FromBrowserContext(browser_context); | 324 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 325 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); | 325 WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, profile, url); |
| 326 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; | 326 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; |
| 327 } | 327 } |
| 328 | 328 |
| 329 bool ChromeWebUIFactory::UseWebUIForURL( | 329 bool ChromeWebUIFactory::UseWebUIForURL( |
| 330 content::BrowserContext* browser_context, const GURL& url) const { | 330 content::BrowserContext* browser_context, const GURL& url) const { |
| 331 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; | 331 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; |
| 332 } | 332 } |
| 333 | 333 |
| 334 bool ChromeWebUIFactory::HasWebUIScheme(const GURL& url) const { | 334 bool ChromeWebUIFactory::HasWebUIScheme(const GURL& url) const { |
| 335 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 335 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
| (...skipping 15 matching lines...) Expand all Loading... |
| 351 url == GURL(chrome::kChromeUIKillURL) || | 351 url == GURL(chrome::kChromeUIKillURL) || |
| 352 url == GURL(chrome::kChromeUIHangURL) || | 352 url == GURL(chrome::kChromeUIHangURL) || |
| 353 url == GURL(chrome::kChromeUIShorthangURL); | 353 url == GURL(chrome::kChromeUIShorthangURL); |
| 354 } | 354 } |
| 355 | 355 |
| 356 WebUI* ChromeWebUIFactory::CreateWebUIForURL( | 356 WebUI* ChromeWebUIFactory::CreateWebUIForURL( |
| 357 TabContents* tab_contents, | 357 TabContents* tab_contents, |
| 358 const GURL& url) const { | 358 const GURL& url) const { |
| 359 Profile* profile = | 359 Profile* profile = |
| 360 Profile::FromBrowserContext(tab_contents->browser_context()); | 360 Profile::FromBrowserContext(tab_contents->browser_context()); |
| 361 WebUIFactoryFunction function = GetWebUIFactoryFunction(profile, url); | 361 WebUIFactoryFunction function = GetWebUIFactoryFunction(tab_contents, |
| 362 profile, url); |
| 362 if (!function) | 363 if (!function) |
| 363 return NULL; | 364 return NULL; |
| 364 return (*function)(tab_contents, url); | 365 return (*function)(tab_contents, url); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void ChromeWebUIFactory::GetFaviconForURL( | 368 void ChromeWebUIFactory::GetFaviconForURL( |
| 368 Profile* profile, | 369 Profile* profile, |
| 369 FaviconService::GetFaviconRequest* request, | 370 FaviconService::GetFaviconRequest* request, |
| 370 const GURL& page_url) const { | 371 const GURL& page_url) const { |
| 371 // All extensions but the bookmark manager get their favicon from the icons | 372 // All extensions but the bookmark manager get their favicon from the icons |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 return FlashUI::GetFaviconResourceBytes(); | 437 return FlashUI::GetFaviconResourceBytes(); |
| 437 | 438 |
| 438 if (page_url.host() == chrome::kChromeUISettingsHost) | 439 if (page_url.host() == chrome::kChromeUISettingsHost) |
| 439 return OptionsUI::GetFaviconResourceBytes(); | 440 return OptionsUI::GetFaviconResourceBytes(); |
| 440 | 441 |
| 441 if (page_url.host() == chrome::kChromeUIPluginsHost) | 442 if (page_url.host() == chrome::kChromeUIPluginsHost) |
| 442 return PluginsUI::GetFaviconResourceBytes(); | 443 return PluginsUI::GetFaviconResourceBytes(); |
| 443 | 444 |
| 444 return NULL; | 445 return NULL; |
| 445 } | 446 } |
| OLD | NEW |