2020-06-17 18:31:42 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-17 18:31:42 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-07-06 22:18:16 +03:00
|
|
|
#include <AK/URL.h>
|
2021-05-03 21:31:58 +03:00
|
|
|
#include <LibGUI/AbstractScrollableWidget.h>
|
2020-06-17 18:31:42 +03:00
|
|
|
#include <LibGUI/Widget.h>
|
2020-07-06 22:18:16 +03:00
|
|
|
#include <LibWeb/WebViewHooks.h>
|
2020-06-17 18:31:42 +03:00
|
|
|
|
2020-08-24 14:03:18 +03:00
|
|
|
namespace Web {
|
|
|
|
|
2020-06-17 18:31:42 +03:00
|
|
|
class WebContentClient;
|
|
|
|
|
2020-08-17 17:20:47 +03:00
|
|
|
class OutOfProcessWebView final
|
2021-05-03 21:31:58 +03:00
|
|
|
: public GUI::AbstractScrollableWidget
|
2020-07-06 22:18:16 +03:00
|
|
|
, public Web::WebViewHooks {
|
2020-08-17 17:20:47 +03:00
|
|
|
C_OBJECT(OutOfProcessWebView);
|
2020-06-17 18:31:42 +03:00
|
|
|
|
|
|
|
public:
|
2020-08-17 17:20:47 +03:00
|
|
|
virtual ~OutOfProcessWebView() override;
|
2020-06-17 18:31:42 +03:00
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
AK::URL url() const { return m_url; }
|
|
|
|
void load(const AK::URL&);
|
2020-06-17 18:31:42 +03:00
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
void load_html(const StringView&, const AK::URL&);
|
2020-10-08 23:58:00 +03:00
|
|
|
void load_empty_document();
|
2020-10-08 23:11:01 +03:00
|
|
|
|
2021-01-31 11:06:25 +03:00
|
|
|
void debug_request(const String& request, const String& argument = {});
|
2021-02-23 15:17:23 +03:00
|
|
|
void get_source();
|
2021-08-27 14:31:55 +03:00
|
|
|
|
2021-06-07 18:35:10 +03:00
|
|
|
void inspect_dom_tree();
|
2021-08-27 14:31:55 +03:00
|
|
|
struct DOMNodeProperties {
|
|
|
|
String specified_values_json;
|
|
|
|
String computed_values_json;
|
|
|
|
};
|
|
|
|
Optional<DOMNodeProperties> inspect_dom_node(i32 node_id);
|
|
|
|
void clear_inspected_dom_node();
|
2021-08-27 19:33:10 +03:00
|
|
|
i32 get_hovered_node_id();
|
2021-08-27 14:31:55 +03:00
|
|
|
|
2021-02-28 06:47:14 +03:00
|
|
|
void js_console_input(const String& js_source);
|
2021-09-04 13:14:25 +03:00
|
|
|
void js_console_request_messages(i32 start_index);
|
2021-01-31 11:06:25 +03:00
|
|
|
|
2021-08-24 17:56:42 +03:00
|
|
|
void run_javascript(StringView);
|
|
|
|
|
2021-07-14 15:32:55 +03:00
|
|
|
String selected_text();
|
2021-07-14 15:53:55 +03:00
|
|
|
void select_all();
|
2021-07-14 15:32:55 +03:00
|
|
|
|
2021-09-08 01:55:35 +03:00
|
|
|
String dump_layout_tree();
|
|
|
|
|
2020-07-05 00:19:32 +03:00
|
|
|
void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
|
2021-01-17 01:15:32 +03:00
|
|
|
void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
|
2020-06-17 19:00:18 +03:00
|
|
|
void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);
|
2020-07-04 21:57:57 +03:00
|
|
|
void notify_server_did_change_selection(Badge<WebContentClient>);
|
2021-02-28 00:12:12 +03:00
|
|
|
void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor);
|
2020-07-05 00:40:17 +03:00
|
|
|
void notify_server_did_change_title(Badge<WebContentClient>, const String&);
|
2021-09-08 13:22:44 +03:00
|
|
|
void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32);
|
2021-09-08 13:44:36 +03:00
|
|
|
void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint const&);
|
2020-07-05 16:43:43 +03:00
|
|
|
void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, const Gfx::IntRect&);
|
2021-03-30 19:10:06 +03:00
|
|
|
void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, const Gfx::IntPoint&, const String&);
|
|
|
|
void notify_server_did_leave_tooltip_area(Badge<WebContentClient>);
|
2021-09-13 00:33:23 +03:00
|
|
|
void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&);
|
2020-07-05 17:59:20 +03:00
|
|
|
void notify_server_did_unhover_link(Badge<WebContentClient>);
|
2021-09-13 00:33:23 +03:00
|
|
|
void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, const String& target, unsigned modifiers);
|
|
|
|
void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, const String& target, unsigned modifiers);
|
|
|
|
void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&);
|
|
|
|
void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&);
|
2020-07-07 13:24:29 +03:00
|
|
|
void notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&);
|
2021-09-13 00:33:23 +03:00
|
|
|
void notify_server_did_request_link_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const AK::URL&, const String& target, unsigned modifiers);
|
|
|
|
void notify_server_did_request_image_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const AK::URL&, const String& target, unsigned modifiers, const Gfx::ShareableBitmap&);
|
2020-09-12 12:56:13 +03:00
|
|
|
void notify_server_did_request_alert(Badge<WebContentClient>, const String& message);
|
2021-02-10 10:48:28 +03:00
|
|
|
bool notify_server_did_request_confirm(Badge<WebContentClient>, const String& message);
|
2021-02-20 14:05:18 +03:00
|
|
|
String notify_server_did_request_prompt(Badge<WebContentClient>, const String& message, const String& default_);
|
2021-09-13 00:33:23 +03:00
|
|
|
void notify_server_did_get_source(const AK::URL& url, const String& source);
|
2021-06-07 18:35:10 +03:00
|
|
|
void notify_server_did_get_dom_tree(const String& dom_tree);
|
2021-08-27 14:47:30 +03:00
|
|
|
void notify_server_did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style);
|
2021-09-04 13:14:25 +03:00
|
|
|
void notify_server_did_output_js_console_message(i32 message_index);
|
|
|
|
void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages);
|
2021-03-26 17:41:25 +03:00
|
|
|
void notify_server_did_change_favicon(const Gfx::Bitmap& favicon);
|
2021-09-13 00:33:23 +03:00
|
|
|
String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Cookie::Source source);
|
|
|
|
void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source);
|
2020-06-17 18:31:42 +03:00
|
|
|
|
|
|
|
private:
|
2020-08-17 17:20:47 +03:00
|
|
|
OutOfProcessWebView();
|
2020-06-17 18:31:42 +03:00
|
|
|
|
2020-07-05 00:19:32 +03:00
|
|
|
// ^Widget
|
2020-06-17 18:31:42 +03:00
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
|
|
|
virtual void resize_event(GUI::ResizeEvent&) override;
|
2020-06-17 19:05:08 +03:00
|
|
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
|
|
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
|
|
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
2021-02-22 21:45:41 +03:00
|
|
|
virtual void mousewheel_event(GUI::MouseEvent&) override;
|
2020-08-03 20:58:59 +03:00
|
|
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
2020-10-09 00:13:54 +03:00
|
|
|
virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
|
2021-06-13 15:16:06 +03:00
|
|
|
virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
|
2020-06-17 18:31:42 +03:00
|
|
|
|
2021-05-03 21:31:58 +03:00
|
|
|
// ^AbstractScrollableWidget
|
2020-07-05 00:19:32 +03:00
|
|
|
virtual void did_scroll() override;
|
|
|
|
|
2020-07-04 21:57:57 +03:00
|
|
|
void request_repaint();
|
2021-01-30 20:20:40 +03:00
|
|
|
void handle_resize();
|
2020-07-04 21:57:57 +03:00
|
|
|
|
2021-01-30 20:20:40 +03:00
|
|
|
void create_client();
|
2020-06-17 18:31:42 +03:00
|
|
|
WebContentClient& client();
|
|
|
|
|
2021-02-22 13:07:40 +03:00
|
|
|
void handle_web_content_process_crash();
|
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
AK::URL m_url;
|
2020-07-06 22:46:37 +03:00
|
|
|
|
2021-09-17 15:30:49 +03:00
|
|
|
struct SharedBitmap {
|
|
|
|
i32 id { -1 };
|
|
|
|
RefPtr<Gfx::Bitmap> bitmap;
|
|
|
|
};
|
|
|
|
|
2021-01-30 20:20:40 +03:00
|
|
|
struct ClientState {
|
|
|
|
RefPtr<WebContentClient> client;
|
2021-09-17 15:30:49 +03:00
|
|
|
SharedBitmap front_bitmap;
|
|
|
|
SharedBitmap back_bitmap;
|
2021-01-30 20:20:40 +03:00
|
|
|
i32 next_bitmap_id { 0 };
|
|
|
|
bool has_usable_bitmap { false };
|
|
|
|
} m_client_state;
|
2021-02-10 00:07:36 +03:00
|
|
|
|
|
|
|
RefPtr<Gfx::Bitmap> m_backup_bitmap;
|
2020-06-17 18:31:42 +03:00
|
|
|
};
|
2020-08-24 14:03:18 +03:00
|
|
|
|
|
|
|
}
|