From e4c3a52cfac7add7d9cc3ae526b1fdd7a8ee7b92 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Sun, 13 Aug 2023 22:34:57 +0200 Subject: [PATCH] LibWeb: Add resource_directory_url for internal HTML pages The error.html page now uses the resource_directory_url this variable contains the relative path to /Base/res/ on the host system as a file:// url. This is needed for future pages to load resource files like icons. For the error.html page this was not really needed because it lies over this own URL in FrameLoader.cpp. --- Base/res/html/error.html | 5 ++++- Ladybird/WebContent/main.cpp | 1 + .../Libraries/LibWeb/Loader/FrameLoader.cpp | 18 ++++++++++++++++++ Userland/Libraries/LibWeb/Loader/FrameLoader.h | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Base/res/html/error.html b/Base/res/html/error.html index c7fb60897f9..280378e43d8 100644 --- a/Base/res/html/error.html +++ b/Base/res/html/error.html @@ -9,11 +9,14 @@ header { margin-bottom: 10px; } + img { + margin-right: 5px; + }
- Warning + Warning

Failed to load @failed_url@

Error: @error@

diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index cdc7e03a4af..3126963aa51 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -98,6 +98,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode)); + Web::FrameLoader::set_resource_directory_url(DeprecatedString::formatted("file://{}/res", s_serenity_resource_root)); Web::FrameLoader::set_error_page_url(DeprecatedString::formatted("file://{}/res/html/error.html", s_serenity_resource_root)); TRY(Web::Bindings::initialize_main_thread_vm()); diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index 9c5a1de94c7..8fc575d0904 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -169,8 +169,25 @@ void FrameLoader::load_html(StringView html, const AK::URL& url) parser->run(url); } +static DeprecatedString s_resource_directory_url = "file:///res"; + +DeprecatedString FrameLoader::resource_directory_url() +{ + return s_resource_directory_url; +} + +void FrameLoader::set_resource_directory_url(DeprecatedString resource_directory_url) +{ + s_resource_directory_url = resource_directory_url; +} + static DeprecatedString s_error_page_url = "file:///res/html/error.html"; +DeprecatedString FrameLoader::error_page_url() +{ + return s_error_page_url; +} + void FrameLoader::set_error_page_url(DeprecatedString error_page_url) { s_error_page_url = error_page_url; @@ -189,6 +206,7 @@ void FrameLoader::load_error_page(const AK::URL& failed_url, DeprecatedString co VERIFY(!data.is_null()); StringBuilder builder; SourceGenerator generator { builder }; + generator.set("resource_directory_url", resource_directory_url()); generator.set("failed_url", escape_html_entities(failed_url.to_deprecated_string())); generator.set("error", escape_html_entities(error)); generator.append(data); diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.h b/Userland/Libraries/LibWeb/Loader/FrameLoader.h index e9fd5759057..e941566ded7 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.h +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.h @@ -25,6 +25,9 @@ public: }; static void set_default_favicon_path(DeprecatedString); + static DeprecatedString resource_directory_url(); + static void set_resource_directory_url(DeprecatedString); + static DeprecatedString error_page_url(); static void set_error_page_url(DeprecatedString); explicit FrameLoader(HTML::BrowsingContext&);