#include "components/omnibox/browser/autocomplete_match.h"
#include <algorithm>
#include <string>
#include <string_view>
#include <vector>
#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/feature_list.h"
#include "base/i18n/case_conversion.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/omnibox/browser/actions/omnibox_action.h"
#include "components/omnibox/browser/actions/omnibox_action_concepts.h"
#include "components/omnibox/browser/actions/omnibox_action_in_suggest.h"
#include "components/omnibox/browser/actions/omnibox_answer_action.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/document_provider.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_engine_utils.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "inline_autocompletion_util.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/omnibox_proto/answer_type.pb.h"
#include "third_party/omnibox_proto/entity_info.pb.h"
#include "third_party/omnibox_proto/groups.pb.h"
#include "ui/gfx/vector_icon_types.h"
#include "url/third_party/mozilla/url_parse.h"
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
#include "components/omnibox/browser/featured_search_provider.h"
#endif
#if (!BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !BUILDFLAG(IS_IOS)
#include "components/omnibox/browser/suggestion_answer.h"
#include "components/omnibox/browser/vector_icons.h"
#include "components/vector_icons/vector_icons.h"
#endif
constexpr bool kIsDesktop = …;
constexpr bool kIsAndroid = …;
namespace {
#if (!BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !BUILDFLAG(IS_IOS)
static gfx::VectorIcon empty_icon;
#endif
bool IsTrivialClassification(const ACMatchClassifications& classifications) { … }
bool WordMatchesURLContent(
const std::vector<std::u16string>& terms_prefixed_by_http_or_https,
const GURL& url) { … }
bool RichAutocompletionApplicable(bool enabled_all_providers,
bool enabled_shortcut_provider,
size_t min_char,
bool shortcut_provider,
const std::u16string& input_text) { … }
int GetDeduplicationProviderPreferenceScore(
const AutocompleteProvider* provider) { … }
template <typename T>
inline void hash_combine(std::size_t& seed, const T& value) { … }
}
template <typename... Args>
size_t ACMatchKeyHash<Args...>::operator()(
const ACMatchKey<Args...>& key) const { … }
template struct ACMatchKeyHash<std::u16string,
std::string>;
template struct ACMatchKeyHash<std::string, bool, bool>;
RichAutocompletionParams::RichAutocompletionParams()
: … { … }
RichAutocompletionParams& RichAutocompletionParams::GetParams() { … }
void RichAutocompletionParams::ClearParamsForTesting() { … }
const char* AutocompleteMatch::DocumentTypeString(DocumentType type) { … }
bool AutocompleteMatch::DocumentTypeFromInteger(int value,
DocumentType* result) { … }
const char16_t AutocompleteMatch::kInvalidChars[] = …;
const char16_t AutocompleteMatch::kEllipsis[] = …;
AutocompleteMatch::AutocompleteMatch()
: … { … }
AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider,
int relevance,
bool deletable,
Type type)
: … { … }
AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match)
: … { … }
AutocompleteMatch::AutocompleteMatch(AutocompleteMatch&& match) noexcept { … }
AutocompleteMatch& AutocompleteMatch::operator=(
AutocompleteMatch&& match) noexcept { … }
AutocompleteMatch::~AutocompleteMatch() { … }
AutocompleteMatch& AutocompleteMatch::operator=(
const AutocompleteMatch& match) { … }
#if (!BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !BUILDFLAG(IS_IOS)
const gfx::VectorIcon& AutocompleteMatch::AnswerTypeToAnswerIcon(int type) { … }
const gfx::VectorIcon& AutocompleteMatch::GetVectorIcon(
bool is_bookmark,
const TemplateURL* turl) const { … }
#endif
bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& match1,
const AutocompleteMatch& match2) { … }
bool AutocompleteMatch::BetterDuplicate(const AutocompleteMatch& match1,
const AutocompleteMatch& match2) { … }
bool AutocompleteMatch::BetterDuplicateByIterator(
const std::vector<AutocompleteMatch>::const_iterator it1,
const std::vector<AutocompleteMatch>::const_iterator it2) { … }
AutocompleteMatch::ACMatchClassifications
AutocompleteMatch::MergeClassifications(
const ACMatchClassifications& classifications1,
const ACMatchClassifications& classifications2) { … }
std::string AutocompleteMatch::ClassificationsToString(
const ACMatchClassifications& classifications) { … }
ACMatchClassifications AutocompleteMatch::ClassificationsFromString(
const std::string& serialized_classifications) { … }
void AutocompleteMatch::AddLastClassificationIfNecessary(
ACMatchClassifications* classifications,
size_t offset,
int style) { … }
std::u16string AutocompleteMatch::SanitizeString(const std::u16string& text) { … }
bool AutocompleteMatch::IsFeaturedEnterpriseSearchType(Type type) { … }
bool AutocompleteMatch::IsFeaturedSearchType(Type type) { … }
bool AutocompleteMatch::IsSearchType(Type type) { … }
bool AutocompleteMatch::IsSpecializedSearchType(Type type) { … }
bool AutocompleteMatch::IsSearchHistoryType(Type type) { … }
bool AutocompleteMatch::IsStarterPackType(Type type) { … }
bool AutocompleteMatch::IsClipboardType(Type type) { … }
bool AutocompleteMatch::ShouldBeSkippedForGroupBySearchVsUrl(Type type) { … }
omnibox::GroupId AutocompleteMatch::GetDefaultGroupId(Type type) { … }
TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
TemplateURLService* template_url_service,
const std::u16string& keyword,
const std::string& host) { … }
const TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
const TemplateURLService* template_url_service,
const std::u16string& keyword,
const std::string& host) { … }
GURL AutocompleteMatch::GURLToStrippedGURL(
const GURL& url,
const AutocompleteInput& input,
const TemplateURLService* template_url_service,
const std::u16string& keyword,
const bool keep_search_intent_params,
const bool normalize_search_terms) { … }
void AutocompleteMatch::GetMatchComponents(
const GURL& url,
const std::vector<MatchPosition>& match_positions,
bool* match_in_scheme,
bool* match_in_subdomain) { … }
url_formatter::FormatUrlTypes AutocompleteMatch::GetFormatTypes(
bool preserve_scheme,
bool preserve_subdomain) { … }
void AutocompleteMatch::LogSearchEngineUsed(
const AutocompleteMatch& match,
TemplateURLService* template_url_service) { … }
void AutocompleteMatch::ComputeStrippedDestinationURL(
const AutocompleteInput& input,
TemplateURLService* template_url_service) { … }
bool AutocompleteMatch::IsDocumentSuggestion() { … }
bool AutocompleteMatch::IsActionCompatible() const { … }
bool AutocompleteMatch::HasInstantKeyword(
TemplateURLService* template_url_service) const { … }
void AutocompleteMatch::GetKeywordUIState(
TemplateURLService* template_url_service,
std::u16string* keyword_out,
bool* is_keyword_hint) const { … }
std::u16string AutocompleteMatch::GetSubstitutingExplicitlyInvokedKeyword(
TemplateURLService* template_url_service) const { … }
TemplateURL* AutocompleteMatch::GetTemplateURL(
TemplateURLService* template_url_service,
bool allow_fallback_to_destination_host) const { … }
GURL AutocompleteMatch::ImageUrl() const { … }
void AutocompleteMatch::RecordAdditionalInfo(const std::string& property,
const std::string& value) { … }
void AutocompleteMatch::RecordAdditionalInfo(const std::string& property,
const std::u16string& value) { … }
void AutocompleteMatch::RecordAdditionalInfo(const std::string& property,
int value) { … }
void AutocompleteMatch::RecordAdditionalInfo(const std::string& property,
double value) { … }
void AutocompleteMatch::RecordAdditionalInfo(const std::string& property,
base::Time value) { … }
std::string AutocompleteMatch::GetAdditionalInfoForDebugging(
const std::string& property) const { … }
metrics::OmniboxEventProto::ProviderType
AutocompleteMatch::GetOmniboxEventProviderType(int action_index) const { … }
metrics::OmniboxEventProto::Suggestion::ResultType
AutocompleteMatch::GetOmniboxEventResultType(int action_index) const { … }
bool AutocompleteMatch::IsVerbatimType() const { … }
bool AutocompleteMatch::IsVerbatimUrlSuggestion() const { … }
bool AutocompleteMatch::IsSearchProviderSearchSuggestion() const { … }
bool AutocompleteMatch::IsOnDeviceSearchSuggestion() const { … }
int AutocompleteMatch::GetSortingOrder() const { … }
bool AutocompleteMatch::IsMlSignalLoggingEligible() const { … }
bool AutocompleteMatch::IsMlScoringEligible() const { … }
bool AutocompleteMatch::IsTrendSuggestion() const { … }
bool AutocompleteMatch::IsIPHSuggestion() const { … }
void AutocompleteMatch::FilterOmniboxActions(
const std::vector<OmniboxActionId>& allowed_action_ids) { … }
void AutocompleteMatch::FilterAndSortActionsInSuggest() { … }
void AutocompleteMatch::RemoveAnswerActions() { … }
bool AutocompleteMatch::IsTrivialAutocompletion() const { … }
bool AutocompleteMatch::SupportsDeletion() const { … }
AutocompleteMatch
AutocompleteMatch::GetMatchWithContentsAndDescriptionPossiblySwapped() const { … }
void AutocompleteMatch::SetAllowedToBeDefault(const AutocompleteInput& input) { … }
size_t AutocompleteMatch::EstimateMemoryUsage() const { … }
void AutocompleteMatch::UpgradeMatchWithPropertiesFrom(
AutocompleteMatch& duplicate_match) { … }
void AutocompleteMatch::MergeScoringSignals(const AutocompleteMatch& other) { … }
bool AutocompleteMatch::TryRichAutocompletion(
const std::u16string& primary_text,
const std::u16string& secondary_text,
const AutocompleteInput& input,
const std::u16string& shortcut_text) { … }
bool AutocompleteMatch::IsEmptyAutocompletion() const { … }
void AutocompleteMatch::WriteIntoTrace(perfetto::TracedValue context) const { … }
OmniboxAction* AutocompleteMatch::GetActionAt(size_t index) const { … }
AutocompleteMatch AutocompleteMatch::CreateActionMatch(
size_t action_index) const { … }
#if DCHECK_IS_ON()
void AutocompleteMatch::Validate() const { … }
#endif
void AutocompleteMatch::ValidateClassifications(
const std::u16string& text,
const ACMatchClassifications& classifications,
const std::string& provider_name) { … }