mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:32:46 +00:00 
			
		
		
		
	Ladybird+LibWeb: Add initial about:version internal page
This commit is contained in:
		
							parent
							
								
									05c0640474
								
							
						
					
					
						commit
						cde14901bc
					
				
					 7 changed files with 100 additions and 1 deletions
				
			
		|  | @ -9,6 +9,7 @@ | ||||||
|     <ul> |     <ul> | ||||||
|         <li><a href="about:about">about:about</a></li> |         <li><a href="about:about">about:about</a></li> | ||||||
|         <li><a href="about:newtab">about:newtab</a></li> |         <li><a href="about:newtab">about:newtab</a></li> | ||||||
|  |         <li><a href="about:version">about:version</a></li> | ||||||
|     </ul> |     </ul> | ||||||
| </body> | </body> | ||||||
| </html> | </html> | ||||||
|  |  | ||||||
							
								
								
									
										53
									
								
								Base/res/ladybird/templates/version.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Base/res/ladybird/templates/version.html
									
										
									
									
									
										Normal 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> | ||||||
|  | @ -148,6 +148,18 @@ | ||||||
| 
 | 
 | ||||||
| #pragma mark - Private methods | #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 | - (nonnull TabController*)createNewTab:(Web::HTML::ActivateTab)activate_tab | ||||||
|                                fromTab:(nullable Tab*)tab |                                fromTab:(nullable Tab*)tab | ||||||
| { | { | ||||||
|  | @ -242,7 +254,7 @@ | ||||||
|     auto* submenu = [[NSMenu alloc] initWithTitle:process_name]; |     auto* submenu = [[NSMenu alloc] initWithTitle:process_name]; | ||||||
| 
 | 
 | ||||||
|     [submenu addItem:[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"About %@", process_name] |     [submenu addItem:[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"About %@", process_name] | ||||||
|                                                 action:@selector(orderFrontStandardAboutPanel:) |                                                 action:@selector(openAboutVersionPage:) | ||||||
|                                          keyEquivalent:@""]]; |                                          keyEquivalent:@""]]; | ||||||
|     [submenu addItem:[NSMenuItem separatorItem]]; |     [submenu addItem:[NSMenuItem separatorItem]]; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -74,6 +74,11 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar | ||||||
| 
 | 
 | ||||||
|     auto* menu = menuBar()->addMenu("&File"); |     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); |     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->setIcon(load_icon_from_uri("resource://icons/16x16/new-tab.png"sv)); | ||||||
|     new_tab_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::AddTab)); |     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"); |         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] { |     QObject::connect(new_tab_action, &QAction::triggered, this, [this] { | ||||||
|         new_tab(Settings::the()->new_tab_page(), Web::HTML::ActivateTab::Yes); |         new_tab(Settings::the()->new_tab_page(), Web::HTML::ActivateTab::Yes); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  | @ -12,6 +12,7 @@ | ||||||
| #include <LibCore/Resource.h> | #include <LibCore/Resource.h> | ||||||
| #include <LibCore/System.h> | #include <LibCore/System.h> | ||||||
| #include <LibWeb/Loader/GeneratedPagesLoader.h> | #include <LibWeb/Loader/GeneratedPagesLoader.h> | ||||||
|  | #include <LibWeb/Loader/ResourceLoader.h> | ||||||
| 
 | 
 | ||||||
| namespace Web { | 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())); |     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())); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -15,4 +15,6 @@ ErrorOr<String> load_error_page(AK::URL const&); | ||||||
| 
 | 
 | ||||||
| ErrorOr<String> load_file_directory_page(AK::URL const&); | ErrorOr<String> load_file_directory_page(AK::URL const&); | ||||||
| 
 | 
 | ||||||
|  | ErrorOr<String> load_about_version_page(); | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -230,6 +230,12 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback | ||||||
|         HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> response_headers; |         HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> response_headers; | ||||||
|         response_headers.set("Content-Type", "text/html; charset=UTF-8"); |         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
 |         // Other about static HTML pages
 | ||||||
|         auto resource = Core::Resource::load_from_uri(MUST(String::formatted("resource://ladybird/{}.html", url.path_segment_at_index(0)))); |         auto resource = Core::Resource::load_from_uri(MUST(String::formatted("resource://ladybird/{}.html", url.path_segment_at_index(0)))); | ||||||
|         if (!resource.is_error()) { |         if (!resource.is_error()) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Bastiaan van der Plaat
						Bastiaan van der Plaat