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

@ -22,6 +22,7 @@
#include <LibWebView/Options.h>
#include <LibWebView/Process.h>
#include <LibWebView/ProcessManager.h>
#include <LibWebView/Settings.h>
namespace WebView {
@ -35,6 +36,8 @@ public:
static Application& the() { return *s_the; }
static Settings& settings() { return the().m_settings; }
static BrowserOptions const& browser_options() { return the().m_browser_options; }
static WebContentOptions& web_content_options() { return the().m_web_content_options; }
@ -69,10 +72,10 @@ public:
protected:
template<DerivedFrom<Application> ApplicationType>
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments, URL::URL new_tab_page_url)
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments)
{
auto app = adopt_own(*new ApplicationType { {}, arguments });
app->initialize(arguments, move(new_tab_page_url));
app->initialize(arguments);
return app;
}
@ -87,7 +90,7 @@ protected:
virtual Optional<ByteString> ask_user_for_download_folder() const { return {}; }
private:
void initialize(Main::Arguments const& arguments, URL::URL new_tab_page_url);
void initialize(Main::Arguments const& arguments);
void launch_spare_web_content_process();
ErrorOr<void> launch_request_server();
@ -127,6 +130,8 @@ private:
static Application* s_the;
Settings m_settings;
BrowserOptions m_browser_options;
WebContentOptions m_web_content_options;
@ -150,11 +155,11 @@ private:
}
#define WEB_VIEW_APPLICATION(ApplicationType) \
public: \
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments, URL::URL new_tab_page_url) \
{ \
return WebView::Application::create<ApplicationType>(arguments, move(new_tab_page_url)); \
} \
\
#define WEB_VIEW_APPLICATION(ApplicationType) \
public: \
static NonnullOwnPtr<ApplicationType> create(Main::Arguments& arguments) \
{ \
return WebView::Application::create<ApplicationType>(arguments); \
} \
\
ApplicationType(Badge<WebView::Application>, Main::Arguments&);