#include "third_party/blink/renderer/core/page/chrome_client_impl.h"
#include <memory>
#include <optional>
#include <utility>
#include "base/debug/alias.h"
#include "build/build_config.h"
#include "cc/animation/animation_host.h"
#include "cc/animation/animation_timeline.h"
#include "cc/layers/picture_layer.h"
#include "cc/trees/paint_holding_reason.h"
#include "third_party/blink/public/common/page/page_zoom.h"
#include "third_party/blink/public/common/widget/constants.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-blink.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_autofill_client.h"
#include "third_party/blink/public/web/web_console_message.h"
#include "third_party/blink/public/web/web_form_element.h"
#include "third_party/blink/public/web/web_input_element.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/public/web/web_node.h"
#include "third_party/blink/public/web/web_plugin.h"
#include "third_party/blink/public/web/web_popup_menu_info.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_view_client.h"
#include "third_party/blink/public/web/web_window_features.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/events/web_input_event_conversion.h"
#include "third_party/blink/renderer/core/exported/web_dev_tools_agent_impl.h"
#include "third_party/blink/renderer/core/exported/web_plugin_container_impl.h"
#include "third_party/blink/renderer/core/exported/web_settings_impl.h"
#include "third_party/blink/renderer/core/exported/web_view_impl.h"
#include "third_party/blink/renderer/core/frame/browser_controls.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_impl.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/frame/web_remote_frame_impl.h"
#include "third_party/blink/renderer/core/fullscreen/fullscreen.h"
#include "third_party/blink/renderer/core/html/forms/color_chooser.h"
#include "third_party/blink/renderer/core/html/forms/color_chooser_client.h"
#include "third_party/blink/renderer/core/html/forms/color_chooser_popup_ui_controller.h"
#include "third_party/blink/renderer/core/html/forms/color_chooser_ui_controller.h"
#include "third_party/blink/renderer/core/html/forms/date_time_chooser.h"
#include "third_party/blink/renderer/core/html/forms/date_time_chooser_client.h"
#include "third_party/blink/renderer/core/html/forms/date_time_chooser_impl.h"
#include "third_party/blink/renderer/core/html/forms/external_date_time_chooser.h"
#include "third_party/blink/renderer/core/html/forms/external_popup_menu.h"
#include "third_party/blink/renderer/core/html/forms/file_chooser.h"
#include "third_party/blink/renderer/core/html/forms/html_form_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/internal_popup_menu.h"
#include "third_party/blink/renderer/core/html/html_embed_element.h"
#include "third_party/blink/renderer/core/html/html_object_element.h"
#include "third_party/blink/renderer/core/inspector/dev_tools_emulator.h"
#include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/loader/navigation_policy.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/popup_opening_observer.h"
#include "third_party/blink/renderer/core/page/validation_message_client.h"
#include "third_party/blink/renderer/platform/exported/wrapped_resource_request.h"
#include "third_party/blink/renderer/platform/graphics/compositor_element_id.h"
#include "third_party/blink/renderer/platform/graphics/touch_action.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/document_resource_coordinator.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/text/text_direction.h"
#include "third_party/blink/renderer/platform/web_test_support.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/widget/frame_widget.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/text/character_names.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/string_concatenate.h"
#include "ui/gfx/geometry/rect.h"
namespace blink {
namespace {
const char* UIElementTypeToString(ChromeClient::UIElementType ui_element_type) { … }
const char* DismissalTypeToString(Document::PageDismissalType dismissal_type) { … }
String TruncateDialogMessage(const String& message) { … }
bool DisplayModeIsBorderless(LocalFrame& frame) { … }
}
static bool g_can_browser_handle_focus = …;
void SetBrowserCanHandleFocusForWebTest(bool value) { … }
ChromeClientImpl::ChromeClientImpl(WebViewImpl* web_view)
: … { … }
ChromeClientImpl::~ChromeClientImpl() { … }
void ChromeClientImpl::Trace(Visitor* visitor) const { … }
WebViewImpl* ChromeClientImpl::GetWebView() const { … }
void ChromeClientImpl::ChromeDestroyed() { … }
void ChromeClientImpl::SetWindowRect(const gfx::Rect& requested_rect,
LocalFrame& frame) { … }
void ChromeClientImpl::Minimize(LocalFrame&) { … }
void ChromeClientImpl::Maximize(LocalFrame&) { … }
void ChromeClientImpl::Restore(LocalFrame&) { … }
void ChromeClientImpl::SetResizable(bool resizable, LocalFrame& frame) { … }
gfx::Rect ChromeClientImpl::RootWindowRect(LocalFrame& frame) { … }
void ChromeClientImpl::DidAccessInitialMainDocument() { … }
void ChromeClientImpl::FocusPage() { … }
void ChromeClientImpl::DidFocusPage() { … }
bool ChromeClientImpl::CanTakeFocus(mojom::blink::FocusType) { … }
void ChromeClientImpl::TakeFocus(mojom::blink::FocusType type) { … }
void ChromeClientImpl::SetKeyboardFocusURL(Element* new_focus_element) { … }
bool ChromeClientImpl::SupportsDraggableRegions() { … }
void ChromeClientImpl::DraggableRegionsChanged() { … }
void ChromeClientImpl::StartDragging(LocalFrame* frame,
const WebDragData& drag_data,
DragOperationsMask mask,
const SkBitmap& drag_image,
const gfx::Vector2d& cursor_offset,
const gfx::Rect& drag_obj_rect) { … }
bool ChromeClientImpl::AcceptsLoadDrops() const { … }
Page* ChromeClientImpl::CreateWindowDelegate(
LocalFrame* frame,
const FrameLoadRequest& r,
const AtomicString& name,
const WebWindowFeatures& features,
network::mojom::blink::WebSandboxFlags sandbox_flags,
const SessionStorageNamespaceId& session_storage_namespace_id,
bool& consumed_user_gesture) { … }
void ChromeClientImpl::InjectScrollbarGestureScroll(
LocalFrame& local_frame,
const gfx::Vector2dF& delta,
ui::ScrollGranularity granularity,
CompositorElementId scrollable_area_element_id,
WebInputEvent::Type injected_type) { … }
void ChromeClientImpl::FinishScrollFocusedEditableIntoView(
const gfx::RectF& caret_rect_in_root_frame,
mojom::blink::ScrollIntoViewParamsPtr params) { … }
void ChromeClientImpl::SetOverscrollBehavior(
LocalFrame& main_frame,
const cc::OverscrollBehavior& overscroll_behavior) { … }
void ChromeClientImpl::Show(LocalFrame& frame,
LocalFrame& opener_frame,
NavigationPolicy navigation_policy,
bool user_gesture) { … }
bool ChromeClientImpl::ShouldReportDetailedMessageForSourceAndSeverity(
LocalFrame& local_frame,
mojom::blink::ConsoleMessageLevel log_level,
const String& url) { … }
void ChromeClientImpl::AddMessageToConsole(LocalFrame* local_frame,
mojom::ConsoleMessageSource source,
mojom::ConsoleMessageLevel level,
const String& message,
unsigned line_number,
const String& source_id,
const String& stack_trace) { … }
bool ChromeClientImpl::CanOpenBeforeUnloadConfirmPanel() { … }
bool ChromeClientImpl::OpenBeforeUnloadConfirmPanelDelegate(LocalFrame* frame,
bool is_reload) { … }
void ChromeClientImpl::SetBeforeUnloadConfirmPanelResultForTesting(
bool result) { … }
void ChromeClientImpl::CloseWindow() { … }
bool ChromeClientImpl::OpenJavaScriptAlertDelegate(LocalFrame* frame,
const String& message) { … }
bool ChromeClientImpl::OpenJavaScriptConfirmDelegate(LocalFrame* frame,
const String& message) { … }
bool ChromeClientImpl::OpenJavaScriptPromptDelegate(LocalFrame* frame,
const String& message,
const String& default_value,
String& result) { … }
bool ChromeClientImpl::TabsToLinks() { … }
void ChromeClientImpl::InvalidateContainer() { … }
void ChromeClientImpl::ScheduleAnimation(const LocalFrameView* frame_view,
base::TimeDelta delay) { … }
gfx::Rect ChromeClientImpl::LocalRootToScreenDIPs(
const gfx::Rect& rect_in_local_root,
const LocalFrameView* frame_view) const { … }
float ChromeClientImpl::WindowToViewportScalar(LocalFrame* frame,
const float scalar_value) const { … }
const display::ScreenInfo& ChromeClientImpl::GetScreenInfo(
LocalFrame& frame) const { … }
const display::ScreenInfos& ChromeClientImpl::GetScreenInfos(
LocalFrame& frame) const { … }
float ChromeClientImpl::InputEventsScaleForEmulation() const { … }
void ChromeClientImpl::ContentsSizeChanged(LocalFrame* frame,
const gfx::Size& size) const { … }
bool ChromeClientImpl::DoubleTapToZoomEnabled() const { … }
void ChromeClientImpl::EnablePreferredSizeChangedMode() { … }
void ChromeClientImpl::ZoomToFindInPageRect(
const gfx::Rect& rect_in_root_frame) { … }
void ChromeClientImpl::PageScaleFactorChanged() const { … }
void ChromeClientImpl::OutermostMainFrameScrollOffsetChanged() const { … }
float ChromeClientImpl::ClampPageScaleFactorToLimits(float scale) const { … }
void ChromeClientImpl::ResizeAfterLayout() const { … }
void ChromeClientImpl::MainFrameLayoutUpdated() const { … }
void ChromeClientImpl::ShowMouseOverURL(const HitTestResult& result) { … }
void ChromeClientImpl::UpdateTooltipUnderCursor(LocalFrame& frame,
const String& tooltip_text,
TextDirection dir) { … }
void ChromeClientImpl::UpdateTooltipFromKeyboard(LocalFrame& frame,
const String& tooltip_text,
TextDirection dir,
const gfx::Rect& bounds) { … }
void ChromeClientImpl::ClearKeyboardTriggeredTooltip(LocalFrame& frame) { … }
void ChromeClientImpl::DispatchViewportPropertiesDidChange(
const ViewportDescription& description) const { … }
void ChromeClientImpl::PrintDelegate(LocalFrame* frame) { … }
ColorChooser* ChromeClientImpl::OpenColorChooser(
LocalFrame* frame,
ColorChooserClient* chooser_client,
const Color&) { … }
DateTimeChooser* ChromeClientImpl::OpenDateTimeChooser(
LocalFrame* frame,
DateTimeChooserClient* picker_client,
const DateTimeChooserParameters& parameters) { … }
ExternalDateTimeChooser*
ChromeClientImpl::GetExternalDateTimeChooserForTesting() { … }
void ChromeClientImpl::OpenFileChooser(
LocalFrame* frame,
scoped_refptr<FileChooser> file_chooser) { … }
void ChromeClientImpl::DidCompleteFileChooser(FileChooser& chooser) { … }
ui::Cursor ChromeClientImpl::LastSetCursorForTesting() const { … }
void ChromeClientImpl::SetCursor(const ui::Cursor& cursor,
LocalFrame* local_frame) { … }
void ChromeClientImpl::SetCursorInternal(const ui::Cursor& cursor,
LocalFrame* local_frame) { … }
void ChromeClientImpl::SetCursorForPlugin(const ui::Cursor& cursor,
LocalFrame* local_frame) { … }
void ChromeClientImpl::SetCursorOverridden(bool overridden) { … }
void ChromeClientImpl::AutoscrollStart(const gfx::PointF& viewport_point,
LocalFrame* local_frame) { … }
void ChromeClientImpl::AutoscrollFling(const gfx::Vector2dF& velocity,
LocalFrame* local_frame) { … }
void ChromeClientImpl::AutoscrollEnd(LocalFrame* local_frame) { … }
String ChromeClientImpl::AcceptLanguages() { … }
void ChromeClientImpl::AttachRootLayer(scoped_refptr<cc::Layer> root_layer,
LocalFrame* local_frame) { … }
cc::AnimationHost* ChromeClientImpl::GetCompositorAnimationHost(
LocalFrame& local_frame) const { … }
cc::AnimationTimeline* ChromeClientImpl::GetScrollAnimationTimeline(
LocalFrame& local_frame) const { … }
void ChromeClientImpl::EnterFullscreen(LocalFrame& frame,
const FullscreenOptions* options,
FullscreenRequestType request_type) { … }
void ChromeClientImpl::ExitFullscreen(LocalFrame& frame) { … }
void ChromeClientImpl::FullscreenElementChanged(
Element* old_element,
Element* new_element,
const FullscreenOptions* options,
FullscreenRequestType request_type) { … }
void ChromeClientImpl::AnimateDoubleTapZoom(const gfx::Point& point,
const gfx::Rect& rect) { … }
bool ChromeClientImpl::HasOpenedPopup() const { … }
PopupMenu* ChromeClientImpl::OpenPopupMenu(LocalFrame& frame,
HTMLSelectElement& select) { … }
PagePopup* ChromeClientImpl::OpenPagePopup(PagePopupClient* client) { … }
void ChromeClientImpl::ClosePagePopup(PagePopup* popup) { … }
DOMWindow* ChromeClientImpl::PagePopupWindowForTesting() const { … }
void ChromeClientImpl::SetBrowserControlsState(float top_height,
float bottom_height,
bool shrinks_layout) { … }
void ChromeClientImpl::SetBrowserControlsShownRatio(float top_ratio,
float bottom_ratio) { … }
bool ChromeClientImpl::ShouldOpenUIElementDuringPageDismissal(
LocalFrame& frame,
UIElementType ui_element_type,
const String& dialog_message,
Document::PageDismissalType dismissal_type) const { … }
viz::FrameSinkId ChromeClientImpl::GetFrameSinkId(LocalFrame* frame) { … }
void ChromeClientImpl::RequestDecode(LocalFrame* frame,
const PaintImage& image,
base::OnceCallback<void(bool)> callback) { … }
void ChromeClientImpl::NotifyPresentationTime(LocalFrame& frame,
ReportTimeCallback callback) { … }
void ChromeClientImpl::RequestBeginMainFrameNotExpected(LocalFrame& frame,
bool request) { … }
int ChromeClientImpl::GetLayerTreeId(LocalFrame& frame) { … }
void ChromeClientImpl::SetEventListenerProperties(
LocalFrame* frame,
cc::EventListenerClass event_class,
cc::EventListenerProperties properties) { … }
void ChromeClientImpl::BeginLifecycleUpdates(LocalFrame& main_frame) { … }
void ChromeClientImpl::RegisterForCommitObservation(CommitObserver* observer) { … }
void ChromeClientImpl::UnregisterFromCommitObservation(
CommitObserver* observer) { … }
void ChromeClientImpl::WillCommitCompositorFrame() { … }
std::unique_ptr<cc::ScopedPauseRendering> ChromeClientImpl::PauseRendering(
LocalFrame& frame) { … }
std::optional<int> ChromeClientImpl::GetMaxRenderBufferBounds(
LocalFrame& frame) const { … }
bool ChromeClientImpl::StartDeferringCommits(LocalFrame& main_frame,
base::TimeDelta timeout,
cc::PaintHoldingReason reason) { … }
void ChromeClientImpl::StopDeferringCommits(
LocalFrame& main_frame,
cc::PaintHoldingCommitTrigger trigger) { … }
void ChromeClientImpl::SetHasScrollEventHandlers(LocalFrame* frame,
bool has_event_handlers) { … }
void ChromeClientImpl::SetNeedsLowLatencyInput(LocalFrame* frame,
bool needs_low_latency) { … }
void ChromeClientImpl::SetNeedsUnbufferedInputForDebugger(LocalFrame* frame,
bool unbuffered) { … }
void ChromeClientImpl::RequestUnbufferedInputEvents(LocalFrame* frame) { … }
void ChromeClientImpl::SetTouchAction(LocalFrame* frame,
TouchAction touch_action) { … }
void ChromeClientImpl::SetPanAction(LocalFrame* frame,
mojom::blink::PanAction pan_action) { … }
void ChromeClientImpl::DidChangeFormRelatedElementDynamically(
LocalFrame* frame,
HTMLElement* element,
WebFormRelatedChangeType form_related_change) { … }
void ChromeClientImpl::ShowVirtualKeyboardOnElementFocus(LocalFrame& frame) { … }
void ChromeClientImpl::OnMouseDown(Node& mouse_down_node) { … }
void ChromeClientImpl::HandleKeyboardEventOnTextField(
HTMLInputElement& input_element,
KeyboardEvent& event) { … }
void ChromeClientImpl::DidChangeValueInTextField(
HTMLFormControlElement& element) { … }
void ChromeClientImpl::DidClearValueInTextField(
HTMLFormControlElement& element) { … }
void ChromeClientImpl::DidUserChangeContentEditableContent(Element& element) { … }
void ChromeClientImpl::DidEndEditingOnTextField(
HTMLInputElement& input_element) { … }
void ChromeClientImpl::OpenTextDataListChooser(HTMLInputElement& input) { … }
void ChromeClientImpl::TextFieldDataListChanged(HTMLInputElement& input) { … }
void ChromeClientImpl::DidChangeSelectionInSelectControl(
HTMLFormControlElement& element) { … }
void ChromeClientImpl::SelectOrSelectListFieldOptionsChanged(
HTMLFormControlElement& element) { … }
void ChromeClientImpl::AjaxSucceeded(LocalFrame* frame) { … }
void ChromeClientImpl::JavaScriptChangedValue(HTMLFormControlElement& element,
const String& old_value,
bool was_autofilled) { … }
gfx::Transform ChromeClientImpl::GetDeviceEmulationTransform() const { … }
void ChromeClientImpl::DidUpdateBrowserControls() const { … }
void ChromeClientImpl::RegisterPopupOpeningObserver(
PopupOpeningObserver* observer) { … }
void ChromeClientImpl::UnregisterPopupOpeningObserver(
PopupOpeningObserver* observer) { … }
void ChromeClientImpl::NotifyPopupOpeningObservers() const { … }
gfx::Vector2dF ChromeClientImpl::ElasticOverscroll() const { … }
WebAutofillClient* ChromeClientImpl::AutofillClientFromFrame(
LocalFrame* frame) { … }
void ChromeClientImpl::DidUpdateTextAutosizerPageInfo(
const mojom::blink::TextAutosizerPageInfo& page_info) { … }
void ChromeClientImpl::DocumentDetached(Document& document) { … }
double ChromeClientImpl::UserZoomFactor(LocalFrame* frame) const { … }
void ChromeClientImpl::SetDelegatedInkMetadata(
LocalFrame* frame,
std::unique_ptr<gfx::DelegatedInkMetadata> metadata) { … }
void ChromeClientImpl::FormElementReset(HTMLFormElement& element) { … }
void ChromeClientImpl::PasswordFieldReset(HTMLInputElement& element) { … }
float ChromeClientImpl::ZoomFactorForViewportLayout() { … }
gfx::Rect ChromeClientImpl::AdjustWindowRectForMinimum(
const gfx::Rect& pending_rect,
int minimum_size) { … }
gfx::Rect ChromeClientImpl::AdjustWindowRectForDisplay(
const gfx::Rect& pending_rect,
LocalFrame& frame,
int minimum_size) { … }
}