/* * Copyright (c) 2022, Andreas Kling * Copyright (c) 2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace WebView { // Note: This only exists inside Serenity to avoid #ifdefs in all implementors of ViewImplementation. enum class EnableCallgrindProfiling { No, Yes }; enum class IsLayoutTestMode { No, Yes }; class ViewImplementation { public: virtual ~ViewImplementation() { } struct DOMNodeProperties { String computed_style_json; String resolved_style_json; String custom_properties_json; String node_box_sizing_json; }; void set_url(Badge, AK::URL url) { m_url = move(url); } AK::URL const& url() const { return m_url; } String const& handle() const { return m_client_state.client_handle; } void load(AK::URL const&); void load_html(StringView, AK::URL const&); void load_empty_document(); void zoom_in(); void zoom_out(); void reset_zoom(); float zoom_level() const { return m_zoom_level; } void set_preferred_color_scheme(Web::CSS::PreferredColorScheme); DeprecatedString selected_text(); void select_all(); void get_source(); void inspect_dom_tree(); void inspect_accessibility_tree(); ErrorOr inspect_dom_node(i32 node_id, Optional pseudo_element); void clear_inspected_dom_node(); i32 get_hovered_node_id(); void debug_request(DeprecatedString const& request, DeprecatedString const& argument = {}); void run_javascript(StringView); void js_console_input(DeprecatedString const& js_source); void js_console_request_messages(i32 start_index); void toggle_video_play_state(); void toggle_video_loop_state(); void toggle_video_controls_state(); enum class ScreenshotType { Visible, Full, }; ErrorOr take_screenshot(ScreenshotType); Function on_new_tab; Function on_activate_tab; Function on_close; Function on_context_menu_request; Function on_link_context_menu_request; Function on_image_context_menu_request; Function on_video_context_menu_request; Function on_link_hover; Function on_link_unhover; Function on_link_click; Function on_link_middle_click; Function on_title_change; Function on_load_start; Function on_load_finish; Function on_navigate_back; Function on_navigate_forward; Function on_refresh; Function on_favicon_change; Function on_get_source; Function on_get_dom_tree; Function on_get_dom_node_properties; Function on_get_accessibility_tree; Function on_js_console_new_message; Function const& message_types, Vector const& messages)> on_get_js_console_messages; Function(AK::URL const& url)> on_get_all_cookies; Function(AK::URL const& url, DeprecatedString const& name)> on_get_named_cookie; Function on_get_cookie; Function on_set_cookie; Function on_update_cookie; Function on_resource_status_change; Function on_restore_window; Function on_reposition_window; Function on_resize_window; Function on_maximize_window; Function on_minimize_window; Function on_fullscreen_window; Function on_back_button; Function on_forward_button; virtual void notify_server_did_layout(Badge, Gfx::IntSize content_size) = 0; virtual void notify_server_did_paint(Badge, i32 bitmap_id, Gfx::IntSize) = 0; virtual void notify_server_did_invalidate_content_rect(Badge, Gfx::IntRect const&) = 0; virtual void notify_server_did_change_selection(Badge) = 0; virtual void notify_server_did_request_cursor_change(Badge, Gfx::StandardCursor cursor) = 0; virtual void notify_server_did_request_scroll(Badge, i32, i32) = 0; virtual void notify_server_did_request_scroll_to(Badge, Gfx::IntPoint) = 0; virtual void notify_server_did_request_scroll_into_view(Badge, Gfx::IntRect const&) = 0; virtual void notify_server_did_enter_tooltip_area(Badge, Gfx::IntPoint, DeprecatedString const&) = 0; virtual void notify_server_did_leave_tooltip_area(Badge) = 0; virtual void notify_server_did_request_alert(Badge, String const& message) = 0; virtual void notify_server_did_request_confirm(Badge, String const& message) = 0; virtual void notify_server_did_request_prompt(Badge, String const& message, String const& default_) = 0; virtual void notify_server_did_request_set_prompt_text(Badge, String const& message) = 0; virtual void notify_server_did_request_accept_dialog(Badge) = 0; virtual void notify_server_did_request_dismiss_dialog(Badge) = 0; virtual void notify_server_did_request_file(Badge, DeprecatedString const& path, i32) = 0; virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0; virtual Gfx::IntRect viewport_rect() const = 0; virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const = 0; virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const = 0; protected: static constexpr auto ZOOM_MIN_LEVEL = 0.3f; static constexpr auto ZOOM_MAX_LEVEL = 5.0f; static constexpr auto ZOOM_STEP = 0.1f; ViewImplementation(); WebContentClient& client(); WebContentClient const& client() const; virtual void update_zoom() = 0; enum class WindowResizeInProgress { No, Yes, }; void resize_backing_stores_if_needed(WindowResizeInProgress); void request_repaint(); void handle_resize(); virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) {}; #if !defined(AK_OS_SERENITY) ErrorOr> launch_web_content_process(ReadonlySpan candidate_web_content_paths, EnableCallgrindProfiling = EnableCallgrindProfiling::No, IsLayoutTestMode = IsLayoutTestMode::No); #endif void handle_web_content_process_crash(); struct SharedBitmap { i32 id { -1 }; i32 pending_paints { 0 }; Gfx::IntSize last_painted_size; RefPtr bitmap; }; struct ClientState { RefPtr client; String client_handle; SharedBitmap front_bitmap; SharedBitmap back_bitmap; i32 next_bitmap_id { 0 }; bool has_usable_bitmap { false }; bool got_repaint_requests_while_painting { false }; } m_client_state; AK::URL m_url; float m_zoom_level { 1.0 }; float m_device_pixel_ratio { 1.0 }; RefPtr m_backing_store_shrink_timer; RefPtr m_backup_bitmap; Gfx::IntSize m_backup_bitmap_size; size_t m_crash_count = 0; RefPtr m_repeated_crash_timer; }; }