#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/strings/strcat.h"
#include "base/task/single_thread_task_runner.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/buildflags.h"
#include "chrome/browser/commerce/shopping_service_factory.h"
#include "chrome/browser/devtools/devtools_ui_bindings.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/media/media_engagement_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_internals_ui.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/chrome_safe_browsing_local_state_delegate.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_dialog_service_factory.h"
#include "chrome/browser/ui/webui/about/about_ui.h"
#include "chrome/browser/ui/webui/components/components_ui.h"
#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
#include "chrome/browser/ui/webui/crashes_ui.h"
#include "chrome/browser/ui/webui/device_log/device_log_ui.h"
#include "chrome/browser/ui/webui/download_internals/download_internals_ui.h"
#include "chrome/browser/ui/webui/engagement/site_engagement_ui.h"
#include "chrome/browser/ui/webui/family_link_user_internals/family_link_user_internals_ui.h"
#include "chrome/browser/ui/webui/flags/flags_ui.h"
#include "chrome/browser/ui/webui/gcm_internals_ui.h"
#include "chrome/browser/ui/webui/internals/internals_ui.h"
#include "chrome/browser/ui/webui/interstitials/interstitial_ui.h"
#include "chrome/browser/ui/webui/intro/intro_ui.h"
#include "chrome/browser/ui/webui/media/media_engagement_ui.h"
#include "chrome/browser/ui/webui/media/webrtc_logs_ui.h"
#include "chrome/browser/ui/webui/net_export_ui.h"
#include "chrome/browser/ui/webui/net_internals/net_internals_ui.h"
#include "chrome/browser/ui/webui/policy/policy_ui.h"
#include "chrome/browser/ui/webui/privacy_sandbox/privacy_sandbox_internals_ui.h"
#include "chrome/browser/ui/webui/segmentation_internals/segmentation_internals_ui.h"
#include "chrome/browser/ui/webui/signin_internals_ui.h"
#include "chrome/browser/ui/webui/suggest_internals/suggest_internals_ui.h"
#include "chrome/browser/ui/webui/sync_internals/sync_internals_ui.h"
#include "chrome/browser/ui/webui/translate_internals/translate_internals_ui.h"
#include "chrome/browser/ui/webui/usb_internals/usb_internals_ui.h"
#include "chrome/browser/ui/webui/user_actions/user_actions_ui.h"
#include "chrome/browser/ui/webui/version/version_ui.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "components/commerce/content/browser/commerce_internals_ui.h"
#include "components/commerce/core/commerce_constants.h"
#include "components/commerce/core/product_specifications/product_specifications_set.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_util.h"
#include "components/favicon_base/select_favicon_frames.h"
#include "components/grit/components_scaled_resources.h"
#include "components/history/core/browser/history_types.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/history_clusters_internals/webui/history_clusters_internals_ui.h"
#include "components/history_clusters/history_clusters_internals/webui/url_constants.h"
#include "components/lens/buildflags.h"
#include "components/nacl/common/buildflags.h"
#include "components/optimization_guide/optimization_guide_internals/webui/url_constants.h"
#include "components/password_manager/content/common/web_ui_constants.h"
#include "components/prefs/pref_service.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/reading_list/features/reading_list_switches.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/content/browser/web_ui/safe_browsing_ui.h"
#include "components/safe_browsing/core/common/web_ui_constants.h"
#include "components/security_interstitials/content/connection_help_ui.h"
#include "components/security_interstitials/content/known_interception_disclosure_ui.h"
#include "components/security_interstitials/content/urls.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/content_client.h"
#include "content/public/common/url_utils.h"
#include "crypto/crypto_buildflags.h"
#include "extensions/buildflags/buildflags.h"
#include "media/media_buildflags.h"
#include "ppapi/buildflags/buildflags.h"
#include "ui/accessibility/accessibility_features.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/favicon_size.h"
#include "ui/web_dialogs/web_dialog_ui.h"
#include "url/gurl.h"
#include "url/url_constants.h"
#if BUILDFLAG(ENABLE_NACL)
#include "chrome/browser/ui/webui/nacl_ui.h"
#endif
#if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP)
#include "chrome/browser/ui/webui/tab_strip/tab_strip_ui.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/webui/feed_internals/feed_internals_ui.h"
#include "chrome/browser/ui/webui/offline/offline_internals_ui.h"
#include "chrome/browser/ui/webui/webapks/webapks_ui.h"
#include "components/feed/feed_feature_list.h"
#else
#include "chrome/browser/media/router/discovery/access_code/access_code_cast_feature.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/webui/access_code_cast/access_code_cast_ui.h"
#include "chrome/browser/ui/webui/app_service_internals/app_service_internals_ui.h"
#include "chrome/browser/ui/webui/bookmarks/bookmarks_ui.h"
#include "chrome/browser/ui/webui/devtools/devtools_ui.h"
#include "chrome/browser/ui/webui/downloads/downloads_ui.h"
#include "chrome/browser/ui/webui/history/history_ui.h"
#include "chrome/browser/ui/webui/identity_internals_ui.h"
#include "chrome/browser/ui/webui/inspect_ui.h"
#include "chrome/browser/ui/webui/management/management_ui.h"
#include "chrome/browser/ui/webui/media_router/media_router_internals_ui.h"
#include "chrome/browser/ui/webui/new_tab_page/new_tab_page_ui.h"
#include "chrome/browser/ui/webui/new_tab_page_third_party/new_tab_page_third_party_ui.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
#include "chrome/browser/ui/webui/omnibox_popup/omnibox_popup_ui.h"
#include "chrome/browser/ui/webui/page_not_available_for_guest/page_not_available_for_guest_ui.h"
#include "chrome/browser/ui/webui/password_manager/password_manager_ui.h"
#include "chrome/browser/ui/webui/privacy_sandbox/privacy_sandbox_dialog_ui.h"
#include "chrome/browser/ui/webui/search_engine_choice/search_engine_choice_ui.h"
#include "chrome/browser/ui/webui/settings/settings_ui.h"
#include "chrome/browser/ui/webui/settings/settings_utils.h"
#include "chrome/browser/ui/webui/signin/sync_confirmation_ui.h"
#include "chrome/browser/ui/webui/support_tool/support_tool_ui.h"
#include "chrome/browser/ui/webui/sync_file_system_internals/sync_file_system_internals_ui.h"
#include "chrome/browser/ui/webui/system/system_info_ui.h"
#include "chrome/browser/ui/webui/web_app_internals/web_app_internals_ui.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "media/base/media_switches.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/url_constants.h"
#include "ash/webui/camera_app_ui/url_constants.h"
#include "ash/webui/file_manager/url_constants.h"
#include "ash/webui/files_internals/url_constants.h"
#include "ash/webui/growth_internals/constants.h"
#include "ash/webui/help_app_ui/url_constants.h"
#include "ash/webui/mall/url_constants.h"
#include "ash/webui/multidevice_debug/url_constants.h"
#include "ash/webui/print_preview_cros/url_constants.h"
#include "ash/webui/recorder_app_ui/url_constants.h"
#include "ash/webui/vc_background_ui/url_constants.h"
#include "chrome/browser/ash/app_mode/kiosk_controller.h"
#include "chrome/browser/ash/extensions/url_constants.h"
#include "chrome/browser/extensions/extension_keeplist_chromeos.h"
#include "chrome/browser/ui/webui/ash/cellular_setup/mobile_setup_ui.h"
#include "chromeos/ash/components/kiosk/vision/internals_page_processor.h"
#include "chromeos/ash/components/kiosk/vision/webui/constants.h"
#include "chromeos/ash/components/kiosk/vision/webui/ui_controller.h"
#include "chromeos/ash/components/scalable_iph/scalable_iph_constants.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/webui/dlp_internals/dlp_internals_ui.h"
#include "chromeos/crosapi/cpp/gurl_os_handler_utils.h"
#include "url/url_util.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/webui/chromeos/chrome_url_disabled/chrome_url_disabled_ui.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/webui/webui_js_error/webui_js_error_ui.h"
#endif
#if !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/webui/app_home/app_home_ui.h"
#include "chrome/browser/ui/webui/app_settings/web_app_settings_ui.h"
#include "chrome/browser/ui/webui/browser_switch/browser_switch_ui.h"
#include "chrome/browser/ui/webui/welcome/helpers.h"
#include "chrome/browser/ui/webui/welcome/welcome_ui.h"
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH) && !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/webui/signin/managed_user_profile_notice_ui.h"
#include "chrome/browser/ui/webui/signin/profile_customization_ui.h"
#include "chrome/browser/ui/webui/signin/profile_picker_ui.h"
#include "chrome/browser/ui/webui/signin/signin_email_confirmation_ui.h"
#include "chrome/browser/ui/webui/signin/signin_error_ui.h"
#endif
#if BUILDFLAG(IS_WIN)
#include "chrome/browser/ui/webui/conflicts/conflicts_ui.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/webui/commerce/product_specifications_ui.h"
#include "chrome/browser/ui/webui/discards/discards_ui.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || \
BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/webui/sandbox/sandbox_internals_ui.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX) || \
BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ui/webui/connectors_internals/connectors_internals_ui.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#include "chrome/browser/ui/webui/whats_new/whats_new_ui.h"
#endif
#if BUILDFLAG(ENABLE_WEBUI_CERTIFICATE_VIEWER)
#include "chrome/browser/ui/webui/certificate_viewer_ui.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/extensions/extension_web_ui.h"
#include "chrome/browser/ui/webui/extensions/extensions_ui.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/manifest.h"
#endif
#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "chrome/browser/ui/webui/reset_password/reset_password_ui.h"
#endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
#include "chrome/browser/ui/webui/signin/dice_web_signin_intercept_ui.h"
#include "chrome/browser/ui/webui/welcome/helpers.h"
#include "chrome/browser/ui/webui/welcome/welcome_ui.h"
#endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT) || BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ui/webui/signin/inline_login_ui.h"
#endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT) || BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/browser/ui/webui/signin/signin_reauth_ui.h"
#endif
#if BUILDFLAG(ENABLE_LENS_DESKTOP_GOOGLE_BRANDED_FEATURES)
#include "chrome/browser/ui/webui/lens/lens_ui.h"
#endif
WebUI;
WebUIController;
WebDialogUI;
namespace {
void SetUpWebUIDataSource(WebUI* web_ui,
const char* web_ui_host,
base::span<const webui::ResourcePath> resources,
int default_resource) { … }
WebUIFactoryFunction;
template <class T>
WebUIController* NewWebUI(WebUI* web_ui, const GURL& url) { … }
template <class WEB_UI_CONTROLLER, class DELEGATE>
WebUIController* NewComponentUI(WebUI* web_ui, const GURL& url) { … }
#if !BUILDFLAG(IS_ANDROID)
template <>
WebUIController* NewWebUI<PageNotAvailableForGuestUI>(WebUI* web_ui,
const GURL& url) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
template <>
WebUIController* NewWebUI<ash::kiosk_vision::UIController>(WebUI* web_ui,
const GURL& url) {
return new ash::kiosk_vision::UIController(
web_ui, base::BindRepeating(webui::SetupWebUIDataSource),
base::BindRepeating([]() {
return ash::KioskController::Get()
.GetKioskVisionInternalsPageProcessor();
}));
}
#endif
template <>
WebUIController* NewWebUI<commerce::CommerceInternalsUI>(WebUI* web_ui,
const GURL& url) { … }
template <>
WebUIController* NewWebUI<OptimizationGuideInternalsUI>(WebUI* web_ui,
const GURL& url) { … }
template <>
WebUIController* NewWebUI<HistoryClustersInternalsUI>(WebUI* web_ui,
const GURL& url) { … }
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
template <>
WebUIController* NewWebUI<WelcomeUI>(WebUI* web_ui, const GURL& url) { … }
#endif
WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
Profile* profile,
const GURL& url) { … }
}
WebUI::TypeID ChromeWebUIControllerFactory::GetWebUIType(
content::BrowserContext* browser_context,
const GURL& url) { … }
bool ChromeWebUIControllerFactory::UseWebUIForURL(
content::BrowserContext* browser_context,
const GURL& url) { … }
std::unique_ptr<WebUIController>
ChromeWebUIControllerFactory::CreateWebUIControllerForURL(WebUI* web_ui,
const GURL& url) { … }
void ChromeWebUIControllerFactory::GetFaviconForURL(
Profile* profile,
const GURL& page_url,
const std::vector<int>& desired_sizes_in_pixel,
favicon_base::FaviconResultsCallback callback) const { … }
ChromeWebUIControllerFactory* ChromeWebUIControllerFactory::GetInstance() { … }
bool ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests(
const url::Origin& origin) { … }
ChromeWebUIControllerFactory::ChromeWebUIControllerFactory() = default;
ChromeWebUIControllerFactory::~ChromeWebUIControllerFactory() = default;
base::RefCountedMemory* ChromeWebUIControllerFactory::GetFaviconResourceBytes(
const GURL& page_url,
ui::ResourceScaleFactor scale_factor) const { … }
#if BUILDFLAG(IS_CHROMEOS)
const std::vector<GURL>&
ChromeWebUIControllerFactory::GetListOfAcceptableURLs() {
static const base::NoDestructor<std::vector<GURL>> urls({
GURL(chrome::kChromeUIAboutURL),
GURL(chrome::kChromeUIAppServiceInternalsURL),
GURL(chrome::kChromeUIChromeURLsURL),
GURL(chrome::kChromeUIComponentsUrl),
GURL(chrome::kChromeUICreditsURL),
GURL(chrome::kChromeUIDeviceLogUrl),
GURL(chrome::kChromeUIDlpInternalsURL),
GURL(chrome::kChromeUIExtensionsInternalsURL),
GURL(chrome::kChromeUIExtensionsURL),
GURL(chrome::kChromeUIFlagsURL),
GURL(chrome::kChromeUIGpuURL),
GURL(chrome::kChromeUIHistogramsURL),
GURL(chrome::kChromeUIInspectURL),
GURL(chrome::kChromeUIManagementURL),
GURL(chrome::kChromeUINetExportURL),
GURL(chrome::kChromeUIPrefsInternalsURL),
GURL(chrome::kChromeUIRestartURL),
GURL(chrome::kChromeUISignInInternalsUrl),
GURL(chrome::kChromeUISyncInternalsUrl),
GURL(chrome::kChromeUISystemURL),
GURL(chrome::kChromeUITermsURL),
GURL(chrome::kChromeUIVersionURL),
GURL(chrome::kChromeUIWebAppInternalsURL),
#if BUILDFLAG(IS_CHROMEOS_ASH)
GURL(ash::file_manager::kChromeUIFileManagerUntrustedURL),
GURL(ash::file_manager::kChromeUIFileManagerURL),
GURL(ash::kChromeUICameraAppURL),
GURL(ash::kChromeUIFilesInternalsURL),
GURL(ash::kChromeUIHelpAppURL),
GURL(ash::kChromeUIMallUrl),
GURL(ash::kChromeUIPrintPreviewCrosURL),
GURL(ash::kGrowthInternalsUntrustedURL),
GURL(ash::multidevice::kChromeUIProximityAuthURL),
GURL(ash::kChromeUIRecorderAppURL),
GURL(ash::vc_background_ui::kChromeUIVcBackgroundURL),
GURL(chrome::kChromeUIAccountManagerErrorURL),
GURL(chrome::kChromeUIAccountMigrationWelcomeURL),
GURL(chrome::kChromeUIAddSupervisionURL),
GURL(chrome::kChromeUIAppDisabledURL),
GURL(chrome::kChromeUIArcOverviewTracingURL),
GURL(chrome::kChromeUIArcPowerControlURL),
GURL(chrome::kChromeUIAssistantOptInURL),
GURL(chrome::kChromeUIBluetoothInternalsURL),
GURL(chrome::kChromeUIBluetoothPairingURL),
GURL(chrome::kChromeUIBorealisCreditsURL),
GURL(chrome::kChromeUIBorealisInstallerUrl),
GURL(chrome::kChromeUICloudUploadURL),
GURL(chrome::kChromeUILocalFilesMigrationURL),
GURL(chrome::kChromeUIConnectivityDiagnosticsAppURL),
GURL(chrome::kChromeUICrashesUrl),
GURL(chrome::kChromeUICrostiniCreditsURL),
GURL(chrome::kChromeUICrostiniInstallerUrl),
GURL(chrome::kChromeUICrostiniUpgraderUrl),
GURL(chrome::kChromeUICryptohomeURL),
GURL(chrome::kChromeUIDeviceEmulatorURL),
GURL(chrome::kChromeUIDiagnosticsAppURL),
GURL(chrome::kChromeUIDriveInternalsUrl),
GURL(chrome::kChromeUIEmojiPickerURL),
GURL(chrome::kChromeUIEnterpriseReportingURL),
GURL(chrome::kChromeUIFirmwareUpdaterAppURL),
GURL(chrome::kChromeUIFocusModeMediaURL),
GURL(chrome::kChromeUIHealthdInternalsURL),
GURL(chrome::kChromeUIInternetConfigDialogURL),
GURL(chrome::kChromeUIInternetDetailDialogURL),
GURL(chrome::kChromeUILauncherInternalsURL),
GURL(chrome::kChromeUILockScreenNetworkURL),
GURL(chrome::kChromeUILockScreenStartReauthURL),
GURL(chrome::kChromeUIManageMirrorSyncURL),
GURL(chrome::kChromeUIMultiDeviceInternalsURL),
GURL(chrome::kChromeUIMultiDeviceSetupUrl),
GURL(chrome::kChromeUINearbyInternalsURL),
GURL(chrome::kChromeUINetworkUrl),
GURL(chrome::kChromeUINotificationTesterURL),
GURL(chrome::kChromeUIOfficeFallbackURL),
GURL(chrome::kChromeUIOSCreditsURL),
GURL(chrome::kChromeUIOSSettingsURL),
GURL(chrome::kChromeUIPowerUrl),
GURL(chrome::kChromeUIPrintManagementUrl),
GURL(chrome::kChromeUISanitizeAppURL),
GURL(chrome::kChromeUIScanningAppURL),
GURL(chrome::kChromeUISensorInfoURL),
GURL(chrome::kChromeUISetTimeURL),
GURL(chrome::kChromeUISlowURL),
GURL(chrome::kChromeUISmbShareURL),
GURL(chrome::kChromeUISupportToolURL),
GURL(chrome::kChromeUISysInternalsUrl),
GURL(chrome::kChromeUIUntrustedCroshURL),
GURL(chrome::kChromeUIUntrustedTerminalURL),
GURL(chrome::kChromeUIUserImageURL),
GURL(chrome::kChromeUIVmUrl),
GURL(scalable_iph::kScalableIphDebugURL),
#elif BUILDFLAG(IS_CHROMEOS_LACROS)
GURL(chrome::kChromeUIPolicyURL),
GURL(chrome::kChromeUISettingsURL),
#endif
});
return *urls;
}
bool ChromeWebUIControllerFactory::CanHandleUrl(const GURL& url) {
#if BUILDFLAG(IS_CHROMEOS_ASH)
if (url.SchemeIs(extensions::kExtensionScheme) && url.has_host()) {
std::string extension_id = url.host();
return extensions::ExtensionRunsInOS(extension_id);
}
#endif
return crosapi::gurl_os_handler_utils::IsAshUrlInList(
url, GetListOfAcceptableURLs());
}
#endif