Serenity Operating System
at master 193 lines 12 kB view raw
1/* 2 * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> 3 * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> 4 * 5 * SPDX-License-Identifier: BSD-2-Clause 6 */ 7 8#pragma once 9 10#include <AK/Queue.h> 11#include <AK/URL.h> 12#include <LibGUI/AbstractScrollableWidget.h> 13#include <LibGUI/Widget.h> 14#include <LibWeb/CSS/Selector.h> 15#include <LibWeb/Page/Page.h> 16#include <LibWebView/ViewImplementation.h> 17 18namespace Messages::WebContentServer { 19class WebdriverExecuteScriptResponse; 20} 21 22namespace WebView { 23 24class WebContentClient; 25 26class OutOfProcessWebView final 27 : public GUI::AbstractScrollableWidget 28 , public ViewImplementation { 29 C_OBJECT(OutOfProcessWebView); 30 31 using Super = GUI::AbstractScrollableWidget; 32 33public: 34 virtual ~OutOfProcessWebView() override; 35 36 void js_console_input(DeprecatedString const& js_source); 37 void js_console_request_messages(i32 start_index); 38 39 DeprecatedString dump_layout_tree(); 40 41 OrderedHashMap<DeprecatedString, DeprecatedString> get_local_storage_entries(); 42 OrderedHashMap<DeprecatedString, DeprecatedString> get_session_storage_entries(); 43 44 void set_content_filters(Vector<DeprecatedString>); 45 void set_proxy_mappings(Vector<DeprecatedString> proxies, HashMap<DeprecatedString, size_t> mappings); 46 void connect_to_webdriver(DeprecatedString const& webdriver_ipc_path); 47 48 void set_window_position(Gfx::IntPoint); 49 void set_window_size(Gfx::IntSize); 50 51 void set_system_visibility_state(bool visible); 52 53 Gfx::ShareableBitmap take_screenshot() const; 54 Gfx::ShareableBitmap take_document_screenshot(); 55 56 // This is a hint that tells OOPWV that the content will scale to the viewport size. 57 // In practice, this means that OOPWV may render scaled stale versions of the content while resizing. 58 void set_content_scales_to_viewport(bool); 59 60 Function<void()> on_close; 61 Function<void(Gfx::IntPoint screen_position)> on_context_menu_request; 62 Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_click; 63 Function<void(const AK::URL&, Gfx::IntPoint screen_position)> on_link_context_menu_request; 64 Function<void(const AK::URL&, Gfx::IntPoint screen_position, Gfx::ShareableBitmap const&)> on_image_context_menu_request; 65 Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_middle_click; 66 Function<void(const AK::URL&)> on_link_hover; 67 Function<void(DeprecatedString const&)> on_title_change; 68 Function<void(const AK::URL&, bool)> on_load_start; 69 Function<void(const AK::URL&)> on_load_finish; 70 Function<void()> on_navigate_back; 71 Function<void()> on_navigate_forward; 72 Function<void()> on_refresh; 73 Function<void(Gfx::Bitmap const&)> on_favicon_change; 74 Function<void(const AK::URL&)> on_url_drop; 75 Function<void(Web::DOM::Document*)> on_set_document; 76 Function<void(const AK::URL&, DeprecatedString const&)> on_get_source; 77 Function<void(DeprecatedString const&)> on_get_dom_tree; 78 Function<void(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing)> on_get_dom_node_properties; 79 Function<void(DeprecatedString const&)> on_get_accessibility_tree; 80 Function<void(i32 message_id)> on_js_console_new_message; 81 Function<void(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages)> on_get_js_console_messages; 82 Function<Vector<Web::Cookie::Cookie>(AK::URL const& url)> on_get_all_cookies; 83 Function<Optional<Web::Cookie::Cookie>(AK::URL const& url, DeprecatedString const& name)> on_get_named_cookie; 84 Function<DeprecatedString(const AK::URL& url, Web::Cookie::Source source)> on_get_cookie; 85 Function<void(const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)> on_set_cookie; 86 Function<void(Web::Cookie::Cookie const& cookie)> on_update_cookie; 87 Function<void(i32 count_waiting)> on_resource_status_change; 88 Function<void()> on_restore_window; 89 Function<Gfx::IntPoint(Gfx::IntPoint)> on_reposition_window; 90 Function<Gfx::IntSize(Gfx::IntSize)> on_resize_window; 91 Function<Gfx::IntRect()> on_maximize_window; 92 Function<Gfx::IntRect()> on_minimize_window; 93 Function<Gfx::IntRect()> on_fullscreen_window; 94 Function<void()> on_back_button; 95 Function<void()> on_forward_button; 96 97private: 98 OutOfProcessWebView(); 99 100 // ^Widget 101 virtual void paint_event(GUI::PaintEvent&) override; 102 virtual void resize_event(GUI::ResizeEvent&) override; 103 virtual void mousedown_event(GUI::MouseEvent&) override; 104 virtual void mouseup_event(GUI::MouseEvent&) override; 105 virtual void mousemove_event(GUI::MouseEvent&) override; 106 virtual void mousewheel_event(GUI::MouseEvent&) override; 107 virtual void doubleclick_event(GUI::MouseEvent&) override; 108 virtual void keydown_event(GUI::KeyEvent&) override; 109 virtual void keyup_event(GUI::KeyEvent&) override; 110 virtual void theme_change_event(GUI::ThemeChangeEvent&) override; 111 virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override; 112 virtual void focusin_event(GUI::FocusEvent&) override; 113 virtual void focusout_event(GUI::FocusEvent&) override; 114 virtual void show_event(GUI::ShowEvent&) override; 115 virtual void hide_event(GUI::HideEvent&) override; 116 117 // ^AbstractScrollableWidget 118 virtual void did_scroll() override; 119 120 // ^WebView::ViewImplementation 121 virtual void create_client() override; 122 virtual void update_zoom() override; 123 virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override; 124 virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) override; 125 virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override; 126 virtual void notify_server_did_change_selection(Badge<WebContentClient>) override; 127 virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override; 128 virtual void notify_server_did_change_title(Badge<WebContentClient>, DeprecatedString const&) override; 129 virtual void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32) override; 130 virtual void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint) override; 131 virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override; 132 virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override; 133 virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override; 134 virtual void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&) override; 135 virtual void notify_server_did_unhover_link(Badge<WebContentClient>) override; 136 virtual void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override; 137 virtual void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override; 138 virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&, bool) override; 139 virtual void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&) override; 140 virtual void notify_server_did_request_navigate_back(Badge<WebContentClient>) override; 141 virtual void notify_server_did_request_navigate_forward(Badge<WebContentClient>) override; 142 virtual void notify_server_did_request_refresh(Badge<WebContentClient>) override; 143 virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint) override; 144 virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override; 145 virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, Gfx::ShareableBitmap const&) override; 146 virtual void notify_server_did_request_alert(Badge<WebContentClient>, DeprecatedString const& message) override; 147 virtual void notify_server_did_request_confirm(Badge<WebContentClient>, DeprecatedString const& message) override; 148 virtual void notify_server_did_request_prompt(Badge<WebContentClient>, DeprecatedString const& message, DeprecatedString const& default_) override; 149 virtual void notify_server_did_request_set_prompt_text(Badge<WebContentClient>, DeprecatedString const& message) override; 150 virtual void notify_server_did_request_accept_dialog(Badge<WebContentClient>) override; 151 virtual void notify_server_did_request_dismiss_dialog(Badge<WebContentClient>) override; 152 virtual void notify_server_did_get_source(const AK::URL& url, DeprecatedString const& source) override; 153 virtual void notify_server_did_get_dom_tree(DeprecatedString const& dom_tree) override; 154 virtual void notify_server_did_get_dom_node_properties(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) override; 155 virtual void notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) override; 156 virtual void notify_server_did_output_js_console_message(i32 message_index) override; 157 virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages) override; 158 virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) override; 159 virtual Vector<Web::Cookie::Cookie> notify_server_did_request_all_cookies(Badge<WebContentClient>, AK::URL const& url) override; 160 virtual Optional<Web::Cookie::Cookie> notify_server_did_request_named_cookie(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& name) override; 161 virtual DeprecatedString notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) override; 162 virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override; 163 virtual void notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie) override; 164 virtual void notify_server_did_close_browsing_context(Badge<WebContentClient>) override; 165 virtual void notify_server_did_update_resource_count(i32 count_waiting) override; 166 virtual void notify_server_did_request_restore_window() override; 167 virtual Gfx::IntPoint notify_server_did_request_reposition_window(Gfx::IntPoint) override; 168 virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize) override; 169 virtual Gfx::IntRect notify_server_did_request_maximize_window() override; 170 virtual Gfx::IntRect notify_server_did_request_minimize_window() override; 171 virtual Gfx::IntRect notify_server_did_request_fullscreen_window() override; 172 virtual void notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32) override; 173 virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override; 174 175 void request_repaint(); 176 void handle_resize(); 177 178 void handle_web_content_process_crash(); 179 180 using InputEvent = Variant<GUI::KeyEvent, GUI::MouseEvent>; 181 void enqueue_input_event(InputEvent const&); 182 void process_next_input_event(); 183 184 RefPtr<Gfx::Bitmap> m_backup_bitmap; 185 RefPtr<GUI::Dialog> m_dialog; 186 187 bool m_is_awaiting_response_for_input_event { false }; 188 Queue<InputEvent> m_pending_input_events; 189 190 bool m_content_scales_to_viewport { false }; 191}; 192 193}