diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn index 32019ab5d2f60c..b0f3dfa2264aad 100644 --- a/chrome/browser/ui/BUILD.gn +++ b/chrome/browser/ui/BUILD.gn @@ -196,6 +196,8 @@ static_library("ui") { "webui/flags/flags_ui_handler.h", "webui/gcm_internals_ui.cc", "webui/gcm_internals_ui.h", + "webui/history_clusters/history_clusters_internals_ui_config.cc", + "webui/history_clusters/history_clusters_internals_ui_config.h", "webui/internals/internals_ui.cc", "webui/internals/internals_ui.h", "webui/interstitials/interstitial_ui.cc", diff --git a/chrome/browser/ui/webui/chrome_web_ui_configs.cc b/chrome/browser/ui/webui/chrome_web_ui_configs.cc index 4b5a6b95a99bf8..e38d6caa0778e2 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_configs.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_configs.cc @@ -21,6 +21,7 @@ #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/history_clusters/history_clusters_internals_ui_config.h" #include "chrome/browser/ui/webui/internals/internals_ui.h" #include "chrome/browser/ui/webui/interstitials/interstitial_ui.h" #include "chrome/browser/ui/webui/local_state/local_state_ui.h" @@ -227,6 +228,9 @@ void RegisterChromeWebUIConfigs() { map.AddWebUIConfig(std::make_unique()); map.AddWebUIConfig(std::make_unique()); map.AddWebUIConfig(std::make_unique()); + map.AddWebUIConfig( + std::make_unique< + history_clusters_internals::HistoryClustersInternalsUIConfig>()); map.AddWebUIConfig(std::make_unique()); map.AddWebUIConfig(std::make_unique()); map.AddWebUIConfig(std::make_unique()); diff --git a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc index 29b796234df061..222fbdd2c778a8 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc +++ b/chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc @@ -21,8 +21,6 @@ #include "chrome/browser/about_flags.h" #include "chrome/browser/buildflags.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/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" @@ -45,9 +43,6 @@ #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/optimization_guide/optimization_guide_internals/webui/url_constants.h" #include "components/password_manager/content/common/web_ui_constants.h" @@ -197,19 +192,6 @@ WebUIController* NewWebUI(WebUI* web_ui, kChromeUIOptimizationGuideInternalsHost)); } -template <> -WebUIController* NewWebUI(WebUI* web_ui, - const GURL& url) { - Profile* profile = Profile::FromWebUI(web_ui); - return new HistoryClustersInternalsUI( - web_ui, HistoryClustersServiceFactory::GetForBrowserContext(profile), - HistoryServiceFactory::GetForProfile(profile, - ServiceAccessType::EXPLICIT_ACCESS), - base::BindOnce( - &SetUpWebUIDataSource, web_ui, - history_clusters_internals::kChromeUIHistoryClustersInternalsHost)); -} - // Returns a function that can be used to create the right type of WebUI for a // tab, based on its URL. Returns nullptr if the URL doesn't have WebUI // associated with it. @@ -234,10 +216,6 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui, optimization_guide_internals::kChromeUIOptimizationGuideInternalsHost) { return &NewWebUI; } - if (url.host_piece() == - history_clusters_internals::kChromeUIHistoryClustersInternalsHost) { - return &NewWebUI; - } #if !BUILDFLAG(IS_ANDROID) if (url.SchemeIs(content::kChromeDevToolsScheme)) { diff --git a/chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.cc b/chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.cc new file mode 100644 index 00000000000000..b84700ed36f15b --- /dev/null +++ b/chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.cc @@ -0,0 +1,50 @@ +// Copyright 2024 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.h" + +#include "chrome/browser/history/history_service_factory.h" +#include "chrome/browser/history_clusters/history_clusters_service_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/webui/webui_util.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 "content/public/browser/web_contents.h" +#include "content/public/browser/web_ui_data_source.h" + +namespace history_clusters_internals { + +// TODO(crbug.com/40222519): Move SetupWebUIDataSource() to a location +// accessible from components/, such as in //ui/base/webui, so that the only +// 'wrapping' in this Config class is HistoryClustersServiceFactory. +void SetUpWebUIDataSource(content::WebUI* web_ui, + const char* web_ui_host, + base::span resources, + int default_resource) { + content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd( + web_ui->GetWebContents()->GetBrowserContext(), web_ui_host); + webui::SetupWebUIDataSource(source, resources, default_resource); +} + +HistoryClustersInternalsUIConfig::HistoryClustersInternalsUIConfig() + : WebUIConfig( + content::kChromeUIScheme, + history_clusters_internals::kChromeUIHistoryClustersInternalsHost) {} + +HistoryClustersInternalsUIConfig::~HistoryClustersInternalsUIConfig() = default; + +std::unique_ptr +HistoryClustersInternalsUIConfig::CreateWebUIController(content::WebUI* web_ui, + const GURL& url) { + Profile* profile = Profile::FromWebUI(web_ui); + return std::make_unique( + web_ui, HistoryClustersServiceFactory::GetForBrowserContext(profile), + HistoryServiceFactory::GetForProfile(profile, + ServiceAccessType::EXPLICIT_ACCESS), + base::BindOnce( + &SetUpWebUIDataSource, web_ui, + history_clusters_internals::kChromeUIHistoryClustersInternalsHost)); +} + +} // namespace history_clusters_internals diff --git a/chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.h b/chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.h new file mode 100644 index 00000000000000..5fe9bae2040dde --- /dev/null +++ b/chrome/browser/ui/webui/history_clusters/history_clusters_internals_ui_config.h @@ -0,0 +1,26 @@ +// Copyright 2024 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_HISTORY_CLUSTERS_HISTORY_CLUSTERS_INTERNALS_UI_CONFIG_H_ +#define CHROME_BROWSER_UI_WEBUI_HISTORY_CLUSTERS_HISTORY_CLUSTERS_INTERNALS_UI_CONFIG_H_ + +#include "content/public/browser/webui_config.h" +#include "content/public/common/url_constants.h" + +namespace history_clusters_internals { + +class HistoryClustersInternalsUIConfig : public content::WebUIConfig { + public: + HistoryClustersInternalsUIConfig(); + ~HistoryClustersInternalsUIConfig() override; + + // content::WebUIConfig: + std::unique_ptr CreateWebUIController( + content::WebUI* web_ui, + const GURL& url) override; +}; + +} // namespace history_clusters_internals + +#endif // CHROME_BROWSER_UI_WEBUI_HISTORY_CLUSTERS_HISTORY_CLUSTERS_INTERNALS_UI_CONFIG_H_ diff --git a/tools/metrics/histograms/enums.xml b/tools/metrics/histograms/enums.xml index 7c099cf6d00fee..414b53451ba8d4 100644 --- a/tools/metrics/histograms/enums.xml +++ b/tools/metrics/histograms/enums.xml @@ -34027,6 +34027,7 @@ Called by update_use_counter_feature_enum.py.--> +