1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/String.h>
#include <LibGfx/Forward.h>
#include <LibGfx/StandardCursor.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWebView/Forward.h>
#include <LibWebView/WebContentClient.h>
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;
};
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<DOMNodeProperties> inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> 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 toggle_video_play_state();
void toggle_video_loop_state();
void toggle_video_controls_state();
enum class ScreenshotType {
Visible,
Full,
};
ErrorOr<void> take_screenshot(ScreenshotType);
virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) = 0;
virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize) = 0;
virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) = 0;
virtual void notify_server_did_change_selection(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) = 0;
virtual void notify_server_did_change_title(Badge<WebContentClient>, DeprecatedString const&) = 0;
virtual void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32) = 0;
virtual void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint) = 0;
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) = 0;
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) = 0;
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) = 0;
virtual void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&) = 0;
virtual void notify_server_did_unhover_link(Badge<WebContentClient>) = 0;
virtual void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, DeprecatedString const& target, unsigned modifiers) = 0;
virtual void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, DeprecatedString const& target, unsigned modifiers) = 0;
virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&, bool is_redirect) = 0;
virtual void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&) = 0;
virtual void notify_server_did_request_navigate_back(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_navigate_forward(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_refresh(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint) = 0;
virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers) = 0;
virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, Gfx::ShareableBitmap const&) = 0;
virtual void notify_server_did_request_video_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, bool is_playing, bool has_user_agent_controls, bool is_looping) = 0;
virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) = 0;
virtual void notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message) = 0;
virtual void notify_server_did_request_accept_dialog(Badge<WebContentClient>) = 0;
virtual void notify_server_did_request_dismiss_dialog(Badge<WebContentClient>) = 0;
virtual void notify_server_did_get_source(const AK::URL& url, DeprecatedString const& source) = 0;
virtual void notify_server_did_get_dom_tree(DeprecatedString const& dom_tree) = 0;
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) = 0;
virtual void notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) = 0;
virtual void notify_server_did_output_js_console_message(i32 message_index) = 0;
virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages) = 0;
virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) = 0;
virtual Vector<Web::Cookie::Cookie> notify_server_did_request_all_cookies(Badge<WebContentClient>, AK::URL const& url) = 0;
virtual Optional<Web::Cookie::Cookie> notify_server_did_request_named_cookie(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& name) = 0;
virtual DeprecatedString notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) = 0;
virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) = 0;
virtual void notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie) = 0;
virtual String notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab) = 0;
virtual void notify_server_did_request_activate_tab(Badge<WebContentClient>) = 0;
virtual void notify_server_did_close_browsing_context(Badge<WebContentClient>) = 0;
virtual void notify_server_did_update_resource_count(i32 count_waiting) = 0;
virtual void notify_server_did_request_restore_window() = 0;
virtual Gfx::IntPoint notify_server_did_request_reposition_window(Gfx::IntPoint) = 0;
virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize) = 0;
virtual Gfx::IntRect notify_server_did_request_maximize_window() = 0;
virtual Gfx::IntRect notify_server_did_request_minimize_window() = 0;
virtual Gfx::IntRect notify_server_did_request_fullscreen_window() = 0;
virtual void notify_server_did_request_file(Badge<WebContentClient>, 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<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(ReadonlySpan<String> 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<Gfx::Bitmap> bitmap;
};
struct ClientState {
RefPtr<WebContentClient> 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<Core::Timer> m_backing_store_shrink_timer;
RefPtr<Gfx::Bitmap> m_backup_bitmap;
Gfx::IntSize m_backup_bitmap_size;
};
}
|