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

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

Issue 383213007: ifdef more extensions code to be used only when extensions are enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments, lint Created 6 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync/profile_sync_service_factory.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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/message_loop/message_loop_proxy.h" 12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/about_flags.h" 14 #include "chrome/browser/about_flags.h"
15 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" 15 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
16 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" 16 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
17 #include "chrome/browser/extensions/extension_web_ui.h"
18 #include "chrome/browser/favicon/favicon_service.h" 17 #include "chrome/browser/favicon/favicon_service.h"
19 #include "chrome/browser/history/history_types.h" 18 #include "chrome/browser/history/history_types.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/webui/about_ui.h" 21 #include "chrome/browser/ui/webui/about_ui.h"
23 #include "chrome/browser/ui/webui/app_launcher_page_ui.h" 22 #include "chrome/browser/ui/webui/app_launcher_page_ui.h"
24 #include "chrome/browser/ui/webui/bookmarks_ui.h" 23 #include "chrome/browser/ui/webui/bookmarks_ui.h"
25 #include "chrome/browser/ui/webui/components_ui.h" 24 #include "chrome/browser/ui/webui/components_ui.h"
26 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 25 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
27 #include "chrome/browser/ui/webui/crashes_ui.h" 26 #include "chrome/browser/ui/webui/crashes_ui.h"
28 #include "chrome/browser/ui/webui/devtools_ui.h" 27 #include "chrome/browser/ui/webui/devtools_ui.h"
29 #include "chrome/browser/ui/webui/domain_reliability_internals_ui.h" 28 #include "chrome/browser/ui/webui/domain_reliability_internals_ui.h"
30 #include "chrome/browser/ui/webui/downloads_ui.h" 29 #include "chrome/browser/ui/webui/downloads_ui.h"
31 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h"
32 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
33 #include "chrome/browser/ui/webui/flags_ui.h" 30 #include "chrome/browser/ui/webui/flags_ui.h"
34 #include "chrome/browser/ui/webui/flash_ui.h" 31 #include "chrome/browser/ui/webui/flash_ui.h"
35 #include "chrome/browser/ui/webui/gcm_internals_ui.h" 32 #include "chrome/browser/ui/webui/gcm_internals_ui.h"
36 #include "chrome/browser/ui/webui/help/help_ui.h" 33 #include "chrome/browser/ui/webui/help/help_ui.h"
37 #include "chrome/browser/ui/webui/history_ui.h" 34 #include "chrome/browser/ui/webui/history_ui.h"
38 #include "chrome/browser/ui/webui/identity_internals_ui.h" 35 #include "chrome/browser/ui/webui/identity_internals_ui.h"
39 #include "chrome/browser/ui/webui/inspect_ui.h" 36 #include "chrome/browser/ui/webui/inspect_ui.h"
40 #include "chrome/browser/ui/webui/instant_ui.h" 37 #include "chrome/browser/ui/webui/instant_ui.h"
41 #include "chrome/browser/ui/webui/invalidations_ui.h" 38 #include "chrome/browser/ui/webui/invalidations_ui.h"
42 #include "chrome/browser/ui/webui/memory_internals/memory_internals_ui.h" 39 #include "chrome/browser/ui/webui/memory_internals/memory_internals_ui.h"
43 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h" 40 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
44 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h" 41 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
45 #include "chrome/browser/ui/webui/options/options_ui.h" 42 #include "chrome/browser/ui/webui/options/options_ui.h"
46 #include "chrome/browser/ui/webui/password_manager_internals/password_manager_in ternals_ui.h" 43 #include "chrome/browser/ui/webui/password_manager_internals/password_manager_in ternals_ui.h"
47 #include "chrome/browser/ui/webui/performance_monitor/performance_monitor_ui.h" 44 #include "chrome/browser/ui/webui/performance_monitor/performance_monitor_ui.h"
48 #include "chrome/browser/ui/webui/plugins_ui.h" 45 #include "chrome/browser/ui/webui/plugins_ui.h"
49 #include "chrome/browser/ui/webui/predictors/predictors_ui.h" 46 #include "chrome/browser/ui/webui/predictors/predictors_ui.h"
50 #include "chrome/browser/ui/webui/profiler_ui.h" 47 #include "chrome/browser/ui/webui/profiler_ui.h"
51 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" 48 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
52 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_ui.h" 49 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_ui.h"
53 #include "chrome/browser/ui/webui/signin/user_manager_ui.h" 50 #include "chrome/browser/ui/webui/signin/user_manager_ui.h"
54 #include "chrome/browser/ui/webui/signin_internals_ui.h" 51 #include "chrome/browser/ui/webui/signin_internals_ui.h"
55 #include "chrome/browser/ui/webui/sync_internals_ui.h" 52 #include "chrome/browser/ui/webui/sync_internals_ui.h"
56 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h" 53 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"
57 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h" 54 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h"
58 #include "chrome/browser/ui/webui/version_ui.h" 55 #include "chrome/browser/ui/webui/version_ui.h"
59 #include "chrome/common/chrome_switches.h" 56 #include "chrome/common/chrome_switches.h"
60 #include "chrome/common/extensions/extension_constants.h"
61 #include "chrome/common/pref_names.h" 57 #include "chrome/common/pref_names.h"
62 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
63 #include "components/dom_distiller/core/dom_distiller_constants.h" 59 #include "components/dom_distiller/core/dom_distiller_constants.h"
64 #include "components/dom_distiller/core/dom_distiller_service.h" 60 #include "components/dom_distiller/core/dom_distiller_service.h"
65 #include "components/dom_distiller/webui/dom_distiller_ui.h" 61 #include "components/dom_distiller/webui/dom_distiller_ui.h"
66 #include "components/favicon_base/favicon_util.h" 62 #include "components/favicon_base/favicon_util.h"
67 #include "components/favicon_base/select_favicon_frames.h" 63 #include "components/favicon_base/select_favicon_frames.h"
68 #include "components/password_manager/core/common/password_manager_switches.h" 64 #include "components/password_manager/core/common/password_manager_switches.h"
69 #include "components/signin/core/common/profile_management_switches.h" 65 #include "components/signin/core/common/profile_management_switches.h"
70 #include "content/public/browser/web_contents.h" 66 #include "content/public/browser/web_contents.h"
71 #include "content/public/browser/web_ui.h" 67 #include "content/public/browser/web_ui.h"
72 #include "content/public/common/content_client.h" 68 #include "content/public/common/content_client.h"
73 #include "content/public/common/url_utils.h" 69 #include "content/public/common/url_utils.h"
74 #include "extensions/browser/extension_registry.h"
75 #include "extensions/browser/extension_system.h"
76 #include "extensions/common/constants.h"
77 #include "extensions/common/extension.h"
78 #include "extensions/common/feature_switch.h"
79 #include "extensions/common/manifest.h"
80 #include "ui/gfx/favicon_size.h" 70 #include "ui/gfx/favicon_size.h"
81 #include "ui/web_dialogs/web_dialog_ui.h" 71 #include "ui/web_dialogs/web_dialog_ui.h"
82 #include "url/gurl.h" 72 #include "url/gurl.h"
83 73
84 #if !defined(DISABLE_NACL) 74 #if !defined(DISABLE_NACL)
85 #include "chrome/browser/ui/webui/nacl_ui.h" 75 #include "chrome/browser/ui/webui/nacl_ui.h"
86 #endif 76 #endif
87 77
88 #if defined(ENABLE_CONFIGURATION_POLICY) 78 #if defined(ENABLE_CONFIGURATION_POLICY)
89 #include "chrome/browser/ui/webui/policy_ui.h" 79 #include "chrome/browser/ui/webui/policy_ui.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 145
156 #if defined(ENABLE_SERVICE_DISCOVERY) 146 #if defined(ENABLE_SERVICE_DISCOVERY)
157 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h" 147 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h"
158 #endif 148 #endif
159 149
160 #if defined(ENABLE_APP_LIST) 150 #if defined(ENABLE_APP_LIST)
161 #include "chrome/browser/ui/webui/app_list/start_page_ui.h" 151 #include "chrome/browser/ui/webui/app_list/start_page_ui.h"
162 #endif 152 #endif
163 153
164 #if defined(ENABLE_EXTENSIONS) 154 #if defined(ENABLE_EXTENSIONS)
155 #include "chrome/browser/extensions/extension_web_ui.h"
156 #include "chrome/browser/ui/webui/extensions/extension_info_ui.h"
157 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
165 #include "chrome/browser/ui/webui/voicesearch_ui.h" 158 #include "chrome/browser/ui/webui/voicesearch_ui.h"
159 #include "chrome/common/extensions/extension_constants.h"
160 #include "extensions/browser/extension_registry.h"
161 #include "extensions/browser/extension_system.h"
162 #include "extensions/common/constants.h"
163 #include "extensions/common/extension.h"
164 #include "extensions/common/feature_switch.h"
165 #include "extensions/common/manifest.h"
166 #endif 166 #endif
167 167
168 using content::WebUI; 168 using content::WebUI;
169 using content::WebUIController; 169 using content::WebUIController;
170 using ui::ExternalWebDialogUI; 170 using ui::ExternalWebDialogUI;
171 using ui::WebDialogUI; 171 using ui::WebDialogUI;
172 172
173 namespace { 173 namespace {
174 174
175 // A function for creating a new WebUI. The caller owns the return value, which 175 // A function for creating a new WebUI. The caller owns the return value, which
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 content::BrowserContext* browser_context = 214 content::BrowserContext* browser_context =
215 web_ui->GetWebContents()->GetBrowserContext(); 215 web_ui->GetWebContents()->GetBrowserContext();
216 dom_distiller::DomDistillerService* service = 216 dom_distiller::DomDistillerService* service =
217 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext( 217 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
218 browser_context); 218 browser_context);
219 return new dom_distiller::DomDistillerUi(web_ui, 219 return new dom_distiller::DomDistillerUi(web_ui,
220 service, 220 service,
221 chrome::kDomDistillerScheme); 221 chrome::kDomDistillerScheme);
222 } 222 }
223 223
224 #if defined(ENABLE_EXTENSIONS)
224 // Only create ExtensionWebUI for URLs that are allowed extension bindings, 225 // Only create ExtensionWebUI for URLs that are allowed extension bindings,
225 // hosted by actual tabs. 226 // hosted by actual tabs.
226 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) { 227 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) {
227 if (!profile) 228 if (!profile)
228 return false; 229 return false;
229 230
230 const extensions::Extension* extension = 231 const extensions::Extension* extension =
231 extensions::ExtensionRegistry::Get(profile)->enabled_extensions(). 232 extensions::ExtensionRegistry::Get(profile)->enabled_extensions().
232 GetExtensionOrAppByURL(url); 233 GetExtensionOrAppByURL(url);
233 // Allow bindings for all packaged extensions and component hosted apps. 234 // Allow bindings for all packaged extensions and component hosted apps.
234 return extension && 235 return extension &&
235 (!extension->is_hosted_app() || 236 (!extension->is_hosted_app() ||
236 extension->location() == extensions::Manifest::COMPONENT); 237 extension->location() == extensions::Manifest::COMPONENT);
237 } 238 }
239 #endif
238 240
239 // Returns a function that can be used to create the right type of WebUI for a 241 // Returns a function that can be used to create the right type of WebUI for a
240 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated 242 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated
241 // with it. 243 // with it.
242 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, 244 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
243 Profile* profile, 245 Profile* profile,
244 const GURL& url) { 246 const GURL& url) {
245 #if defined(ENABLE_EXTENSIONS) 247 #if defined(ENABLE_EXTENSIONS)
246 if (NeedsExtensionWebUI(profile, url)) 248 if (NeedsExtensionWebUI(profile, url))
247 return &NewWebUI<ExtensionWebUI>; 249 return &NewWebUI<ExtensionWebUI>;
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI; 557 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI;
556 } 558 }
557 559
558 bool ChromeWebUIControllerFactory::UseWebUIForURL( 560 bool ChromeWebUIControllerFactory::UseWebUIForURL(
559 content::BrowserContext* browser_context, const GURL& url) const { 561 content::BrowserContext* browser_context, const GURL& url) const {
560 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; 562 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI;
561 } 563 }
562 564
563 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL( 565 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL(
564 content::BrowserContext* browser_context, const GURL& url) const { 566 content::BrowserContext* browser_context, const GURL& url) const {
567 bool needs_extensions_web_ui = false;
568 #if defined(ENABLE_EXTENSIONS)
565 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI 569 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI
566 // bindings (see the ExtensionWebUI constructor). 570 // bindings (see the ExtensionWebUI constructor).
567 return 571 needs_extensions_web_ui =
568 !NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context), url) && 572 NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context), url);
569 UseWebUIForURL(browser_context, url); 573 #endif
574 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url);
570 } 575 }
571 576
572 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL( 577 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL(
573 WebUI* web_ui, 578 WebUI* web_ui,
574 const GURL& url) const { 579 const GURL& url) const {
575 Profile* profile = Profile::FromWebUI(web_ui); 580 Profile* profile = Profile::FromWebUI(web_ui);
576 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url); 581 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url);
577 if (!function) 582 if (!function)
578 return NULL; 583 return NULL;
579 584
580 return (*function)(web_ui, url); 585 return (*function)(web_ui, url);
581 } 586 }
582 587
583 void ChromeWebUIControllerFactory::GetFaviconForURL( 588 void ChromeWebUIControllerFactory::GetFaviconForURL(
584 Profile* profile, 589 Profile* profile,
585 const GURL& page_url, 590 const GURL& page_url,
586 const std::vector<int>& desired_sizes_in_pixel, 591 const std::vector<int>& desired_sizes_in_pixel,
587 const favicon_base::FaviconResultsCallback& callback) const { 592 const favicon_base::FaviconResultsCallback& callback) const {
588 // Before determining whether page_url is an extension url, we must handle 593 // Before determining whether page_url is an extension url, we must handle
589 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and 594 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and
590 // allows to use ExtensionWebUI::GetFaviconForURL. 595 // allows to use ExtensionWebUI::GetFaviconForURL.
591 GURL url(page_url); 596 GURL url(page_url);
597 #if defined(ENABLE_EXTENSIONS)
592 ExtensionWebUI::HandleChromeURLOverride(&url, profile); 598 ExtensionWebUI::HandleChromeURLOverride(&url, profile);
593 599
594 // All extensions but the bookmark manager get their favicon from the icons 600 // All extensions but the bookmark manager get their favicon from the icons
595 // part of the manifest. 601 // part of the manifest.
596 if (url.SchemeIs(extensions::kExtensionScheme) && 602 if (url.SchemeIs(extensions::kExtensionScheme) &&
597 url.host() != extension_misc::kBookmarkManagerId) { 603 url.host() != extension_misc::kBookmarkManagerId) {
598 #if defined(ENABLE_EXTENSIONS)
599 ExtensionWebUI::GetFaviconForURL(profile, url, callback); 604 ExtensionWebUI::GetFaviconForURL(profile, url, callback);
600 #else
601 RunFaviconCallbackAsync(
602 callback, new std::vector<favicon_base::FaviconRawBitmapResult>());
603 #endif
604 return; 605 return;
605 } 606 }
607 #endif
606 608
607 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results = 609 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results =
608 new std::vector<favicon_base::FaviconRawBitmapResult>(); 610 new std::vector<favicon_base::FaviconRawBitmapResult>();
609 611
610 // Use ui::GetSupportedScaleFactors instead of 612 // Use ui::GetSupportedScaleFactors instead of
611 // favicon_base::GetFaviconScales() because chrome favicons comes from 613 // favicon_base::GetFaviconScales() because chrome favicons comes from
612 // resources. 614 // resources.
613 std::vector<ui::ScaleFactor> resource_scale_factors = 615 std::vector<ui::ScaleFactor> resource_scale_factors =
614 ui::GetSupportedScaleFactors(); 616 ui::GetSupportedScaleFactors();
615 617
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 #endif 720 #endif
719 721
720 // Android doesn't use the plugins pages. 722 // Android doesn't use the plugins pages.
721 if (page_url.host() == chrome::kChromeUIPluginsHost) 723 if (page_url.host() == chrome::kChromeUIPluginsHost)
722 return PluginsUI::GetFaviconResourceBytes(scale_factor); 724 return PluginsUI::GetFaviconResourceBytes(scale_factor);
723 725
724 #endif 726 #endif
725 727
726 return NULL; 728 return NULL;
727 } 729 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698