LibWebView+UI: Introduce a persistent settings object

This adds a WebView::Settings class to own persistent browser settings.
In this first pass, it now owns the new tab page URL and search engine
settings.

For simplicitly, we currently use a JSON format for these settings. They
are stored alongside the cookie database. As of this commit, the saved
JSON will have the form:

    {
        "newTabPageURL": "about:blank",
        "searchEngine": {
            "name": "Google"
        }
    }

(The search engine is an object to allow room for a future patch to
implement custom search engine URLs.)

For Qt, this replaces the management of these particular settings in the
Qt settings UI. We will have an internal browser page to control these
settings instead. In the future, we will want to port all settings to
this new class. We will also want to allow UI-specific settings (such as
whether the hamburger menu is displayed in Qt).
This commit is contained in:
Timothy Flynn 2025-03-20 12:59:44 -04:00 committed by Alexander Kalenik
commit e084a86861
Notes: github-actions[bot] 2025-03-22 16:28:56 +00:00
28 changed files with 313 additions and 246 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -234,7 +234,7 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
self.tab.titlebarAppearsTransparent = NO;
[delegate createNewTab:WebView::Application::browser_options().new_tab_page_url
[delegate createNewTab:WebView::Application::settings().new_tab_page_url()
fromTab:[self tab]
activateTab:Web::HTML::ActivateTab::Yes];
@ -705,9 +705,12 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
}
auto url_string = Ladybird::ns_string_to_string([[text_view textStorage] string]);
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
if (auto url = WebView::sanitize_url(url_string, [delegate searchEngine].query_url); url.has_value()) {
Optional<StringView> search_engine_url;
if (auto const& search_engine = WebView::Application::settings().search_engine(); search_engine.has_value())
search_engine_url = search_engine->query_url;
if (auto url = WebView::sanitize_url(url_string, search_engine_url); url.has_value()) {
[self loadURL:*url];
}