Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc

Issue 2452773002: [Extensions] Limit Extension WebUI (Closed)
Patch Set: sky's Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
305 bool IsAboutUI(const GURL& url) { 288 bool IsAboutUI(const GURL& url) {
306 return (url.host() == chrome::kChromeUIChromeURLsHost || 289 return (url.host() == chrome::kChromeUIChromeURLsHost ||
307 url.host() == chrome::kChromeUICreditsHost || 290 url.host() == chrome::kChromeUICreditsHost ||
308 url.host() == chrome::kChromeUIDNSHost 291 url.host() == chrome::kChromeUIDNSHost
309 #if !defined(OS_ANDROID) 292 #if !defined(OS_ANDROID)
310 || url.host() == chrome::kChromeUITermsHost 293 || url.host() == chrome::kChromeUITermsHost
311 #endif 294 #endif
312 #if defined(OS_LINUX) || defined(OS_OPENBSD) 295 #if defined(OS_LINUX) || defined(OS_OPENBSD)
313 || url.host() == chrome::kChromeUILinuxProxyConfigHost || 296 || url.host() == chrome::kChromeUILinuxProxyConfigHost ||
314 url.host() == chrome::kChromeUISandboxHost 297 url.host() == chrome::kChromeUISandboxHost
315 #endif 298 #endif
316 #if defined(OS_CHROMEOS) 299 #if defined(OS_CHROMEOS)
317 || url.host() == chrome::kChromeUIOSCreditsHost 300 || url.host() == chrome::kChromeUIOSCreditsHost
318 #endif 301 #endif
319 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 302 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
320 || url.host() == chrome::kChromeUIDiscardsHost 303 || url.host() == chrome::kChromeUIDiscardsHost
321 #endif 304 #endif
322 ); // NOLINT 305 ); // NOLINT
323 } 306 }
324 307
325 // Returns a function that can be used to create the right type of WebUI for a 308 // Returns a function that can be used to create the right type of WebUI for a
326 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated 309 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated
327 // with it. 310 // with it.
328 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, 311 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
329 Profile* profile, 312 Profile* profile,
330 const GURL& url) { 313 const GURL& url) {
331 #if defined(ENABLE_EXTENSIONS) 314 #if defined(ENABLE_EXTENSIONS)
332 if (NeedsExtensionWebUI(profile, url)) 315 if (ExtensionWebUI::NeedsExtensionWebUI(profile, url))
333 return &NewWebUI<ExtensionWebUI>; 316 return &NewWebUI<ExtensionWebUI>;
334 #endif 317 #endif
335 318
336 // This will get called a lot to check all URLs, so do a quick check of other 319 // This will get called a lot to check all URLs, so do a quick check of other
337 // schemes to filter out most URLs. 320 // schemes to filter out most URLs.
338 if (!url.SchemeIs(content::kChromeDevToolsScheme) && 321 if (!url.SchemeIs(content::kChromeDevToolsScheme) &&
339 !url.SchemeIs(content::kChromeUIScheme)) { 322 !url.SchemeIs(content::kChromeUIScheme)) {
340 return NULL; 323 return NULL;
341 } 324 }
342 325
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; 668 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI;
686 } 669 }
687 670
688 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( 671 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL(
689 content::BrowserContext* browser_context, const GURL& url) const { 672 content::BrowserContext* browser_context, const GURL& url) const {
690 bool needs_extensions_web_ui = false; 673 bool needs_extensions_web_ui = false;
691 #if defined(ENABLE_EXTENSIONS) 674 #if defined(ENABLE_EXTENSIONS)
692 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI 675 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI
693 // bindings (see the ExtensionWebUI constructor). 676 // bindings (see the ExtensionWebUI constructor).
694 needs_extensions_web_ui = 677 needs_extensions_web_ui =
695 NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context), url); 678 ExtensionWebUI::NeedsExtensionWebUI(browser_context, url);
696 #endif 679 #endif
697 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url); 680 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url);
698 } 681 }
699 682
700 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( 683 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL(
701 WebUI* web_ui, 684 WebUI* web_ui,
702 const GURL& url) const { 685 const GURL& url) const {
703 Profile* profile = Profile::FromWebUI(web_ui); 686 Profile* profile = Profile::FromWebUI(web_ui);
704 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); 687 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url);
705 if (!function) 688 if (!function)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 #endif 831 #endif
849 832
850 // Android doesn't use the plugins pages. 833 // Android doesn't use the plugins pages.
851 if (page_url.host() == chrome::kChromeUIPluginsHost) 834 if (page_url.host() == chrome::kChromeUIPluginsHost)
852 return PluginsUI::GetFaviconResourceBytes(scale_factor); 835 return PluginsUI::GetFaviconResourceBytes(scale_factor);
853 836
854 #endif 837 #endif
855 838
856 return NULL; 839 return NULL;
857 } 840 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_context_menu_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698