From bacf3cede43d85fc238217100f3104fa933f9bb5 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 23 Dec 2023 15:47:58 -0500 Subject: [PATCH] Ladybird+BrowserSettings: Load the NTP/home resource files with LibWeb --- Base/res/ladybird/new-tab.html | 2 +- Ladybird/AppKit/main.mm | 2 +- Ladybird/Qt/Settings.cpp | 2 +- .../Applications/Browser/BrowserWindow.cpp | 2 +- Userland/Applications/Browser/main.cpp | 4 +-- .../BrowserSettings/BrowserSettingsWidget.cpp | 8 +++--- .../Applications/BrowserSettings/Defaults.h | 26 ++----------------- 7 files changed, 12 insertions(+), 34 deletions(-) diff --git a/Base/res/ladybird/new-tab.html b/Base/res/ladybird/new-tab.html index d18313c6c97dc8..4bbc2069e5c7a2 100644 --- a/Base/res/ladybird/new-tab.html +++ b/Base/res/ladybird/new-tab.html @@ -40,7 +40,7 @@

-

+



diff --git a/Ladybird/AppKit/main.mm b/Ladybird/AppKit/main.mm index 4bf24a84b8a440..984e17bbff847d 100644 --- a/Ladybird/AppKit/main.mm +++ b/Ladybird/AppKit/main.mm @@ -57,7 +57,7 @@ auto database = TRY(WebView::Database::create(move(sql_server_paths))); auto cookie_jar = TRY(WebView::CookieJar::create(*database)); - URL new_tab_page_url = Browser::default_new_tab_url(); + URL new_tab_page_url = Browser::default_new_tab_url; Vector initial_urls; for (auto const& raw_url : raw_urls) { diff --git a/Ladybird/Qt/Settings.cpp b/Ladybird/Qt/Settings.cpp index 704a1c472ede9f..6f2339f2f4a963 100644 --- a/Ladybird/Qt/Settings.cpp +++ b/Ladybird/Qt/Settings.cpp @@ -82,7 +82,7 @@ void Settings::set_autocomplete_engine(EngineProvider const& engine_provider) QString Settings::new_tab_page() { - static auto const default_new_tab_url = qstring_from_ak_string(Browser::default_new_tab_url()); + static auto const default_new_tab_url = qstring_from_ak_string(Browser::default_new_tab_url); return m_qsettings->value("new_tab_page", default_new_tab_url).toString(); } diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 3a16d7159c35e6..8f047d1c3654fd 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -275,7 +275,7 @@ void BrowserWindow::build_menus() m_change_homepage_action = GUI::Action::create( "Set Homepage URL...", g_icon_bag.go_home, [this](auto&) { - String homepage_url = String::from_byte_string(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url())).release_value_but_fixme_should_propagate_errors(); + String homepage_url = String::from_byte_string(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url)).release_value_but_fixme_should_propagate_errors(); if (GUI::InputBox::show(this, homepage_url, "Enter a URL:"sv, "Change Homepage"sv) == GUI::InputBox::ExecResult::OK) { if (URL(homepage_url).is_valid()) { Config::write_string("Browser"sv, "Preferences"sv, "Home"sv, homepage_url); diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 74310675893dae..d3a2c3ed4b2992 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -133,8 +133,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app_icon = GUI::Icon::default_icon("app-browser"sv); - Browser::g_home_url = Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url()); - Browser::g_new_tab_url = Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url()); + Browser::g_home_url = Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url); + Browser::g_new_tab_url = Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url); Browser::g_search_engine = Config::read_string("Browser"sv, "Preferences"sv, "SearchEngine"sv, WebView::default_search_engine().query_url); Browser::g_content_filters_enabled = Config::read_bool("Browser"sv, "Preferences"sv, "EnableContentFilters"sv, Browser::default_enable_content_filters); Browser::g_autoplay_allowed_on_all_websites = Config::read_bool("Browser"sv, "Preferences"sv, "AllowAutoplayOnAllWebsites"sv, Browser::default_allow_autoplay_on_all_websites); diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp index abba6c51a00bf0..a2619f7148f15a 100644 --- a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp +++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp @@ -107,11 +107,11 @@ ErrorOr> BrowserSettingsWidget::create() ErrorOr BrowserSettingsWidget::setup() { m_homepage_url_textbox = find_descendant_of_type_named("homepage_url_textbox"); - m_homepage_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url()), GUI::AllowCallback::No); + m_homepage_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "Home"sv, Browser::default_homepage_url), GUI::AllowCallback::No); m_homepage_url_textbox->on_change = [&]() { set_modified(true); }; m_new_tab_url_textbox = find_descendant_of_type_named("new_tab_url_textbox"); - m_new_tab_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url()), GUI::AllowCallback::No); + m_new_tab_url_textbox->set_text(Config::read_string("Browser"sv, "Preferences"sv, "NewTab"sv, Browser::default_new_tab_url), GUI::AllowCallback::No); m_new_tab_url_textbox->on_change = [&]() { set_modified(true); }; m_color_scheme_combobox = find_descendant_of_type_named("color_scheme_combobox"); @@ -244,8 +244,8 @@ void BrowserSettingsWidget::apply_settings() void BrowserSettingsWidget::reset_default_values() { - m_homepage_url_textbox->set_text(Browser::default_homepage_url()); - m_new_tab_url_textbox->set_text(Browser::default_new_tab_url()); + m_homepage_url_textbox->set_text(Browser::default_homepage_url); + m_new_tab_url_textbox->set_text(Browser::default_new_tab_url); m_show_bookmarks_bar_checkbox->set_checked(Browser::default_show_bookmarks_bar); set_color_scheme(Browser::default_color_scheme); m_auto_close_download_windows_checkbox->set_checked(Browser::default_close_download_widget_on_finish); diff --git a/Userland/Applications/BrowserSettings/Defaults.h b/Userland/Applications/BrowserSettings/Defaults.h index f9347d08d165e2..28d9fd34e42275 100644 --- a/Userland/Applications/BrowserSettings/Defaults.h +++ b/Userland/Applications/BrowserSettings/Defaults.h @@ -6,38 +6,16 @@ #pragma once -#include #include -#include namespace Browser { +static constexpr StringView default_homepage_url = "resource://html/misc/welcome.html"sv; +static constexpr StringView default_new_tab_url = "resource://ladybird/new-tab.html"sv; static constexpr StringView default_color_scheme = "auto"sv; static constexpr bool default_enable_content_filters = true; static constexpr bool default_show_bookmarks_bar = true; static constexpr bool default_close_download_widget_on_finish = false; static constexpr bool default_allow_autoplay_on_all_websites = false; -inline String const& default_homepage_url() -{ - // FIXME: Teach LibWeb how to load resource:// URLs, rather than converting to a file:// URL here. - static auto default_homepage_url = []() { - static constexpr auto url = "resource://html/misc/welcome.html"sv; - return MUST(Core::Resource::load_from_uri(url))->file_url(); - }(); - - return default_homepage_url; -} - -inline String const& default_new_tab_url() -{ - // FIXME: Teach LibWeb how to load resource:// URLs, rather than converting to a file:// URL here. - static auto default_new_tab_url = []() { - static constexpr auto url = "resource://ladybird/new-tab.html"sv; - return MUST(Core::Resource::load_from_uri(url))->file_url(); - }(); - - return default_new_tab_url; -} - }