Skip to content

Truly independent web browser

Hub+LibWebView+UI/Qt: Give the UI settings of its own

Andreas Kling7aeea3f0916b
diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp
index 41e601efbca..96ed303a1a6 100644
--- a/Libraries/LibWebView/Settings.cpp
+++ b/Libraries/LibWebView/Settings.cpp
@@ -373,63 +373,44 @@ static bool config_variable_value_is_valid(ConfigVariableDefinition const& varia
return true;
}
-Settings Settings::create(ByteString settings_path, Vector<String> platform_languages)
+void Settings::load_from_json(JsonValue const& json_value)
{
- Settings settings { move(settings_path) };
+ auto const& json = json_value.as_object();
+ m_first_run_complete = json.get_bool(FIRST_RUN_COMPLETE_KEY).value_or(false);
- // The user's first platform language, then that language alone (en-US, then en): the list a browser starts with.
- platform_languages.remove_all_matching([](auto const& language) { return !Unicode::is_locale_available(language); });
- if (!platform_languages.is_empty()) {
- Vector<String> languages { platform_languages.first() };
- if (auto separator = languages.first().find_byte_offset('-'); separator.has_value()) {
- auto language = MUST(languages.first().substring_from_byte_offset(0, *separator));
- if (Unicode::is_locale_available(language))
- languages.append(move(language));
- }
- settings.m_languages = move(languages);
- }
+ if (auto window_settings = json.get(WINDOW_SETTINGS_KEY); window_settings.has_value())
+ m_window_settings = parse_window_settings(*window_settings);
- auto settings_json = read_json_file(settings.m_settings_path);
- if (settings_json.is_error()) {
- warnln("Unable to read Ladybird settings: {}", settings_json.error());
- return settings;
- }
-
- settings.m_first_run_complete = settings_json.value().get_bool(FIRST_RUN_COMPLETE_KEY).value_or(false);
-
- if (auto window_settings = settings_json.value().get(WINDOW_SETTINGS_KEY); window_settings.has_value())
- settings.m_window_settings = parse_window_settings(*window_settings);
-
- if (auto new_tab_page_url = settings_json.value().get_string(NEW_TAB_PAGE_URL_KEY); new_tab_page_url.has_value()) {
+ if (auto new_tab_page_url = json.get_string(NEW_TAB_PAGE_URL_KEY); new_tab_page_url.has_value()) {
if (auto parsed_new_tab_page_url = URL::Parser::basic_parse(*new_tab_page_url); parsed_new_tab_page_url.has_value())
- settings.m_new_tab_page_url = parsed_new_tab_page_url.release_value();
+ m_new_tab_page_url = parsed_new_tab_page_url.release_value();
}
- settings.m_restore_previous_session = settings_json.value().get_bool(RESTORE_PREVIOUS_SESSION_KEY).value_or(false);
+ m_restore_previous_session = json.get_bool(RESTORE_PREVIOUS_SESSION_KEY).value_or(false);
- if (auto languages = settings_json.value().get(LANGUAGES_KEY); languages.has_value())
- settings.m_languages = parse_json_languages(*languages);
+ if (auto languages = json.get(LANGUAGES_KEY); languages.has_value())
+ m_languages = parse_json_languages(*languages);
- if (auto appearance = settings_json.value().get(APPEARANCE_KEY); appearance.has_value())
- settings.m_appearance = parse_appearance(*appearance);
+ if (auto appearance = json.get(APPEARANCE_KEY); appearance.has_value())
+ m_appearance = parse_appearance(*appearance);
- if (auto content_settings = settings_json.value().get(CONTENT_SETTINGS_KEY); content_settings.has_value())
- settings.m_content_settings = parse_content_settings(*content_settings);
+ if (auto content_settings = json.get(CONTENT_SETTINGS_KEY); content_settings.has_value())
+ m_content_settings = parse_content_settings(*content_settings);
- if (auto tab_settings = settings_json.value().get(TAB_SETTINGS_KEY); tab_settings.has_value())
- settings.m_tab_settings = parse_tab_settings(*tab_settings);
+ if (auto tab_settings = json.get(TAB_SETTINGS_KEY); tab_settings.has_value())
+ m_tab_settings = parse_tab_settings(*tab_settings);
- if (auto browsing_behavior = settings_json.value().get(BROWSING_BEHAVIOR_KEY); browsing_behavior.has_value())
- settings.m_browsing_behavior = parse_browsing_behavior(*browsing_behavior);
+ if (auto browsing_behavior = json.get(BROWSING_BEHAVIOR_KEY); browsing_behavior.has_value())
+ m_browsing_behavior = parse_browsing_behavior(*browsing_behavior);
- if (auto search_engine = settings_json.value().get_object(SEARCH_ENGINE_KEY); search_engine.has_value()) {
+ if (auto search_engine = json.get_object(SEARCH_ENGINE_KEY); search_engine.has_value()) {
if (auto custom_engines = search_engine->get_array(SEARCH_ENGINE_CUSTOM_KEY); custom_engines.has_value()) {
custom_engines->for_each([&](JsonValue const& engine) {
auto custom_engine = parse_custom_search_engine(engine);
- if (!custom_engine.has_value() || settings.find_search_engine_by_name(custom_engine->name).has_value())
+ if (!custom_engine.has_value() || find_search_engine_by_name(custom_engine->name).has_value())
return;
- settings.m_custom_search_engines.append(custom_engine.release_value());
+ m_custom_search_engines.append(custom_engine.release_value());
});
}
@@ -438,24 +419,24 @@ Settings Settings::create(ByteString settings_path, Vector<String> platform_lang
? search_engine->get_string(SEARCH_ENGINE_SELECTION_KEY)
: search_engine->get_string(SEARCH_ENGINE_NAME_KEY);
if (search_engine_name.has_value())
- settings.m_search_engine_settings.engine = settings.find_search_engine_by_name(*search_engine_name);
+ m_search_engine_settings.engine = find_search_engine_by_name(*search_engine_name);
if (auto enabled = search_engine->get(SEARCH_SUGGESTIONS_ENABLED_KEY); enabled.has_value()) {
- settings.m_search_engine_settings.suggestions = enabled->is_bool() && enabled->as_bool();
- } else if (settings.m_search_engine_settings.engine.has_value() && settings.m_search_engine_settings.engine->suggestions.has_value()) {
+ m_search_engine_settings.suggestions = enabled->is_bool() && enabled->as_bool();
+ } else if (m_search_engine_settings.engine.has_value() && m_search_engine_settings.engine->suggestions.has_value()) {
// NB: Only migrate suggestions when the old provider matches the selected search engine, so typed text
// does not start going to a different provider without the user's consent.
- if (auto legacy_engine = settings_json.value().get_object("autocompleteEngine"sv); legacy_engine.has_value()) {
+ if (auto legacy_engine = json.get_object("autocompleteEngine"sv); legacy_engine.has_value()) {
auto legacy_name = legacy_engine->get_string("name"sv);
- settings.m_search_engine_settings.suggestions = legacy_name.has_value()
+ m_search_engine_settings.suggestions = legacy_name.has_value()
&& legacy_name->is_one_of("DuckDuckGo"sv, "Google"sv, "Kagi"sv, "Yahoo"sv)
- && *legacy_name == settings.m_search_engine_settings.engine->name;
+ && *legacy_name == m_search_engine_settings.engine->name;
}
}
}
auto load_site_setting = [&](AutoplaySiteSetting& site_setting, StringView key) {
- auto saved_settings = settings_json.value().get_object(key);
+ auto saved_settings = json.get_object(key);
if (!saved_settings.has_value())
return;
@@ -475,51 +456,51 @@ Settings Settings::create(ByteString settings_path, Vector<String> platform_lang
}
};
- load_site_setting(settings.m_autoplay, AUTOPLAY_KEY);
+ load_site_setting(m_autoplay, AUTOPLAY_KEY);
// NB: The geolocationEnabled key this replaced was written on every save, so its false was rarely the user's
// choice; it's ignored, and every profile starts out letting sites ask.
- if (auto location_policy = settings_json.value().get_string(LOCATION_POLICY_KEY); location_policy.has_value() && *location_policy == "block"sv)
- settings.m_location_policy = LocationPolicy::Block;
- if (auto microphone_policy = settings_json.value().get_string(MICROPHONE_POLICY_KEY); microphone_policy.has_value() && *microphone_policy == "block"sv)
- settings.m_microphone_policy = MicrophonePolicy::Block;
- if (auto notifications_policy = settings_json.value().get_string(NOTIFICATIONS_POLICY_KEY); notifications_policy.has_value() && *notifications_policy == "block"sv)
- settings.m_notifications_policy = NotificationsPolicy::Block;
+ if (auto location_policy = json.get_string(LOCATION_POLICY_KEY); location_policy.has_value() && *location_policy == "block"sv)
+ m_location_policy = LocationPolicy::Block;
+ if (auto microphone_policy = json.get_string(MICROPHONE_POLICY_KEY); microphone_policy.has_value() && *microphone_policy == "block"sv)
+ m_microphone_policy = MicrophonePolicy::Block;
+ if (auto notifications_policy = json.get_string(NOTIFICATIONS_POLICY_KEY); notifications_policy.has_value() && *notifications_policy == "block"sv)
+ m_notifications_policy = NotificationsPolicy::Block;
- if (auto browsing_data_settings = settings_json.value().get(BROWSING_DATA_KEY); browsing_data_settings.has_value())
- settings.m_browsing_data_settings = parse_browsing_data_settings(*browsing_data_settings);
+ if (auto browsing_data_settings = json.get(BROWSING_DATA_KEY); browsing_data_settings.has_value())
+ m_browsing_data_settings = parse_browsing_data_settings(*browsing_data_settings);
- if (auto global_privacy_control = settings_json.value().get_bool(GLOBAL_PRIVACY_CONTROL_KEY); global_privacy_control.has_value())
- settings.m_global_privacy_control = *global_privacy_control ? GlobalPrivacyControl::Yes : GlobalPrivacyControl::No;
+ if (auto global_privacy_control = json.get_bool(GLOBAL_PRIVACY_CONTROL_KEY); global_privacy_control.has_value())
+ m_global_privacy_control = *global_privacy_control ? GlobalPrivacyControl::Yes : GlobalPrivacyControl::No;
- if (auto crash_report_sending = settings_json.value().get_string(CRASH_REPORT_SENDING_KEY); crash_report_sending.has_value())
- settings.m_crash_report_sending = crash_report_sending_from_string(*crash_report_sending);
+ if (auto crash_report_sending = json.get_string(CRASH_REPORT_SENDING_KEY); crash_report_sending.has_value())
+ m_crash_report_sending = crash_report_sending_from_string(*crash_report_sending);
- if (auto background_networking = settings_json.value().get_object(BACKGROUND_NETWORKING_KEY); background_networking.has_value()) {
+ if (auto background_networking = json.get_object(BACKGROUND_NETWORKING_KEY); background_networking.has_value()) {
if (auto enabled = background_networking->get_bool(BACKGROUND_NETWORKING_ENABLED_KEY); enabled.has_value())
- settings.m_background_networking_enabled = *enabled;
+ m_background_networking_enabled = *enabled;
if (auto features = background_networking->get_object(BACKGROUND_NETWORKING_FEATURES_KEY); features.has_value()) {
if (auto filter_list_updates_enabled = features->get_bool(CONTENT_BLOCKER_SUBSCRIPTION_UPDATES_KEY); filter_list_updates_enabled.has_value())
- settings.m_filter_list_updates_enabled = *filter_list_updates_enabled;
+ m_filter_list_updates_enabled = *filter_list_updates_enabled;
}
}
- if (auto content_blockers = settings_json.value().get_object(CONTENT_BLOCKERS_KEY); content_blockers.has_value()) {
+ if (auto content_blockers = json.get_object(CONTENT_BLOCKERS_KEY); content_blockers.has_value()) {
if (auto content_blocker_enabled = content_blockers->get_bool(CONTENT_BLOCKER_ENABLED_KEY); content_blocker_enabled.has_value())
- settings.m_content_blocker_enabled = *content_blocker_enabled;
+ m_content_blocker_enabled = *content_blocker_enabled;
if (auto sites = content_blockers->get_array(CONTENT_BLOCKER_DISABLED_SITES_KEY); sites.has_value()) {
sites->for_each([&](JsonValue const& entry) {
if (!entry.is_string())
return;
if (auto host = Web::canonical_content_blocking_host(entry.as_string()); host.has_value())
- settings.m_content_blocker_disabled_sites.set(host.release_value());
+ m_content_blocker_disabled_sites.set(host.release_value());
});
}
if (auto built_in_lists = content_blockers->get_object(CONTENT_BLOCKER_BUILT_IN_LISTS_KEY); built_in_lists.has_value()) {
- for (auto& list : settings.m_content_blocker_lists)
+ for (auto& list : m_content_blocker_lists)
list.enabled = built_in_lists->get_bool(list.identifier).value_or(list.enabled);
}
@@ -533,7 +514,7 @@ Settings Settings::create(ByteString settings_path, Vector<String> platform_lang
auto identifier = value.as_object().get_string(CONTENT_BLOCKER_IDENTIFIER_KEY);
auto enabled = value.as_object().get_bool(CONTENT_BLOCKER_ENABLED_KEY);
auto source = value.as_object().get_string(key == CONTENT_BLOCKER_CUSTOM_SUBSCRIPTIONS_KEY ? CONTENT_BLOCKER_URL_KEY : CONTENT_BLOCKER_NAME_KEY);
- if (!identifier.has_value() || !is_valid_content_blocker_list_identifier(*identifier) || !enabled.has_value() || !source.has_value() || settings.content_blocker_list(*identifier).has_value())
+ if (!identifier.has_value() || !is_valid_content_blocker_list_identifier(*identifier) || !enabled.has_value() || !source.has_value() || content_blocker_list(*identifier).has_value())
continue;
Optional<URL::URL> url;
if (key == CONTENT_BLOCKER_CUSTOM_SUBSCRIPTIONS_KEY) {
@@ -541,34 +522,161 @@ Settings Settings::create(ByteString settings_path, Vector<String> platform_lang
if (!url.has_value() || !(url->scheme() == "http"sv || url->scheme() == "https"sv))
continue;
}
- settings.m_content_blocker_lists.append({ *identifier, *source, move(url), *enabled });
+ m_content_blocker_lists.append({ *identifier, *source, move(url), *enabled });
}
}
if (auto filters = content_blockers->get_string(CONTENT_BLOCKER_CUSTOM_FILTERS_KEY); filters.has_value())
- settings.m_custom_content_blocker_filters = *filters;
+ m_custom_content_blocker_filters = *filters;
}
- if (auto dns_settings = settings_json.value().get(DNS_SETTINGS_KEY); dns_settings.has_value())
- settings.m_dns_settings = parse_dns_settings(*dns_settings);
+ if (auto dns_settings = json.get(DNS_SETTINGS_KEY); dns_settings.has_value())
+ m_dns_settings = parse_dns_settings(*dns_settings);
- if (auto config_variables = settings_json.value().get_object(CONFIG_VARIABLES_KEY); config_variables.has_value()) {
+ if (auto config_variables = json.get_object(CONFIG_VARIABLES_KEY); config_variables.has_value()) {
for (auto const& variable : config_variable_definitions()) {
if (auto value = config_variables->get(variable.name); value.has_value()) {
if (config_variable_value_is_valid(variable, *value))
- settings.m_config_variables[static_cast<size_t>(variable.id)] = *value;
+ m_config_variables[static_cast<size_t>(variable.id)] = *value;
}
}
}
+}
+
+Settings Settings::create_from_json(JsonValue const& json)
+{
+ Settings settings { {} };
+ settings.load_from_json(json);
+ return settings;
+}
+
+void Settings::replace_with_json(JsonValue const& json, PersistChange persist_change)
+{
+ auto previous_config_variables = m_config_variables;
+ auto previous_settings = serialize_json();
+
+ // NB: Loading only sets what the JSON has, so what it leaves out must go back to its default first.
+ reset_to_defaults();
+ load_from_json(json);
+ if (persist_change == PersistChange::Yes)
+ persist_settings();
+
+ // NB: Observers can do a lot of work, such as reloading the content blocker lists or reconfiguring DNS, so they only
+ // hear of what changed.
+ auto current_settings = serialize_json();
+ auto changed = [&](StringView key) {
+ auto previous = previous_settings.as_object().get(key);
+ auto current = current_settings.as_object().get(key);
+ if (previous.has_value() != current.has_value())
+ return true;
+ return previous.has_value() && !previous->equals(*current);
+ };
+ auto new_tab_page_url_changed = changed(NEW_TAB_PAGE_URL_KEY);
+ auto restore_previous_session_changed = changed(RESTORE_PREVIOUS_SESSION_KEY);
+ auto languages_changed = changed(LANGUAGES_KEY);
+ auto appearance_changed = changed(APPEARANCE_KEY);
+ auto content_settings_changed = changed(CONTENT_SETTINGS_KEY);
+ auto tab_settings_changed = changed(TAB_SETTINGS_KEY);
+ auto browsing_behavior_changed = changed(BROWSING_BEHAVIOR_KEY);
+ auto search_engine_settings_changed = changed(SEARCH_ENGINE_KEY);
+ auto autoplay_settings_changed = changed(AUTOPLAY_KEY);
+ auto browsing_data_settings_changed = changed(BROWSING_DATA_KEY);
+ auto global_privacy_control_changed = changed(GLOBAL_PRIVACY_CONTROL_KEY);
+ auto crash_report_sending_changed = changed(CRASH_REPORT_SENDING_KEY);
+ auto dns_settings_changed = changed(DNS_SETTINGS_KEY);
+ auto geolocation_settings_changed = changed(LOCATION_POLICY_KEY);
+ auto microphone_settings_changed = changed(MICROPHONE_POLICY_KEY);
+ auto notifications_settings_changed = changed(NOTIFICATIONS_POLICY_KEY);
+ auto background_networking_settings_changed = changed(BACKGROUND_NETWORKING_KEY);
+ auto content_blocker_settings_changed = changed(CONTENT_BLOCKERS_KEY);
+
+ for (auto& observer : m_observers) {
+ if (new_tab_page_url_changed)
+ observer.new_tab_page_url_changed();
+ if (restore_previous_session_changed)
+ observer.restore_previous_session_changed();
+ if (languages_changed)
+ observer.languages_changed();
+ if (appearance_changed)
+ observer.appearance_changed();
+ if (content_settings_changed)
+ observer.content_settings_changed();
+ if (tab_settings_changed)
+ observer.tab_settings_changed();
+ if (browsing_behavior_changed)
+ observer.browsing_behavior_changed();
+ if (search_engine_settings_changed)
+ observer.search_engine_settings_changed();
+ if (autoplay_settings_changed)
+ observer.autoplay_settings_changed();
+ if (browsing_data_settings_changed)
+ observer.browsing_data_settings_changed();
+ if (global_privacy_control_changed)
+ observer.global_privacy_control_changed();
+ if (crash_report_sending_changed)
+ observer.crash_report_sending_changed();
+ if (dns_settings_changed)
+ observer.dns_settings_changed();
+ if (geolocation_settings_changed)
+ observer.geolocation_settings_changed();
+ if (microphone_settings_changed)
+ observer.microphone_settings_changed();
+ if (notifications_settings_changed)
+ observer.notifications_settings_changed();
+ if (background_networking_settings_changed)
+ observer.background_networking_settings_changed();
+ if (content_blocker_settings_changed)
+ observer.content_blocker_settings_changed();
+ }
+
+ for (auto const& variable : config_variable_definitions()) {
+ auto index = static_cast<size_t>(variable.id);
+ if (m_config_variables[index].equals(previous_config_variables[index]))
+ continue;
+ for (auto& observer : m_observers)
+ observer.config_variable_changed(variable.id);
+ }
+}
+
+Settings Settings::create(ByteString settings_path, Vector<String> platform_languages)
+{
+ Settings settings { move(settings_path) };
+
+ // The user's first platform language, then that language alone (en-US, then en): the list a browser starts with.
+ platform_languages.remove_all_matching([](auto const& language) { return !Unicode::is_locale_available(language); });
+ if (!platform_languages.is_empty()) {
+ Vector<String> languages { platform_languages.first() };
+ if (auto separator = languages.first().find_byte_offset('-'); separator.has_value()) {
+ auto language = MUST(languages.first().substring_from_byte_offset(0, *separator));
+ if (Unicode::is_locale_available(language))
+ languages.append(move(language));
+ }
+ settings.m_languages = move(languages);
+ }
+
+ auto settings_json = read_json_file(settings.m_settings_path);
+ if (settings_json.is_error()) {
+ warnln("Unable to read Ladybird settings: {}", settings_json.error());
+ return settings;
+ }
+
+ settings.load_from_json(settings_json.value());
return settings;
}
Settings::Settings(ByteString settings_path)
: m_settings_path(move(settings_path))
- , m_new_tab_page_url(URL::about_blank())
- , m_languages(Web::default_preferred_languages())
{
+ reset_to_defaults();
+}
+
+void Settings::reset_to_defaults()
+{
+ static_cast<SettingsData&>(*this) = SettingsData();
+ m_new_tab_page_url = URL::about_blank();
+ m_languages = Web::default_preferred_languages();
+
for (auto const& variable : config_variable_definitions()) {
m_config_variables[static_cast<size_t>(variable.id)] = variable.default_value;
}
@@ -1493,8 +1601,13 @@ void Settings::persist_settings()
{
auto settings = serialize_json();
- if (auto result = write_json_file(m_settings_path, settings); result.is_error())
- warnln("Unable to persist Ladybird settings: {}", result.error());
+ if (!m_settings_path.is_empty()) {
+ if (auto result = write_json_file(m_settings_path, settings); result.is_error())
+ warnln("Unable to persist Ladybird settings: {}", result.error());
+ }
+
+ if (on_persist)
+ on_persist(settings);
}
void Settings::add_observer(Badge<SettingsObserver>, SettingsObserver& observer)
diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h
index 30adfbd934f..e26088d2f8a 100644
--- a/Libraries/LibWebView/Settings.h
+++ b/Libraries/LibWebView/Settings.h
@@ -214,13 +214,65 @@ private:
WeakPtr<Settings> m_settings;
};
-class WEBVIEW_API Settings : public Weakable<Settings> {
+// What the settings hold, which a Settings can start over from.
+struct WEBVIEW_API SettingsData {
+ bool m_first_run_complete { false };
+
+ WindowSettings m_window_settings;
+
+ URL::URL m_new_tab_page_url;
+ bool m_restore_previous_session { false };
+ Vector<String> m_languages;
+
+ Appearance m_appearance;
+ ContentSettings m_content_settings;
+ TabSettings m_tab_settings;
+ BrowsingBehavior m_browsing_behavior;
+
+ SearchEngineSettings m_search_engine_settings;
+ Vector<SearchEngine> m_custom_search_engines;
+
+ AutoplaySiteSetting m_autoplay;
+ LocationPolicy m_location_policy { LocationPolicy::Ask };
+ MicrophonePolicy m_microphone_policy { MicrophonePolicy::Ask };
+ NotificationsPolicy m_notifications_policy { NotificationsPolicy::Ask };
+
+ BrowsingDataSettings m_browsing_data_settings;
+ GlobalPrivacyControl m_global_privacy_control { GlobalPrivacyControl::No };
+ CrashReportSending m_crash_report_sending { CrashReportSending::AskMe };
+
+ bool m_background_networking_enabled { true };
+ bool m_filter_list_updates_enabled { false };
+ bool m_content_blocker_enabled { false };
+ HashTable<String> m_content_blocker_disabled_sites;
+ Vector<ContentBlockerList> m_content_blocker_lists;
+ String m_custom_content_blocker_filters;
+
+ DNSSettings m_dns_settings { SystemDNS() };
+
+ Array<JsonValue, static_cast<size_t>(ConfigVariableID::Count)> m_config_variables {};
+};
+
+class WEBVIEW_API Settings
+ : public Weakable<Settings>
+ , private SettingsData {
public:
AK_ALLOC_WITH_KMALLOC;
// The platform's languages stand in for the user's list until the settings file carries one.
static Settings create(ByteString settings_path, Vector<String> platform_languages = {});
+ // Settings that live in another process, and are never read from or written to a file here.
+ static Settings create_from_json(JsonValue const&);
+ enum class PersistChange {
+ No,
+ Yes,
+ };
+ void replace_with_json(JsonValue const&, PersistChange);
+
+ // Called with the settings as they are, whenever they have changed.
+ Function<void(JsonValue const&)> on_persist;
+
JsonValue serialize_json() const;
bool first_run_complete() const { return m_first_run_complete; }
@@ -343,46 +395,14 @@ public:
private:
explicit Settings(ByteString settings_path);
+ void reset_to_defaults();
+ void load_from_json(JsonValue const&);
+
void persist_settings();
ByteString m_settings_path;
- bool m_first_run_complete { false };
-
- WindowSettings m_window_settings;
-
- URL::URL m_new_tab_page_url;
- bool m_restore_previous_session { false };
- Vector<String> m_languages;
-
- Appearance m_appearance;
- ContentSettings m_content_settings;
- TabSettings m_tab_settings;
- BrowsingBehavior m_browsing_behavior;
-
- SearchEngineSettings m_search_engine_settings;
- Vector<SearchEngine> m_custom_search_engines;
-
- AutoplaySiteSetting m_autoplay;
- LocationPolicy m_location_policy { LocationPolicy::Ask };
- MicrophonePolicy m_microphone_policy { MicrophonePolicy::Ask };
- NotificationsPolicy m_notifications_policy { NotificationsPolicy::Ask };
-
- BrowsingDataSettings m_browsing_data_settings;
- GlobalPrivacyControl m_global_privacy_control { GlobalPrivacyControl::No };
- CrashReportSending m_crash_report_sending { CrashReportSending::AskMe };
-
- bool m_background_networking_enabled { true };
- bool m_filter_list_updates_enabled { false };
- bool m_content_blocker_enabled { false };
- HashTable<String> m_content_blocker_disabled_sites;
- Vector<ContentBlockerList> m_content_blocker_lists;
- String m_custom_content_blocker_filters;
-
- DNSSettings m_dns_settings { SystemDNS() };
bool m_dns_override_by_command_line { false };
- Array<JsonValue, static_cast<size_t>(ConfigVariableID::Count)> m_config_variables {};
-
Vector<SettingsObserver&> m_observers;
};
diff --git a/Services/Hub/Application.cpp b/Services/Hub/Application.cpp
index d229bb4e62e..a2263fb52a7 100644
--- a/Services/Hub/Application.cpp
+++ b/Services/Hub/Application.cpp
@@ -95,9 +95,10 @@ void Application::on_devtools_disabled() const
WebView::SessionLaunchPolicy Application::launch_restore_policy() const
{
- if (m_host)
- return m_host->launch_restore_policy();
- return WebView::Application::launch_restore_policy();
+ // Without the setting, only pinned tabs come back; with it, every window and tab does.
+ if (settings().restore_previous_session())
+ return WebView::SessionLaunchPolicy::Everything;
+ return WebView::SessionLaunchPolicy::PinnedOnly;
}
void Application::create_platform_actions()
diff --git a/Services/Hub/Application.h b/Services/Hub/Application.h
index ebf57e65b57..a463f31a26a 100644
--- a/Services/Hub/Application.h
+++ b/Services/Hub/Application.h
@@ -34,7 +34,6 @@ public:
virtual void did_enable_devtools() const = 0;
virtual void did_disable_devtools() const = 0;
- virtual WebView::SessionLaunchPolicy launch_restore_policy() const = 0;
virtual void create_platform_actions() = 0;
virtual Optional<String> ui_font_family() const = 0;
virtual Web::CSS::PreferredColorScheme interface_color_scheme() const = 0;
diff --git a/Services/Hub/ConnectionFromUI.cpp b/Services/Hub/ConnectionFromUI.cpp
index 526bb68b3da..5ed31d8713a 100644
--- a/Services/Hub/ConnectionFromUI.cpp
+++ b/Services/Hub/ConnectionFromUI.cpp
@@ -16,10 +16,15 @@ ConnectionFromUI::ConnectionFromUI(NonnullOwnPtr<IPC::Transport> transport)
: IPC::ConnectionFromClient<HubClientEndpoint, HubServerEndpoint>(*this, move(transport), 1)
{
s_the = this;
+
+ Application::settings().on_persist = [this](JsonValue const& settings) {
+ async_settings_changed(settings.serialized().to_byte_string());
+ };
}
ConnectionFromUI::~ConnectionFromUI()
{
+ Application::settings().on_persist = nullptr;
s_the = nullptr;
}
@@ -117,6 +122,14 @@ void ConnectionFromUI::view_answer_permission_request(u64 view_id, u64 answer_id
}
}
+void ConnectionFromUI::update_settings(ByteString settings_json)
+{
+ auto settings = JsonValue::from_string(settings_json);
+ if (settings.is_error() || !settings.value().is_object())
+ return;
+ Application::settings().replace_with_json(settings.value(), WebView::Settings::PersistChange::Yes);
+}
+
void ConnectionFromUI::activate_action(u64 handle, Optional<bool> checked)
{
ActionMirror::the().activate(handle, checked);
diff --git a/Services/Hub/ConnectionFromUI.h b/Services/Hub/ConnectionFromUI.h
index da3ad2c2d43..b9634b06a8f 100644
--- a/Services/Hub/ConnectionFromUI.h
+++ b/Services/Hub/ConnectionFromUI.h
@@ -33,6 +33,7 @@ private:
static View* find_view(u64 view_id);
// ^HubServerEndpoint
+ virtual void update_settings(ByteString settings_json) override;
virtual void activate_action(u64 handle, Optional<bool> checked) override;
virtual void view_answer(u64 view_id, u64 answer_id, bool answer) override;
virtual void view_answer_permission_request(u64 view_id, u64 answer_id, Web::Permissions::PromptOutcome outcome) override;
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index 49403d5d9bd..c863f6215b9 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -175,6 +175,7 @@ struct Hub::ViewState {
// What the Hub tells the UI.
endpoint HubClient
{
+ settings_changed(ByteString settings_json) =|
action_changed(Hub::ActionState state) =|
action_retired(u64 handle) =|
bookmarks_menu_changed(Vector<Hub::MenuEntry> entries) =|
diff --git a/Services/Hub/HubServer.ipc b/Services/Hub/HubServer.ipc
index 46ea1f1fcc6..766163a66f5 100644
--- a/Services/Hub/HubServer.ipc
+++ b/Services/Hub/HubServer.ipc
@@ -19,6 +19,7 @@ struct WebView::ViewImplementation::ScreenRects {
// What the UI asks of the Hub.
endpoint HubServer
{
+ update_settings(ByteString settings_json) =|
activate_action(u64 handle, Optional<bool> checked) =|
view_answer(u64 view_id, u64 answer_id, bool answer) =|
view_answer_permission_request(u64 view_id, u64 answer_id, Web::Permissions::PromptOutcome outcome) =|
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index e24e4976173..01eac8da450 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -682,6 +682,12 @@ void Application::show_process_manager()
void Application::create_platform_actions()
{
+ m_settings = make<WebView::Settings>(WebView::Settings::create_from_json(WebView::Application::settings().serialize_json()));
+ m_settings->on_persist = [](JsonValue const& settings) {
+ if (auto* hub = HubConnection::the_if_connected())
+ hub->async_update_settings(settings.serialized().to_byte_string());
+ };
+
RemoteActions::the().set_application_actions(Hub::ActionMirror::the().application_actions());
RemoteActions::the().inspect_menu().add_action(WebView::Action::create("Open Task Manager"sv, WebView::ActionID::OpenTaskManager, [this]() {
@@ -840,7 +846,7 @@ BrowserWindow& Application::new_window(Vector<URL::URL> const& initial_urls, Win
{
auto* window = new BrowserWindow(initial_urls, is_popup_window, is_private, parent_tab, hub_view_id);
- auto should_focus_location_editor = initial_urls.size() == 1 && initial_urls.first() == WebView::Application::settings().new_tab_page_url();
+ auto should_focus_location_editor = initial_urls.size() == 1 && initial_urls.first() == Application::settings().new_tab_page_url();
if (should_focus_location_editor) {
if (auto* tab = window->current_tab())
tab->set_url_is_hidden(true);
@@ -890,7 +896,7 @@ void Application::present_window(BrowserWindow& window, WindowConfiguration cons
WebView::SessionLaunchPolicy Application::launch_restore_policy() const
{
// Without the setting, only pinned tabs come back; with it, every window and tab does.
- if (WebView::Application::settings().restore_previous_session())
+ if (Application::settings().restore_previous_session())
return WebView::SessionLaunchPolicy::Everything;
return WebView::SessionLaunchPolicy::PinnedOnly;
}
@@ -961,7 +967,7 @@ void Application::offer_to_restore_unexpectedly_closed_tabs(BrowserWindow& windo
QPointer<Tab> new_tab_page;
if (window && window->tab_count() == 1) {
auto* tab = window->tab_at(0);
- if (tab->view().url() == WebView::Application::settings().new_tab_page_url() && !tab->view().navigate_back_action().enabled())
+ if (tab->view().url() == Application::settings().new_tab_page_url() && !tab->view().navigate_back_action().enabled())
new_tab_page = tab;
}
@@ -978,7 +984,7 @@ void Application::offer_to_restore_unexpectedly_closed_tabs(BrowserWindow& windo
void Application::open_startup_tabs(BrowserWindow& window, Vector<URL::URL> const& urls)
{
- auto const& new_tab_page_url = WebView::Application::settings().new_tab_page_url();
+ auto const& new_tab_page_url = Application::settings().new_tab_page_url();
for (size_t i = 0; i < urls.size(); ++i) {
auto& tab = window.new_tab_from_url(urls[i], i == 0 ? Web::HTML::ActivateTab::Yes : Web::HTML::ActivateTab::No, BrowserWindow::TabLocation::end());
if (urls.size() == 1 && urls[i] == new_tab_page_url) {
@@ -1016,7 +1022,7 @@ WindowConfiguration Application::configuration_for_new_window() const
};
}
- auto const& window_settings = WebView::Application::settings().window_settings();
+ auto const& window_settings = Application::settings().window_settings();
WindowConfiguration configuration {
.width = window_settings.size.width(),
.height = window_settings.size.height(),
@@ -1032,7 +1038,7 @@ WindowConfiguration Application::configuration_for_new_window() const
void Application::open_new_tab()
{
if (!m_active_window) {
- new_window({ WebView::Application::settings().new_tab_page_url() });
+ new_window({ Application::settings().new_tab_page_url() });
return;
}
@@ -1042,7 +1048,7 @@ void Application::open_new_tab()
void Application::open_new_window(WebView::IsPrivate is_private)
{
// FIXME: Create a new tab page specific to private windows.
- new_window({ WebView::Application::settings().new_tab_page_url() }, configuration_for_new_window(), BrowserWindow::IsPopupWindow::No, is_private);
+ new_window({ Application::settings().new_tab_page_url() }, configuration_for_new_window(), BrowserWindow::IsPopupWindow::No, is_private);
}
void Application::restart_private_browsing_session()
@@ -1129,7 +1135,7 @@ void Application::cancel_private_session_restart()
void Application::focus_location_editor()
{
if (!m_active_window) {
- new_window({ WebView::Application::settings().new_tab_page_url() });
+ new_window({ Application::settings().new_tab_page_url() });
return;
}
@@ -1495,7 +1501,7 @@ Optional<WebView::ViewImplementation&> Application::activate_tab_with_url(URL::U
Optional<WebView::ViewImplementation&> Application::open_blank_new_tab(Web::HTML::ActivateTab activate_tab) const
{
if (!m_active_window) {
- auto& window = const_cast<Application&>(*this).new_window({ WebView::Application::settings().new_tab_page_url() });
+ auto& window = const_cast<Application&>(*this).new_window({ Application::settings().new_tab_page_url() });
if (auto* tab = window.current_tab())
return tab->view().hub_view();
return {};
diff --git a/UI/Qt/Application.h b/UI/Qt/Application.h
index efa960c445a..cb9f271fb23 100644
--- a/UI/Qt/Application.h
+++ b/UI/Qt/Application.h
@@ -59,7 +59,7 @@ public:
static Hub::Application& hub() { return Hub::Application::the(); }
static WebView::BrowserOptions const& browser_options() { return WebView::Application::browser_options(); }
- static WebView::Settings& settings() { return WebView::Application::settings(); }
+ static WebView::Settings& settings() { return *s_the->m_settings; }
static WebView::Profile const& profile() { return WebView::Application::profile(); }
virtual ~Application() override;
@@ -75,7 +75,7 @@ public:
// After the last run ended unexpectedly, offers to restore the tabs it left open that didn't come back by themselves.
void offer_to_restore_unexpectedly_closed_tabs(BrowserWindow&);
void open_startup_tabs(BrowserWindow&, Vector<URL::URL> const&);
- virtual WebView::SessionLaunchPolicy launch_restore_policy() const override;
+ WebView::SessionLaunchPolicy launch_restore_policy() const;
void open_new_tab();
void open_new_window(WebView::IsPrivate);
@@ -232,6 +232,7 @@ private:
static Application* s_the;
OwnPtr<Hub::Application> m_hub;
+ OwnPtr<WebView::Settings> m_settings;
RefPtr<Hub::ConnectionFromUI> m_connection_from_ui;
RefPtr<HubConnection> m_hub_connection;
OwnPtr<QApplication> m_application;
diff --git a/UI/Qt/BookmarksBar.cpp b/UI/Qt/BookmarksBar.cpp
index 5ad901973a7..184c0bd0dcd 100644
--- a/UI/Qt/BookmarksBar.cpp
+++ b/UI/Qt/BookmarksBar.cpp
@@ -8,6 +8,7 @@
#include <AK/HashTable.h>
#include <LibWebView/Application.h>
#include <LibWebView/BookmarkStore.h>
+#include <UI/Qt/Application.h>
#include <UI/Qt/BookmarksBar.h>
#include <UI/Qt/BrowserWindow.h>
#include <UI/Qt/ChromeLayout.h>
@@ -644,7 +645,7 @@ void BookmarksBarContainer::set_sidebar(QWidget& sidebar)
bool BookmarksBarContainer::shows_over_page() const
{
- return WebView::Application::settings().appearance().show_bookmarks_bar == WebView::ShowBookmarksBar::OnHover;
+ return Application::settings().appearance().show_bookmarks_bar == WebView::ShowBookmarksBar::OnHover;
}
bool BookmarksBarContainer::can_expand_on_hover() const
@@ -683,7 +684,7 @@ void BookmarksBarContainer::update_hover()
}
if (!m_hover_expanded && !m_hover_expand_timer->isActive()) {
- auto delay = WebView::Application::settings().config_variable_as_integer<int>(WebView::ConfigVariableID::VerticalTabsHoverExpandDelay);
+ auto delay = Application::settings().config_variable_as_integer<int>(WebView::ConfigVariableID::VerticalTabsHoverExpandDelay);
m_hover_expand_timer->start(delay);
}
}
@@ -699,7 +700,7 @@ void BookmarksBarContainer::set_hover_expanded(bool expanded)
m_hover_expand_animation->stop();
auto duration = expanded && !SystemAppearance::prefers_reduced_motion()
- ? WebView::Application::settings().config_variable_as_integer<int>(WebView::ConfigVariableID::VerticalTabsHoverExpandAnimationDuration)
+ ? Application::settings().config_variable_as_integer<int>(WebView::ConfigVariableID::VerticalTabsHoverExpandAnimationDuration)
: 0;
m_hover_expand_progress = expanded && duration == 0 ? 1.0 : 0.0;
@@ -718,7 +719,7 @@ void BookmarksBarContainer::set_hover_expanded(bool expanded)
void BookmarksBarContainer::update_geometry()
{
- auto show_bookmarks_bar = WebView::Application::settings().appearance().show_bookmarks_bar;
+ auto show_bookmarks_bar = Application::settings().appearance().show_bookmarks_bar;
auto on_hover = show_bookmarks_bar == WebView::ShowBookmarksBar::OnHover;
auto visible = !window()->isFullScreen()
&& (show_bookmarks_bar == WebView::ShowBookmarksBar::Always
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index f5bdac61ee0..2a4d3b53ce6 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -338,7 +338,8 @@ static QIcon const& app_icon(WebView::IsPrivate is_private)
}
BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow is_popup_window, WebView::IsPrivate is_private, Tab* parent_tab, Optional<u64> hub_view_id, Optional<WebView::SessionWindowId> restored_session_window_id)
- : m_is_private(is_private)
+ : WebView::SettingsObserver(Application::settings())
+ , m_is_private(is_private)
, m_session(WebView::Application::session_for_new_view(is_private))
, m_tabs_container(new TabWidget(is_private, this))
, m_is_popup_window(is_popup_window)
@@ -746,7 +747,7 @@ void BrowserWindow::open_new_tab()
// NB: With the focus already in the selected tab's address field, its focus ring moves to the new tab's field as it
// is, rather than fading in again.
auto focus_ring_transition = focus_is_in_location_edit_of(*this) ? Tab::FocusRingTransition::Immediate : Tab::FocusRingTransition::FadeIn;
- auto& tab = new_tab_from_url(WebView::Application::settings().new_tab_page_url(), Web::HTML::ActivateTab::Yes, TabLocation::end());
+ auto& tab = new_tab_from_url(Application::settings().new_tab_page_url(), Web::HTML::ActivateTab::Yes, TabLocation::end());
tab.set_url_is_hidden(true);
tab.focus_location_editor(focus_ring_transition);
}
@@ -866,7 +867,7 @@ FullscreenMode& BrowserWindow::fullscreen_mode()
bool BrowserWindow::uses_client_side_decorations()
{
- return !use_native_macos_window_controls() && WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::UseClientSideWindowDecorations);
+ return !use_native_macos_window_controls() && Application::settings().config_variable_as_bool(WebView::ConfigVariableID::UseClientSideWindowDecorations);
}
bool BrowserWindow::has_chrome_in_titlebar()
@@ -1948,8 +1949,8 @@ void BrowserWindow::changeEvent(QEvent* event)
void BrowserWindow::appearance_changed()
{
- SystemAppearance::the().apply_interface_theme(WebView::Application::settings().appearance().interface_theme);
- SystemAppearance::the().apply_color_theme(WebView::Application::settings().appearance().color_theme);
+ SystemAppearance::the().apply_interface_theme(Application::settings().appearance().interface_theme);
+ SystemAppearance::the().apply_color_theme(Application::settings().appearance().color_theme);
update_menu_bar_visibility();
m_tabs_container->update_bookmarks_bar_visibility();
@@ -2054,7 +2055,7 @@ void BrowserWindow::closeEvent(QCloseEvent* event)
if (m_is_private == WebView::IsPrivate::No) {
if (m_is_popup_window == IsPopupWindow::No) {
- WebView::Application::settings().set_window_settings({
+ Application::settings().set_window_settings({
.position = Gfx::IntPoint { pos().x(), pos().y() },
.size = Gfx::IntSize { width(), height() },
.maximized = isMaximized(),
diff --git a/UI/Qt/HubConnection.cpp b/UI/Qt/HubConnection.cpp
index 23265f201f5..3713d77b59f 100644
--- a/UI/Qt/HubConnection.cpp
+++ b/UI/Qt/HubConnection.cpp
@@ -4,6 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/JsonValue.h>
+#include <UI/Qt/Application.h>
#include <UI/Qt/HubConnection.h>
#include <UI/Qt/RemoteActions.h>
#include <UI/Qt/RemoteView.h>
@@ -183,6 +185,14 @@ void HubConnection::view_request_dictionary_lookup(u64 view_id, WebView::Diction
view->on_request_dictionary_lookup(lookup, position);
}
+void HubConnection::settings_changed(ByteString settings_json)
+{
+ auto settings = JsonValue::from_string(settings_json);
+ if (settings.is_error() || !settings.value().is_object())
+ return;
+ Application::settings().replace_with_json(settings.value(), WebView::Settings::PersistChange::No);
+}
+
void HubConnection::action_changed(Hub::ActionState state)
{
RemoteActions::the().update(state);
diff --git a/UI/Qt/HubConnection.h b/UI/Qt/HubConnection.h
index 8e6a9e4362f..0f5d18b471b 100644
--- a/UI/Qt/HubConnection.h
+++ b/UI/Qt/HubConnection.h
@@ -29,6 +29,7 @@ private:
virtual void die() override;
// ^HubClientEndpoint
+ virtual void settings_changed(ByteString settings_json) override;
virtual void action_changed(Hub::ActionState state) override;
virtual void bookmarks_menu_changed(Vector<Hub::MenuEntry> entries) override;
virtual void action_retired(u64 handle) override;
diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cpp
index 68cb98e97fe..d2b6c8db1dc 100644
--- a/UI/Qt/LocationEdit.cpp
+++ b/UI/Qt/LocationEdit.cpp
@@ -10,6 +10,7 @@
#include <LibURL/URL.h>
#include <LibWebView/Application.h>
#include <LibWebView/URL.h>
+#include <UI/Qt/Application.h>
#include <UI/Qt/Autocomplete.h>
#include <UI/Qt/ChromeStyle.h>
#include <UI/Qt/Icon.h>
@@ -300,6 +301,7 @@ private:
LocationEdit::LocationEdit(QWidget* parent, WebView::IsPrivate is_private)
: NativeTextEditingLineEdit(parent)
+ , WebView::SettingsObserver(Application::settings())
, m_omnibox(is_private)
, m_autocomplete(new Autocomplete(this))
{
@@ -454,7 +456,7 @@ LocationEdit::LocationEdit(QWidget* parent, WebView::IsPrivate is_private)
auto ctrl_held = QApplication::keyboardModifiers() & Qt::ControlModifier;
auto append_tld = ctrl_held ? WebView::AppendTLD::Yes : WebView::AppendTLD::No;
- auto url = WebView::sanitize_url(input, WebView::Application::settings().search_engine_settings().engine, append_tld);
+ auto url = WebView::sanitize_url(input, Application::settings().search_engine_settings().engine, append_tld);
auto classified_input = WebView::classify_user_input(input, append_tld);
if (destination_kind == WebView::OmniboxDestinationKind::Search
|| classified_input.classification != WebView::UserInputClassification::ExternalURL)
@@ -735,7 +737,7 @@ void LocationEdit::contextMenuEvent(QContextMenuEvent* event)
auto qt_clipboard_text = QGuiApplication::clipboard()->text();
auto clipboard_text = ak_string_from_qstring(qt_clipboard_text);
- bool has_search_engine = WebView::Application::settings().search_engine_settings().engine.has_value();
+ bool has_search_engine = Application::settings().search_engine_settings().engine.has_value();
auto paste_and_go_text = WebView::Omnibox::text_for_paste_and_go_action(clipboard_text, has_search_engine);
// Escape any &s so Qt doesn't treat them as mnemonics.
paste_and_go_text = MUST(paste_and_go_text.replace("&"sv, "&&"sv, ReplaceMode::All));
diff --git a/UI/Qt/Menu.cpp b/UI/Qt/Menu.cpp
index aacf19e3207..baac303b2de 100644
--- a/UI/Qt/Menu.cpp
+++ b/UI/Qt/Menu.cpp
@@ -80,7 +80,7 @@ public:
switch (action.id()) {
case WebView::ActionID::ToggleVerticalTabsExpanded:
if (auto* parent = as_if<QWidget>(m_action->parent())) {
- auto const& tab_settings = WebView::Application::settings().tab_settings();
+ auto const& tab_settings = Application::settings().tab_settings();
auto icon = tab_settings.vertical_tabs_position == WebView::VerticalTabsPosition::Right ? ChromeIcon::SidebarRight : ChromeIcon::Sidebar;
m_action->setIcon(create_chrome_icon(icon, parent->palette()));
}
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index d52dd32081f..2f5b5308ad3 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -174,6 +174,7 @@ private:
Tab::Tab(BrowserWindow* window, Optional<u64> hub_view_id)
: QWidget(window)
+ , WebView::SettingsObserver(Application::settings())
, m_window(window)
{
create_tab_shell();
@@ -182,6 +183,7 @@ Tab::Tab(BrowserWindow* window, Optional<u64> hub_view_id)
Tab::Tab(BrowserWindow* window, DeferredTab deferred_tab)
: QWidget(window)
+ , WebView::SettingsObserver(Application::settings())
, m_window(window)
, m_title(deferred_tab.title)
, m_favicon(favicon_with_rounded_corners(deferred_tab.favicon, TAB_FAVICON_SIZE))
@@ -888,7 +890,7 @@ void Tab::create_tab_context_menu()
auto* new_tab_to_the_right_action = new QAction("New Tab to the &Right", this);
QObject::connect(new_tab_to_the_right_action, &QAction::triggered, this, [this]() {
- m_window->new_tab_from_url(WebView::Application::settings().new_tab_page_url(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_tab(*this));
+ m_window->new_tab_from_url(Application::settings().new_tab_page_url(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_tab(*this));
});
auto* mute_tab_action = new QAction("&Mute Tab", this);
@@ -1118,7 +1120,7 @@ QString Tab::title() const
// A blank page is what a new tab shows, so it is called a new tab.
if (!m_fixed_title.has_value() && is_loaded() && view().url() == URL::about_blank() && (title.isEmpty() || title == QStringLiteral("about:blank")))
title = "New Tab";
- if (!is_loaded() || !WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowWebContentProcessIDInTabTitle))
+ if (!is_loaded() || !Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowWebContentProcessIDInTabTitle))
return title;
return QString("%1 [%2]").arg(title).arg(view().web_content_pid());
@@ -1517,13 +1519,13 @@ void Tab::show_site_settings_popover()
return;
if (!m_site_settings_popover) {
- m_site_settings_popover = new SiteSettingsPopover(this, WebView::Application::settings());
+ m_site_settings_popover = new SiteSettingsPopover(this, Application::settings());
m_location_edit->follow_site_settings_popover(*m_site_settings_popover);
m_site_settings_popover->on_content_blocking_toggle = [this](bool enabled) {
auto snapshot = view().content_blocking_snapshot();
if (!snapshot.site.has_value() || !snapshot.can_toggle())
return;
- if (WebView::Application::settings().set_content_blocker_enabled_for_site(*snapshot.site, enabled).is_error())
+ if (Application::settings().set_content_blocker_enabled_for_site(*snapshot.site, enabled).is_error())
return;
view().reload();
};
diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cpp
index 97f5eb2bb08..4e97880607a 100644
--- a/UI/Qt/WebContentView.cpp
+++ b/UI/Qt/WebContentView.cpp
@@ -100,7 +100,7 @@ namespace Ladybird {
// theme, so pages can stay light in a dark window.
static bool websites_prefer_dark()
{
- switch (WebView::Application::settings().appearance().website_color_scheme) {
+ switch (Application::settings().appearance().website_color_scheme) {
case WebView::ThemePreference::System:
return SystemAppearance::the().prefers_dark();
case WebView::ThemePreference::Light:
diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cpp
index 09613456a7a..651e45eaec4 100644
--- a/UI/Qt/WindowToolbar.cpp
+++ b/UI/Qt/WindowToolbar.cpp
@@ -1154,6 +1154,7 @@ private:
WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)
: QWidget(parent)
+ , WebView::SettingsObserver(Application::settings())
, m_is_private(is_private)
{
auto& application = RemoteActions::the();
@@ -1888,7 +1889,7 @@ void WindowToolbar::tab_settings_changed()
void WindowToolbar::config_variable_changed(WebView::ConfigVariableID variable)
{
if (variable == WebView::ConfigVariableID::ShowFeedbackButton && m_feedback_button) {
- auto show_button = WebView::Application::settings().config_variable_as_bool(variable);
+ auto show_button = Application::settings().config_variable_as_bool(variable);
if (!show_button && m_feedback_popover)
m_feedback_popover->close();
m_feedback_button->setVisible(show_button);
@@ -1899,7 +1900,7 @@ void WindowToolbar::config_variable_changed(WebView::ConfigVariableID variable)
void WindowToolbar::update_performance_monitor_row()
{
- auto enabled = WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowTabPerformanceMonitor);
+ auto enabled = Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowTabPerformanceMonitor);
m_performance_monitor_row->setVisible(enabled && isVisible());
}