LibWeb: Use resources to find internal HTML template paths

This commit is contained in:
Bastiaan van der Plaat 2023-12-26 10:24:05 +01:00 committed by Tim Flynn
parent f8feca5d21
commit 009729d5e3
Notes: sideshowbarker 2024-07-16 21:51:02 +09:00
5 changed files with 3 additions and 40 deletions

View file

@ -72,9 +72,6 @@ ErrorOr<int> service_main(int ipc_socket, int fd_passing_socket)
Web::HTML::Window::set_internals_object_exposed(is_layout_test_mode);
Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode));
Web::set_error_page_url(TRY(String::formatted("file://{}/res/ladybird/error.html", s_serenity_resource_root)));
Web::set_directory_page_url(TRY(String::formatted("file://{}/res/ladybird/directory.html", s_serenity_resource_root)));
TRY(Web::Bindings::initialize_main_thread_vm());
auto maybe_content_filter_error = load_content_filters();

View file

@ -115,9 +115,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode));
Web::set_error_page_url(TRY(String::formatted("file://{}/res/ladybird/error.html", s_serenity_resource_root)));
Web::set_directory_page_url(TRY(String::formatted("file://{}/res/ladybird/directory.html", s_serenity_resource_root)));
TRY(Web::Bindings::initialize_main_thread_vm());
auto maybe_content_filter_error = load_content_filters();

View file

@ -49,9 +49,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
VERIFY(fd_passing_socket >= 0);
Web::set_error_page_url(TRY(String::formatted("file://{}/res/ladybird/error.html", s_serenity_resource_root)));
Web::set_directory_page_url(TRY(String::formatted("file://{}/res/ladybird/directory.html", s_serenity_resource_root)));
TRY(Web::Bindings::initialize_main_thread_vm());
auto client = TRY(IPC::take_over_accepted_client_from_system_server<WebWorker::ConnectionFromClient>());

View file

@ -9,40 +9,17 @@
#include <AK/SourceGenerator.h>
#include <LibCore/DateTime.h>
#include <LibCore/Directory.h>
#include <LibCore/Resource.h>
#include <LibCore/System.h>
#include <LibWeb/Loader/GeneratedPagesLoader.h>
namespace Web {
static String s_error_page_url = "file:///res/ladybird/error.html"_string;
String error_page_url()
{
return s_error_page_url;
}
void set_error_page_url(String error_page_url)
{
s_error_page_url = error_page_url;
}
static String s_directory_page_url = "file:///res/ladybird/directory.html"_string;
String directory_page_url()
{
return s_directory_page_url;
}
void set_directory_page_url(String directory_page_url)
{
s_directory_page_url = directory_page_url;
}
ErrorOr<String> load_error_page(AK::URL const& url)
{
// Generate HTML error page from error template file
// FIXME: Use an actual templating engine (our own one when it's built, preferably with a way to check these usages at compile time)
auto template_path = AK::URL::create_with_url_or_path(error_page_url().to_byte_string()).serialize_path();
auto template_path = TRY(Core::Resource::load_from_uri("resource://ladybird/error.html"sv))->filesystem_path();
auto template_file = TRY(Core::File::open(template_path, Core::File::OpenMode::Read));
auto template_contents = TRY(template_file->read_until_eof());
StringBuilder builder;
@ -83,7 +60,7 @@ ErrorOr<String> load_file_directory_page(AK::URL const& url)
// Generate HTML directory page from directory template file
// FIXME: Use an actual templating engine (our own one when it's built, preferably with a way to check these usages at compile time)
auto template_path = AK::URL::create_with_url_or_path(directory_page_url().to_byte_string()).serialize_path();
auto template_path = TRY(Core::Resource::load_from_uri("resource://ladybird/directory.html"sv))->filesystem_path();
auto template_file = TRY(Core::File::open(template_path, Core::File::OpenMode::Read));
auto template_contents = TRY(template_file->read_until_eof());
StringBuilder builder;

View file

@ -11,11 +11,6 @@
namespace Web {
String error_page_url();
void set_error_page_url(String);
String directory_page_url();
void set_directory_page_url(String);
ErrorOr<String> load_error_page(AK::URL const&);
ErrorOr<String> load_file_directory_page(AK::URL const&);