#include "chrome/renderer/searchbox/searchbox_extension.h"
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <string_view>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/i18n/rtl.h"
#include "base/json/json_writer.h"
#include "base/json/string_escape.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/string_number_conversions.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 "chrome/common/search/instant_types.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/renderer_resources.h"
#include "chrome/renderer/searchbox/searchbox.h"
#include "components/crx_file/id_util.h"
#include "components/ntp_tiles/features.h"
#include "components/ntp_tiles/ntp_tile_impression.h"
#include "components/ntp_tiles/tile_source.h"
#include "components/ntp_tiles/tile_visual_type.h"
#include "content/public/common/url_constants.h"
#include "content/public/renderer/chrome_object_extensions_utils.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_thread.h"
#include "gin/data_object_builder.h"
#include "gin/handle.h"
#include "gin/object_template_builder.h"
#include "gin/wrappable.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/platform/scheduler/web_agent_group_scheduler.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_frame_widget.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_script_source.h"
#include "third_party/blink/public/web/web_view.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/window_open_disposition.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/text_constants.h"
#include "ui/gfx/text_elider.h"
#include "url/gurl.h"
#include "url/url_constants.h"
#include "v8/include/v8.h"
namespace {
const char kCSSBackgroundImageFormat[] = …;
const char kCSSBackgroundPositionCenter[] = …;
const char kCSSBackgroundPositionLeft[] = …;
const char kCSSBackgroundPositionTop[] = …;
const char kCSSBackgroundPositionRight[] = …;
const char kCSSBackgroundPositionBottom[] = …;
const char kCSSBackgroundRepeatNo[] = …;
const char kCSSBackgroundRepeatX[] = …;
const char kCSSBackgroundRepeatY[] = …;
const char kCSSBackgroundRepeat[] = …;
const char kThemeAttributionFormat[] = …;
const char kLTRHtmlTextDirection[] = …;
const char kRTLHtmlTextDirection[] = …;
void Dispatch(blink::WebLocalFrame* frame, const blink::WebString& script) { … }
v8::Local<v8::Object> GenerateMostVisitedItem(
v8::Isolate* isolate,
float device_pixel_ratio,
const blink::LocalFrameToken& frame_token,
InstantRestrictedID restricted_id) { … }
v8::Local<v8::Object> GenerateMostVisitedItemData(
v8::Isolate* isolate,
InstantRestrictedID restricted_id,
const InstantMostVisitedItem& mv_item) { … }
std::optional<int> CoerceToInt(v8::Isolate* isolate, v8::Value* value) { … }
v8::Local<v8::Value> SkColorToArray(v8::Isolate* isolate,
const SkColor& color) { … }
v8::Local<v8::Object> GenerateNtpTheme(v8::Isolate* isolate,
const NtpTheme& theme) { … }
content::RenderFrame* GetMainRenderFrameForCurrentContext() { … }
SearchBox* GetSearchBoxForCurrentContext() { … }
static const char kDispatchFocusChangedScript[] = …;
static const char kDispatchInputCancelScript[] = …;
static const char kDispatchInputStartScript[] = …;
static const char kDispatchKeyCaptureChangeScript[] = …;
static const char kDispatchMostVisitedChangedScript[] = …;
static const char kDispatchThemeChangeEventScript[] = …;
class SearchBoxBindings : public gin::Wrappable<SearchBoxBindings> { … };
gin::WrapperInfo SearchBoxBindings::kWrapperInfo = …;
SearchBoxBindings::SearchBoxBindings() = default;
SearchBoxBindings::~SearchBoxBindings() = default;
gin::ObjectTemplateBuilder SearchBoxBindings::GetObjectTemplateBuilder(
v8::Isolate* isolate) { … }
bool SearchBoxBindings::IsFocused() { … }
bool SearchBoxBindings::IsKeyCaptureEnabled() { … }
void SearchBoxBindings::StartCapturingKeyStrokes() { … }
void SearchBoxBindings::StopCapturingKeyStrokes() { … }
class NewTabPageBindings : public gin::Wrappable<NewTabPageBindings> { … };
gin::WrapperInfo NewTabPageBindings::kWrapperInfo = …;
NewTabPageBindings::NewTabPageBindings() = default;
NewTabPageBindings::~NewTabPageBindings() = default;
gin::ObjectTemplateBuilder NewTabPageBindings::GetObjectTemplateBuilder(
v8::Isolate* isolate) { … }
bool NewTabPageBindings::HasOrigin(const GURL& origin) { … }
bool NewTabPageBindings::IsInputInProgress() { … }
v8::Local<v8::Value> NewTabPageBindings::GetMostVisited(v8::Isolate* isolate) { … }
bool NewTabPageBindings::GetMostVisitedAvailable(v8::Isolate* isolate) { … }
v8::Local<v8::Value> NewTabPageBindings::GetNtpTheme(v8::Isolate* isolate) { … }
void NewTabPageBindings::DeleteMostVisitedItem(v8::Isolate* isolate,
v8::Local<v8::Value> rid_value) { … }
void NewTabPageBindings::UndoAllMostVisitedDeletions() { … }
void NewTabPageBindings::UndoMostVisitedDeletion(
v8::Isolate* isolate,
v8::Local<v8::Value> rid_value) { … }
v8::Local<v8::Value> NewTabPageBindings::GetMostVisitedItemData(
v8::Isolate* isolate,
int rid) { … }
}
void SearchBoxExtension::Install(blink::WebLocalFrame* frame) { … }
void SearchBoxExtension::DispatchFocusChange(blink::WebLocalFrame* frame) { … }
void SearchBoxExtension::DispatchInputCancel(blink::WebLocalFrame* frame) { … }
void SearchBoxExtension::DispatchInputStart(blink::WebLocalFrame* frame) { … }
void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebLocalFrame* frame) { … }
void SearchBoxExtension::DispatchMostVisitedChanged(
blink::WebLocalFrame* frame) { … }
void SearchBoxExtension::DispatchThemeChange(blink::WebLocalFrame* frame) { … }