#include "components/omnibox/browser/search_suggestion_parser.h"
#include <stddef.h>
#include <memory>
#include <optional>
#include <string_view>
#include "base/base64.h"
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h"
#include "base/i18n/icu_string_conversions.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/metrics/histogram_functions.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/utf_string_conversions.h"
#include "base/values.h"
#include "components/omnibox/browser/autocomplete_i18n.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match_classification.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/suggestion_group_util.h"
#include "components/omnibox/browser/url_prefix.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/url_fixer.h"
#include "components/url_formatter/url_formatter.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/omnibox_proto/entity_info.pb.h"
#include "third_party/omnibox_proto/navigational_intent.pb.h"
#include "third_party/omnibox_proto/rich_suggest_template.pb.h"
#include "ui/base/device_form_factor.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/url_constants.h"
namespace {
omnibox::SuggestType GetSuggestType(const std::string& type) { … }
AutocompleteMatchType::Type GetAutocompleteMatchType(
omnibox::SuggestType suggest_type) { … }
std::vector<std::vector<int>> ParseMatchSubtypes(
const base::Value::List* subtypes_list,
size_t expected_size) { … }
std::string FindStringOrEmpty(const base::Value::Dict& value, std::string key) { … }
constexpr char kTypeIntFieldNumber[] = …;
constexpr char kStringValueFieldNumber[] = …;
constexpr auto kReservedReservedGroupSectionsMap = …;
omnibox::GroupSection ChromeGroupSectionForRemoteGroupIndex(
const int group_index) { … }
template <typename T>
bool DecodeProtoFromBase64(const std::string* encoded_data, T& result_proto) { … }
void FormatAnswerTemplateImageURL(
omnibox::RichAnswerTemplate* answer_template) { … }
}
omnibox::SuggestSubtype SuggestSubtypeForNumber(int value) { … }
omnibox::NavigationalIntent NavigationalIntentForNumber(int value) { … }
omnibox::AnswerType AnswerTypeForNumber(int value) { … }
SearchSuggestionParser::Result::Result(
bool from_keyword,
int relevance,
bool relevance_from_server,
AutocompleteMatchType::Type type,
omnibox::SuggestType suggest_type,
std::vector<int> subtypes,
const std::string& deletion_url,
omnibox::NavigationalIntent navigational_intent)
: … { … }
SearchSuggestionParser::Result::Result(const Result& other) = default;
SearchSuggestionParser::Result::~Result() { … }
SearchSuggestionParser::SuggestResult::SuggestResult(
const std::u16string& suggestion,
AutocompleteMatchType::Type type,
omnibox::SuggestType suggest_type,
std::vector<int> subtypes,
bool from_keyword,
omnibox::NavigationalIntent navigational_intent,
int relevance,
bool relevance_from_server,
const std::u16string& input_text)
: … { … }
SearchSuggestionParser::SuggestResult::SuggestResult(
const std::u16string& suggestion,
AutocompleteMatchType::Type type,
omnibox::SuggestType suggest_type,
std::vector<int> subtypes,
const std::u16string& match_contents,
const std::u16string& match_contents_prefix,
const std::u16string& annotation,
omnibox::EntityInfo entity_info,
const std::string& deletion_url,
bool from_keyword,
omnibox::NavigationalIntent navigational_intent,
int relevance,
bool relevance_from_server,
bool should_prefetch,
bool should_prerender,
const std::u16string& input_text)
: … { … }
SearchSuggestionParser::SuggestResult::SuggestResult(
const SuggestResult& result) = default;
SearchSuggestionParser::SuggestResult::~SuggestResult() { … }
SearchSuggestionParser::SuggestResult&
SearchSuggestionParser::SuggestResult::operator=(const SuggestResult& rhs) =
default;
void SearchSuggestionParser::SuggestResult::ClassifyMatchContents(
const bool allow_bolding_all,
const std::u16string& input_text) { … }
void SearchSuggestionParser::SuggestResult::SetAnswer(
const SuggestionAnswer& answer) { … }
void SearchSuggestionParser::SuggestResult::SetRichAnswerTemplate(
const omnibox::RichAnswerTemplate& answer_template) { … }
void SearchSuggestionParser::SuggestResult::SetAnswerType(
const omnibox::AnswerType& answer_type) { … }
void SearchSuggestionParser::SuggestResult::SetEntityInfo(
const omnibox::EntityInfo& entity_info) { … }
int SearchSuggestionParser::SuggestResult::CalculateRelevance(
const AutocompleteInput& input,
bool keyword_provider_requested) const { … }
SearchSuggestionParser::NavigationResult::NavigationResult(
const AutocompleteSchemeClassifier& scheme_classifier,
const GURL& url,
AutocompleteMatchType::Type match_type,
omnibox::SuggestType suggest_type,
std::vector<int> subtypes,
const std::u16string& description,
const std::string& deletion_url,
bool from_keyword,
omnibox::NavigationalIntent navigational_intent,
int relevance,
bool relevance_from_server,
const std::u16string& input_text)
: … { … }
SearchSuggestionParser::NavigationResult::NavigationResult(
const NavigationResult& other) = default;
SearchSuggestionParser::NavigationResult::~NavigationResult() { … }
void SearchSuggestionParser::NavigationResult::
CalculateAndClassifyMatchContents(const bool allow_bolding_nothing,
const std::u16string& input_text) { … }
int SearchSuggestionParser::NavigationResult::CalculateRelevance(
const AutocompleteInput& input,
bool keyword_provider_requested) const { … }
void SearchSuggestionParser::NavigationResult::ClassifyDescription(
const std::u16string& input_text) { … }
SearchSuggestionParser::Results::Results()
: … { … }
SearchSuggestionParser::Results::~Results() { … }
void SearchSuggestionParser::Results::Clear() { … }
bool SearchSuggestionParser::Results::HasServerProvidedScores() const { … }
std::string SearchSuggestionParser::ExtractJsonData(
const network::SimpleURLLoader* source,
std::unique_ptr<std::string> response_body) { … }
std::optional<base::Value::List> SearchSuggestionParser::DeserializeJsonData(
std::string_view json_data) { … }
bool SearchSuggestionParser::ParseSuggestResults(
const base::Value::List& root_list,
const AutocompleteInput& input,
const AutocompleteSchemeClassifier& scheme_classifier,
int default_result_relevance,
bool is_keyword_result,
Results* results) { … }