1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:17:44 +00:00

Ladybird+LibWeb: Add initial about:version internal page

This commit is contained in:
Bastiaan van der Plaat 2024-01-12 19:41:26 +01:00 committed by Tim Flynn
parent 05c0640474
commit cde14901bc
7 changed files with 100 additions and 1 deletions

View file

@ -12,6 +12,7 @@
#include <LibCore/Resource.h>
#include <LibCore/System.h>
#include <LibWeb/Loader/GeneratedPagesLoader.h>
#include <LibWeb/Loader/ResourceLoader.h>
namespace Web {
@ -68,4 +69,20 @@ ErrorOr<String> load_file_directory_page(AK::URL const& url)
return TRY(String::from_utf8(generator.as_string_view()));
}
ErrorOr<String> load_about_version_page()
{
// Generate HTML about version page from 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_file = TRY(Core::Resource::load_from_uri("resource://ladybird/templates/version.html"sv));
StringBuilder builder;
SourceGenerator generator { builder };
generator.set("browser_name", BROWSER_NAME);
generator.set("browser_version", BROWSER_VERSION);
generator.set("arch_name", CPU_STRING);
generator.set("os_name", OS_STRING);
generator.set("user_agent", default_user_agent);
generator.append(template_file->data());
return TRY(String::from_utf8(generator.as_string_view()));
}
}

View file

@ -15,4 +15,6 @@ ErrorOr<String> load_error_page(AK::URL const&);
ErrorOr<String> load_file_directory_page(AK::URL const&);
ErrorOr<String> load_about_version_page();
}

View file

@ -230,6 +230,12 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> response_headers;
response_headers.set("Content-Type", "text/html; charset=UTF-8");
// About version page
if (url.path_segment_at_index(0) == "version") {
success_callback(MUST(load_about_version_page()).bytes(), response_headers, {});
return;
}
// Other about static HTML pages
auto resource = Core::Resource::load_from_uri(MUST(String::formatted("resource://ladybird/{}.html", url.path_segment_at_index(0))));
if (!resource.is_error()) {