1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

Ladybird+LibWebView: Migrate file APIs to LibWebView callbacks

This also sets the default callback to do what every non-Serenity
browser is doing, rather than copy-pasting this callback into every
implementation. The callback is still available for any platform which
might want to override the default behavior. For example, OOPWV now
overrides this callback to use FileSystemAccessClient.
This commit is contained in:
Timothy Flynn 2023-08-23 06:54:22 -04:00 committed by Tim Flynn
parent ebdcba8b3b
commit 15da77f4c4
10 changed files with 21 additions and 44 deletions

View file

@ -7,7 +7,6 @@
#include <Ladybird/HelperProcess.h> #include <Ladybird/HelperProcess.h>
#include <Ladybird/Types.h> #include <Ladybird/Types.h>
#include <Ladybird/Utilities.h> #include <Ladybird/Utilities.h>
#include <LibCore/File.h>
#include <LibGfx/Font/FontDatabase.h> #include <LibGfx/Font/FontDatabase.h>
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
#include <LibIPC/File.h> #include <LibIPC/File.h>
@ -197,15 +196,6 @@ void WebViewBridge::notify_server_did_leave_tooltip_area(Badge<WebView::WebConte
if (on_tooltip_left) if (on_tooltip_left)
on_tooltip_left(); on_tooltip_left();
} }
void WebViewBridge::notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const& path, i32 request_id)
{
auto file = Core::File::open(path, Core::File::OpenMode::Read);
if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
}
void WebViewBridge::notify_server_did_finish_handling_input_event(bool) void WebViewBridge::notify_server_did_finish_handling_input_event(bool)
{ {

View file

@ -72,7 +72,6 @@ private:
virtual void notify_server_did_request_scroll_into_view(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override; virtual void notify_server_did_request_scroll_into_view(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override;
virtual void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override; virtual void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
virtual void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override; virtual void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override;
virtual void notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const& path, i32) override;
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override; virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
virtual void update_zoom() override; virtual void update_zoom() override;

View file

@ -725,15 +725,6 @@ void WebContentView::notify_server_did_leave_tooltip_area(Badge<WebContentClient
QToolTip::hideText(); QToolTip::hideText();
} }
void WebContentView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
{
auto file = Core::File::open(path, Core::File::OpenMode::Read);
if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
}
Gfx::IntRect WebContentView::viewport_rect() const Gfx::IntRect WebContentView::viewport_rect() const
{ {
return m_viewport_rect; return m_viewport_rect;

View file

@ -86,7 +86,6 @@ public:
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override; virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override;
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override; virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override; virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
virtual void notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32) override;
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override; virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
signals: signals:

View file

@ -28,6 +28,15 @@ OutOfProcessWebView::OutOfProcessWebView()
set_focus_policy(GUI::FocusPolicy::StrongFocus); set_focus_policy(GUI::FocusPolicy::StrongFocus);
create_client(); create_client();
on_request_file = [this](auto const& path, auto request_id) {
auto file = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), path);
if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(file.value().stream()), request_id);
};
} }
OutOfProcessWebView::~OutOfProcessWebView() = default; OutOfProcessWebView::~OutOfProcessWebView() = default;
@ -231,15 +240,6 @@ void OutOfProcessWebView::notify_server_did_leave_tooltip_area(Badge<WebContentC
GUI::Application::the()->hide_tooltip(); GUI::Application::the()->hide_tooltip();
} }
void OutOfProcessWebView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
{
auto file = FileSystemAccessClient::Client::the().request_file_read_only_approved(window(), path);
if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(file.value().stream()), request_id);
}
void OutOfProcessWebView::did_scroll() void OutOfProcessWebView::did_scroll()
{ {
client().async_set_viewport_rect(visible_content_rect()); client().async_set_viewport_rect(visible_content_rect());

View file

@ -92,7 +92,6 @@ private:
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override; virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override;
virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override; virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override; virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
virtual void notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32) override;
virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override; virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
virtual Gfx::IntRect viewport_rect() const override; virtual Gfx::IntRect viewport_rect() const override;

View file

@ -25,6 +25,15 @@ ViewImplementation::ViewImplementation()
// happen to be visiting crashy websites a lot. // happen to be visiting crashy websites a lot.
this->m_crash_count = 0; this->m_crash_count = 0;
}).release_value_but_fixme_should_propagate_errors(); }).release_value_but_fixme_should_propagate_errors();
on_request_file = [this](auto const& path, auto request_id) {
auto file = Core::File::open(path, Core::File::OpenMode::Read);
if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
};
} }
WebContentClient& ViewImplementation::client() WebContentClient& ViewImplementation::client()

View file

@ -104,6 +104,7 @@ public:
Function<void(DeprecatedString const&)> on_title_change; Function<void(DeprecatedString const&)> on_title_change;
Function<void(const AK::URL&, bool)> on_load_start; Function<void(const AK::URL&, bool)> on_load_start;
Function<void(const AK::URL&)> on_load_finish; Function<void(const AK::URL&)> on_load_finish;
Function<void(DeprecatedString const& path, i32)> on_request_file;
Function<void()> on_navigate_back; Function<void()> on_navigate_back;
Function<void()> on_navigate_forward; Function<void()> on_navigate_forward;
Function<void()> on_refresh; Function<void()> on_refresh;
@ -143,7 +144,6 @@ public:
virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) = 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_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_leave_tooltip_area(Badge<WebContentClient>) = 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 void notify_server_did_finish_handling_input_event(bool event_was_accepted) = 0;
virtual Gfx::IntRect viewport_rect() const = 0; virtual Gfx::IntRect viewport_rect() const = 0;

View file

@ -366,7 +366,8 @@ Messages::WebContentClient::DidRequestFullscreenWindowResponse WebContentClient:
void WebContentClient::did_request_file(DeprecatedString const& path, i32 request_id) void WebContentClient::did_request_file(DeprecatedString const& path, i32 request_id)
{ {
m_view.notify_server_did_request_file({}, path, request_id); if (m_view.on_request_file)
m_view.on_request_file(path, request_id);
} }
void WebContentClient::did_finish_handling_input_event(bool event_was_accepted) void WebContentClient::did_finish_handling_input_event(bool event_was_accepted)

View file

@ -112,17 +112,6 @@ private:
void notify_server_did_request_scroll_into_view(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override { } void notify_server_did_request_scroll_into_view(Badge<WebView::WebContentClient>, Gfx::IntRect const&) override { }
void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override { } void notify_server_did_enter_tooltip_area(Badge<WebView::WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override { }
void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override { } void notify_server_did_leave_tooltip_area(Badge<WebView::WebContentClient>) override { }
void notify_server_did_request_file(Badge<WebView::WebContentClient>, DeprecatedString const& path, i32 request_id) override
{
auto file = Core::File::open(path, Core::File::OpenMode::Read);
if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id);
else
client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
}
void notify_server_did_finish_handling_input_event(bool) override { } void notify_server_did_finish_handling_input_event(bool) override { }
void update_zoom() override { } void update_zoom() override { }
void create_client(WebView::EnableCallgrindProfiling) override { } void create_client(WebView::EnableCallgrindProfiling) override { }