#include "chrome/browser/ui/webui/omnibox/omnibox_page_handler.h"
#include <stddef.h>
#include <string>
#include <utility>
#include "base/auto_reset.h"
#include "base/base64.h"
#include "base/check.h"
#include "base/functional/bind.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 "base/values.h"
#include "chrome/browser/autocomplete/autocomplete_scoring_model_service_factory.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/webui/omnibox/omnibox.mojom-forward.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/url_database.h"
#include "components/omnibox/browser/actions/omnibox_pedal.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_controller_emitter.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/optimization_guide/machine_learning_tflite_buildflags.h"
#include "components/search_engines/template_url.h"
#include "content/public/browser/web_ui.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
#include "third_party/omnibox_proto/answer_data.pb.h"
#include "third_party/omnibox_proto/answer_type.pb.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
#if BUILDFLAG(BUILD_WITH_TFLITE_LIB)
#include "components/omnibox/browser/autocomplete_scoring_model_service.h"
#endif
BookmarkModel;
namespace {
std::string AnswerTypeToString(int answer_type) { … }
std::string SuggestionAnswerImageLineToString(
const SuggestionAnswer::ImageLine& image_line) { … }
}
namespace mojo {
template <>
struct TypeConverter<std::vector<mojom::ACMatchClassificationPtr>,
AutocompleteMatch::ACMatchClassifications> { … };
#define PROTO_TO_MOJOM_SIGNAL …
#define MOJOM_TO_PROTO_SIGNAL …
template <>
struct TypeConverter<mojom::SignalsPtr, AutocompleteMatch::ScoringSignals> { … };
template <>
struct TypeConverter<AutocompleteMatch::ScoringSignals, mojom::SignalsPtr> { … };
#undef PROTO_TO_MOJOM_SIGNAL
#undef MOJOM_TO_PROTO_SIGNAL
template <>
struct TypeConverter<std::vector<mojom::DictionaryEntryPtr>,
AutocompleteMatch::AdditionalInfo> { … };
template <>
struct TypeConverter<mojom::AutocompleteMatchPtr, AutocompleteMatch> { … };
template <>
struct TypeConverter<mojom::AutocompleteResultsForProviderPtr,
scoped_refptr<AutocompleteProvider>> { … };
}
OmniboxPageHandler::OmniboxPageHandler(
Profile* profile,
mojo::PendingReceiver<mojom::OmniboxPageHandler> receiver)
: … { … }
OmniboxPageHandler::~OmniboxPageHandler() = default;
void OmniboxPageHandler::OnStart(AutocompleteController* controller,
const AutocompleteInput& input) { … }
void OmniboxPageHandler::OnResultChanged(AutocompleteController* controller,
bool default_match_changed) { … }
void OmniboxPageHandler::OnMlScored(AutocompleteController* controller,
const AutocompleteResult& result) { … }
void OmniboxPageHandler::OnBitmapFetched(mojom::AutocompleteControllerType type,
const std::string& image_url,
const SkBitmap& bitmap) { … }
bool OmniboxPageHandler::LookupIsTypedHost(const std::u16string& host,
bool* is_typed_host) const { … }
void OmniboxPageHandler::SetClientPage(
mojo::PendingRemote<mojom::OmniboxPage> page) { … }
void OmniboxPageHandler::StartOmniboxQuery(const std::string& input_string,
bool reset_autocomplete_controller,
int32_t cursor_position,
bool zero_suggest,
bool prevent_inline_autocomplete,
bool prefer_keyword,
const std::string& current_url,
int32_t page_classification) { … }
void OmniboxPageHandler::GetMlModelVersion(GetMlModelVersionCallback callback) { … }
void OmniboxPageHandler::StartMl(mojom::SignalsPtr mojom_signals,
StartMlCallback callback) { … }
std::unique_ptr<AutocompleteController> OmniboxPageHandler::CreateController(
bool ml_disabled) { … }
mojom::AutocompleteControllerType
OmniboxPageHandler::GetAutocompleteControllerType(
AutocompleteController* controller) { … }
AutocompleteScoringModelService* OmniboxPageHandler::GetMlService() { … }