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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 #endif // !defined(OS_CHROMEOS) | 278 #endif // !defined(OS_CHROMEOS) |
279 #endif // !defined(OS_ANDROID) | 279 #endif // !defined(OS_ANDROID) |
280 | 280 |
281 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
282 template <> | 282 template <> |
283 WebUIController* NewWebUI<WelcomeWin10UI>(WebUI* web_ui, const GURL& url) { | 283 WebUIController* NewWebUI<WelcomeWin10UI>(WebUI* web_ui, const GURL& url) { |
284 return new WelcomeWin10UI(web_ui, url); | 284 return new WelcomeWin10UI(web_ui, url); |
285 } | 285 } |
286 #endif // defined(OS_WIN) | 286 #endif // defined(OS_WIN) |
287 | 287 |
| 288 #if defined(ENABLE_EXTENSIONS) |
| 289 // Only create ExtensionWebUI for URLs that are allowed extension bindings, |
| 290 // hosted by actual tabs. |
| 291 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { |
| 292 if (!profile) |
| 293 return false; |
| 294 |
| 295 const extensions::Extension* extension = |
| 296 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(). |
| 297 GetExtensionOrAppByURL(url); |
| 298 // Allow bindings for all packaged extensions and component hosted apps. |
| 299 return extension && |
| 300 (!extension->is_hosted_app() || |
| 301 extension->location() == extensions::Manifest::COMPONENT); |
| 302 } |
| 303 #endif |
| 304 |
288 bool IsAboutUI(const GURL& url) { | 305 bool IsAboutUI(const GURL& url) { |
289 return (url.host() == chrome::kChromeUIChromeURLsHost || | 306 return (url.host() == chrome::kChromeUIChromeURLsHost || |
290 url.host() == chrome::kChromeUICreditsHost || | 307 url.host() == chrome::kChromeUICreditsHost || |
291 url.host() == chrome::kChromeUIDNSHost | 308 url.host() == chrome::kChromeUIDNSHost |
292 #if !defined(OS_ANDROID) | 309 #if !defined(OS_ANDROID) |
293 || url.host() == chrome::kChromeUITermsHost | 310 || url.host() == chrome::kChromeUITermsHost |
294 #endif | 311 #endif |
295 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 312 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
296 || url.host() == chrome::kChromeUILinuxProxyConfigHost || | 313 || url.host() == chrome::kChromeUILinuxProxyConfigHost || |
297 url.host() == chrome::kChromeUISandboxHost | 314 url.host() == chrome::kChromeUISandboxHost |
298 #endif | 315 #endif |
299 #if defined(OS_CHROMEOS) | 316 #if defined(OS_CHROMEOS) |
300 || url.host() == chrome::kChromeUIOSCreditsHost | 317 || url.host() == chrome::kChromeUIOSCreditsHost |
301 #endif | 318 #endif |
302 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 319 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
303 || url.host() == chrome::kChromeUIDiscardsHost | 320 || url.host() == chrome::kChromeUIDiscardsHost |
304 #endif | 321 #endif |
305 ); // NOLINT | 322 ); // NOLINT |
306 } | 323 } |
307 | 324 |
308 // Returns a function that can be used to create the right type of WebUI for a | 325 // Returns a function that can be used to create the right type of WebUI for a |
309 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated | 326 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated |
310 // with it. | 327 // with it. |
311 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, | 328 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, |
312 Profile* profile, | 329 Profile* profile, |
313 const GURL& url) { | 330 const GURL& url) { |
314 #if defined(ENABLE_EXTENSIONS) | 331 #if defined(ENABLE_EXTENSIONS) |
315 if (ExtensionWebUI::NeedsExtensionWebUI(profile, url)) | 332 if (NeedsExtensionWebUI(profile, url)) |
316 return &NewWebUI<ExtensionWebUI>; | 333 return &NewWebUI<ExtensionWebUI>; |
317 #endif | 334 #endif |
318 | 335 |
319 // This will get called a lot to check all URLs, so do a quick check of other | 336 // This will get called a lot to check all URLs, so do a quick check of other |
320 // schemes to filter out most URLs. | 337 // schemes to filter out most URLs. |
321 if (!url.SchemeIs(content::kChromeDevToolsScheme) && | 338 if (!url.SchemeIs(content::kChromeDevToolsScheme) && |
322 !url.SchemeIs(content::kChromeUIScheme)) { | 339 !url.SchemeIs(content::kChromeUIScheme)) { |
323 return NULL; | 340 return NULL; |
324 } | 341 } |
325 | 342 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; | 685 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; |
669 } | 686 } |
670 | 687 |
671 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( | 688 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( |
672 content::BrowserContext* browser_context, const GURL& url) const { | 689 content::BrowserContext* browser_context, const GURL& url) const { |
673 bool needs_extensions_web_ui = false; | 690 bool needs_extensions_web_ui = false; |
674 #if defined(ENABLE_EXTENSIONS) | 691 #if defined(ENABLE_EXTENSIONS) |
675 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI | 692 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI |
676 // bindings (see the ExtensionWebUI constructor). | 693 // bindings (see the ExtensionWebUI constructor). |
677 needs_extensions_web_ui = | 694 needs_extensions_web_ui = |
678 ExtensionWebUI::NeedsExtensionWebUI(browser_context, url); | 695 NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context), url); |
679 #endif | 696 #endif |
680 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url); | 697 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url); |
681 } | 698 } |
682 | 699 |
683 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( | 700 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( |
684 WebUI* web_ui, | 701 WebUI* web_ui, |
685 const GURL& url) const { | 702 const GURL& url) const { |
686 Profile* profile = Profile::FromWebUI(web_ui); | 703 Profile* profile = Profile::FromWebUI(web_ui); |
687 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); | 704 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); |
688 if (!function) | 705 if (!function) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 #endif | 848 #endif |
832 | 849 |
833 // Android doesn't use the plugins pages. | 850 // Android doesn't use the plugins pages. |
834 if (page_url.host() == chrome::kChromeUIPluginsHost) | 851 if (page_url.host() == chrome::kChromeUIPluginsHost) |
835 return PluginsUI::GetFaviconResourceBytes(scale_factor); | 852 return PluginsUI::GetFaviconResourceBytes(scale_factor); |
836 | 853 |
837 #endif | 854 #endif |
838 | 855 |
839 return NULL; | 856 return NULL; |
840 } | 857 } |
OLD | NEW |