LibWebView: Add autocomplete settings to about:settings

This implements an autocomplete engine inside LibWebView, to replace the
engine currently used by Qt. Whereas Qt uses the Qt Network framework to
perform autocomplete requests, LibWebView uses RequestServer. This moves
downloading this untrusted data out of the browser process.

This patch only implements the persisted settings and their UI. It does
not integrate this engine into the browser UI.
This commit is contained in:
Timothy Flynn 2025-03-30 16:21:24 -04:00 committed by Tim Flynn
commit 5d2e6ffe30
Notes: github-actions[bot] 2025-04-02 12:53:55 +00:00
9 changed files with 432 additions and 66 deletions

View file

@ -24,6 +24,9 @@ static constexpr auto new_tab_page_url_key = "newTabPageURL"sv;
static constexpr auto search_engine_key = "searchEngine"sv;
static constexpr auto search_engine_name_key = "name"sv;
static constexpr auto autocomplete_engine_key = "autocompleteEngine"sv;
static constexpr auto autocomplete_engine_name_key = "name"sv;
static constexpr auto site_setting_enabled_globally_key = "enabledGlobally"sv;
static constexpr auto site_setting_site_filters_key = "siteFilters"sv;
@ -81,6 +84,11 @@ Settings Settings::create(Badge<Application>)
settings.m_search_engine = find_search_engine_by_name(*search_engine_name);
}
if (auto autocomplete_engine = settings_json.value().get_object(autocomplete_engine_key); autocomplete_engine.has_value()) {
if (auto autocomplete_engine_name = autocomplete_engine->get_string(autocomplete_engine_name_key); autocomplete_engine_name.has_value())
settings.m_autocomplete_engine = find_autocomplete_engine_by_name(*autocomplete_engine_name);
}
auto load_site_setting = [&](SiteSetting& site_setting, StringView key) {
auto saved_settings = settings_json.value().get_object(key);
if (!saved_settings.has_value())
@ -122,6 +130,13 @@ JsonValue Settings::serialize_json() const
settings.set(search_engine_key, move(search_engine));
}
if (m_autocomplete_engine.has_value()) {
JsonObject autocomplete_engine;
autocomplete_engine.set(autocomplete_engine_name_key, m_autocomplete_engine->name);
settings.set(autocomplete_engine_key, move(autocomplete_engine));
}
auto save_site_setting = [&](SiteSetting const& site_setting, StringView key) {
JsonArray site_filters;
site_filters.ensure_capacity(site_setting.site_filters.size());
@ -145,6 +160,7 @@ void Settings::restore_defaults()
{
m_new_tab_page_url = URL::about_newtab();
m_search_engine.clear();
m_autocomplete_engine.clear();
m_autoplay = SiteSetting {};
persist_settings();
@ -175,6 +191,19 @@ void Settings::set_search_engine(Optional<StringView> search_engine_name)
observer.search_engine_changed();
}
void Settings::set_autocomplete_engine(Optional<StringView> autocomplete_engine_name)
{
if (autocomplete_engine_name.has_value())
m_autocomplete_engine = find_autocomplete_engine_by_name(*autocomplete_engine_name);
else
m_autocomplete_engine.clear();
persist_settings();
for (auto& observer : m_observers)
observer.autocomplete_engine_changed();
}
void Settings::set_autoplay_enabled_globally(bool enabled_globally)
{
m_autoplay.enabled_globally = enabled_globally;