OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_controller_factory.h" | 5 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // may be NULL (for example, if the URL refers to an non-existent extension). | 209 // may be NULL (for example, if the URL refers to an non-existent extension). |
210 typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui, | 210 typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui, |
211 const GURL& url); | 211 const GURL& url); |
212 | 212 |
213 // Template for defining WebUIFactoryFunction. | 213 // Template for defining WebUIFactoryFunction. |
214 template<class T> | 214 template<class T> |
215 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { | 215 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { |
216 return new T(web_ui); | 216 return new T(web_ui); |
217 } | 217 } |
218 | 218 |
219 #if defined(ENABLE_EXTENSIONS) | |
220 // Special cases for extensions. | |
221 template<> | |
222 WebUIController* NewWebUI<ExtensionWebUI>(WebUI* web_ui, | |
223 const GURL& url) { | |
224 return new ExtensionWebUI(web_ui, url); | |
225 } | |
226 #endif // defined(ENABLE_EXTENSIONS) | |
227 | |
228 // Special case for older about: handlers. | 219 // Special case for older about: handlers. |
229 template<> | 220 template<> |
230 WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) { | 221 WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) { |
231 return new AboutUI(web_ui, url.host()); | 222 return new AboutUI(web_ui, url.host()); |
232 } | 223 } |
233 | 224 |
234 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
235 template<> | 226 template<> |
236 WebUIController* NewWebUI<chromeos::OobeUI>(WebUI* web_ui, const GURL& url) { | 227 WebUIController* NewWebUI<chromeos::OobeUI>(WebUI* web_ui, const GURL& url) { |
237 return new chromeos::OobeUI(web_ui, url); | 228 return new chromeos::OobeUI(web_ui, url); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 #endif | 296 #endif |
306 ); // NOLINT | 297 ); // NOLINT |
307 } | 298 } |
308 | 299 |
309 // Returns a function that can be used to create the right type of WebUI for a | 300 // Returns a function that can be used to create the right type of WebUI for a |
310 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 301 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
311 // with it. | 302 // with it. |
312 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, | 303 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, |
313 Profile* profile, | 304 Profile* profile, |
314 const GURL& url) { | 305 const GURL& url) { |
315 #if defined(ENABLE_EXTENSIONS) | |
316 if (ExtensionWebUI::NeedsExtensionWebUI(profile, url)) | |
317 return &NewWebUI<ExtensionWebUI>; | |
318 #endif | |
319 | |
320 // This will get called a lot to check all URLs, so do a quick check of other | 306 // This will get called a lot to check all URLs, so do a quick check of other |
321 // schemes to filter out most URLs. | 307 // schemes to filter out most URLs. |
322 if (!url.SchemeIs(content::kChromeDevToolsScheme) && | 308 if (!url.SchemeIs(content::kChromeDevToolsScheme) && |
323 !url.SchemeIs(content::kChromeUIScheme)) { | 309 !url.SchemeIs(content::kChromeUIScheme)) { |
324 return NULL; | 310 return NULL; |
325 } | 311 } |
326 | 312 |
327 /**************************************************************************** | 313 /**************************************************************************** |
328 * Please keep this in alphabetical order. If #ifs or special logics are | 314 * Please keep this in alphabetical order. If #ifs or special logics are |
329 * required, add it below in the appropriate section. | 315 * required, add it below in the appropriate section. |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; | 650 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; |
665 } | 651 } |
666 | 652 |
667 bool ChromeWebUIControllerFactory::UseWebUIForURL( | 653 bool ChromeWebUIControllerFactory::UseWebUIForURL( |
668 content::BrowserContext* browser_context, const GURL& url) const { | 654 content::BrowserContext* browser_context, const GURL& url) const { |
669 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; | 655 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; |
670 } | 656 } |
671 | 657 |
672 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( | 658 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( |
673 content::BrowserContext* browser_context, const GURL& url) const { | 659 content::BrowserContext* browser_context, const GURL& url) const { |
674 bool needs_extensions_web_ui = false; | 660 return UseWebUIForURL(browser_context, url); |
675 #if defined(ENABLE_EXTENSIONS) | |
676 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI | |
677 // bindings (see the ExtensionWebUI constructor). | |
678 needs_extensions_web_ui = | |
679 ExtensionWebUI::NeedsExtensionWebUI(browser_context, url); | |
680 #endif | |
681 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url); | |
682 } | 661 } |
683 | 662 |
684 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( | 663 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( |
685 WebUI* web_ui, | 664 WebUI* web_ui, |
686 const GURL& url) const { | 665 const GURL& url) const { |
687 Profile* profile = Profile::FromWebUI(web_ui); | 666 Profile* profile = Profile::FromWebUI(web_ui); |
688 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); | 667 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); |
689 if (!function) | 668 if (!function) |
690 return NULL; | 669 return NULL; |
691 | 670 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 #endif | 813 #endif |
835 | 814 |
836 // Android doesn't use the plugins pages. | 815 // Android doesn't use the plugins pages. |
837 if (page_url.host() == chrome::kChromeUIPluginsHost) | 816 if (page_url.host() == chrome::kChromeUIPluginsHost) |
838 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 817 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
839 | 818 |
840 #endif | 819 #endif |
841 | 820 |
842 return NULL; | 821 return NULL; |
843 } | 822 } |
OLD | NEW |