chromium/components/omnibox/browser/autocomplete_match.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)

#if (!BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !BUILDFLAG(IS_IOS)
#include "components/omnibox/browser/suggestion_answer.h"
#include "components/omnibox/browser/vector_icons.h"  // nogncheck
#include "components/vector_icons/vector_icons.h"     // nogncheck
#endif

constexpr bool kIsDesktop =;
constexpr bool kIsAndroid =;

namespace {

#if (!BUILDFLAG(IS_ANDROID) || BUILDFLAG(ENABLE_VR)) && !BUILDFLAG(IS_IOS)
// Used for `SEARCH_SUGGEST_TAIL` and `NULL_RESULT_MESSAGE` (e.g. starter pack)
// type suggestion icons.
static gfx::VectorIcon empty_icon;
#endif

bool IsTrivialClassification(const ACMatchClassifications& classifications) {}

// Returns true if one of the |terms_prefixed_by_http_or_https| matches the
// beginning of the URL (sans scheme).  (Recall that
// |terms_prefixed_by_http_or_https|, for the input "http://a b" will be
// ["a"].)  This suggests that the user wants a particular URL with a scheme
// in mind, hence the caller should not consider another URL like this one
// but with a different scheme to be a duplicate.
bool WordMatchesURLContent(
    const std::vector<std::u16string>& terms_prefixed_by_http_or_https,
    const GURL& url) {}

// Check if title, non-prefix, or shortcut rich autocompletion is possible. Both
// must be true:
// 1) Either the feature is enabled for all providers OR the suggestion is from
//    the shortcut provider.
// 2) The input is at least `min_char` long.
bool RichAutocompletionApplicable(bool enabled_all_providers,
                                  bool enabled_shortcut_provider,
                                  size_t min_char,
                                  bool shortcut_provider,
                                  const std::u16string& input_text) {}

// Gives a basis for match comparison that prefers some providers over others
// while remaining neutral with a default score of zero for most providers.
int GetDeduplicationProviderPreferenceScore(
    const AutocompleteProvider* provider) {}

// Implementation of boost::hash_combine
// http://www.boost.org/doc/libs/1_43_0/doc/html/hash/reference.html#boost.hash_combine
template <typename T>
inline void hash_combine(std::size_t& seed, const T& value) {}

}  // namespace

template <typename... Args>
size_t ACMatchKeyHash<Args...>::operator()(
    const ACMatchKey<Args...>& key) const {}

// This trick allows implementing ACMatchKeyHash in the implementation file.
// Every unique specialization of ACMatchKey should have a corresponding
// declaration here.
template struct ACMatchKeyHash<std::u16string,
                               std::string>;  // base_search_provider
template struct ACMatchKeyHash<std::string, bool, bool>;  // autocomplete_result

// RichAutocompletionParams ---------------------------------------------------

RichAutocompletionParams::RichAutocompletionParams()
    :{}

RichAutocompletionParams& RichAutocompletionParams::GetParams() {}

void RichAutocompletionParams::ClearParamsForTesting() {}

// AutocompleteMatch ----------------------------------------------------------

// static
const char* AutocompleteMatch::DocumentTypeString(DocumentType type) {}

// static
bool AutocompleteMatch::DocumentTypeFromInteger(int value,
                                                DocumentType* result) {}

// static
const char16_t AutocompleteMatch::kInvalidChars[] =;

// static
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)
// static
const gfx::VectorIcon& AutocompleteMatch::AnswerTypeToAnswerIcon(int type) {}

const gfx::VectorIcon& AutocompleteMatch::GetVectorIcon(
    bool is_bookmark,
    const TemplateURL* turl) const {}
#endif

// static
bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& match1,
                                     const AutocompleteMatch& match2) {}

// static
bool AutocompleteMatch::BetterDuplicate(const AutocompleteMatch& match1,
                                        const AutocompleteMatch& match2) {}

// static
bool AutocompleteMatch::BetterDuplicateByIterator(
    const std::vector<AutocompleteMatch>::const_iterator it1,
    const std::vector<AutocompleteMatch>::const_iterator it2) {}

// static
AutocompleteMatch::ACMatchClassifications
AutocompleteMatch::MergeClassifications(
    const ACMatchClassifications& classifications1,
    const ACMatchClassifications& classifications2) {}

// static
std::string AutocompleteMatch::ClassificationsToString(
    const ACMatchClassifications& classifications) {}

// static
ACMatchClassifications AutocompleteMatch::ClassificationsFromString(
    const std::string& serialized_classifications) {}

// static
void AutocompleteMatch::AddLastClassificationIfNecessary(
    ACMatchClassifications* classifications,
    size_t offset,
    int style) {}

// static
std::u16string AutocompleteMatch::SanitizeString(const std::u16string& text) {}

// static
bool AutocompleteMatch::IsFeaturedEnterpriseSearchType(Type type) {}

// static
bool AutocompleteMatch::IsFeaturedSearchType(Type type) {}

// static
bool AutocompleteMatch::IsSearchType(Type type) {}

// static
bool AutocompleteMatch::IsSpecializedSearchType(Type type) {}

// static
bool AutocompleteMatch::IsSearchHistoryType(Type type) {}

bool AutocompleteMatch::IsStarterPackType(Type type) {}

bool AutocompleteMatch::IsClipboardType(Type type) {}

// static
bool AutocompleteMatch::ShouldBeSkippedForGroupBySearchVsUrl(Type type) {}

// static
omnibox::GroupId AutocompleteMatch::GetDefaultGroupId(Type type) {}

// static
TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
    TemplateURLService* template_url_service,
    const std::u16string& keyword,
    const std::string& host) {}

// static
const TemplateURL* AutocompleteMatch::GetTemplateURLWithKeyword(
    const TemplateURLService* template_url_service,
    const std::u16string& keyword,
    const std::string& host) {}

// static
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) {}

// static
void AutocompleteMatch::GetMatchComponents(
    const GURL& url,
    const std::vector<MatchPosition>& match_positions,
    bool* match_in_scheme,
    bool* match_in_subdomain) {}

// static
url_formatter::FormatUrlTypes AutocompleteMatch::GetFormatTypes(
    bool preserve_scheme,
    bool preserve_subdomain) {}

// static
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  // DCHECK_IS_ON()

// static
void AutocompleteMatch::ValidateClassifications(
    const std::u16string& text,
    const ACMatchClassifications& classifications,
    const std::string& provider_name) {}