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

@ -9,6 +9,7 @@
<ul>
<li><a href="about:about">about:about</a></li>
<li><a href="about:newtab">about:newtab</a></li>
<li><a href="about:version">about:version</a></li>
</ul>
</body>
</html>

View file

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>About @browser_name@</title>
<style>
img {
float: left;
image-rendering: pixelated;
margin-right: 10px;
}
th {
text-align: right;
}
td {
font-family: monospace;
}
</style>
</head>
<body>
<header>
<img src="resource://icons/32x32/app-browser.png">
<h1>About @browser_name@</h1>
</header>
<table>
<tr>
<th>Version:</th>
<td>@browser_version@ <!-- FIXME: Add build commit hash --></td>
</tr>
<tr>
<th>Arch:</th>
<td>@arch_name@</td>
</tr>
<tr>
<th>Operating System:</th>
<td>@os_name@</td>
</tr>
<tr>
<th>User Agent:</th>
<td>@user_agent@</td>
</tr>
<!-- FIXME: Add these fields
<tr>
<th>Command Line:</th>
<td></td>
</tr>
<tr>
<th>Executable Path:</th>
<td></td>
</tr> -->
</table>
</body>
</html>

View file

@ -148,6 +148,18 @@
#pragma mark - Private methods
- (void)openAboutVersionPage:(id)sender
{
auto* current_tab = [NSApp keyWindow];
if (![current_tab isKindOfClass:[Tab class]]) {
return;
}
[self createNewTab:URL("about:version"sv)
fromTab:(Tab*)current_tab
activateTab:Web::HTML::ActivateTab::Yes];
}
- (nonnull TabController*)createNewTab:(Web::HTML::ActivateTab)activate_tab
fromTab:(nullable Tab*)tab
{
@ -242,7 +254,7 @@
auto* submenu = [[NSMenu alloc] initWithTitle:process_name];
[submenu addItem:[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"About %@", process_name]
action:@selector(orderFrontStandardAboutPanel:)
action:@selector(openAboutVersionPage:)
keyEquivalent:@""]];
[submenu addItem:[NSMenuItem separatorItem]];

View file

@ -74,6 +74,11 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
auto* menu = menuBar()->addMenu("&File");
auto* about_action = new QAction("&About Ladybird", this);
menu->addAction(about_action);
menu->addSeparator();
auto* new_tab_action = new QAction("New &Tab", this);
new_tab_action->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv));
new_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::AddTab));
@ -375,6 +380,9 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
debug_request("same-origin-policy", state ? "on" : "off");
});
QObject::connect(about_action, &QAction::triggered, this, [this] {
new_tab("about:version", Web::HTML::ActivateTab::Yes);
});
QObject::connect(new_tab_action, &QAction::triggered, this, [this] {
new_tab(Settings::the()->new_tab_page(), Web::HTML::ActivateTab::Yes);
});

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()) {