summaryrefslogtreecommitdiff
path: root/Userland/Services/WebContent
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2022-02-26 17:50:31 +0100
committerLinus Groh <mail@linusgroh.de>2022-06-27 20:22:15 +0100
commit662711fa26de109d4c8fe1d93f17e1983d66ebf3 (patch)
treec138ed6b424be28e01db85e74f81f5a31632d6f4 /Userland/Services/WebContent
parent1ba9c821fbfc54562e10981a3403aa25fb6079b3 (diff)
downloadserenity-662711fa26de109d4c8fe1d93f17e1983d66ebf3.zip
Browser+LibWeb+WebContent: Allow Browser to load local files
To achieve this goal: - The Browser unveils "/tmp/portal/filesystemaccess" - Pass the page through LoadRequest => ResourceLoader - ResourceLoader requests a file to the FileSystemAccessServer via IPC - OutOfProcessWebView handles it and sends a file descriptor back to the Page.
Diffstat (limited to 'Userland/Services/WebContent')
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp18
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.h7
-rw-r--r--Userland/Services/WebContent/PageHost.cpp5
-rw-r--r--Userland/Services/WebContent/PageHost.h1
-rw-r--r--Userland/Services/WebContent/WebContentClient.ipc1
-rw-r--r--Userland/Services/WebContent/WebContentServer.ipc3
6 files changed, 35 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp
index 89f03fa9ea..f2f483ce1f 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.cpp
+++ b/Userland/Services/WebContent/ConnectionFromClient.cpp
@@ -505,4 +505,22 @@ Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClien
auto session_storage = document->window().session_storage();
return session_storage->map();
}
+
+void ConnectionFromClient::handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id)
+{
+ auto result = m_requested_files.get(request_id);
+ VERIFY(result.has_value());
+
+ VERIFY(result.value()->on_file_request_finish);
+ result.value()->on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() });
+ m_requested_files.remove(request_id);
+}
+
+void ConnectionFromClient::request_file(NonnullRefPtr<Web::FileRequest>& file_request)
+{
+ i32 const id = last_id++;
+ m_requested_files.set(id, file_request);
+
+ async_did_request_file(file_request->path(), id);
+}
}
diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h
index 943e4ff359..8071e5d3fe 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.h
+++ b/Userland/Services/WebContent/ConnectionFromClient.h
@@ -13,6 +13,7 @@
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWeb/Forward.h>
+#include <LibWeb/Loader/FileRequest.h>
#include <WebContent/Forward.h>
#include <WebContent/WebContentClientEndpoint.h>
#include <WebContent/WebContentConsoleClient.h>
@@ -31,6 +32,8 @@ public:
void initialize_js_console(Badge<PageHost>);
+ void request_file(NonnullRefPtr<Web::FileRequest>&);
+
private:
explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>);
@@ -64,6 +67,7 @@ private:
virtual void set_preferred_color_scheme(Web::CSS::PreferredColorScheme const&) override;
virtual void set_has_focus(bool) override;
virtual void set_is_scripting_enabled(bool) override;
+ virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
virtual void js_console_input(String const&) override;
virtual void run_javascript(String const&) override;
@@ -91,6 +95,9 @@ private:
WeakPtr<JS::Interpreter> m_interpreter;
OwnPtr<WebContentConsoleClient> m_console_client;
JS::Handle<JS::GlobalObject> m_console_global_object;
+
+ HashMap<int, NonnullRefPtr<Web::FileRequest>> m_requested_files {};
+ int last_id { 0 };
};
}
diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp
index e7cd81d63b..5e377d4117 100644
--- a/Userland/Services/WebContent/PageHost.cpp
+++ b/Userland/Services/WebContent/PageHost.cpp
@@ -263,4 +263,9 @@ void PageHost::page_did_update_resource_count(i32 count_waiting)
m_client.async_did_update_resource_count(count_waiting);
}
+void PageHost::request_file(NonnullRefPtr<Web::FileRequest>& file_request)
+{
+ m_client.request_file(file_request);
+}
+
}
diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h
index a9815f2fec..13faaa5819 100644
--- a/Userland/Services/WebContent/PageHost.h
+++ b/Userland/Services/WebContent/PageHost.h
@@ -66,6 +66,7 @@ private:
virtual String page_did_request_cookie(const URL&, Web::Cookie::Source) override;
virtual void page_did_set_cookie(const URL&, Web::Cookie::ParsedCookie const&, Web::Cookie::Source) override;
virtual void page_did_update_resource_count(i32) override;
+ virtual void request_file(NonnullRefPtr<Web::FileRequest>&) override;
explicit PageHost(ConnectionFromClient&);
diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc
index aaa5c67138..a2865d4ca6 100644
--- a/Userland/Services/WebContent/WebContentClient.ipc
+++ b/Userland/Services/WebContent/WebContentClient.ipc
@@ -35,6 +35,7 @@ endpoint WebContentClient
did_request_cookie(URL url, u8 source) => (String cookie)
did_set_cookie(URL url, Web::Cookie::ParsedCookie cookie, u8 source) =|
did_update_resource_count(i32 count_waiting) =|
+ did_request_file(String path, i32 request_id) =|
did_output_js_console_message(i32 message_index) =|
did_get_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages) =|
diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc
index 418c33a32d..b8b01749f3 100644
--- a/Userland/Services/WebContent/WebContentServer.ipc
+++ b/Userland/Services/WebContent/WebContentServer.ipc
@@ -1,4 +1,5 @@
#include <AK/URL.h>
+#include <LibIPC/File.h>
#include <LibCore/AnonymousBuffer.h>
#include <LibGfx/ShareableBitmap.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
@@ -51,4 +52,6 @@ endpoint WebContentServer
get_local_storage_entries() => (OrderedHashMap<String,String> entries)
get_session_storage_entries() => (OrderedHashMap<String,String> entries)
+
+ handle_file_return(i32 error, Optional<IPC::File> file, i32 request_id) =|
}