cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / ui / webui / chrome_web_ui_controller_factory.cc
blobcb00c1c82b5157b79e1a017d5741bb88cbcbbb94
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"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "chrome/browser/about_flags.h"
15 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/ui/webui/about_ui.h"
19 #include "chrome/browser/ui/webui/bookmarks_ui.h"
20 #include "chrome/browser/ui/webui/components_ui.h"
21 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
22 #include "chrome/browser/ui/webui/crashes_ui.h"
23 #include "chrome/browser/ui/webui/device_log_ui.h"
24 #include "chrome/browser/ui/webui/domain_reliability_internals_ui.h"
25 #include "chrome/browser/ui/webui/downloads_ui.h"
26 #include "chrome/browser/ui/webui/flags_ui.h"
27 #include "chrome/browser/ui/webui/flash_ui.h"
28 #include "chrome/browser/ui/webui/gcm_internals_ui.h"
29 #include "chrome/browser/ui/webui/help/help_ui.h"
30 #include "chrome/browser/ui/webui/history_ui.h"
31 #include "chrome/browser/ui/webui/identity_internals_ui.h"
32 #include "chrome/browser/ui/webui/instant_ui.h"
33 #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
34 #include "chrome/browser/ui/webui/invalidations_ui.h"
35 #include "chrome/browser/ui/webui/local_state/local_state_ui.h"
36 #include "chrome/browser/ui/webui/memory_internals/memory_internals_ui.h"
37 #include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
38 #include "chrome/browser/ui/webui/omnibox/omnibox_ui.h"
39 #include "chrome/browser/ui/webui/options/options_ui.h"
40 #include "chrome/browser/ui/webui/password_manager_internals/password_manager_internals_ui.h"
41 #include "chrome/browser/ui/webui/plugins_ui.h"
42 #include "chrome/browser/ui/webui/predictors/predictors_ui.h"
43 #include "chrome/browser/ui/webui/profiler_ui.h"
44 #include "chrome/browser/ui/webui/settings/md_settings_ui.h"
45 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
46 #include "chrome/browser/ui/webui/signin/profile_signin_confirmation_ui.h"
47 #include "chrome/browser/ui/webui/signin/user_manager_ui.h"
48 #include "chrome/browser/ui/webui/signin_internals_ui.h"
49 #include "chrome/browser/ui/webui/supervised_user_internals_ui.h"
50 #include "chrome/browser/ui/webui/sync_internals_ui.h"
51 #include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"
52 #include "chrome/browser/ui/webui/user_actions/user_actions_ui.h"
53 #include "chrome/browser/ui/webui/version_ui.h"
54 #include "chrome/common/chrome_switches.h"
55 #include "chrome/common/pref_names.h"
56 #include "chrome/common/url_constants.h"
57 #include "components/dom_distiller/core/dom_distiller_constants.h"
58 #include "components/dom_distiller/core/dom_distiller_features.h"
59 #include "components/dom_distiller/core/dom_distiller_service.h"
60 #include "components/dom_distiller/core/url_constants.h"
61 #include "components/dom_distiller/webui/dom_distiller_ui.h"
62 #include "components/favicon/core/favicon_service.h"
63 #include "components/favicon_base/favicon_util.h"
64 #include "components/favicon_base/select_favicon_frames.h"
65 #include "components/history/core/browser/history_types.h"
66 #include "components/password_manager/core/common/password_manager_switches.h"
67 #include "components/signin/core/common/profile_management_switches.h"
68 #include "content/public/browser/web_contents.h"
69 #include "content/public/browser/web_ui.h"
70 #include "content/public/common/content_client.h"
71 #include "content/public/common/url_utils.h"
72 #include "ui/gfx/favicon_size.h"
73 #include "ui/web_dialogs/web_dialog_ui.h"
74 #include "url/gurl.h"
76 #if !defined(DISABLE_NACL)
77 #include "chrome/browser/ui/webui/nacl_ui.h"
78 #endif
80 #if defined(ENABLE_CONFIGURATION_POLICY)
81 #include "chrome/browser/ui/webui/policy_ui.h"
82 #endif
84 #if defined(ENABLE_WEBRTC)
85 #include "chrome/browser/ui/webui/media/webrtc_logs_ui.h"
86 #endif
88 #if defined(ENABLE_PRINT_PREVIEW)
89 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
90 #endif
92 #if defined(ENABLE_MEDIA_ROUTER) && !defined(OS_ANDROID)
93 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
94 #endif
96 #if !defined(OS_ANDROID)
97 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
98 #include "chrome/browser/ui/webui/quota_internals/quota_internals_ui.h"
99 #include "chrome/browser/ui/webui/sync_file_system_internals/sync_file_system_internals_ui.h"
100 #include "chrome/browser/ui/webui/system_info_ui.h"
101 #include "chrome/browser/ui/webui/uber/uber_ui.h"
102 #endif
104 #if defined(OS_ANDROID) || defined(OS_IOS)
105 #include "chrome/browser/ui/webui/net_export_ui.h"
106 #else
107 #include "chrome/browser/devtools/device/webrtc/webrtc_device_provider.h"
108 #include "chrome/browser/signin/easy_unlock_service.h"
109 #include "chrome/browser/signin/easy_unlock_service_factory.h"
110 #include "chrome/browser/ui/webui/copresence_ui.h"
111 #include "chrome/browser/ui/webui/devtools_ui.h"
112 #include "chrome/browser/ui/webui/inspect_ui.h"
113 #endif
115 #if defined(OS_CHROMEOS)
116 #include "base/sys_info.h"
117 #include "chrome/browser/ui/webui/chromeos/bluetooth_pairing_ui.h"
118 #include "chrome/browser/ui/webui/chromeos/certificate_manager_dialog_ui.h"
119 #include "chrome/browser/ui/webui/chromeos/choose_mobile_network_ui.h"
120 #include "chrome/browser/ui/webui/chromeos/cryptohome_ui.h"
121 #include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
122 #include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
123 #include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h"
124 #include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h"
125 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
126 #include "chrome/browser/ui/webui/chromeos/mobile_setup_ui.h"
127 #include "chrome/browser/ui/webui/chromeos/network_ui.h"
128 #include "chrome/browser/ui/webui/chromeos/nfc_debug_ui.h"
129 #include "chrome/browser/ui/webui/chromeos/power_ui.h"
130 #include "chrome/browser/ui/webui/chromeos/proxy_settings_ui.h"
131 #include "chrome/browser/ui/webui/chromeos/salsa_ui.h"
132 #include "chrome/browser/ui/webui/chromeos/set_time_ui.h"
133 #include "chrome/browser/ui/webui/chromeos/sim_unlock_ui.h"
134 #include "chrome/browser/ui/webui/chromeos/slow_trace_ui.h"
135 #include "chrome/browser/ui/webui/chromeos/slow_ui.h"
136 #include "chrome/browser/ui/webui/voice_search_ui.h"
137 #include "components/proximity_auth/webui/proximity_auth_ui.h"
138 #include "components/proximity_auth/webui/url_constants.h"
139 #endif
141 #if !defined(OFFICIAL_BUILD) && defined(OS_CHROMEOS) && !defined(NDEBUG)
142 #include "chrome/browser/ui/webui/chromeos/emulator/device_emulator_ui.h"
143 #endif
145 #if !defined(OS_CHROMEOS)
146 #include "chrome/browser/ui/webui/app_launcher_page_ui.h"
147 #endif
149 #if defined(USE_AURA)
150 #include "chrome/browser/ui/webui/gesture_config_ui.h"
151 #endif
153 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
154 #include "chrome/browser/ui/sync/sync_promo_ui.h"
155 #endif
157 #if defined(OS_WIN)
158 #include "chrome/browser/ui/webui/conflicts_ui.h"
159 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h"
160 #endif
162 #if (defined(USE_NSS_CERTS) || defined(USE_OPENSSL_CERTS)) && defined(USE_AURA)
163 #include "chrome/browser/ui/webui/certificate_viewer_ui.h"
164 #endif
166 #if defined(ENABLE_SERVICE_DISCOVERY)
167 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui.h"
168 #endif
170 #if defined(ENABLE_APP_LIST)
171 #include "chrome/browser/ui/webui/app_list/start_page_ui.h"
172 #endif
174 #if defined(ENABLE_EXTENSIONS)
175 #include "chrome/browser/extensions/extension_web_ui.h"
176 #include "chrome/browser/ui/webui/extensions/extensions_ui.h"
177 #include "chrome/common/extensions/extension_constants.h"
178 #include "extensions/browser/extension_registry.h"
179 #include "extensions/browser/extension_system.h"
180 #include "extensions/common/constants.h"
181 #include "extensions/common/extension.h"
182 #include "extensions/common/feature_switch.h"
183 #include "extensions/common/manifest.h"
184 #endif
186 using content::WebUI;
187 using content::WebUIController;
188 using ui::WebDialogUI;
190 namespace {
192 // A function for creating a new WebUI. The caller owns the return value, which
193 // may be NULL (for example, if the URL refers to an non-existent extension).
194 typedef WebUIController* (*WebUIFactoryFunction)(WebUI* web_ui,
195 const GURL& url);
197 // Template for defining WebUIFactoryFunction.
198 template<class T>
199 WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) {
200 return new T(web_ui);
203 #if defined(ENABLE_EXTENSIONS)
204 // Special cases for extensions.
205 template<>
206 WebUIController* NewWebUI<ExtensionWebUI>(WebUI* web_ui,
207 const GURL& url) {
208 return new ExtensionWebUI(web_ui, url);
210 #endif // defined(ENABLE_EXTENSIONS)
212 // Special case for older about: handlers.
213 template<>
214 WebUIController* NewWebUI<AboutUI>(WebUI* web_ui, const GURL& url) {
215 return new AboutUI(web_ui, url.host());
218 #if defined(OS_CHROMEOS)
219 template<>
220 WebUIController* NewWebUI<chromeos::OobeUI>(WebUI* web_ui, const GURL& url) {
221 return new chromeos::OobeUI(web_ui, url);
224 // Special case for chrome://proximity_auth.
225 template <>
226 WebUIController* NewWebUI<proximity_auth::ProximityAuthUI>(WebUI* web_ui,
227 const GURL& url) {
228 content::BrowserContext* browser_context =
229 web_ui->GetWebContents()->GetBrowserContext();
230 return new proximity_auth::ProximityAuthUI(
231 web_ui, EasyUnlockServiceFactory::GetForBrowserContext(browser_context)
232 ->proximity_auth_client());
234 #endif
236 // Special cases for DOM distiller.
237 template<>
238 WebUIController* NewWebUI<dom_distiller::DomDistillerUi>(WebUI* web_ui,
239 const GURL& url) {
240 // The DomDistillerUi can not depend on components/dom_distiller/content,
241 // so inject the correct DomDistillerService from chrome/.
242 content::BrowserContext* browser_context =
243 web_ui->GetWebContents()->GetBrowserContext();
244 dom_distiller::DomDistillerService* service =
245 dom_distiller::DomDistillerServiceFactory::GetForBrowserContext(
246 browser_context);
247 return new dom_distiller::DomDistillerUi(
248 web_ui, service, dom_distiller::kDomDistillerScheme);
251 #if defined(ENABLE_EXTENSIONS)
252 // Only create ExtensionWebUI for URLs that are allowed extension bindings,
253 // hosted by actual tabs.
254 bool NeedsExtensionWebUI(Profile* profile, const GURL& url) {
255 if (!profile)
256 return false;
258 const extensions::Extension* extension =
259 extensions::ExtensionRegistry::Get(profile)->enabled_extensions().
260 GetExtensionOrAppByURL(url);
261 // Allow bindings for all packaged extensions and component hosted apps.
262 return extension &&
263 (!extension->is_hosted_app() ||
264 extension->location() == extensions::Manifest::COMPONENT);
266 #endif
268 bool IsAboutUI(const GURL& url) {
269 return (url.host() == chrome::kChromeUIChromeURLsHost ||
270 url.host() == chrome::kChromeUICreditsHost ||
271 url.host() == chrome::kChromeUIDNSHost ||
272 url.host() == chrome::kChromeUIMemoryHost ||
273 url.host() == chrome::kChromeUIMemoryRedirectHost
274 #if !defined(OS_ANDROID)
275 || url.host() == chrome::kChromeUITermsHost
276 #endif
277 #if defined(OS_LINUX) || defined(OS_OPENBSD)
278 || url.host() == chrome::kChromeUILinuxProxyConfigHost ||
279 url.host() == chrome::kChromeUISandboxHost
280 #endif
281 #if defined(OS_CHROMEOS)
282 || url.host() == chrome::kChromeUIOSCreditsHost
283 #endif
284 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
285 || url.host() == chrome::kChromeUIDiscardsHost
286 #endif
287 ); // NOLINT
290 // Returns a function that can be used to create the right type of WebUI for a
291 // tab, based on its URL. Returns NULL if the URL doesn't have WebUI associated
292 // with it.
293 WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
294 Profile* profile,
295 const GURL& url) {
296 #if defined(ENABLE_EXTENSIONS)
297 if (NeedsExtensionWebUI(profile, url))
298 return &NewWebUI<ExtensionWebUI>;
299 #endif
301 // This will get called a lot to check all URLs, so do a quick check of other
302 // schemes to filter out most URLs.
303 if (!url.SchemeIs(content::kChromeDevToolsScheme) &&
304 !url.SchemeIs(content::kChromeUIScheme)) {
305 return NULL;
308 /****************************************************************************
309 * Please keep this in alphabetical order. If #ifs or special logics are
310 * required, add it below in the appropriate section.
311 ***************************************************************************/
312 // We must compare hosts only since some of the Web UIs append extra stuff
313 // after the host name.
314 // All platform builds of Chrome will need to have a cloud printing
315 // dialog as backup. It's just that on Chrome OS, it's the only
316 // print dialog.
317 if (url.host() == chrome::kChromeUIComponentsHost)
318 return &NewWebUI<ComponentsUI>;
319 if (url.spec() == chrome::kChromeUIConstrainedHTMLTestURL)
320 return &NewWebUI<ConstrainedWebDialogUI>;
321 if (url.host() == chrome::kChromeUICrashesHost)
322 return &NewWebUI<CrashesUI>;
323 if (url.host() == chrome::kChromeUIDeviceLogHost)
324 return &NewWebUI<chromeos::DeviceLogUI>;
325 if (url.host() == chrome::kChromeUIDomainReliabilityInternalsHost)
326 return &NewWebUI<DomainReliabilityInternalsUI>;
327 if (url.host() == chrome::kChromeUIFlagsHost)
328 return &NewWebUI<FlagsUI>;
329 if (url.host() == chrome::kChromeUIHistoryFrameHost)
330 return &NewWebUI<HistoryUI>;
331 if (url.host() == chrome::kChromeUIInstantHost)
332 return &NewWebUI<InstantUI>;
333 if (url.host() == chrome::kChromeUIInterstitialHost)
334 return &NewWebUI<InterstitialUI>;
335 if (url.host() == chrome::kChromeUIInvalidationsHost)
336 return &NewWebUI<InvalidationsUI>;
337 if (url.host() == chrome::kChromeUILocalStateHost)
338 return &NewWebUI<LocalStateUI>;
339 if (url.host() == chrome::kChromeUIMemoryInternalsHost)
340 return &NewWebUI<MemoryInternalsUI>;
341 if (url.host() == chrome::kChromeUINetInternalsHost)
342 return &NewWebUI<NetInternalsUI>;
343 if (url.host() == chrome::kChromeUIOmniboxHost)
344 return &NewWebUI<OmniboxUI>;
345 if (url.host() == chrome::kChromeUIPasswordManagerInternalsHost)
346 return &NewWebUI<PasswordManagerInternalsUI>;
347 if (url.host() == chrome::kChromeUIPredictorsHost)
348 return &NewWebUI<PredictorsUI>;
349 if (url.host() == chrome::kChromeUIProfilerHost)
350 return &NewWebUI<ProfilerUI>;
351 if (url.host() == chrome::kChromeUISignInInternalsHost)
352 return &NewWebUI<SignInInternalsUI>;
353 if (url.host() == chrome::kChromeUISupervisedUserInternalsHost)
354 return &NewWebUI<SupervisedUserInternalsUI>;
355 if (url.host() == chrome::kChromeUISupervisedUserPassphrasePageHost)
356 return &NewWebUI<ConstrainedWebDialogUI>;
357 if (url.host() == chrome::kChromeUISyncInternalsHost)
358 return &NewWebUI<SyncInternalsUI>;
359 if (url.host() == chrome::kChromeUISyncResourcesHost)
360 return &NewWebUI<WebDialogUI>;
361 if (url.host() == chrome::kChromeUITranslateInternalsHost)
362 return &NewWebUI<TranslateInternalsUI>;
363 if (url.host() == chrome::kChromeUIUserActionsHost)
364 return &NewWebUI<UserActionsUI>;
365 if (url.host() == chrome::kChromeUIVersionHost)
366 return &NewWebUI<VersionUI>;
368 /****************************************************************************
369 * OS Specific #defines
370 ***************************************************************************/
371 #if !defined(OS_ANDROID)
372 #if !defined(OS_CHROMEOS)
373 // AppLauncherPage is not needed on Android or ChromeOS.
374 if (url.host() == chrome::kChromeUIAppLauncherPageHost &&
375 profile && extensions::ExtensionSystem::Get(profile)->
376 extension_service()) {
377 return &NewWebUI<AppLauncherPageUI>;
379 #endif
381 // Bookmarks are part of NTP on Android.
382 if (url.host() == chrome::kChromeUIBookmarksHost)
383 return &NewWebUI<BookmarksUI>;
384 // Downloads list on Android uses the built-in download manager.
385 if (url.host() == chrome::kChromeUIDownloadsHost)
386 return &NewWebUI<DownloadsUI>;
387 if (url.host() == chrome::kChromeUIGCMInternalsHost)
388 return &NewWebUI<GCMInternalsUI>;
389 // Help is implemented with native UI elements on Android.
390 if (url.host() == chrome::kChromeUIHelpFrameHost)
391 return &NewWebUI<HelpUI>;
392 // Identity API is not available on Android.
393 if (url.host() == chrome::kChromeUIIdentityInternalsHost)
394 return &NewWebUI<IdentityInternalsUI>;
395 if (url.host() == chrome::kChromeUINewTabHost)
396 return &NewWebUI<NewTabUI>;
397 if (url.host() == chrome::kChromeUIMdSettingsHost &&
398 ::switches::MdSettingsEnabled()) {
399 return &NewWebUI<settings::MdSettingsUI>;
401 if (url.host() == chrome::kChromeUIQuotaInternalsHost)
402 return &NewWebUI<QuotaInternalsUI>;
403 // Settings are implemented with native UI elements on Android.
404 // Handle chrome://settings if settings in a window and about in settings
405 // are enabled.
406 if (url.host() == chrome::kChromeUISettingsFrameHost ||
407 (url.host() == chrome::kChromeUISettingsHost &&
408 ::switches::AboutInSettingsEnabled())) {
409 return &NewWebUI<options::OptionsUI>;
411 if (url.host() == chrome::kChromeUISyncFileSystemInternalsHost)
412 return &NewWebUI<SyncFileSystemInternalsUI>;
413 if (url.host() == chrome::kChromeUISystemInfoHost)
414 return &NewWebUI<SystemInfoUI>;
415 // Uber frame is not used on Android.
416 if (url.host() == chrome::kChromeUIUberFrameHost)
417 return &NewWebUI<UberFrameUI>;
418 // Uber page is not used on Android.
419 if (url.host() == chrome::kChromeUIUberHost)
420 return &NewWebUI<UberUI>;
421 #endif // !defined(OS_ANDROID)
422 #if defined(OS_WIN)
423 if (url.host() == chrome::kChromeUIConflictsHost)
424 return &NewWebUI<ConflictsUI>;
425 if (url.host() == chrome::kChromeUIMetroFlowHost)
426 return &NewWebUI<SetAsDefaultBrowserUI>;
427 #endif
428 #if defined(OS_CHROMEOS)
429 if (url.host() == chrome::kChromeUIBluetoothPairingHost)
430 return &NewWebUI<chromeos::BluetoothPairingUI>;
431 if (url.host() == chrome::kChromeUICertificateManagerHost)
432 return &NewWebUI<chromeos::CertificateManagerDialogUI>;
433 if (url.host() == chrome::kChromeUIChooseMobileNetworkHost)
434 return &NewWebUI<chromeos::ChooseMobileNetworkUI>;
435 if (url.host() == chrome::kChromeUICryptohomeHost)
436 return &NewWebUI<chromeos::CryptohomeUI>;
437 if (url.host() == chrome::kChromeUIDriveInternalsHost)
438 return &NewWebUI<chromeos::DriveInternalsUI>;
439 if (url.host() == chrome::kChromeUIImageBurnerHost)
440 return &NewWebUI<ImageBurnUI>;
441 if (url.host() == chrome::kChromeUIFirstRunHost)
442 return &NewWebUI<chromeos::FirstRunUI>;
443 if (url.host() == chrome::kChromeUIKeyboardOverlayHost)
444 return &NewWebUI<KeyboardOverlayUI>;
445 if (url.host() == chrome::kChromeUIMobileSetupHost)
446 return &NewWebUI<MobileSetupUI>;
447 if (url.host() == chrome::kChromeUINetworkHost)
448 return &NewWebUI<chromeos::NetworkUI>;
449 if (url.host() == chrome::kChromeUINfcDebugHost)
450 return &NewWebUI<chromeos::NfcDebugUI>;
451 if (url.host() == chrome::kChromeUIOobeHost)
452 return &NewWebUI<chromeos::OobeUI>;
453 if (url.host() == chrome::kChromeUIPowerHost)
454 return &NewWebUI<chromeos::PowerUI>;
455 if (url.host() == proximity_auth::kChromeUIProximityAuthHost)
456 return &NewWebUI<proximity_auth::ProximityAuthUI>;
457 if (url.host() == chrome::kChromeUIProxySettingsHost)
458 return &NewWebUI<chromeos::ProxySettingsUI>;
459 if (url.host() == chrome::kChromeUISalsaHost)
460 return &NewWebUI<SalsaUI>;
461 if (url.host() == chrome::kChromeUISetTimeHost)
462 return &NewWebUI<chromeos::SetTimeUI>;
463 if (url.host() == chrome::kChromeUISimUnlockHost)
464 return &NewWebUI<chromeos::SimUnlockUI>;
465 if (url.host() == chrome::kChromeUISlowHost)
466 return &NewWebUI<chromeos::SlowUI>;
467 if (url.host() == chrome::kChromeUISlowTraceHost)
468 return &NewWebUI<chromeos::SlowTraceController>;
469 if (url.host() == chrome::kChromeUIVoiceSearchHost)
470 return &NewWebUI<VoiceSearchUI>;
471 #endif // defined(OS_CHROMEOS)
472 #if !defined(OFFICIAL_BUILD) && defined(OS_CHROMEOS) && !defined(NDEBUG)
473 if (!base::SysInfo::IsRunningOnChromeOS()) {
474 if (url.host() == chrome::kChromeUIDeviceEmulatorHost)
475 return &NewWebUI<DeviceEmulatorUI>;
477 #endif // !defined(OFFICIAL_BUILD) && defined(OS_CHROMEOS) && !defined(NDEBUG)
478 #if defined(OS_ANDROID) || defined(OS_IOS)
479 if (url.host() == chrome::kChromeUINetExportHost)
480 return &NewWebUI<NetExportUI>;
481 #else
482 if (url.host() == chrome::kChromeUICopresenceHost)
483 return &NewWebUI<CopresenceUI>;
484 if (url.host() == chrome::kChromeUIChromeSigninHost)
485 return &NewWebUI<InlineLoginUI>;
486 if (url.SchemeIs(content::kChromeDevToolsScheme))
487 return &NewWebUI<DevToolsUI>;
488 if (url.host() == chrome::kChromeUIWebRTCDeviceProviderHost)
489 return &NewWebUI<WebRTCDeviceProvider::WebUI>;
491 // chrome://inspect isn't supported on Android nor iOS. Page debugging is
492 // handled by a remote devtools on the host machine, and other elements, i.e.
493 // extensions aren't supported.
494 if (url.host() == chrome::kChromeUIInspectHost)
495 return &NewWebUI<InspectUI>;
496 #endif
497 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS)
498 if (url.host() == chrome::kChromeUIUserManagerHost &&
499 switches::IsNewAvatarMenu()) {
500 return &NewWebUI<UserManagerUI>;
502 #endif
504 /****************************************************************************
505 * Other #defines and special logics.
506 ***************************************************************************/
507 #if !defined(DISABLE_NACL)
508 if (url.host() == chrome::kChromeUINaClHost)
509 return &NewWebUI<NaClUI>;
510 #endif
511 #if (defined(OS_LINUX) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA)
512 if (url.host() == chrome::kChromeUITabModalConfirmDialogHost) {
513 return &NewWebUI<ConstrainedWebDialogUI>;
515 #endif
516 #if defined(USE_AURA)
517 if (url.host() == chrome::kChromeUIGestureConfigHost)
518 return &NewWebUI<GestureConfigUI>;
519 #endif
520 #if (defined(USE_NSS_CERTS) || defined(USE_OPENSSL_CERTS)) && defined(USE_AURA)
521 if (url.host() == chrome::kChromeUICertificateViewerHost)
522 return &NewWebUI<CertificateViewerUI>;
523 #if defined(OS_CHROMEOS)
524 if (url.host() == chrome::kChromeUICertificateViewerDialogHost)
525 return &NewWebUI<CertificateViewerModalDialogUI>;
526 #endif
527 #endif // (USE_NSS_CERTS || USE_OPENSSL_CERTS) && USE_AURA
529 #if defined(ENABLE_CONFIGURATION_POLICY)
530 if (url.host() == chrome::kChromeUIPolicyHost)
531 return &NewWebUI<PolicyUI>;
532 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
533 if (url.host() == chrome::kChromeUIProfileSigninConfirmationHost)
534 return &NewWebUI<ProfileSigninConfirmationUI>;
535 #endif
536 #endif // defined(ENABLE_CONFIGURATION_POLICY)
538 #if defined(ENABLE_APP_LIST)
539 if (url.host() == chrome::kChromeUIAppListStartPageHost)
540 return &NewWebUI<app_list::StartPageUI>;
541 #endif
542 #if defined(ENABLE_EXTENSIONS)
543 if (url.host() == chrome::kChromeUIExtensionsFrameHost)
544 return &NewWebUI<extensions::ExtensionsUI>;
545 #endif
546 #if defined(ENABLE_PLUGINS)
547 if (url.host() == chrome::kChromeUIFlashHost)
548 return &NewWebUI<FlashUI>;
549 if (url.host() == chrome::kChromeUIPluginsHost)
550 return &NewWebUI<PluginsUI>;
551 #endif
552 #if defined(ENABLE_PRINT_PREVIEW)
553 if (url.host() == chrome::kChromeUIPrintHost &&
554 !profile->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) {
555 return &NewWebUI<PrintPreviewUI>;
557 #endif
558 #if defined(ENABLE_SERVICE_DISCOVERY)
559 if (url.host() == chrome::kChromeUIDevicesHost) {
560 return &NewWebUI<LocalDiscoveryUI>;
562 #endif
563 #if defined(ENABLE_WEBRTC)
564 if (url.host() == chrome::kChromeUIWebRtcLogsHost)
565 return &NewWebUI<WebRtcLogsUI>;
566 #endif
567 #if defined(ENABLE_MEDIA_ROUTER) && !defined(OS_ANDROID)
568 if (url.host() == chrome::kChromeUIMediaRouterHost &&
569 switches::MediaRouterEnabled()) {
570 return &NewWebUI<media_router::MediaRouterUI>;
572 #endif
573 if (IsAboutUI(url))
574 return &NewWebUI<AboutUI>;
576 if (dom_distiller::IsEnableDomDistillerSet() &&
577 url.host() == dom_distiller::kChromeUIDomDistillerHost) {
578 return &NewWebUI<dom_distiller::DomDistillerUi>;
581 return NULL;
584 void RunFaviconCallbackAsync(
585 const favicon_base::FaviconResultsCallback& callback,
586 const std::vector<favicon_base::FaviconRawBitmapResult>* results) {
587 base::ThreadTaskRunnerHandle::Get()->PostTask(
588 FROM_HERE,
589 base::Bind(&favicon::FaviconService::FaviconResultsCallbackRunner,
590 callback, base::Owned(results)));
593 } // namespace
595 WebUI::TypeID ChromeWebUIControllerFactory::GetWebUIType(
596 content::BrowserContext* browser_context, const GURL& url) const {
597 Profile* profile = Profile::FromBrowserContext(browser_context);
598 WebUIFactoryFunction function = GetWebUIFactoryFunction(NULL, profile, url);
599 return function ? reinterpret_cast<WebUI::TypeID>(function) : WebUI::kNoWebUI;
602 bool ChromeWebUIControllerFactory::UseWebUIForURL(
603 content::BrowserContext* browser_context, const GURL& url) const {
604 return GetWebUIType(browser_context, url) != WebUI::kNoWebUI;
607 bool ChromeWebUIControllerFactory::UseWebUIBindingsForURL(
608 content::BrowserContext* browser_context, const GURL& url) const {
609 bool needs_extensions_web_ui = false;
610 #if defined(ENABLE_EXTENSIONS)
611 // Extensions are rendered via WebUI in tabs, but don't actually need WebUI
612 // bindings (see the ExtensionWebUI constructor).
613 needs_extensions_web_ui =
614 NeedsExtensionWebUI(Profile::FromBrowserContext(browser_context), url);
615 #endif
616 return !needs_extensions_web_ui && UseWebUIForURL(browser_context, url);
619 WebUIController* ChromeWebUIControllerFactory::CreateWebUIControllerForURL(
620 WebUI* web_ui,
621 const GURL& url) const {
622 Profile* profile = Profile::FromWebUI(web_ui);
623 WebUIFactoryFunction function = GetWebUIFactoryFunction(web_ui, profile, url);
624 if (!function)
625 return NULL;
627 return (*function)(web_ui, url);
630 void ChromeWebUIControllerFactory::GetFaviconForURL(
631 Profile* profile,
632 const GURL& page_url,
633 const std::vector<int>& desired_sizes_in_pixel,
634 const favicon_base::FaviconResultsCallback& callback) const {
635 // Before determining whether page_url is an extension url, we must handle
636 // overrides. This changes urls in |kChromeUIScheme| to extension urls, and
637 // allows to use ExtensionWebUI::GetFaviconForURL.
638 GURL url(page_url);
639 #if defined(ENABLE_EXTENSIONS)
640 ExtensionWebUI::HandleChromeURLOverride(&url, profile);
642 // All extensions but the bookmark manager get their favicon from the icons
643 // part of the manifest.
644 if (url.SchemeIs(extensions::kExtensionScheme) &&
645 url.host() != extension_misc::kBookmarkManagerId) {
646 ExtensionWebUI::GetFaviconForURL(profile, url, callback);
647 return;
649 #endif
651 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results =
652 new std::vector<favicon_base::FaviconRawBitmapResult>();
654 // Use ui::GetSupportedScaleFactors instead of
655 // favicon_base::GetFaviconScales() because chrome favicons comes from
656 // resources.
657 std::vector<ui::ScaleFactor> resource_scale_factors =
658 ui::GetSupportedScaleFactors();
660 std::vector<gfx::Size> candidate_sizes;
661 for (size_t i = 0; i < resource_scale_factors.size(); ++i) {
662 float scale = ui::GetScaleForScaleFactor(resource_scale_factors[i]);
663 // Assume that GetFaviconResourceBytes() returns favicons which are
664 // |gfx::kFaviconSize| x |gfx::kFaviconSize| DIP.
665 int candidate_edge_size =
666 static_cast<int>(gfx::kFaviconSize * scale + 0.5f);
667 candidate_sizes.push_back(
668 gfx::Size(candidate_edge_size, candidate_edge_size));
670 std::vector<size_t> selected_indices;
671 SelectFaviconFrameIndices(
672 candidate_sizes, desired_sizes_in_pixel, &selected_indices, NULL);
673 for (size_t i = 0; i < selected_indices.size(); ++i) {
674 size_t selected_index = selected_indices[i];
675 ui::ScaleFactor selected_resource_scale =
676 resource_scale_factors[selected_index];
678 scoped_refptr<base::RefCountedMemory> bitmap(
679 GetFaviconResourceBytes(url, selected_resource_scale));
680 if (bitmap.get() && bitmap->size()) {
681 favicon_base::FaviconRawBitmapResult bitmap_result;
682 bitmap_result.bitmap_data = bitmap;
683 // Leave |bitmap_result|'s icon URL as the default of GURL().
684 bitmap_result.icon_type = favicon_base::FAVICON;
685 favicon_bitmap_results->push_back(bitmap_result);
687 bitmap_result.pixel_size = candidate_sizes[selected_index];
691 RunFaviconCallbackAsync(callback, favicon_bitmap_results);
694 // static
695 ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() {
696 return Singleton<ChromeWebUIControllerFactory>::get();
699 ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() {
702 ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() {
705 base::RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes(
706 const GURL& page_url, ui::ScaleFactor scale_factor) const {
707 #if !defined(OS_ANDROID) // Bookmarks are part of NTP on Android.
708 // The bookmark manager is a chrome extension, so we have to check for it
709 // before we check for extension scheme.
710 if (page_url.host() == extension_misc::kBookmarkManagerId)
711 return BookmarksUI::GetFaviconResourceBytes(scale_factor);
713 // The extension scheme is handled in GetFaviconForURL.
714 if (page_url.SchemeIs(extensions::kExtensionScheme)) {
715 NOTREACHED();
716 return NULL;
718 #endif
720 if (!content::HasWebUIScheme(page_url))
721 return NULL;
723 if (page_url.host() == chrome::kChromeUIComponentsHost)
724 return ComponentsUI::GetFaviconResourceBytes(scale_factor);
726 #if defined(OS_WIN)
727 if (page_url.host() == chrome::kChromeUIConflictsHost)
728 return ConflictsUI::GetFaviconResourceBytes(scale_factor);
729 #endif
731 if (page_url.host() == chrome::kChromeUICrashesHost)
732 return CrashesUI::GetFaviconResourceBytes(scale_factor);
734 if (page_url.host() == chrome::kChromeUIFlagsHost)
735 return FlagsUI::GetFaviconResourceBytes(scale_factor);
737 if (page_url.host() == chrome::kChromeUIHistoryHost)
738 return HistoryUI::GetFaviconResourceBytes(scale_factor);
740 #if !defined(OS_ANDROID)
741 #if !defined(OS_CHROMEOS)
742 // The Apps launcher page is not available on android or ChromeOS.
743 if (page_url.host() == chrome::kChromeUIAppLauncherPageHost)
744 return AppLauncherPageUI::GetFaviconResourceBytes(scale_factor);
745 #endif
747 // Flash is not available on android.
748 if (page_url.host() == chrome::kChromeUIFlashHost)
749 return FlashUI::GetFaviconResourceBytes(scale_factor);
751 // Android uses the native download manager.
752 if (page_url.host() == chrome::kChromeUIDownloadsHost)
753 return DownloadsUI::GetFaviconResourceBytes(scale_factor);
755 // Android doesn't use the Options pages.
756 if (page_url.host() == chrome::kChromeUISettingsHost ||
757 page_url.host() == chrome::kChromeUISettingsFrameHost)
758 return options::OptionsUI::GetFaviconResourceBytes(scale_factor);
760 #if defined(ENABLE_EXTENSIONS)
761 if (page_url.host() == chrome::kChromeUIExtensionsHost ||
762 page_url.host() == chrome::kChromeUIExtensionsFrameHost)
763 return extensions::ExtensionsUI::GetFaviconResourceBytes(scale_factor);
764 #endif
766 // Android doesn't use the plugins pages.
767 if (page_url.host() == chrome::kChromeUIPluginsHost)
768 return PluginsUI::GetFaviconResourceBytes(scale_factor);
770 #endif
772 return NULL;