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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/about_flags.h"
15 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
16 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
17 #include "chrome/browser/favicon/favicon_service.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/webui/about_ui.h"
21 #include "chrome/browser/ui/webui/app_launcher_page_ui.h"
22 #include "chrome/browser/ui/webui/bookmarks_ui.h"
23 #include "chrome/browser/ui/webui/components_ui.h"
24 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
25 #include "chrome/browser/ui/webui/copresence_ui.h"
26 #include "chrome/browser/ui/webui/crashes_ui.h"
27 #include "chrome/browser/ui/webui/device_log_ui.h"
28 #include "chrome/browser/ui/webui/domain_reliability_internals_ui.h"
29 #include "chrome/browser/ui/webui/downloads_ui.h"
30 #include "chrome/browser/ui/webui/flags_ui.h"
31 #include "chrome/browser/ui/webui/flash_ui.h"
32 #include "chrome/browser/ui/webui/gcm_internals_ui.h"
33 #include "chrome/browser/ui/webui/help/help_ui.h"
34 #include "chrome/browser/ui/webui/history_ui.h"
35 #include "chrome/browser/ui/webui/identity_internals_ui.h"
36 #include "chrome/browser/ui/webui/instant_ui.h"
37 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
38 #include "chrome/browser/ui/webui/invalidations_ui.h"
39 #include "chrome/browser/ui/webui/local_state/local_state_ui.h"
40 #include "chrome/browser/ui/webui/md_settings_ui.h"
41 #include "chrome/browser/ui/webui/memory_internals/memory_internals_ui.h"
42 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
43 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
44 #include "chrome/browser/ui/webui/options/options_ui.h"
45 #include "chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.h"
46 #include "chrome/browser/ui/webui/plugins_ui.h"
47 #include "chrome/browser/ui/webui/predictors/predictors_ui.h"
48 #include "chrome/browser/ui/webui/profiler_ui.h"
49 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
50 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_ui.h"
51 #include "chrome/browser/ui/webui/signin/user_manager_ui.h"
52 #include "chrome/browser/ui/webui/signin_internals_ui.h"
53 #include "chrome/browser/ui/webui/sync_internals_ui.h"
54 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"
55 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h"
56 #include "chrome/browser/ui/webui/version_ui.h"
57 #include "chrome/common/chrome_switches.h"
58 #include "chrome/common/pref_names.h"
59 #include "chrome/common/url_constants.h"
60 #include "components/dom_distiller/core/dom_distiller_constants.h"
61 #include "components/dom_distiller/core/dom_distiller_service.h"
62 #include "components/dom_distiller/core/url_constants.h"
63 #include "components/dom_distiller/webui/dom_distiller_ui.h"
64 #include "components/favicon_base/favicon_util.h"
65 #include "components/favicon_base/select_favicon_frames.h"
66 #include "components/history/core/browser/history_types.h"
67 #include "components/password_manager/core/common/password_manager_switches.h"
68 #include "components/signin/core/common/profile_management_switches.h"
69 #include "content/public/browser/web_contents.h"
70 #include "content/public/browser/web_ui.h"
71 #include "content/public/common/content_client.h"
72 #include "content/public/common/url_utils.h"
73 #include "ui/gfx/favicon_size.h"
74 #include "ui/web_dialogs/web_dialog_ui.h"
77 #if !defined(DISABLE_NACL)
78 #include "chrome/browser/ui/webui/nacl_ui.h"
81 #if defined(ENABLE_CONFIGURATION_POLICY)
82 #include "chrome/browser/ui/webui/policy_ui.h"
85 #if defined(ENABLE_WEBRTC)
86 #include "chrome/browser/ui/webui/media/webrtc_logs_ui.h"
89 #if defined(ENABLE_PRINT_PREVIEW)
90 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
93 #if !defined(OS_ANDROID)
94 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
95 #include "chrome/browser/ui/webui/quota_internals/quota_internals_ui.h"
96 #include "chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui.h"
97 #include "chrome/browser/ui/webui/sync_file_system_internals/sync_file_system_internals_ui.h"
98 #include "chrome/browser/ui/webui/system_info_ui.h"
99 #include "chrome/browser/ui/webui/uber/uber_ui.h"
102 #if defined(OS_ANDROID) || defined(OS_IOS)
103 #include "chrome/browser/ui/webui/net_export_ui.h"
105 #include "chrome/browser/devtools/device/webrtc/webrtc_device_provider.h"
106 #include "chrome/browser/ui/webui/devtools_ui.h"
107 #include "chrome/browser/ui/webui/inspect_ui.h"
110 #if defined(OS_CHROMEOS)
111 #include "chrome/browser/ui/webui/chromeos/bluetooth_pairing_ui.h"
112 #include "chrome/browser/ui/webui/chromeos/certificate_manager_dialog_ui.h"
113 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h"
114 #include "chrome/browser/ui/webui/chromeos/cryptohome_ui.h"
115 #include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
116 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
117 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h"
118 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h"
119 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
120 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
121 #include "chrome/browser/ui/webui/chromeos/network_ui.h"
122 #include "chrome/browser/ui/webui/chromeos/nfc_debug_ui.h"
123 #include "chrome/browser/ui/webui/chromeos/power_ui.h"
124 #include "chrome/browser/ui/webui/chromeos/provided_file_systems_ui.h"
125 #include "chrome/browser/ui/webui/chromeos/proxy_settings_ui.h"
126 #include "chrome/browser/ui/webui/chromeos/salsa_ui.h"
127 #include "chrome/browser/ui/webui/chromeos/set_time_ui.h"
128 #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h"
129 #include "chrome/browser/ui/webui/chromeos/slow_trace_ui.h"
130 #include "chrome/browser/ui/webui/chromeos/slow_ui.h"
133 #if defined(USE_AURA)
134 #include "chrome/browser/ui/webui/gesture_config_ui.h"
137 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
138 #include "chrome/browser/ui/sync/sync_promo_ui.h"
142 #include "chrome/browser/ui/webui/conflicts_ui.h"
143 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h"
146 #if (defined(USE_NSS) || defined(USE_OPENSSL_CERTS)) && defined(USE_AURA)
147 #include "chrome/browser/ui/webui/certificate_viewer_ui.h"
150 #if defined(ENABLE_SERVICE_DISCOVERY)
151 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h"
154 #if defined(ENABLE_APP_LIST)
155 #include "chrome/browser/ui/webui/app_list/start_page_ui.h"
158 #if defined(ENABLE_EXTENSIONS)
159 #include "chrome/browser/extensions/extension_web_ui.h"
160 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
161 #include "chrome/browser/ui/webui/voice_search_ui.h"
162 #include "chrome/common/extensions/extension_constants.h"
163 #include "extensions/browser/extension_registry.h"
164 #include "extensions/browser/extension_system.h"
165 #include "extensions/common/constants.h"
166 #include "extensions/common/extension.h"
167 #include "extensions/common/feature_switch.h"
168 #include "extensions/common/manifest.h"
171 using content::WebUI
;
172 using content::WebUIController
;
173 using ui::ExternalWebDialogUI
;
174 using ui::WebDialogUI
;
178 // A function for creating a new WebUI. The caller owns the return value, which
179 // may be NULL (for example, if the URL refers to an non-existent extension).
180 typedef WebUIController
* (*WebUIFactoryFunction
)(WebUI
* web_ui
,
183 // Template for defining WebUIFactoryFunction.
185 WebUIController
* NewWebUI(WebUI
* web_ui
, const GURL
& url
) {
186 return new T(web_ui
);
189 #if defined(ENABLE_EXTENSIONS)
190 // Special cases for extensions.
192 WebUIController
* NewWebUI
<ExtensionWebUI
>(WebUI
* web_ui
,
194 return new ExtensionWebUI(web_ui
, url
);
196 #endif // defined(ENABLE_EXTENSIONS)
198 // Special case for older about: handlers.
200 WebUIController
* NewWebUI
<AboutUI
>(WebUI
* web_ui
, const GURL
& url
) {
201 return new AboutUI(web_ui
, url
.host());
204 #if defined(OS_CHROMEOS)
206 WebUIController
* NewWebUI
<chromeos::OobeUI
>(WebUI
* web_ui
, const GURL
& url
) {
207 return new chromeos::OobeUI(web_ui
, url
);
211 // Special cases for DOM distiller.
213 WebUIController
* NewWebUI
<dom_distiller::DomDistillerUi
>(WebUI
* web_ui
,
215 // The DomDistillerUi can not depend on components/dom_distiller/content,
216 // so inject the correct DomDistillerService from chrome/.
217 content::BrowserContext
* browser_context
=
218 web_ui
->GetWebContents()->GetBrowserContext();
219 dom_distiller::DomDistillerService
* service
=
220 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
222 return new dom_distiller::DomDistillerUi(
223 web_ui
, service
, dom_distiller::kDomDistillerScheme
);
226 #if defined(ENABLE_EXTENSIONS)
227 // Only create ExtensionWebUI for URLs that are allowed extension bindings,
228 // hosted by actual tabs.
229 bool NeedsExtensionWebUI(Profile
* profile
, const GURL
& url
) {
233 const extensions::Extension
* extension
=
234 extensions::ExtensionRegistry::Get(profile
)->enabled_extensions().
235 GetExtensionOrAppByURL(url
);
236 // Allow bindings for all packaged extensions and component hosted apps.
238 (!extension
->is_hosted_app() ||
239 extension
->location() == extensions::Manifest::COMPONENT
);
243 bool IsAboutUI(const GURL
& url
) {
244 return (url
.host() == chrome::kChromeUIChromeURLsHost
||
245 url
.host() == chrome::kChromeUICreditsHost
||
246 url
.host() == chrome::kChromeUIDNSHost
||
247 url
.host() == chrome::kChromeUIMemoryHost
||
248 url
.host() == chrome::kChromeUIMemoryRedirectHost
249 #if !defined(OS_ANDROID)
250 || url
.host() == chrome::kChromeUITermsHost
252 #if defined(OS_LINUX) || defined(OS_OPENBSD)
253 || url
.host() == chrome::kChromeUILinuxProxyConfigHost
254 || url
.host() == chrome::kChromeUISandboxHost
256 #if defined(OS_CHROMEOS)
257 || url
.host() == chrome::kChromeUIDiscardsHost
258 || url
.host() == chrome::kChromeUIOSCreditsHost
263 // Returns a function that can be used to create the right type of WebUI for a
264 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated
266 WebUIFactoryFunction
GetWebUIFactoryFunction(WebUI
* web_ui
,
269 #if defined(ENABLE_EXTENSIONS)
270 if (NeedsExtensionWebUI(profile
, url
))
271 return &NewWebUI
<ExtensionWebUI
>;
274 // This will get called a lot to check all URLs, so do a quick check of other
275 // schemes to filter out most URLs.
276 if (!url
.SchemeIs(content::kChromeDevToolsScheme
) &&
277 !url
.SchemeIs(content::kChromeUIScheme
)) {
281 /****************************************************************************
282 * Please keep this in alphabetical order. If #ifs or special logics are
283 * required, add it below in the appropriate section.
284 ***************************************************************************/
285 // We must compare hosts only since some of the Web UIs append extra stuff
286 // after the host name.
287 // All platform builds of Chrome will need to have a cloud printing
288 // dialog as backup. It's just that on Chrome OS, it's the only
290 if (url
.host() == chrome::kChromeUICloudPrintResourcesHost
)
291 return &NewWebUI
<ExternalWebDialogUI
>;
292 if (url
.host() == chrome::kChromeUICloudPrintSetupHost
)
293 return &NewWebUI
<WebDialogUI
>;
294 if (url
.host() == chrome::kChromeUIComponentsHost
)
295 return &NewWebUI
<ComponentsUI
>;
296 if (url
.spec() == chrome::kChromeUIConstrainedHTMLTestURL
)
297 return &NewWebUI
<ConstrainedWebDialogUI
>;
298 if (url
.host() == chrome::kChromeUICrashesHost
)
299 return &NewWebUI
<CrashesUI
>;
300 if (url
.host() == chrome::kChromeUIDeviceLogHost
)
301 return &NewWebUI
<chromeos::DeviceLogUI
>;
302 if (url
.host() == chrome::kChromeUIDomainReliabilityInternalsHost
)
303 return &NewWebUI
<DomainReliabilityInternalsUI
>;
304 if (url
.host() == chrome::kChromeUIFlagsHost
)
305 return &NewWebUI
<FlagsUI
>;
306 if (url
.host() == chrome::kChromeUIHistoryFrameHost
)
307 return &NewWebUI
<HistoryUI
>;
308 if (url
.host() == chrome::kChromeUIInstantHost
)
309 return &NewWebUI
<InstantUI
>;
310 if (url
.host() == chrome::kChromeUIInterstitialHost
)
311 return &NewWebUI
<InterstitialUI
>;
312 if (url
.host() == chrome::kChromeUIInvalidationsHost
)
313 return &NewWebUI
<InvalidationsUI
>;
314 if (url
.host() == chrome::kChromeUILocalStateHost
)
315 return &NewWebUI
<LocalStateUI
>;
316 if (url
.host() == chrome::kChromeUIMemoryInternalsHost
)
317 return &NewWebUI
<MemoryInternalsUI
>;
318 if (url
.host() == chrome::kChromeUINetInternalsHost
)
319 return &NewWebUI
<NetInternalsUI
>;
320 if (url
.host() == chrome::kChromeUIOmniboxHost
)
321 return &NewWebUI
<OmniboxUI
>;
322 if (url
.host() == chrome::kChromeUIPasswordManagerInternalsHost
)
323 return &NewWebUI
<PasswordManagerInternalsUI
>;
324 if (url
.host() == chrome::kChromeUIPredictorsHost
)
325 return &NewWebUI
<PredictorsUI
>;
326 if (url
.host() == chrome::kChromeUIProfilerHost
)
327 return &NewWebUI
<ProfilerUI
>;
328 if (url
.host() == chrome::kChromeUISignInInternalsHost
)
329 return &NewWebUI
<SignInInternalsUI
>;
330 if (url
.host() == chrome::kChromeUISupervisedUserPassphrasePageHost
)
331 return &NewWebUI
<ConstrainedWebDialogUI
>;
332 if (url
.host() == chrome::kChromeUISyncInternalsHost
)
333 return &NewWebUI
<SyncInternalsUI
>;
334 if (url
.host() == chrome::kChromeUISyncResourcesHost
)
335 return &NewWebUI
<WebDialogUI
>;
336 if (url
.host() == chrome::kChromeUITranslateInternalsHost
)
337 return &NewWebUI
<TranslateInternalsUI
>;
338 if (url
.host() == chrome::kChromeUIUserActionsHost
)
339 return &NewWebUI
<UserActionsUI
>;
340 if (url
.host() == chrome::kChromeUIVersionHost
)
341 return &NewWebUI
<VersionUI
>;
343 /****************************************************************************
344 * OS Specific #defines
345 ***************************************************************************/
346 #if !defined(OS_ANDROID)
347 // AppLauncherPage is not needed on Android.
348 if (url
.host() == chrome::kChromeUIAppLauncherPageHost
&&
349 profile
&& extensions::ExtensionSystem::Get(profile
)->
350 extension_service()) {
351 return &NewWebUI
<AppLauncherPageUI
>;
353 // Bookmarks are part of NTP on Android.
354 if (url
.host() == chrome::kChromeUIBookmarksHost
)
355 return &NewWebUI
<BookmarksUI
>;
356 // Downloads list on Android uses the built-in download manager.
357 if (url
.host() == chrome::kChromeUIDownloadsHost
)
358 return &NewWebUI
<DownloadsUI
>;
359 // Flash is not available on android.
360 if (url
.host() == chrome::kChromeUIFlashHost
)
361 return &NewWebUI
<FlashUI
>;
362 if (url
.host() == chrome::kChromeUIGCMInternalsHost
)
363 return &NewWebUI
<GCMInternalsUI
>;
364 // Help is implemented with native UI elements on Android.
365 if (url
.host() == chrome::kChromeUIHelpFrameHost
)
366 return &NewWebUI
<HelpUI
>;
367 // Identity API is not available on Android.
368 if (url
.host() == chrome::kChromeUIIdentityInternalsHost
)
369 return &NewWebUI
<IdentityInternalsUI
>;
370 if (url
.host() == chrome::kChromeUINewTabHost
)
371 return &NewWebUI
<NewTabUI
>;
372 if (url
.host() == chrome::kChromeUIMdSettingsHost
&&
373 ::switches::MdSettingsEnabled()) {
374 return &NewWebUI
<MdSettingsUI
>;
376 // Android does not support plugins for now.
377 if (url
.host() == chrome::kChromeUIPluginsHost
)
378 return &NewWebUI
<PluginsUI
>;
379 if (url
.host() == chrome::kChromeUIQuotaInternalsHost
)
380 return &NewWebUI
<QuotaInternalsUI
>;
381 // Settings are implemented with native UI elements on Android.
382 // Handle chrome://settings if settings in a window and about in settings
384 if (url
.host() == chrome::kChromeUISettingsFrameHost
||
385 (url
.host() == chrome::kChromeUISettingsHost
&&
386 ::switches::AboutInSettingsEnabled())) {
387 return &NewWebUI
<options::OptionsUI
>;
389 if (url
.host() == chrome::kChromeUISuggestionsInternalsHost
)
390 return &NewWebUI
<SuggestionsInternalsUI
>;
391 if (url
.host() == chrome::kChromeUISyncFileSystemInternalsHost
)
392 return &NewWebUI
<SyncFileSystemInternalsUI
>;
393 if (url
.host() == chrome::kChromeUISystemInfoHost
)
394 return &NewWebUI
<SystemInfoUI
>;
395 // Uber frame is not used on Android.
396 if (url
.host() == chrome::kChromeUIUberFrameHost
)
397 return &NewWebUI
<UberFrameUI
>;
398 // Uber page is not used on Android.
399 if (url
.host() == chrome::kChromeUIUberHost
)
400 return &NewWebUI
<UberUI
>;
401 #endif // !defined(OS_ANDROID)
403 if (url
.host() == chrome::kChromeUIConflictsHost
)
404 return &NewWebUI
<ConflictsUI
>;
405 if (url
.host() == chrome::kChromeUIMetroFlowHost
)
406 return &NewWebUI
<SetAsDefaultBrowserUI
>;
408 #if defined(OS_CHROMEOS)
409 if (url
.host() == chrome::kChromeUIBluetoothPairingHost
)
410 return &NewWebUI
<chromeos::BluetoothPairingUI
>;
411 if (url
.host() == chrome::kChromeUICertificateManagerHost
)
412 return &NewWebUI
<chromeos::CertificateManagerDialogUI
>;
413 if (url
.host() == chrome::kChromeUIChooseMobileNetworkHost
)
414 return &NewWebUI
<chromeos::ChooseMobileNetworkUI
>;
415 if (url
.host() == chrome::kChromeUICryptohomeHost
)
416 return &NewWebUI
<chromeos::CryptohomeUI
>;
417 if (url
.host() == chrome::kChromeUIDriveInternalsHost
)
418 return &NewWebUI
<chromeos::DriveInternalsUI
>;
419 if (url
.host() == chrome::kChromeUIImageBurnerHost
)
420 return &NewWebUI
<ImageBurnUI
>;
421 if (url
.host() == chrome::kChromeUIFirstRunHost
)
422 return &NewWebUI
<chromeos::FirstRunUI
>;
423 if (url
.host() == chrome::kChromeUIKeyboardOverlayHost
)
424 return &NewWebUI
<KeyboardOverlayUI
>;
425 if (url
.host() == chrome::kChromeUIMobileSetupHost
)
426 return &NewWebUI
<MobileSetupUI
>;
427 if (url
.host() == chrome::kChromeUINfcDebugHost
)
428 return &NewWebUI
<chromeos::NfcDebugUI
>;
429 if (url
.host() == chrome::kChromeUIOobeHost
)
430 return &NewWebUI
<chromeos::OobeUI
>;
431 if (url
.host() == chrome::kChromeUIProvidedFileSystemsHost
)
432 return &NewWebUI
<chromeos::ProvidedFileSystemsUI
>;
433 if (url
.host() == chrome::kChromeUIProxySettingsHost
)
434 return &NewWebUI
<chromeos::ProxySettingsUI
>;
435 if (url
.host() == chrome::kChromeUISalsaHost
)
436 return &NewWebUI
<SalsaUI
>;
437 if (url
.host() == chrome::kChromeUISetTimeHost
)
438 return &NewWebUI
<chromeos::SetTimeUI
>;
439 if (url
.host() == chrome::kChromeUISimUnlockHost
)
440 return &NewWebUI
<chromeos::SimUnlockUI
>;
441 if (url
.host() == chrome::kChromeUISlowHost
)
442 return &NewWebUI
<chromeos::SlowUI
>;
443 if (url
.host() == chrome::kChromeUISlowTraceHost
)
444 return &NewWebUI
<chromeos::SlowTraceController
>;
445 if (url
.host() == chrome::kChromeUINetworkHost
)
446 return &NewWebUI
<chromeos::NetworkUI
>;
447 if (url
.host() == chrome::kChromeUIPowerHost
)
448 return &NewWebUI
<chromeos::PowerUI
>;
449 #endif // defined(OS_CHROMEOS)
450 #if defined(OS_ANDROID) || defined(OS_IOS)
451 if (url
.host() == chrome::kChromeUINetExportHost
)
452 return &NewWebUI
<NetExportUI
>;
454 if (url
.host() == chrome::kChromeUICopresenceHost
)
455 return &NewWebUI
<CopresenceUI
>;
456 if (url
.host() == chrome::kChromeUIChromeSigninHost
)
457 return &NewWebUI
<InlineLoginUI
>;
458 if (url
.SchemeIs(content::kChromeDevToolsScheme
))
459 return &NewWebUI
<DevToolsUI
>;
460 if (url
.host() == chrome::kChromeUIWebRTCDeviceProviderHost
)
461 return &NewWebUI
<WebRTCDeviceProvider::WebUI
>;
463 // chrome://inspect isn't supported on Android nor iOS. Page debugging is
464 // handled by a remote devtools on the host machine, and other elements, i.e.
465 // extensions aren't supported.
466 if (url
.host() == chrome::kChromeUIInspectHost
)
467 return &NewWebUI
<InspectUI
>;
469 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
470 if (url
.host() == chrome::kChromeUIUserManagerHost
&&
471 switches::IsNewAvatarMenu()) {
472 return &NewWebUI
<UserManagerUI
>;
476 /****************************************************************************
477 * Other #defines and special logics.
478 ***************************************************************************/
479 #if !defined(DISABLE_NACL)
480 if (url
.host() == chrome::kChromeUINaClHost
)
481 return &NewWebUI
<NaClUI
>;
483 #if (defined(OS_LINUX) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA)
484 if (url
.host() == chrome::kChromeUITabModalConfirmDialogHost
) {
485 return &NewWebUI
<ConstrainedWebDialogUI
>;
488 #if defined(USE_AURA)
489 if (url
.host() == chrome::kChromeUIGestureConfigHost
)
490 return &NewWebUI
<GestureConfigUI
>;
492 #if (defined(USE_NSS) || defined(USE_OPENSSL_CERTS)) && defined(USE_AURA)
493 if (url
.host() == chrome::kChromeUICertificateViewerHost
)
494 return &NewWebUI
<CertificateViewerUI
>;
495 #if defined(OS_CHROMEOS)
496 if (url
.host() == chrome::kChromeUICertificateViewerDialogHost
)
497 return &NewWebUI
<CertificateViewerModalDialogUI
>;
499 #endif // (defined(USE_NSS) || defined(USE_OPENSSL_CERTS)) && defined(USE_AURA)
501 #if defined(ENABLE_CONFIGURATION_POLICY)
502 if (url
.host() == chrome::kChromeUIPolicyHost
)
503 return &NewWebUI
<PolicyUI
>;
504 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
505 if (url
.host() == chrome::kChromeUIProfileSigninConfirmationHost
)
506 return &NewWebUI
<ProfileSigninConfirmationUI
>;
508 #endif // defined(ENABLE_CONFIGURATION_POLICY)
510 #if defined(ENABLE_APP_LIST)
511 if (url
.host() == chrome::kChromeUIAppListStartPageHost
)
512 return &NewWebUI
<app_list::StartPageUI
>;
514 #if defined(ENABLE_EXTENSIONS)
515 if (url
.host() == chrome::kChromeUIExtensionsFrameHost
)
516 return &NewWebUI
<extensions::ExtensionsUI
>;
517 if (url
.host() == chrome::kChromeUIVoiceSearchHost
)
518 return &NewWebUI
<VoiceSearchUI
>;
520 #if defined(ENABLE_PRINT_PREVIEW)
521 if (url
.host() == chrome::kChromeUIPrintHost
&&
522 !profile
->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled
)) {
523 return &NewWebUI
<PrintPreviewUI
>;
526 #if defined(ENABLE_SERVICE_DISCOVERY)
527 if (url
.host() == chrome::kChromeUIDevicesHost
) {
528 return &NewWebUI
<LocalDiscoveryUI
>;
531 #if defined(ENABLE_WEBRTC)
532 if (url
.host() == chrome::kChromeUIWebRtcLogsHost
)
533 return &NewWebUI
<WebRtcLogsUI
>;
537 return &NewWebUI
<AboutUI
>;
539 if (IsEnableDomDistillerSet() &&
540 url
.host() == dom_distiller::kChromeUIDomDistillerHost
) {
541 return &NewWebUI
<dom_distiller::DomDistillerUi
>;
547 void RunFaviconCallbackAsync(
548 const favicon_base::FaviconResultsCallback
& callback
,
549 const std::vector
<favicon_base::FaviconRawBitmapResult
>* results
) {
550 base::MessageLoopProxy::current()->PostTask(
552 base::Bind(&FaviconService::FaviconResultsCallbackRunner
,
553 callback
, base::Owned(results
)));
558 WebUI::TypeID
ChromeWebUIControllerFactory::GetWebUIType(
559 content::BrowserContext
* browser_context
, const GURL
& url
) const {
560 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
561 WebUIFactoryFunction function
= GetWebUIFactoryFunction(NULL
, profile
, url
);
562 return function
? reinterpret_cast<WebUI::TypeID
>(function
) : WebUI::kNoWebUI
;
565 bool ChromeWebUIControllerFactory::UseWebUIForURL(
566 content::BrowserContext
* browser_context
, const GURL
& url
) const {
567 return GetWebUIType(browser_context
, url
) != WebUI::kNoWebUI
;
570 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL(
571 content::BrowserContext
* browser_context
, const GURL
& url
) const {
572 bool needs_extensions_web_ui
= false;
573 #if defined(ENABLE_EXTENSIONS)
574 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI
575 // bindings (see the ExtensionWebUI constructor).
576 needs_extensions_web_ui
=
577 NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context
), url
);
579 return !needs_extensions_web_ui
&& UseWebUIForURL(browser_context
, url
);
582 WebUIController
* ChromeWebUIControllerFactory::CreateWebUIControllerForURL(
584 const GURL
& url
) const {
585 Profile
* profile
= Profile::FromWebUI(web_ui
);
586 WebUIFactoryFunction function
= GetWebUIFactoryFunction(web_ui
, profile
, url
);
590 return (*function
)(web_ui
, url
);
593 void ChromeWebUIControllerFactory::GetFaviconForURL(
595 const GURL
& page_url
,
596 const std::vector
<int>& desired_sizes_in_pixel
,
597 const favicon_base::FaviconResultsCallback
& callback
) const {
598 // Before determining whether page_url is an extension url, we must handle
599 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and
600 // allows to use ExtensionWebUI::GetFaviconForURL.
602 #if defined(ENABLE_EXTENSIONS)
603 ExtensionWebUI::HandleChromeURLOverride(&url
, profile
);
605 // All extensions but the bookmark manager get their favicon from the icons
606 // part of the manifest.
607 if (url
.SchemeIs(extensions::kExtensionScheme
) &&
608 url
.host() != extension_misc::kBookmarkManagerId
) {
609 ExtensionWebUI::GetFaviconForURL(profile
, url
, callback
);
614 std::vector
<favicon_base::FaviconRawBitmapResult
>* favicon_bitmap_results
=
615 new std::vector
<favicon_base::FaviconRawBitmapResult
>();
617 // Use ui::GetSupportedScaleFactors instead of
618 // favicon_base::GetFaviconScales() because chrome favicons comes from
620 std::vector
<ui::ScaleFactor
> resource_scale_factors
=
621 ui::GetSupportedScaleFactors();
623 std::vector
<gfx::Size
> candidate_sizes
;
624 for (size_t i
= 0; i
< resource_scale_factors
.size(); ++i
) {
625 float scale
= ui::GetScaleForScaleFactor(resource_scale_factors
[i
]);
626 // Assume that GetFaviconResourceBytes() returns favicons which are
627 // |gfx::kFaviconSize| x |gfx::kFaviconSize| DIP.
628 int candidate_edge_size
=
629 static_cast<int>(gfx::kFaviconSize
* scale
+ 0.5f
);
630 candidate_sizes
.push_back(
631 gfx::Size(candidate_edge_size
, candidate_edge_size
));
633 std::vector
<size_t> selected_indices
;
634 SelectFaviconFrameIndices(
635 candidate_sizes
, desired_sizes_in_pixel
, &selected_indices
, NULL
);
636 for (size_t i
= 0; i
< selected_indices
.size(); ++i
) {
637 size_t selected_index
= selected_indices
[i
];
638 ui::ScaleFactor selected_resource_scale
=
639 resource_scale_factors
[selected_index
];
641 scoped_refptr
<base::RefCountedMemory
> bitmap(
642 GetFaviconResourceBytes(url
, selected_resource_scale
));
643 if (bitmap
.get() && bitmap
->size()) {
644 favicon_base::FaviconRawBitmapResult bitmap_result
;
645 bitmap_result
.bitmap_data
= bitmap
;
646 // Leave |bitmap_result|'s icon URL as the default of GURL().
647 bitmap_result
.icon_type
= favicon_base::FAVICON
;
648 favicon_bitmap_results
->push_back(bitmap_result
);
650 bitmap_result
.pixel_size
= candidate_sizes
[selected_index
];
654 RunFaviconCallbackAsync(callback
, favicon_bitmap_results
);
658 ChromeWebUIControllerFactory
* ChromeWebUIControllerFactory::GetInstance() {
659 return Singleton
<ChromeWebUIControllerFactory
>::get();
662 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() {
665 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() {
668 base::RefCountedMemory
* ChromeWebUIControllerFactory::GetFaviconResourceBytes(
669 const GURL
& page_url
, ui::ScaleFactor scale_factor
) const {
670 #if !defined(OS_ANDROID) // Bookmarks are part of NTP on Android.
671 // The bookmark manager is a chrome extension, so we have to check for it
672 // before we check for extension scheme.
673 if (page_url
.host() == extension_misc::kBookmarkManagerId
)
674 return BookmarksUI::GetFaviconResourceBytes(scale_factor
);
676 // The extension scheme is handled in GetFaviconForURL.
677 if (page_url
.SchemeIs(extensions::kExtensionScheme
)) {
683 if (!content::HasWebUIScheme(page_url
))
686 if (page_url
.host() == chrome::kChromeUIComponentsHost
)
687 return ComponentsUI::GetFaviconResourceBytes(scale_factor
);
690 if (page_url
.host() == chrome::kChromeUIConflictsHost
)
691 return ConflictsUI::GetFaviconResourceBytes(scale_factor
);
694 if (page_url
.host() == chrome::kChromeUICrashesHost
)
695 return CrashesUI::GetFaviconResourceBytes(scale_factor
);
697 if (page_url
.host() == chrome::kChromeUIFlagsHost
)
698 return FlagsUI::GetFaviconResourceBytes(scale_factor
);
700 if (page_url
.host() == chrome::kChromeUIHistoryHost
)
701 return HistoryUI::GetFaviconResourceBytes(scale_factor
);
703 #if !defined(OS_ANDROID)
704 // The Apps launcher page is not available on android.
705 if (page_url
.host() == chrome::kChromeUIAppLauncherPageHost
)
706 return AppLauncherPageUI::GetFaviconResourceBytes(scale_factor
);
708 // Flash is not available on android.
709 if (page_url
.host() == chrome::kChromeUIFlashHost
)
710 return FlashUI::GetFaviconResourceBytes(scale_factor
);
712 // Android uses the native download manager.
713 if (page_url
.host() == chrome::kChromeUIDownloadsHost
)
714 return DownloadsUI::GetFaviconResourceBytes(scale_factor
);
716 // Android doesn't use the Options pages.
717 if (page_url
.host() == chrome::kChromeUISettingsHost
||
718 page_url
.host() == chrome::kChromeUISettingsFrameHost
)
719 return options::OptionsUI::GetFaviconResourceBytes(scale_factor
);
721 #if defined(ENABLE_EXTENSIONS)
722 if (page_url
.host() == chrome::kChromeUIExtensionsHost
||
723 page_url
.host() == chrome::kChromeUIExtensionsFrameHost
)
724 return extensions::ExtensionsUI::GetFaviconResourceBytes(scale_factor
);
727 // Android doesn't use the plugins pages.
728 if (page_url
.host() == chrome::kChromeUIPluginsHost
)
729 return PluginsUI::GetFaviconResourceBytes(scale_factor
);