From cde14901bc64b780c3061975ffdd08ce4f3f92ee Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Fri, 12 Jan 2024 19:41:26 +0100 Subject: [PATCH] Ladybird+LibWeb: Add initial about:version internal page --- Base/res/ladybird/about.html | 1 + Base/res/ladybird/templates/version.html | 53 +++++++++++++++++++ .../AppKit/Application/ApplicationDelegate.mm | 14 ++++- Ladybird/Qt/BrowserWindow.cpp | 8 +++ .../LibWeb/Loader/GeneratedPagesLoader.cpp | 17 ++++++ .../LibWeb/Loader/GeneratedPagesLoader.h | 2 + .../LibWeb/Loader/ResourceLoader.cpp | 6 +++ 7 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 Base/res/ladybird/templates/version.html diff --git a/Base/res/ladybird/about.html b/Base/res/ladybird/about.html index ec6143133c7..e01e3e29bac 100644 --- a/Base/res/ladybird/about.html +++ b/Base/res/ladybird/about.html @@ -9,6 +9,7 @@ diff --git a/Base/res/ladybird/templates/version.html b/Base/res/ladybird/templates/version.html new file mode 100644 index 00000000000..219f1024713 --- /dev/null +++ b/Base/res/ladybird/templates/version.html @@ -0,0 +1,53 @@ + + + + + About @browser_name@ + + + +
+ +

About @browser_name@

+
+ + + + + + + + + + + + + + + + + + +
Version:@browser_version@
Arch:@arch_name@
Operating System:@os_name@
User Agent:@user_agent@
+ + diff --git a/Ladybird/AppKit/Application/ApplicationDelegate.mm b/Ladybird/AppKit/Application/ApplicationDelegate.mm index aeec1252acc..cda221d7485 100644 --- a/Ladybird/AppKit/Application/ApplicationDelegate.mm +++ b/Ladybird/AppKit/Application/ApplicationDelegate.mm @@ -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]]; diff --git a/Ladybird/Qt/BrowserWindow.cpp b/Ladybird/Qt/BrowserWindow.cpp index 804d380db71..73fceae2ba2 100644 --- a/Ladybird/Qt/BrowserWindow.cpp +++ b/Ladybird/Qt/BrowserWindow.cpp @@ -74,6 +74,11 @@ BrowserWindow::BrowserWindow(Vector 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 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); }); diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp index 5eb4f8735ce..46da0a8f3bf 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace Web { @@ -68,4 +69,20 @@ ErrorOr load_file_directory_page(AK::URL const& url) return TRY(String::from_utf8(generator.as_string_view())); } +ErrorOr 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())); +} + } diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h index 631d9fb73c7..0e7153f319a 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h @@ -15,4 +15,6 @@ ErrorOr load_error_page(AK::URL const&); ErrorOr load_file_directory_page(AK::URL const&); +ErrorOr load_about_version_page(); + } diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index 8290295ff5d..518ab5ffea9 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -230,6 +230,12 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback HashMap 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()) {