#include "chrome/browser/ui/webui/history_clusters/history_clusters_handler.h"
#include <algorithm>
#include <optional>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history_clusters/history_clusters_metrics_logger.h"
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/browser_actions.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
#include "chrome/browser/ui/tabs/public/tab_interface.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_web_ui_controller.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/common/pref_names.h"
#include "components/history_clusters/core/cluster_metrics_utils.h"
#include "components/history_clusters/core/config.h"
#include "components/history_clusters/core/features.h"
#include "components/history_clusters/core/history_cluster_type_utils.h"
#include "components/history_clusters/core/history_clusters_prefs.h"
#include "components/history_clusters/core/query_clusters_state.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/page_image_service/image_service.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "ui/actions/actions.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/mojom/window_open_disposition.mojom.h"
#include "ui/base/window_open_disposition.h"
#include "ui/base/window_open_disposition_utils.h"
#include "ui/webui/resources/cr_components/history_clusters/history_clusters.mojom.h"
#include "url/gurl.h"
namespace history_clusters {
namespace {
void InvokeAction(actions::ActionId id, actions::ActionItem* scope) { … }
BrowserWindowInterface* GetBrowserWindowInterface(
absl::variant<BrowserWindowInterface*, tabs::TabInterface*> interface) { … }
class HistoryClustersSidePanelContextMenu
: public ui::SimpleMenuModel,
public ui::SimpleMenuModel::Delegate { … };
}
mojom::QueryResultPtr QueryClustersResultToMojom(
Profile* profile,
const std::string& query,
const std::vector<history::Cluster> clusters_batch,
bool can_load_more,
bool is_continuation) { … }
HistoryClustersHandler::HistoryClustersHandler(
mojo::PendingReceiver<mojom::PageHandler> pending_page_handler,
Profile* profile,
content::WebContents* web_contents,
BrowserWindowInterface* browser_window_interface)
: … { … }
HistoryClustersHandler::HistoryClustersHandler(
mojo::PendingReceiver<mojom::PageHandler> pending_page_handler,
Profile* profile,
content::WebContents* web_contents,
tabs::TabInterface* tab_interface)
: … { … }
void HistoryClustersHandler::CommonInit() { … }
HistoryClustersHandler::~HistoryClustersHandler() = default;
void HistoryClustersHandler::SetSidePanelUIEmbedder(
base::WeakPtr<TopChromeWebUIController::Embedder> side_panel_embedder) { … }
void HistoryClustersHandler::SetQuery(const std::string& query) { … }
void HistoryClustersHandler::OpenHistoryCluster(
const GURL& url,
ui::mojom::ClickModifiersPtr click_modifiers) { … }
void HistoryClustersHandler::SetPage(
mojo::PendingRemote<mojom::Page> pending_page) { … }
void HistoryClustersHandler::ShowSidePanelUI() { … }
void HistoryClustersHandler::ToggleVisibility(
bool visible,
ToggleVisibilityCallback callback) { … }
void HistoryClustersHandler::StartQueryClusters(
const std::string& query,
std::optional<base::Time> begin_time,
bool recluster) { … }
void HistoryClustersHandler::LoadMoreClusters(const std::string& query) { … }
void HistoryClustersHandler::HideVisits(std::vector<mojom::URLVisitPtr> visits,
HideVisitsCallback callback) { … }
void HistoryClustersHandler::RemoveVisits(
std::vector<mojom::URLVisitPtr> visits,
RemoveVisitsCallback callback) { … }
void HistoryClustersHandler::OpenVisitUrlsInTabGroup(
std::vector<mojom::URLVisitPtr> visits,
const std::optional<std::string>& tab_group_name) { … }
void HistoryClustersHandler::OnDebugMessage(const std::string& message) { … }
void HistoryClustersHandler::OnRemoveVisitsComplete() { … }
void HistoryClustersHandler::OnRemoveVisitsFailed() { … }
void HistoryClustersHandler::HistoryDeleted() { … }
Profile* HistoryClustersHandler::GetProfile() { … }
void HistoryClustersHandler::SendClustersToPage(
const std::string& query,
const std::vector<history::Cluster> clusters_batch,
bool can_load_more,
bool is_continuation) { … }
void HistoryClustersHandler::OnHideVisitsComplete() { … }
void HistoryClustersHandler::RecordVisitAction(mojom::VisitAction visit_action,
uint32_t visit_index,
mojom::VisitType visit_type) { … }
void HistoryClustersHandler::RecordClusterAction(
mojom::ClusterAction cluster_action,
uint32_t cluster_index) { … }
void HistoryClustersHandler::RecordRelatedSearchAction(
mojom::RelatedSearchAction action,
uint32_t related_search_index) { … }
void HistoryClustersHandler::RecordToggledVisibility(bool visible) { … }
void HistoryClustersHandler::ShowContextMenuForSearchbox(
const std::string& query,
const gfx::Point& point) { … }
void HistoryClustersHandler::ShowContextMenuForURL(const GURL& url,
const gfx::Point& point) { … }
}