#include "chrome/browser/ui/webui/searchbox/searchbox_handler.h"
#include "base/base64.h"
#include "base/base64url.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/new_tab_page/new_tab_page_util.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_service.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/metrics_reporter/metrics_reporter.h"
#include "chrome/grit/generated_resources.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/omnibox/browser/omnibox_controller.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/vector_icons.h"
#include "components/search/ntp_features.h"
#include "components/strings/grit/components_strings.h"
#include "components/variations/variations_client.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_ui_data_source.h"
#include "third_party/omnibox_proto/answer_data.pb.h"
#include "third_party/omnibox_proto/answer_type.pb.h"
#include "third_party/omnibox_proto/rich_answer_template.pb.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
const char* kAnswerCurrencyIconResourceName = …;
constexpr char kAnswerDefaultIconResourceName[] = …;
const char* kAnswerDictionaryIconResourceName = …;
const char* kAnswerFinanceIconResourceName = …;
const char* kAnswerSunriseIconResourceName = …;
const char* kAnswerTranslationIconResourceName = …;
const char* kAnswerWhenIsIconResourceName = …;
const char* kBookmarkIconResourceName = …;
const char* kCalculatorIconResourceName = …;
const char* kChromeProductIconResourceName = …;
const char* kClockIconResourceName = …;
const char* kDinoIconResourceName = …;
constexpr char kDriveDocsIconResourceName[] = …;
constexpr char kDriveFolderIconResourceName[] = …;
constexpr char kDriveFormIconResourceName[] = …;
constexpr char kDriveImageIconResourceName[] = …;
constexpr char kDriveLogoIconResourceName[] = …;
constexpr char kDrivePdfIconResourceName[] = …;
constexpr char kDriveSheetsIconResourceName[] = …;
constexpr char kDriveSlidesIconResourceName[] = …;
constexpr char kDriveVideoIconResourceName[] = …;
constexpr char kExtensionAppIconResourceName[] = …;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
constexpr char kGoogleCalendarIconResourceName[] =
"//resources/cr_components/searchbox/icons/calendar.svg";
const char* kGoogleGIconResourceName =
"//resources/cr_components/searchbox/icons/google_g.svg";
constexpr char kGoogleKeepNoteIconResourceName[] =
"//resources/cr_components/searchbox/icons/note.svg";
constexpr char kGoogleSitesIconResourceName[] =
"//resources/cr_components/searchbox/icons/sites.svg";
#endif
const char* kHistoryIconResourceName = …;
const char* kIncognitoIconResourceName = …;
const char* kJourneysIconResourceName = …;
const char* kPageIconResourceName = …;
const char* kPedalsIconResourceName = …;
const char* kSearchIconResourceName = …;
const char* kSparkIconResourceName = …;
const char* kStarActiveIconResourceName = …;
const char* kTabIconResourceName = …;
const char* kTrendingUpIconResourceName = …;
#if BUILDFLAG(IS_MAC)
const char* kMacShareIconResourceName =
"//resources/cr_components/searchbox/icons/mac_share.svg";
#elif BUILDFLAG(IS_WIN)
const char* kWinShareIconResourceName =
"//resources/cr_components/searchbox/icons/win_share.svg";
#elif BUILDFLAG(IS_LINUX)
const char* kLinuxShareIconResourceName = …;
#else
const char* kShareIconResourceName =
"//resources/cr_components/searchbox/icons/share.svg";
#endif
static void DefineChromeRefreshRealboxIcons() { … }
std::u16string GetAdditionalA11yMessage(
const AutocompleteMatch& match,
searchbox::mojom::SelectionLineState state) { … }
std::optional<std::u16string> GetAdditionalText(
const SuggestionAnswer::ImageLine& line) { … }
std::u16string ImageLineToString16(const SuggestionAnswer::ImageLine& line) { … }
bool MatchHasSideTypeAndRenderType(
const AutocompleteMatch& match,
omnibox::GroupConfig_SideType side_type,
omnibox::GroupConfig_RenderType render_type,
const omnibox::GroupConfigMap& suggestion_groups_map) { … }
std::vector<searchbox::mojom::AutocompleteMatchPtr> CreateAutocompleteMatches(
const AutocompleteResult& result,
bookmarks::BookmarkModel* bookmark_model,
const omnibox::GroupConfigMap& suggestion_groups_map) { … }
std::string GetBase64UrlVariations(Profile* profile) { … }
base::flat_map<int32_t, searchbox::mojom::SuggestionGroupPtr>
CreateSuggestionGroupsMap(
const AutocompleteResult& result,
PrefService* prefs,
const omnibox::GroupConfigMap& suggestion_groups_map) { … }
searchbox::mojom::AutocompleteResultPtr CreateAutocompleteResult(
const std::u16string& input,
const AutocompleteResult& result,
bookmarks::BookmarkModel* bookmark_model,
PrefService* prefs) { … }
}
void SearchboxHandler::SetupWebUIDataSource(content::WebUIDataSource* source,
Profile* profile,
bool enable_voice_search,
bool enable_lens_search) { … }
std::string SearchboxHandler::AutocompleteMatchVectorIconToResourceName(
const gfx::VectorIcon& icon) { … }
std::string SearchboxHandler::ActionVectorIconToResourceName(
const gfx::VectorIcon& icon) { … }
SearchboxHandler::SearchboxHandler(
mojo::PendingReceiver<searchbox::mojom::PageHandler> pending_page_handler,
Profile* profile,
content::WebContents* web_contents,
MetricsReporter* metrics_reporter)
: … { … }
SearchboxHandler::~SearchboxHandler() { … }
void SearchboxHandler::OnResultChanged(AutocompleteController* controller,
bool default_match_changed) { … }
OmniboxController* SearchboxHandler::omnibox_controller() const { … }
AutocompleteController* SearchboxHandler::autocomplete_controller() const { … }