mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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.
This commit is contained in:
parent
af01cf70eb
commit
e4c3a52cfa
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/e4c3a52cfa Pull-request: https://github.com/SerenityOS/serenity/pull/20447 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/gmta
4 changed files with 26 additions and 1 deletions
|
@ -9,11 +9,14 @@
|
|||
header {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
img {
|
||||
margin-right: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<img src="../icons/32x32/msgbox-warning.png" alt="Warning" width="24" height="24">
|
||||
<img src="@resource_directory_url@/icons/32x32/msgbox-warning.png" alt="Warning" width="24" height="24">
|
||||
<h1>Failed to load @failed_url@</h1>
|
||||
</header>
|
||||
<p>Error: @error@</p>
|
||||
|
|
|
@ -98,6 +98,7 @@ ErrorOr<int> 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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&);
|
||||
|
|
Loading…
Reference in a new issue