#include "components/omnibox/browser/omnibox_edit_model.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include "base/auto_reset.h"
#include "base/feature_list.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/dom_distiller/core/url_constants.h"
#include "components/dom_distiller/core/url_utils.h"
#include "components/history_embeddings/history_embeddings_features.h"
#include "components/navigation_metrics/navigation_metrics.h"
#include "components/omnibox/browser/actions/omnibox_action.h"
#include "components/omnibox/browser/actions/omnibox_pedal.h"
#include "components/omnibox/browser/actions/omnibox_pedal_concepts.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/history_fuzzy_provider.h"
#include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/keyword_provider.h"
#include "components/omnibox/browser/omnibox.mojom-shared.h"
#include "components/omnibox/browser/omnibox_client.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_event_global_tracker.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_log.h"
#include "components/omnibox/browser/omnibox_navigation_observer.h"
#include "components/omnibox/browser/omnibox_popup_selection.h"
#include "components/omnibox/browser/omnibox_popup_view.h"
#include "components/omnibox/browser/omnibox_prefs.h"
#include "components/omnibox/browser/omnibox_view.h"
#include "components/omnibox/browser/page_classification_functions.h"
#include "components/omnibox/browser/search_provider.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "components/omnibox/browser/verbatim_match.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h"
#include "components/strings/grit/components_strings.h"
#include "net/cookies/cookie_util.h"
#include "third_party/icu/source/common/unicode/ubidi.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h"
#include "url/third_party/mozilla/url_parse.h"
#include "url/url_util.h"
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
#include "components/omnibox/browser/vector_icons.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#include "components/vector_icons/vector_icons.h"
#endif
constexpr bool kIsDesktop = …;
BookmarkModel;
OmniboxEventProto;
NavigationPredictor;
namespace {
enum class OmniboxEscapeAction { … };
const char kOmniboxFocusResultedInNavigation[] = …;
const char kEnteredKeywordModeHistogram[] = …;
const char kFocusToOpenTimeHistogram[] = …;
const char kAcceptedKeywordSuggestionHistogram[] = …;
const char kKeywordModeUsageByEngineTypeEnteredHistogramName[] = …;
const char kKeywordModeUsageByEngineTypeAcceptedHistogramName[] = …;
void EmitEnteredKeywordModeHistogram(
OmniboxEventProto::KeywordModeEntryMethod entry_method,
const TemplateURL* turl) { … }
void EmitAcceptedKeywordSuggestionHistogram(
OmniboxEventProto::KeywordModeEntryMethod entry_method,
const TemplateURL* turl) { … }
void RecordActionShownForAllActions(
const AutocompleteResult& result,
OmniboxPopupSelection executed_selection =
OmniboxPopupSelection(OmniboxPopupSelection::kNoMatch)) { … }
size_t CountNumberOfIPv4Parts(const std::u16string& text,
const GURL& url,
size_t completed_length) { … }
}
OmniboxEditModel::State::State(
bool user_input_in_progress,
const std::u16string& user_text,
const std::u16string& keyword,
bool is_keyword_hint,
OmniboxEventProto::KeywordModeEntryMethod keyword_mode_entry_method,
OmniboxFocusState focus_state,
const AutocompleteInput& autocomplete_input)
: … { … }
OmniboxEditModel::State::State(const State& other) = default;
OmniboxEditModel::State::~State() = default;
OmniboxEditModel::OmniboxEditModel(OmniboxController* controller,
OmniboxView* view)
: … { … }
OmniboxEditModel::~OmniboxEditModel() = default;
void OmniboxEditModel::set_popup_view(OmniboxPopupView* popup_view) { … }
metrics::OmniboxEventProto::PageClassification
OmniboxEditModel::GetPageClassification() const { … }
OmniboxEditModel::State OmniboxEditModel::GetStateForTabSwitch() const { … }
void OmniboxEditModel::RestoreState(const State* state) { … }
AutocompleteMatch OmniboxEditModel::CurrentMatch(
GURL* alternate_nav_url) const { … }
bool OmniboxEditModel::ResetDisplayTexts() { … }
std::u16string OmniboxEditModel::GetPermanentDisplayText() const { … }
void OmniboxEditModel::SetUserText(const std::u16string& text) { … }
bool OmniboxEditModel::Unelide() { … }
void OmniboxEditModel::OnChanged() { … }
void OmniboxEditModel::GetDataForURLExport(GURL* url,
std::u16string* title,
gfx::Image* favicon) { … }
bool OmniboxEditModel::CurrentTextIsURL() const { … }
void OmniboxEditModel::AdjustTextForCopy(int sel_min,
std::u16string* text,
GURL* url_from_text,
bool* write_url) { … }
bool OmniboxEditModel::ShouldShowCurrentPageIcon() const { … }
ui::ImageModel OmniboxEditModel::GetSuperGIcon(int image_size,
bool dark_mode) const { … }
void OmniboxEditModel::UpdateInput(bool has_selected_text,
bool prevent_inline_autocomplete) { … }
void OmniboxEditModel::SetInputInProgress(bool in_progress) { … }
void OmniboxEditModel::Revert() { … }
void OmniboxEditModel::StartAutocomplete(bool has_selected_text,
bool prevent_inline_autocomplete) { … }
bool OmniboxEditModel::CanPasteAndGo(const std::u16string& text) const { … }
void OmniboxEditModel::PasteAndGo(const std::u16string& text,
base::TimeTicks match_selection_timestamp) { … }
void OmniboxEditModel::EnterKeywordModeForDefaultSearchProvider(
OmniboxEventProto::KeywordModeEntryMethod entry_method) { … }
void OmniboxEditModel::OpenSelection(OmniboxPopupSelection selection,
base::TimeTicks timestamp,
WindowOpenDisposition disposition) { … }
void OmniboxEditModel::OpenSelection(base::TimeTicks timestamp,
WindowOpenDisposition disposition) { … }
bool OmniboxEditModel::AcceptKeyword(
OmniboxEventProto::KeywordModeEntryMethod entry_method) { … }
void OmniboxEditModel::AcceptTemporaryTextAsUserText() { … }
void OmniboxEditModel::ClearKeyword() { … }
void OmniboxEditModel::ClearAdditionalText() { … }
void OmniboxEditModel::OnSetFocus(bool control_down) { … }
void OmniboxEditModel::StartZeroSuggestRequest(
bool user_clobbered_permanent_text) { … }
void OmniboxEditModel::SetCaretVisibility(bool visible) { … }
void OmniboxEditModel::ConsumeCtrlKey() { … }
void OmniboxEditModel::OnWillKillFocus() { … }
void OmniboxEditModel::OnKillFocus() { … }
bool OmniboxEditModel::OnEscapeKeyPressed() { … }
void OmniboxEditModel::OnControlKeyChanged(bool pressed) { … }
void OmniboxEditModel::OnPaste() { … }
void OmniboxEditModel::OnUpOrDownPressed(bool down, bool page) { … }
void OmniboxEditModel::OnTabPressed(bool shift) { … }
bool OmniboxEditModel::OnSpacePressed() { … }
bool OmniboxEditModel::MaybeAccelerateKeywordSelection(
const std::u16string& input_text,
char16_t ch) { … }
void OmniboxEditModel::OnNavigationLikely(
size_t line,
NavigationPredictor navigation_predictor) { … }
void OmniboxEditModel::OpenMatchForTesting(
AutocompleteMatch match,
WindowOpenDisposition disposition,
const GURL& alternate_nav_url,
const std::u16string& pasted_text,
size_t index,
base::TimeTicks match_selection_timestamp) { … }
void OmniboxEditModel::OnPopupDataChanged(
const std::u16string& temporary_text,
bool is_temporary_text,
const std::u16string& inline_autocompletion,
const std::u16string& prefix_autocompletion,
const std::u16string& keyword,
bool is_keyword_hint,
const std::u16string& additional_text,
const AutocompleteMatch& new_match) { … }
bool OmniboxEditModel::OnAfterPossibleChange(
const OmniboxView::StateChanges& state_changes,
bool allow_keyword_ui_change) { … }
void OmniboxEditModel::OnCurrentMatchChanged() { … }
const char OmniboxEditModel::kCutOrCopyAllTextHistogram[] = …;
void OmniboxEditModel::SetAccessibilityLabel(const AutocompleteMatch& match) { … }
void OmniboxEditModel::InternalSetUserText(const std::u16string& text) { … }
std::u16string OmniboxEditModel::MaybeStripKeyword(
const std::u16string& text) const { … }
std::u16string OmniboxEditModel::MaybePrependKeyword(
const std::u16string& text) const { … }
void OmniboxEditModel::GetInfoForCurrentText(AutocompleteMatch* match,
GURL* alternate_nav_url) const { … }
void OmniboxEditModel::RevertTemporaryTextAndPopup() { … }
bool OmniboxEditModel::IsStarredMatch(const AutocompleteMatch& match) const { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
gfx::Image OmniboxEditModel::GetMatchIcon(const AutocompleteMatch& match,
SkColor vector_icon_color) const { … }
#endif
bool OmniboxEditModel::PopupIsOpen() const { … }
void OmniboxEditModel::ResetPopupToInitialState() { … }
OmniboxPopupSelection OmniboxEditModel::GetPopupSelection() const { … }
void OmniboxEditModel::SetPopupSelection(OmniboxPopupSelection new_selection,
bool reset_to_default,
bool force_update_ui) { … }
bool OmniboxEditModel::IsPopupSelectionOnInitialLine() const { … }
bool OmniboxEditModel::IsPopupControlPresentOnMatch(
OmniboxPopupSelection selection) const { … }
void OmniboxEditModel::TryDeletingPopupLine(size_t line) { … }
std::u16string OmniboxEditModel::GetPopupAccessibilityLabelForCurrentSelection(
const std::u16string& match_text,
bool include_positional_info,
int* label_prefix_length) { … }
std::u16string
OmniboxEditModel::MaybeGetPopupAccessibilityLabelForIPHSuggestion() { … }
void OmniboxEditModel::OnPopupResultChanged() { … }
const SkBitmap* OmniboxEditModel::GetPopupRichSuggestionBitmap(
int result_index) const { … }
void OmniboxEditModel::SetPopupRichSuggestionBitmap(int result_index,
const SkBitmap& bitmap) { … }
void OmniboxEditModel::SetPopupSuggestionGroupVisibility(
size_t match_index,
bool suggestion_group_hidden) { … }
PrefService* OmniboxEditModel::GetPrefService() const { … }
AutocompleteController* OmniboxEditModel::autocomplete_controller() const { … }
bool OmniboxEditModel::MaybeStartQueryForPopup() { … }
void OmniboxEditModel::StepPopupSelection(
OmniboxPopupSelection::Direction direction,
OmniboxPopupSelection::Step step) { … }
void OmniboxEditModel::AcceptInput(WindowOpenDisposition disposition,
base::TimeTicks match_selection_timestamp) { … }
void OmniboxEditModel::OpenMatch(OmniboxPopupSelection selection,
AutocompleteMatch match,
WindowOpenDisposition disposition,
const GURL& alternate_nav_url,
const std::u16string& pasted_text,
base::TimeTicks match_selection_timestamp) { … }
void OmniboxEditModel::UpdateFeedbackOnMatch(size_t match_index,
FeedbackType feedback_type) { … }
bool OmniboxEditModel::AllowKeywordSpaceTriggering() const { … }
bool OmniboxEditModel::MaybeAcceptKeywordBySpace(
const std::u16string& new_text) { … }
bool OmniboxEditModel::CreatedKeywordSearchByInsertingSpaceInMiddle(
const std::u16string& old_text,
const std::u16string& new_text,
size_t caret_position) const { … }
bool OmniboxEditModel::IsSpaceCharForAcceptingKeyword(wchar_t c) { … }
void OmniboxEditModel::ClassifyString(const std::u16string& text,
AutocompleteMatch* match,
GURL* alternate_nav_url) const { … }
bool OmniboxEditModel::SetInputInProgressNoNotify(bool in_progress) { … }
void OmniboxEditModel::NotifyObserversInputInProgress(bool in_progress) { … }
void OmniboxEditModel::SetFocusState(OmniboxFocusState state,
OmniboxFocusChangeReason reason) { … }
void OmniboxEditModel::OnFaviconFetched(const GURL& page_url,
const gfx::Image& icon) const { … }
std::u16string OmniboxEditModel::GetText() const { … }