Skip to content

Commit

Permalink
Ladybird+BrowserSettings: Load the NTP/home resource files with LibWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
trflynn89 authored and awesomekling committed Dec 24, 2023
1 parent 947136c commit bacf3ce
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Base/res/ladybird/new-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<body>
<main>
<br>
<img src="../icons/32x32/app-browser.png" width="64" height="64"><br><br>
<img src="resource://icons/32x32/app-browser.png" width="64" height="64"><br><br>
<form>
<input type="search" name="q" id="user_query"><br><br>
<div id="search-buttons">
Expand Down
2 changes: 1 addition & 1 deletion Ladybird/AppKit/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<URL> initial_urls;

for (auto const& raw_url : raw_urls) {
Expand Down
2 changes: 1 addition & 1 deletion Ladybird/Qt/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/Browser/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/Browser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 2 additions & 24 deletions Userland/Applications/BrowserSettings/Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,16 @@

#pragma once

#include <AK/String.h>
#include <AK/StringView.h>
#include <LibCore/Resource.h>

namespace Browser {

static constexpr StringView default_homepage_url = "resource:https://html/misc/welcome.html"sv;
static constexpr StringView default_new_tab_url = "resource:https://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:https:// URLs, rather than converting to a file:https:// URL here.
static auto default_homepage_url = []() {
static constexpr auto url = "resource:https://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:https:// URLs, rather than converting to a file:https:// URL here.
static auto default_new_tab_url = []() {
static constexpr auto url = "resource:https://ladybird/new-tab.html"sv;
return MUST(Core::Resource::load_from_uri(url))->file_url();
}();

return default_new_tab_url;
}

}

0 comments on commit bacf3ce

Please sign in to comment.