diff --git a/Base/res/ladybird/about-pages/settings.html b/Base/res/ladybird/about-pages/settings.html index 0870d2f8840..5efa4a90f62 100644 --- a/Base/res/ladybird/about-pages/settings.html +++ b/Base/res/ladybird/about-pages/settings.html @@ -334,6 +334,16 @@ +
+
Privacy
+
+
+ + +
+
+
+
@@ -378,6 +388,7 @@ const siteSettingsInput = document.querySelector("#site-settings-input"); const siteSettingsRemoveAll = document.querySelector("#site-settings-remove-all"); const siteSettingsTitle = document.querySelector("#site-settings-title"); + const doNotTrackToggle = document.querySelector("#do-not-track-toggle"); const restoreDefaults = document.querySelector("#restore-defaults"); window.settings = {}; @@ -412,6 +423,8 @@ if (siteSetting === "autoplay") { showSiteSettings("Autoplay", window.settings.autoplay); } + + doNotTrackToggle.checked = window.settings.doNotTrack; }; newTabPageURL.addEventListener("change", () => { @@ -609,6 +622,10 @@ event.stopPropagation(); }); + doNotTrackToggle.addEventListener("change", () => { + ladybird.sendMessage("setDoNotTrack", doNotTrackToggle.checked); + }); + restoreDefaults.addEventListener("click", () => { ladybird.sendMessage("restoreDefaultSettings"); }); diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp index 1612f4e4d91..1b3a045c0fa 100644 --- a/Libraries/LibWebView/Settings.cpp +++ b/Libraries/LibWebView/Settings.cpp @@ -32,6 +32,8 @@ static constexpr auto site_setting_site_filters_key = "siteFilters"sv; static constexpr auto autoplay_key = "autoplay"sv; +static constexpr auto do_not_track_key = "doNotTrack"sv; + static ErrorOr read_settings_file(StringView settings_path) { auto settings_file = Core::File::open(settings_path, Core::File::OpenMode::Read); @@ -109,6 +111,9 @@ Settings Settings::create(Badge) load_site_setting(settings.m_autoplay, autoplay_key); + if (auto do_not_track = settings_json.value().get_bool(do_not_track_key); do_not_track.has_value()) + settings.m_do_not_track = *do_not_track ? DoNotTrack::Yes : DoNotTrack::No; + return settings; } @@ -153,6 +158,8 @@ JsonValue Settings::serialize_json() const save_site_setting(m_autoplay, autoplay_key); + settings.set(do_not_track_key, m_do_not_track == DoNotTrack::Yes); + return settings; } @@ -162,6 +169,7 @@ void Settings::restore_defaults() m_search_engine.clear(); m_autocomplete_engine.clear(); m_autoplay = SiteSetting {}; + m_do_not_track = DoNotTrack::No; persist_settings(); @@ -244,6 +252,15 @@ void Settings::remove_all_autoplay_site_filters() observer.autoplay_settings_changed(); } +void Settings::set_do_not_track(DoNotTrack do_not_track) +{ + m_do_not_track = do_not_track; + persist_settings(); + + for (auto& observer : m_observers) + observer.do_not_track_changed(); +} + void Settings::persist_settings() { auto settings = serialize_json(); diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h index 71edcfc1f1f..f3789d064f8 100644 --- a/Libraries/LibWebView/Settings.h +++ b/Libraries/LibWebView/Settings.h @@ -24,6 +24,11 @@ struct SiteSetting { OrderedHashTable site_filters; }; +enum class DoNotTrack { + No, + Yes, +}; + class SettingsObserver { public: SettingsObserver(); @@ -33,6 +38,7 @@ public: virtual void search_engine_changed() { } virtual void autocomplete_engine_changed() { } virtual void autoplay_settings_changed() { } + virtual void do_not_track_changed() { } }; class Settings { @@ -58,6 +64,9 @@ public: void remove_autoplay_site_filter(String const&); void remove_all_autoplay_site_filters(); + DoNotTrack do_not_track() const { return m_do_not_track; } + void set_do_not_track(DoNotTrack); + static void add_observer(Badge, SettingsObserver&); static void remove_observer(Badge, SettingsObserver&); @@ -72,6 +81,7 @@ private: Optional m_search_engine; Optional m_autocomplete_engine; SiteSetting m_autoplay; + DoNotTrack m_do_not_track { DoNotTrack::No }; Vector m_observers; }; diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp index 1e7816f96db..af484833047 100644 --- a/Libraries/LibWebView/ViewImplementation.cpp +++ b/Libraries/LibWebView/ViewImplementation.cpp @@ -605,6 +605,7 @@ void ViewImplementation::initialize_client(CreateNewClient create_new_client) client().async_debug_request(m_client_state.page_index, "spoof-user-agent"sv, *user_agents.get(*user_agent_preset)); autoplay_settings_changed(); + do_not_track_changed(); } void ViewImplementation::handle_web_content_process_crash(LoadErrorPage load_error_page) @@ -663,6 +664,12 @@ void ViewImplementation::autoplay_settings_changed() client().async_set_autoplay_allowlist(page_id(), autoplay_settings.site_filters.values()); } +void ViewImplementation::do_not_track_changed() +{ + auto do_not_track = Application::settings().do_not_track(); + client().async_set_enable_do_not_track(page_id(), do_not_track == DoNotTrack::Yes); +} + static ErrorOr save_screenshot(Gfx::ShareableBitmap const& bitmap) { if (!bitmap.is_valid()) diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h index c4adec69815..5a210472851 100644 --- a/Libraries/LibWebView/ViewImplementation.h +++ b/Libraries/LibWebView/ViewImplementation.h @@ -265,6 +265,7 @@ protected: void handle_web_content_process_crash(LoadErrorPage = LoadErrorPage::Yes); virtual void autoplay_settings_changed() override; + virtual void do_not_track_changed() override; struct SharedBitmap { i32 id { -1 }; diff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cpp index 57488bae532..c418a65cbf2 100644 --- a/Libraries/LibWebView/WebUI/SettingsUI.cpp +++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp @@ -50,6 +50,10 @@ void SettingsUI::register_interfaces() register_interface("removeAllSiteSettingFilters"sv, [this](auto const& data) { remove_all_site_setting_filters(data); }); + + register_interface("setDoNotTrack"sv, [this](auto const& data) { + set_do_not_track(data); + }); } void SettingsUI::load_current_settings() @@ -218,4 +222,12 @@ void SettingsUI::remove_all_site_setting_filters(JsonValue const& site_setting) load_current_settings(); } +void SettingsUI::set_do_not_track(JsonValue const& do_not_track) +{ + if (!do_not_track.is_bool()) + return; + + WebView::Application::settings().set_do_not_track(do_not_track.as_bool() ? DoNotTrack::Yes : DoNotTrack::No); +} + } diff --git a/Libraries/LibWebView/WebUI/SettingsUI.h b/Libraries/LibWebView/WebUI/SettingsUI.h index 362ff986b93..bcb33c1f5e9 100644 --- a/Libraries/LibWebView/WebUI/SettingsUI.h +++ b/Libraries/LibWebView/WebUI/SettingsUI.h @@ -30,6 +30,8 @@ private: void add_site_setting_filter(JsonValue const&); void remove_site_setting_filter(JsonValue const&); void remove_all_site_setting_filters(JsonValue const&); + + void set_do_not_track(JsonValue const&); }; }