BrowserSettings+Ladybird: Convert home / new tab page to resource URIs

This commit is contained in:
Timothy Flynn 2023-11-05 09:35:20 -05:00 committed by Andreas Kling
parent 1b30b510b9
commit 818471b7a7
Notes: sideshowbarker 2024-07-17 22:01:16 +09:00
6 changed files with 33 additions and 45 deletions

View file

@ -24,22 +24,6 @@
# error "This project requires ARC"
#endif
static URL rebase_url_on_serenity_resource_root(StringView url_string)
{
URL url { url_string };
Vector<DeprecatedString> paths;
for (auto segment : s_serenity_resource_root.split('/'))
paths.append(move(segment));
for (size_t i = 0; i < url.path_segment_count(); ++i)
paths.append(url.path_segment_at_index(i));
url.set_paths(move(paths));
return url;
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
[Application sharedApplication];
@ -66,7 +50,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto database = TRY(WebView::Database::create(move(sql_server_paths)));
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
auto new_tab_page_url = rebase_url_on_serenity_resource_root(Browser::default_new_tab_url);
URL new_tab_page_url = Browser::default_new_tab_url();
Vector<URL> initial_urls;
for (auto const& raw_url : raw_urls) {

View file

@ -7,28 +7,10 @@
#include "Settings.h"
#include "StringUtils.h"
#include <AK/URL.h>
#include <BrowserSettings/Defaults.h>
#include <Ladybird/Utilities.h>
namespace Ladybird {
static QString rebase_default_url_on_serenity_resource_root(StringView default_url)
{
URL url { default_url };
Vector<DeprecatedString> paths;
for (auto segment : s_serenity_resource_root.split('/'))
paths.append(move(segment));
for (size_t i = 0; i < url.path_segment_count(); ++i)
paths.append(url.path_segment_at_index(i));
url.set_paths(move(paths));
return qstring_from_ak_deprecated_string(url.to_deprecated_string());
}
Settings::Settings()
: m_search_engine(WebView::default_search_engine())
{
@ -100,7 +82,7 @@ void Settings::set_autocomplete_engine(EngineProvider const& engine_provider)
QString Settings::new_tab_page()
{
static auto const default_new_tab_url = rebase_default_url_on_serenity_resource_root(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();
}

View file

@ -284,7 +284,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_deprecated_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_deprecated_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);

View file

@ -133,8 +133,8 @@ ErrorOr<int> 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);

View file

@ -107,11 +107,11 @@ ErrorOr<NonnullRefPtr<BrowserSettingsWidget>> BrowserSettingsWidget::create()
ErrorOr<void> BrowserSettingsWidget::setup()
{
m_homepage_url_textbox = find_descendant_of_type_named<GUI::TextBox>("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<GUI::TextBox>("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<GUI::ComboBox>("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);

View file

@ -6,16 +6,38 @@
#pragma once
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibCore/Resource.h>
namespace Browser {
static constexpr StringView default_homepage_url = "file:///res/html/misc/welcome.html"sv;
static constexpr StringView default_new_tab_url = "file:///res/html/misc/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://html/misc/new-tab.html"sv;
return MUST(Core::Resource::load_from_uri(url))->file_url();
}();
return default_new_tab_url;
}
}