2023-11-29 16:34:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
|
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibGfx/Rect.h>
|
2024-08-23 09:42:35 +00:00
|
|
|
#include <LibWeb/CSS/StyleSheetIdentifier.h>
|
2024-03-26 23:27:06 +00:00
|
|
|
#include <LibWeb/HTML/AudioPlayState.h>
|
2024-03-14 16:26:00 +00:00
|
|
|
#include <LibWeb/HTML/FileFilter.h>
|
2023-11-29 16:34:38 +00:00
|
|
|
#include <LibWeb/Page/Page.h>
|
|
|
|
#include <LibWeb/PixelUnits.h>
|
2024-06-17 15:50:57 +00:00
|
|
|
#include <WebContent/BackingStoreManager.h>
|
2023-11-29 16:34:38 +00:00
|
|
|
#include <WebContent/Forward.h>
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
|
|
|
class PageClient final : public Web::PageClient {
|
2023-12-04 08:40:33 +00:00
|
|
|
JS_CELL(PageClient, Web::PageClient);
|
2024-04-06 17:16:18 +00:00
|
|
|
JS_DECLARE_ALLOCATOR(PageClient);
|
2023-11-29 16:34:38 +00:00
|
|
|
|
|
|
|
public:
|
2023-12-04 08:40:33 +00:00
|
|
|
static JS::NonnullGCPtr<PageClient> create(JS::VM& vm, PageHost& page_host, u64 id);
|
2023-11-29 16:34:38 +00:00
|
|
|
|
2024-06-16 08:38:35 +00:00
|
|
|
virtual ~PageClient() override;
|
|
|
|
|
2024-07-17 11:13:32 +00:00
|
|
|
enum class UseSkiaPainter {
|
|
|
|
CPUBackend,
|
|
|
|
GPUBackendIfAvailable,
|
|
|
|
};
|
|
|
|
static void set_use_skia_painter(UseSkiaPainter);
|
2023-11-29 16:34:38 +00:00
|
|
|
|
2024-02-18 18:40:11 +00:00
|
|
|
virtual void schedule_repaint() override;
|
2024-03-18 19:11:06 +00:00
|
|
|
virtual bool is_ready_to_paint() const override;
|
2023-12-21 21:58:54 +00:00
|
|
|
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual Web::Page& page() override { return *m_page; }
|
|
|
|
virtual Web::Page const& page() const override { return *m_page; }
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
ErrorOr<void> connect_to_webdriver(ByteString const& webdriver_ipc_path);
|
2023-11-29 16:34:38 +00:00
|
|
|
|
2024-05-28 13:51:53 +00:00
|
|
|
virtual void paint_next_frame() override;
|
2024-07-03 12:12:28 +00:00
|
|
|
virtual void process_screenshot_requests() override;
|
2024-06-25 14:43:39 +00:00
|
|
|
virtual void paint(Web::DevicePixelRect const& content_rect, Web::Painting::BackingStore&, Web::PaintOptions = {}) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
|
|
|
|
void set_palette_impl(Gfx::PaletteImpl&);
|
2024-06-03 14:53:55 +00:00
|
|
|
void set_viewport_size(Web::DevicePixelSize const&);
|
2023-12-14 06:17:00 +00:00
|
|
|
void set_screen_rects(Vector<Web::DevicePixelRect, 4> const& rects, size_t main_screen_index) { m_screen_rect = rects[main_screen_index]; }
|
2023-11-29 16:34:38 +00:00
|
|
|
void set_device_pixels_per_css_pixel(float device_pixels_per_css_pixel) { m_device_pixels_per_css_pixel = device_pixels_per_css_pixel; }
|
|
|
|
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
|
2024-06-12 23:03:56 +00:00
|
|
|
void set_preferred_contrast(Web::CSS::PreferredContrast);
|
2024-06-13 14:15:59 +00:00
|
|
|
void set_preferred_motion(Web::CSS::PreferredMotion);
|
2023-11-29 16:34:38 +00:00
|
|
|
void set_should_show_line_box_borders(bool b) { m_should_show_line_box_borders = b; }
|
|
|
|
void set_has_focus(bool);
|
|
|
|
void set_is_scripting_enabled(bool);
|
|
|
|
void set_window_position(Web::DevicePixelPoint);
|
|
|
|
void set_window_size(Web::DevicePixelSize);
|
|
|
|
|
|
|
|
Web::DevicePixelSize content_size() const { return m_content_size; }
|
|
|
|
|
|
|
|
Web::WebIDL::ExceptionOr<void> toggle_media_play_state();
|
|
|
|
void toggle_media_mute_state();
|
|
|
|
Web::WebIDL::ExceptionOr<void> toggle_media_loop_state();
|
|
|
|
Web::WebIDL::ExceptionOr<void> toggle_media_controls_state();
|
|
|
|
|
|
|
|
void alert_closed();
|
|
|
|
void confirm_closed(bool accepted);
|
|
|
|
void prompt_closed(Optional<String> response);
|
2023-12-11 05:53:10 +00:00
|
|
|
void color_picker_update(Optional<Color> picked_color, Web::HTML::ColorPickerUpdateState state);
|
2024-04-03 17:19:08 +00:00
|
|
|
void select_dropdown_closed(Optional<u32> const& selected_item_id);
|
2023-11-29 16:34:38 +00:00
|
|
|
|
|
|
|
void set_user_style(String source);
|
|
|
|
|
2024-01-07 15:35:45 +00:00
|
|
|
void ready_to_paint();
|
|
|
|
|
2024-02-03 01:00:48 +00:00
|
|
|
void initialize_js_console(Web::DOM::Document& document);
|
|
|
|
void js_console_input(ByteString const& js_source);
|
|
|
|
void run_javascript(ByteString const& js_source);
|
|
|
|
void js_console_request_messages(i32 start_index);
|
|
|
|
void did_output_js_console_message(i32 message_index);
|
|
|
|
void console_peer_did_misbehave(char const* reason);
|
|
|
|
void did_get_js_console_messages(i32 start_index, Vector<ByteString> message_types, Vector<ByteString> messages);
|
|
|
|
|
2024-08-23 09:42:35 +00:00
|
|
|
Vector<Web::CSS::StyleSheetIdentifier> list_style_sheets() const;
|
|
|
|
|
2024-01-15 10:28:21 +00:00
|
|
|
virtual double device_pixels_per_css_pixel() const override { return m_device_pixels_per_css_pixel; }
|
|
|
|
|
2024-06-23 16:42:39 +00:00
|
|
|
virtual Web::DisplayListPlayerType display_list_player_type() const override;
|
2024-06-19 11:46:27 +00:00
|
|
|
|
2024-06-21 16:15:32 +00:00
|
|
|
void queue_screenshot_task(Optional<i32> node_id);
|
|
|
|
|
2024-06-17 15:50:57 +00:00
|
|
|
friend class BackingStoreManager;
|
|
|
|
|
2023-11-29 16:34:38 +00:00
|
|
|
private:
|
2023-12-04 08:40:33 +00:00
|
|
|
PageClient(PageHost&, u64 id);
|
|
|
|
|
2023-12-04 08:57:13 +00:00
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
|
|
|
|
2023-11-29 16:34:38 +00:00
|
|
|
// ^PageClient
|
|
|
|
virtual bool is_connection_open() const override;
|
|
|
|
virtual Gfx::Palette palette() const override;
|
|
|
|
virtual Web::DevicePixelRect screen_rect() const override { return m_screen_rect; }
|
|
|
|
virtual Web::CSS::PreferredColorScheme preferred_color_scheme() const override { return m_preferred_color_scheme; }
|
2024-06-12 23:03:56 +00:00
|
|
|
virtual Web::CSS::PreferredContrast preferred_contrast() const override { return m_preferred_contrast; }
|
2024-06-13 14:15:59 +00:00
|
|
|
virtual Web::CSS::PreferredMotion preferred_motion() const override { return m_preferred_motion; }
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_request_cursor_change(Gfx::StandardCursor) override;
|
|
|
|
virtual void page_did_layout() override;
|
2023-12-16 14:19:34 +00:00
|
|
|
virtual void page_did_change_title(ByteString const&) override;
|
2024-04-14 08:27:20 +00:00
|
|
|
virtual void page_did_change_url(URL::URL const&) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_request_navigate_back() override;
|
|
|
|
virtual void page_did_request_navigate_forward() override;
|
|
|
|
virtual void page_did_request_refresh() override;
|
|
|
|
virtual Gfx::IntSize page_did_request_resize_window(Gfx::IntSize) override;
|
|
|
|
virtual Gfx::IntPoint page_did_request_reposition_window(Gfx::IntPoint) override;
|
|
|
|
virtual void page_did_request_restore_window() override;
|
|
|
|
virtual Gfx::IntRect page_did_request_maximize_window() override;
|
|
|
|
virtual Gfx::IntRect page_did_request_minimize_window() override;
|
|
|
|
virtual Gfx::IntRect page_did_request_fullscreen_window() override;
|
2024-07-02 14:48:57 +00:00
|
|
|
virtual void page_did_request_tooltip_override(Web::CSSPixelPoint, ByteString const&) override;
|
|
|
|
virtual void page_did_stop_tooltip_override() override;
|
2024-07-02 12:16:24 +00:00
|
|
|
virtual void page_did_enter_tooltip_area(ByteString const&) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_leave_tooltip_area() override;
|
2024-03-29 02:02:55 +00:00
|
|
|
virtual void page_did_hover_link(URL::URL const&) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_unhover_link() override;
|
2024-08-01 17:38:21 +00:00
|
|
|
virtual void page_did_click_link(URL::URL const&, ByteString const& target, unsigned modifiers) override;
|
2024-03-29 02:02:55 +00:00
|
|
|
virtual void page_did_middle_click_link(URL::URL const&, ByteString const& target, unsigned modifiers) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_request_context_menu(Web::CSSPixelPoint) override;
|
2024-03-18 03:22:27 +00:00
|
|
|
virtual void page_did_request_link_context_menu(Web::CSSPixelPoint, URL::URL const&, ByteString const& target, unsigned modifiers) override;
|
2024-03-29 02:02:55 +00:00
|
|
|
virtual void page_did_request_image_context_menu(Web::CSSPixelPoint, URL::URL const&, ByteString const& target, unsigned modifiers, Gfx::Bitmap const*) override;
|
2023-12-16 14:19:34 +00:00
|
|
|
virtual void page_did_request_media_context_menu(Web::CSSPixelPoint, ByteString const& target, unsigned modifiers, Web::Page::MediaContextMenu) override;
|
2024-03-29 02:02:55 +00:00
|
|
|
virtual void page_did_start_loading(URL::URL const&, bool) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_create_new_document(Web::DOM::Document&) override;
|
2024-04-11 15:21:09 +00:00
|
|
|
virtual void page_did_change_active_document_in_top_level_browsing_context(Web::DOM::Document&) override;
|
2024-03-29 02:02:55 +00:00
|
|
|
virtual void page_did_finish_loading(URL::URL const&) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_request_alert(String const&) override;
|
|
|
|
virtual void page_did_request_confirm(String const&) override;
|
|
|
|
virtual void page_did_request_prompt(String const&, String const&) override;
|
|
|
|
virtual void page_did_request_set_prompt_text(String const&) override;
|
|
|
|
virtual void page_did_request_accept_dialog() override;
|
|
|
|
virtual void page_did_request_dismiss_dialog() override;
|
|
|
|
virtual void page_did_change_favicon(Gfx::Bitmap const&) override;
|
2024-03-18 03:22:27 +00:00
|
|
|
virtual Vector<Web::Cookie::Cookie> page_did_request_all_cookies(URL::URL const&) override;
|
|
|
|
virtual Optional<Web::Cookie::Cookie> page_did_request_named_cookie(URL::URL const&, String const&) override;
|
2024-03-29 02:02:55 +00:00
|
|
|
virtual String page_did_request_cookie(URL::URL const&, Web::Cookie::Source) override;
|
|
|
|
virtual void page_did_set_cookie(URL::URL const&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_update_cookie(Web::Cookie::Cookie) override;
|
|
|
|
virtual void page_did_update_resource_count(i32) override;
|
2024-01-31 03:55:24 +00:00
|
|
|
virtual NewWebViewResult page_did_request_new_web_view(Web::HTML::ActivateTab, Web::HTML::WebViewHints, Web::HTML::TokenizedFeature::NoOpener) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_request_activate_tab() override;
|
2024-02-03 01:00:48 +00:00
|
|
|
virtual void page_did_close_top_level_traversable() override;
|
2024-04-13 21:12:55 +00:00
|
|
|
virtual void page_did_update_navigation_buttons_state(bool back_enabled, bool forward_enabled) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void request_file(Web::FileRequest) override;
|
|
|
|
virtual void page_did_request_color_picker(Color current_color) override;
|
2024-03-14 16:26:00 +00:00
|
|
|
virtual void page_did_request_file_picker(Web::HTML::FileFilter accepted_file_types, Web::HTML::AllowMultipleFiles) override;
|
2023-12-12 21:35:37 +00:00
|
|
|
virtual void page_did_request_select_dropdown(Web::CSSPixelPoint content_position, Web::CSSPixels minimum_width, Vector<Web::HTML::SelectItem> items) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void page_did_finish_text_test() override;
|
|
|
|
virtual void page_did_change_theme_color(Gfx::Color color) override;
|
|
|
|
virtual void page_did_insert_clipboard_entry(String data, String presentation_style, String mime_type) override;
|
2024-03-26 23:27:06 +00:00
|
|
|
virtual void page_did_change_audio_play_state(Web::HTML::AudioPlayState) override;
|
2024-06-17 15:50:57 +00:00
|
|
|
virtual void page_did_allocate_backing_stores(i32 front_bitmap_id, Gfx::ShareableBitmap front_bitmap, i32 back_bitmap_id, Gfx::ShareableBitmap back_bitmap) override;
|
2024-04-18 00:44:39 +00:00
|
|
|
virtual IPC::File request_worker_agent() override;
|
2023-11-29 16:34:38 +00:00
|
|
|
virtual void inspector_did_load() override;
|
2023-12-10 08:00:03 +00:00
|
|
|
virtual void inspector_did_select_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) override;
|
2023-12-03 16:49:08 +00:00
|
|
|
virtual void inspector_did_set_dom_node_text(i32 node_id, String const& text) override;
|
|
|
|
virtual void inspector_did_set_dom_node_tag(i32 node_id, String const& tag) override;
|
2023-12-05 21:43:14 +00:00
|
|
|
virtual void inspector_did_add_dom_node_attributes(i32 node_id, JS::NonnullGCPtr<Web::DOM::NamedNodeMap> attributes) override;
|
2024-02-18 18:59:28 +00:00
|
|
|
virtual void inspector_did_replace_dom_node_attribute(i32 node_id, size_t attribute_index, JS::NonnullGCPtr<Web::DOM::NamedNodeMap> replacement_attributes) override;
|
|
|
|
virtual void inspector_did_request_dom_tree_context_menu(i32 node_id, Web::CSSPixelPoint position, String const& type, Optional<String> const& tag, Optional<size_t> const& attribute_index) override;
|
2024-09-06 17:22:16 +00:00
|
|
|
virtual void inspector_did_request_cookie_context_menu(size_t cookie_index, Web::CSSPixelPoint position) override;
|
2024-08-23 10:18:35 +00:00
|
|
|
virtual void inspector_did_request_style_sheet_source(Web::CSS::StyleSheetIdentifier const& stylesheet_source) override;
|
2023-12-01 00:27:32 +00:00
|
|
|
virtual void inspector_did_execute_console_script(String const& script) override;
|
2024-08-19 16:11:39 +00:00
|
|
|
virtual void inspector_did_export_inspector_html(String const& script) override;
|
2023-11-29 16:34:38 +00:00
|
|
|
|
|
|
|
Web::Layout::Viewport* layout_root();
|
|
|
|
void setup_palette();
|
|
|
|
ConnectionFromClient& client() const;
|
|
|
|
|
|
|
|
PageHost& m_owner;
|
2023-12-04 08:57:13 +00:00
|
|
|
JS::NonnullGCPtr<Web::Page> m_page;
|
2023-11-29 16:34:38 +00:00
|
|
|
RefPtr<Gfx::PaletteImpl> m_palette_impl;
|
|
|
|
Web::DevicePixelRect m_screen_rect;
|
|
|
|
Web::DevicePixelSize m_content_size;
|
|
|
|
float m_device_pixels_per_css_pixel { 1.0f };
|
|
|
|
u64 m_id { 0 };
|
|
|
|
bool m_should_show_line_box_borders { false };
|
|
|
|
bool m_has_focus { false };
|
|
|
|
|
2024-01-07 15:35:45 +00:00
|
|
|
enum class PaintState {
|
|
|
|
Ready,
|
|
|
|
WaitingForClient,
|
|
|
|
PaintWhenReady,
|
|
|
|
};
|
|
|
|
|
|
|
|
PaintState m_paint_state { PaintState::Ready };
|
2023-12-21 21:58:54 +00:00
|
|
|
|
2024-06-21 16:15:32 +00:00
|
|
|
struct ScreenshotTask {
|
|
|
|
Optional<i32> node_id;
|
|
|
|
};
|
|
|
|
Queue<ScreenshotTask> m_screenshot_tasks;
|
|
|
|
|
2023-11-29 16:34:38 +00:00
|
|
|
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };
|
2024-06-12 23:03:56 +00:00
|
|
|
Web::CSS::PreferredContrast m_preferred_contrast { Web::CSS::PreferredContrast::NoPreference };
|
2024-06-13 14:15:59 +00:00
|
|
|
Web::CSS::PreferredMotion m_preferred_motion { Web::CSS::PreferredMotion::NoPreference };
|
2023-11-29 16:34:38 +00:00
|
|
|
|
|
|
|
RefPtr<WebDriverConnection> m_webdriver;
|
2023-12-16 15:22:11 +00:00
|
|
|
|
2024-06-17 15:50:57 +00:00
|
|
|
BackingStoreManager m_backing_store_manager;
|
2024-02-03 01:00:48 +00:00
|
|
|
|
|
|
|
WeakPtr<WebContentConsoleClient> m_top_level_document_console_client;
|
|
|
|
|
|
|
|
JS::Handle<JS::GlobalObject> m_console_global_object;
|
2023-11-29 16:34:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|