Skip to content

Truly independent web browser

LibWebView: Share a dialog for host setting overrides

Timothy Flynna543630889dc
diff --git a/Base/res/ladybird/about-pages/settings.html b/Base/res/ladybird/about-pages/settings.html
index 1f39aa6d3b2..2f9441f29ba 100644
--- a/Base/res/ladybird/about-pages/settings.html
+++ b/Base/res/ladybird/about-pages/settings.html
@@ -297,8 +297,7 @@
flex-grow: 1;
}
- dialog .dialog-list-item,
- #force-dark-sites .dialog-list-item {
+ dialog .dialog-list-item {
padding: 10px;
display: flex;
@@ -306,8 +305,7 @@
align-items: center;
}
- dialog .dialog-list-item:hover,
- #force-dark-sites .dialog-list-item:hover {
+ dialog .dialog-list-item:hover {
background-color: var(--control);
}
@@ -316,8 +314,7 @@
opacity: 0.6;
}
- dialog .dialog-list-item-label,
- #force-dark-sites .dialog-list-item-label {
+ dialog .dialog-list-item-label {
flex-grow: 1;
}
@@ -331,19 +328,24 @@
height: 16px;
}
- #force-dark-sites .dialog-list-item {
+ #host-settings .dialog-list-item {
gap: 16px;
}
- #force-dark-sites .dialog-list-item-label {
+ #host-settings .dialog-list-item-label {
min-width: 0;
overflow-wrap: anywhere;
}
- #force-dark-sites button {
+ #host-settings .dialog-list-item-value,
+ #host-settings button {
flex-shrink: 0;
}
+ #host-settings .dialog-list-item-value {
+ font-variant-numeric: tabular-nums;
+ }
+
dialog .dialog-controls {
display: flex;
justify-content: flex-end;
@@ -595,8 +597,8 @@
0 0 0 3px var(--focus-ring);
}
- /* A permission's default and its exceptions sit side by side. */
- .permission-controls {
+ /* A setting's default and its overrides sit side by side. */
+ .setting-controls {
display: flex;
align-items: center;
gap: 12px;
@@ -967,9 +969,11 @@
Darken web pages that don’t provide a dark theme of their own.
</p>
</label>
- <input id="enable-force-dark" type="checkbox" switch />
+ <div class="setting-controls">
+ <input id="enable-force-dark" type="checkbox" switch />
+ <button id="force-dark-settings" class="secondary-button" hidden>Overrides…</button>
+ </div>
</div>
- <div id="force-dark-sites" class="card-group" aria-label="Sites with a force-dark choice"></div>
<div id="tab-layout-group" class="card-group">
<span id="tab-layout-title">Layout</span>
<div class="tab-options" role="radiogroup" aria-labelledby="tab-layout-title">
@@ -1028,7 +1032,10 @@
</div>
<div class="card-group inline-container">
<label for="default-zoom-level">Default page zoom</label>
- <select id="default-zoom-level"></select>
+ <div class="setting-controls">
+ <select id="default-zoom-level"></select>
+ <button id="zoom-settings" class="secondary-button" hidden>Overrides…</button>
+ </div>
</div>
</div>
</div>
@@ -1179,7 +1186,7 @@
<span id="autoplay-forcibly-enabled" class="forcibly-enabled hidden">
This setting is controlled via the command line
</span>
- <div id="autoplay-controls" class="permission-controls">
+ <div id="autoplay-controls" class="setting-controls">
<select id="autoplay-policy">
<option value="allow-audio-and-video">Allow audio and video</option>
<option value="block-audio">Block audio</option>
@@ -1193,7 +1200,7 @@
Location
<p class="description">Sites can ask to know your location.</p>
</label>
- <div class="permission-controls">
+ <div class="setting-controls">
<input id="geolocation-policy" type="checkbox" switch />
<button id="geolocation-settings" class="secondary-button">Exceptions…</button>
</div>
@@ -1203,7 +1210,7 @@
Microphone
<p class="description">Sites can ask to use your microphone.</p>
</label>
- <div class="permission-controls">
+ <div class="setting-controls">
<input id="microphone-policy" type="checkbox" switch />
<button id="microphone-settings" class="secondary-button">Exceptions…</button>
</div>
@@ -1213,7 +1220,7 @@
Notifications
<p class="description">Sites can ask to send you notifications.</p>
</label>
- <div class="permission-controls">
+ <div class="setting-controls">
<input id="notifications-policy" type="checkbox" switch />
<button id="notifications-settings" class="secondary-button">Exceptions…</button>
</div>
@@ -1529,6 +1536,20 @@
</div>
</dialog>
+ <dialog id="host-settings" closedby="any" aria-labelledby="host-settings-title">
+ <div class="dialog-header">
+ <h3 id="host-settings-title" class="dialog-title"></h3>
+ <button id="host-settings-close" class="close-button dialog-button" aria-label="Close">&times;</button>
+ </div>
+ <div class="dialog-body">
+ <p>Sites without an override use the default setting.</p>
+ <div id="host-settings-list" class="dialog-list"></div>
+ </div>
+ <div class="dialog-footer">
+ <button id="host-settings-reset-all" class="secondary-button">Reset all</button>
+ </div>
+ </dialog>
+
<dialog id="browsing-data-settings-dialog" closedby="any">
<div class="dialog-header">
<h3 class="dialog-title">Clear browsing data</h3>
diff --git a/Base/res/ladybird/about-pages/settings/content.js b/Base/res/ladybird/about-pages/settings/content.js
index 8ea92d9212a..e22b6b55157 100644
--- a/Base/res/ladybird/about-pages/settings/content.js
+++ b/Base/res/ladybird/about-pages/settings/content.js
@@ -1,20 +1,102 @@
+import { registerDialogDeepLink } from "./dialog-deep-link.js";
+
const defaultZoomLevel = document.querySelector("#default-zoom-level");
const enableForceDark = document.querySelector("#enable-force-dark");
-const forceDarkSites = document.querySelector("#force-dark-sites");
+const hostSettings = document.querySelector("#host-settings");
+const hostSettingsTitle = document.querySelector("#host-settings-title");
+const hostSettingsList = document.querySelector("#host-settings-list");
+const hostSettingsResetAll = document.querySelector("#host-settings-reset-all");
+
+const HOST_SETTINGS = {
+ "force-dark": {
+ title: "Force dark mode overrides",
+ key: "forceDarkPerHost",
+ format: enabled => (enabled ? "On" : "Off"),
+ },
+ zoom: {
+ title: "Page zoom overrides",
+ key: "zoomPerHost",
+ format: factor => `${Math.round(factor * 100)}%`,
+ },
+};
let CONTENT = {};
-let forceDarkSitesReadOnly = false;
+let CURRENT_HOST_SETTING = null;
-const loadSettings = settings => {
- if (Object.hasOwn(settings, "forceDarkSitesReadOnly")) {
- forceDarkSitesReadOnly = settings.forceDarkSitesReadOnly;
+function renderHostSettings() {
+ const { key, format } = HOST_SETTINGS[CURRENT_HOST_SETTING];
+ const overrides = Object.entries(CONTENT[key] ?? {}).sort(([a], [b]) => a.localeCompare(b));
+ hostSettingsList.replaceChildren();
+ hostSettingsResetAll.disabled = overrides.length === 0;
+
+ if (overrides.length === 0) {
+ const placeholder = document.createElement("div");
+ placeholder.className = "dialog-list-item-placeholder";
+ placeholder.textContent = "No site overrides";
+ hostSettingsList.appendChild(placeholder);
+ }
+
+ for (const [host, value] of overrides) {
+ const row = document.createElement("div");
+ row.className = "dialog-list-item";
+ row.dataset.host = host;
+
+ const label = document.createElement("span");
+ label.className = "dialog-list-item-label";
+ label.textContent = host;
+
+ const savedValue = document.createElement("span");
+ savedValue.className = "dialog-list-item-value";
+ savedValue.textContent = format(value);
+
+ const reset = document.createElement("button");
+ reset.className = "secondary-button";
+ reset.textContent = "Use default";
+ reset.setAttribute("aria-label", `Use default for ${host}`);
+ reset.addEventListener("click", () => {
+ ladybird.sendMessage("resetHostSetting", { setting: CURRENT_HOST_SETTING, host });
+ });
+ row.append(label, savedValue, reset);
+ hostSettingsList.appendChild(row);
}
+}
+
+for (const [setting, { title }] of Object.entries(HOST_SETTINGS)) {
+ registerDialogDeepLink({
+ hash: setting,
+ tab: "appearance",
+ dialog: hostSettings,
+ onOpen: () => {
+ CURRENT_HOST_SETTING = setting;
+ hostSettingsTitle.textContent = title;
+ renderHostSettings();
+ },
+ });
+
+ document.querySelector(`#${setting}-settings`).addEventListener("click", () => {
+ location.hash = setting;
+ });
+}
+
+document.querySelector("#host-settings-close").addEventListener("click", () => {
+ hostSettings.close();
+});
+
+hostSettingsResetAll.addEventListener("click", () => {
+ ladybird.sendMessage("resetHostSetting", { setting: CURRENT_HOST_SETTING });
+});
+
+const loadSettings = settings => {
if (!Object.hasOwn(settings, "content")) {
return;
}
CONTENT = settings.content || {};
+ for (const [setting, { key }] of Object.entries(HOST_SETTINGS)) {
+ document.querySelector(`#${setting}-settings`).hidden = Object.keys(CONTENT[key] ?? {}).length === 0;
+ }
+
const snapped = snapToClosestFactor(CONTENT.defaultZoomLevelFactor);
if (snapped !== null) {
defaultZoomLevel.value = snapped.toString();
@@ -23,23 +105,8 @@ const loadSettings = settings => {
}
enableForceDark.checked = !!CONTENT.enableForceDark;
- forceDarkSites.replaceChildren();
- const choices = Object.entries(CONTENT.forceDarkPerHost || {}).sort(([a], [b]) => a.localeCompare(b));
- forceDarkSites.hidden = choices.length === 0;
- for (const [host, enabled] of choices) {
- const row = document.createElement("div");
- row.className = "dialog-list-item";
- row.dataset.host = host;
- const label = document.createElement("span");
- label.className = "dialog-list-item-label";
- label.textContent = `${host}: ${enabled ? "On" : "Off"}`;
- const reset = document.createElement("button");
- reset.textContent = "Use default";
- reset.disabled = forceDarkSitesReadOnly;
- reset.setAttribute("aria-label", `Use default force-dark setting for ${host}`);
- reset.addEventListener("click", () => ladybird.sendMessage("resetForceDarkForHost", host));
- row.append(label, reset);
- forceDarkSites.appendChild(row);
+ if (hostSettings.open) {
+ renderHostSettings();
}
};
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index cfb16db1a16..b717ff7a2ab 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -114,6 +114,7 @@
#include <LibWebCommon/HTML/SandboxingFlagSet.h>
#include <LibWebCommon/Infra/Strings.h>
#include <LibWebCommon/Loader/DownloadFilename.h>
+#include <LibWebCommon/WebView/Utilities.h>
#include <AK/Debug.h>
#include <AK/LexicalPath.h>
@@ -6847,9 +6848,8 @@ void LocalNavigable::update_force_dark_for_active_document()
if (!is_top_level_traversable())
return;
auto enabled = m_force_dark_default;
- if (auto document = active_document(); document && document->url().host().has_value()) {
- auto host = MUST(String::from_utf8(document->url().serialized_host()));
- if (!host.is_empty())
+ if (auto document = active_document()) {
+ if (auto host = WebView::host_for_settings(document->url()); !host.is_empty())
enabled = m_force_dark_per_host.get(host).value_or(enabled);
}
set_force_dark_enabled(enabled);
diff --git a/Libraries/LibWebCommon/WebView/Utilities.cpp b/Libraries/LibWebCommon/WebView/Utilities.cpp
index 146fc0759cb..eb9a38dd105 100644
--- a/Libraries/LibWebCommon/WebView/Utilities.cpp
+++ b/Libraries/LibWebCommon/WebView/Utilities.cpp
@@ -13,6 +13,7 @@
#include <LibCore/ResourceImplementationFile.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h>
+#include <LibURL/URL.h>
#include <LibWebCommon/WebView/Utilities.h>
#define TOKENCAT(x, y) x##y
@@ -122,4 +123,13 @@ ErrorOr<void> handle_attached_debugger()
return {};
}
+String host_for_settings(URL::URL const& url)
+{
+ if (url.host().has_value())
+ return MUST(String::from_utf8(url.serialized_host()));
+ if (url.scheme() == "about"sv)
+ return MUST(String::from_utf8(url.serialize_path()));
+ return {};
+}
+
}
diff --git a/Libraries/LibWebCommon/WebView/Utilities.h b/Libraries/LibWebCommon/WebView/Utilities.h
index a73ac9add59..11e98a45b5b 100644
--- a/Libraries/LibWebCommon/WebView/Utilities.h
+++ b/Libraries/LibWebCommon/WebView/Utilities.h
@@ -10,8 +10,10 @@
#include <AK/ByteString.h>
#include <AK/Error.h>
#include <AK/Optional.h>
+#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>
+#include <LibURL/Forward.h>
#include <LibWebCommon/Export.h>
namespace WebView {
@@ -31,4 +33,6 @@ WEBCOMMON_API ByteString mach_server_name_for_process(StringView process_name, p
WEBCOMMON_API ErrorOr<void> handle_attached_debugger();
+WEBCOMMON_API String host_for_settings(URL::URL const&);
+
}
diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp
index deb72e88ca6..7ebaabe5466 100644
--- a/Libraries/LibWebView/Settings.cpp
+++ b/Libraries/LibWebView/Settings.cpp
@@ -1169,11 +1169,31 @@ void Settings::set_force_dark_for_host(String const& host, bool enabled)
observer.content_settings_changed();
}
-void Settings::reset_force_dark_for_host(StringView host)
-{
- if (!m_content_settings.force_dark_per_host.remove(host))
+void Settings::reset_host_setting(HostSetting setting, Optional<StringView> host)
+{
+ auto reset = [&](auto& overrides) {
+ if (host.has_value())
+ return overrides.remove(*host);
+ if (overrides.is_empty())
+ return false;
+ overrides.clear();
+ return true;
+ };
+
+ auto changed = [&]() {
+ switch (setting) {
+ case HostSetting::Zoom:
+ return reset(m_content_settings.zoom_per_host);
+ case HostSetting::ForceDark:
+ return reset(m_content_settings.force_dark_per_host);
+ }
+ VERIFY_NOT_REACHED();
+ }();
+ if (!changed)
return;
+
persist_settings();
+
for (auto& observer : m_observers)
observer.content_settings_changed();
}
diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h
index 2197bf847ca..24775bfca59 100644
--- a/Libraries/LibWebView/Settings.h
+++ b/Libraries/LibWebView/Settings.h
@@ -72,6 +72,11 @@ struct Appearance {
ColorTheme color_theme { ColorTheme::Neutral };
};
+enum class HostSetting : u8 {
+ Zoom,
+ ForceDark,
+};
+
struct ContentSettings {
double default_zoom_level_factor { 1.0 };
HashMap<String, double> zoom_per_host;
@@ -293,11 +298,13 @@ public:
bool force_dark_for_host(StringView host) const;
void set_force_dark_for_host(String const& host, bool enabled);
- void reset_force_dark_for_host(StringView host);
double zoom_for_host(StringView host) const;
void set_zoom_for_host(String const& host, double zoom_level);
+ // Omitting the host resets every override for this setting.
+ void reset_host_setting(HostSetting, Optional<StringView> host = {});
+
static TabSettings parse_tab_settings(JsonValue const&);
TabSettings const& tab_settings() const { return m_tab_settings; }
void set_tab_settings(TabSettings);
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 4b536c16938..34d4118f2ec 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -28,6 +28,7 @@
#include <LibWebCommon/WebDriver/Error.h>
#include <LibWebCommon/WebDriver/Input.h>
#include <LibWebCommon/WebView/SiteIsolation.h>
+#include <LibWebCommon/WebView/Utilities.h>
#include <LibWebView/Application.h>
#include <LibWebView/CanonicalSessionHistoryEntry.h>
#include <LibWebView/CrashReportOutbox.h>
@@ -794,6 +795,15 @@ void ViewImplementation::set_zoom(double zoom_level)
update_zoom();
}
+void ViewImplementation::reset_zoom()
+{
+ set_zoom(1.0);
+ page().async_reset_zoom();
+
+ if (m_is_private == IsPrivate::No)
+ Application::settings().set_zoom_for_host(current_host_for_settings(), m_zoom_level);
+}
+
void ViewImplementation::set_display_metadata(Optional<u64> display_id, double maximum_frames_per_second)
{
m_display_id = display_id;
@@ -847,16 +857,6 @@ void ViewImplementation::send_system_theme_to_page(WebContentPage& page)
page.async_update_system_theme(theme);
}
-void ViewImplementation::reset_zoom()
-{
- m_zoom_level = 1.0;
- update_zoom();
- page().async_reset_zoom();
-
- if (m_is_private == IsPrivate::No)
- Application::settings().set_zoom_for_host(current_host_for_settings(), m_zoom_level);
-}
-
// NB: The event is handled once it leaves the queue of pending input events, or when it never enters it.
struct WebDriverInputData final : public Web::BrowserInputData {
explicit WebDriverInputData(Function<void()> on_handled)
@@ -4366,38 +4366,25 @@ Optional<String> ViewImplementation::crash_report_website() const
return CrashReportReview::website_from_url(m_crash_state->failed_url);
}
-String ViewImplementation::force_dark_host() const
-{
- auto url = this->url();
- if (!url.host().has_value())
- return {};
- return current_host_for_settings();
-}
-
bool ViewImplementation::force_dark_enabled() const
{
- return Application::settings().force_dark_for_host(force_dark_host());
+ return Application::settings().force_dark_for_host(current_host_for_settings());
}
bool ViewImplementation::can_set_force_dark() const
{
- return m_is_private == IsPrivate::No && !force_dark_host().is_empty();
+ return m_is_private == IsPrivate::No && !current_host_for_settings().is_empty();
}
void ViewImplementation::set_force_dark_enabled(bool enabled)
{
if (can_set_force_dark())
- Application::settings().set_force_dark_for_host(force_dark_host(), enabled);
+ Application::settings().set_force_dark_for_host(current_host_for_settings(), enabled);
}
String ViewImplementation::current_host_for_settings() const
{
- auto url = this->url();
- if (url.host().has_value())
- return MUST(String::from_utf8(url.serialized_host()));
- if (url.scheme() == "about"sv)
- return MUST(String::from_utf8(url.serialize_path()));
- return {};
+ return host_for_settings(url());
}
void ViewImplementation::languages_changed()
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 8ef25f0f39b..900d4d354b7 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -277,10 +277,12 @@ public:
void zoom_in();
void zoom_out();
void set_zoom(double zoom_level);
- void set_device_pixel_ratio_for_testing(WebContentPage&, double device_pixel_ratio);
void reset_zoom();
double zoom_level() const { return m_zoom_level; }
+
+ void set_device_pixel_ratio_for_testing(WebContentPage&, double device_pixel_ratio);
double device_pixel_ratio() const { return m_device_pixel_ratio; }
+
Optional<u64> display_id() const { return m_display_id; }
double maximum_frames_per_second() const { return m_maximum_frames_per_second; }
// Sends the display metadata to every page hosting documents of the tab.
@@ -334,7 +336,8 @@ public:
return m_backing_stores->displayed_frame().map([](auto const& frame) { return frame.device_pixel_ratio; });
}
- String force_dark_host() const;
+ String current_host_for_settings() const;
+
bool force_dark_enabled() const;
bool can_set_force_dark() const;
void set_force_dark_enabled(bool);
@@ -862,8 +865,6 @@ protected:
void prepare_for_navigation_after_crash(Optional<NavigationToRetry> navigation_to_retry = {});
void set_crash_state(Optional<CrashState>);
- String current_host_for_settings() const;
-
virtual void languages_changed() override;
virtual void content_settings_changed() override;
virtual void browsing_behavior_changed() override;
diff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cpp
index 06c7d086614..cfae886ca9c 100644
--- a/Libraries/LibWebView/WebUI/SettingsUI.cpp
+++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp
@@ -144,8 +144,8 @@ void SettingsUI::register_interfaces()
register_interface("setLanguages"sv, [this](auto const& data) {
set_languages(data);
});
- register_interface("resetForceDarkForHost"sv, [this](auto const& data) {
- reset_force_dark_for_host(data);
+ register_interface("resetHostSetting"sv, [this](auto const& data) {
+ reset_host_setting(data);
});
register_interface("setContentSettings"sv, [this](auto const& data) {
set_content_settings(data);
@@ -236,7 +236,6 @@ void SettingsUI::load_features()
JsonObject SettingsUI::serialize_settings() const
{
auto settings = Application::settings().serialize_json();
- settings.as_object().set("forceDarkSitesReadOnly"sv, !has_client() || client().is_private() == IsPrivate::Yes);
// The sites the user allowed or blocked, for each permission.
JsonObject site_settings;
@@ -397,19 +396,29 @@ void SettingsUI::set_content_settings(JsonValue const& content_settings)
auto parsed_content_settings = Settings::parse_content_settings(content_settings);
auto const& current_content_settings = settings.content_settings();
- // Zoom-per-host is not controlled by the settings UI. Don't overwrite it.
- parsed_content_settings.zoom_per_host = current_content_settings.zoom_per_host;
// Host choices change through their own controls, independently of edits to the default.
+ parsed_content_settings.zoom_per_host = current_content_settings.zoom_per_host;
parsed_content_settings.force_dark_per_host = current_content_settings.force_dark_per_host;
Application::settings().set_content_settings(move(parsed_content_settings));
}
-void SettingsUI::reset_force_dark_for_host(JsonValue const& host)
+void SettingsUI::reset_host_setting(JsonValue const& data)
{
- if (!host.is_string() || !has_client() || client().is_private() == IsPrivate::Yes)
+ if (!data.is_object())
return;
- Application::settings().reset_force_dark_for_host(host.as_string());
+
+ auto setting = data.as_object().get_string("setting"sv);
+ auto host = data.as_object().get_string("host"sv);
+ if (data.as_object().has("host"sv) && !host.has_value())
+ return;
+
+ auto host_view = host.map([](auto const& value) { return value.bytes_as_string_view(); });
+
+ if (setting == "zoom"sv)
+ Application::settings().reset_host_setting(HostSetting::Zoom, host_view);
+ else if (setting == "force-dark"sv)
+ Application::settings().reset_host_setting(HostSetting::ForceDark, host_view);
}
void SettingsUI::set_tab_settings(JsonValue const& tab_settings)
diff --git a/Libraries/LibWebView/WebUI/SettingsUI.h b/Libraries/LibWebView/WebUI/SettingsUI.h
index 318146fd37b..71a308233fe 100644
--- a/Libraries/LibWebView/WebUI/SettingsUI.h
+++ b/Libraries/LibWebView/WebUI/SettingsUI.h
@@ -74,7 +74,7 @@ private:
void set_languages(JsonValue const&);
void set_appearance(JsonValue const&);
void set_content_settings(JsonValue const&);
- void reset_force_dark_for_host(JsonValue const&);
+ void reset_host_setting(JsonValue const&);
void set_tab_settings(JsonValue const&);
void set_browsing_behavior(JsonValue const&);
void set_config_variable(JsonValue const&);
diff --git a/Services/Hub/HubClient.ipc b/Services/Hub/HubClient.ipc
index cbb7f01dbac..a7e748e9905 100644
--- a/Services/Hub/HubClient.ipc
+++ b/Services/Hub/HubClient.ipc
@@ -206,7 +206,7 @@ struct Hub::ViewState {
Optional<ByteString> crash_report_name;
Optional<String> crash_report_website;
double zoom_level;
- String force_dark_host;
+ String host_for_settings;
i32 web_content_pid;
bool can_report_website_issue;
bool can_undo;
diff --git a/Services/Hub/View.cpp b/Services/Hub/View.cpp
index e7c99eb53b5..46252c092f3 100644
--- a/Services/Hub/View.cpp
+++ b/Services/Hub/View.cpp
@@ -645,7 +645,7 @@ ViewState View::current_state() const
state.crash_report_name = crash_report_name();
state.crash_report_website = crash_report_website();
state.crash_overlay_failed_url = crash_overlay_failed_url();
- state.force_dark_host = force_dark_host();
+ state.host_for_settings = current_host_for_settings();
state.can_report_website_issue = can_report_website_issue();
state.can_undo = can_undo();
state.can_redo = can_redo();
diff --git a/Tests/LibWebView/TestForceDarkSettings.cpp b/Tests/LibWebView/TestForceDarkSettings.cpp
index f00def98538..c45e250434d 100644
--- a/Tests/LibWebView/TestForceDarkSettings.cpp
+++ b/Tests/LibWebView/TestForceDarkSettings.cpp
@@ -35,7 +35,7 @@ TEST_CASE(force_dark_choices_survive_default_changes_and_restart)
auto settings = WebView::Settings::create(path);
EXPECT(!settings.force_dark_for_host("example.com"sv));
EXPECT(settings.force_dark_for_host("other.example"sv));
- settings.reset_force_dark_for_host("example.com"sv);
+ settings.reset_host_setting(WebView::HostSetting::ForceDark, "example.com"sv);
EXPECT(settings.force_dark_for_host("example.com"sv));
EXPECT_EQ(settings.content_settings().force_dark_per_host.size(), 1u);
}
@@ -73,10 +73,10 @@ TEST_CASE(force_dark_notifies_only_when_a_choice_changes)
EXPECT_EQ(observer.changes, 1u);
settings.set_force_dark_for_host("example.com"_string, false);
settings.set_force_dark_for_host({}, true);
- settings.reset_force_dark_for_host("missing.example"sv);
+ settings.reset_host_setting(WebView::HostSetting::ForceDark, "missing.example"sv);
EXPECT_EQ(observer.changes, 1u);
settings.set_force_dark_for_host("example.com"_string, true);
- settings.reset_force_dark_for_host("example.com"sv);
+ settings.reset_host_setting(WebView::HostSetting::ForceDark, "example.com"sv);
EXPECT_EQ(observer.changes, 3u);
MUST(FileSystem::remove(path, FileSystem::RecursionMode::Disallowed));
}
diff --git a/Tests/LibWebView/test-webdriver-force-dark.py b/Tests/LibWebView/test-webdriver-force-dark.py
index c7f8ab3105e..5c2c4d026fa 100755
--- a/Tests/LibWebView/test-webdriver-force-dark.py
+++ b/Tests/LibWebView/test-webdriver-force-dark.py
@@ -203,12 +203,16 @@ def run_test(default):
status, _, raw = command("POST", "url", {"url": "about:settings"})
assert status == 200, raw
wait_for_page("about:settings")
- wait_for_condition("return document.querySelector('#force-dark-sites button') !== null")
+ evaluate("document.querySelector('#force-dark-settings').click()")
+ wait_for_condition(
+ "return document.querySelector('#host-settings').open && document.querySelector('#host-settings-list button') !== null"
+ )
assert evaluate(
- "return document.querySelector('#force-dark-sites').textContent.includes('localhost: ' + "
+ "return document.querySelector('#host-settings-list [data-host=localhost] .dialog-list-item-value').textContent === "
+ ("'Off'" if default else "'On'")
- + ")"
)
+ evaluate("document.querySelector('#host-settings-close').click()")
+ wait_for_condition("return !document.querySelector('#host-settings').open")
evaluate("document.querySelector('#enable-force-dark').click()")
wait_for_condition(
"return document.querySelector('#enable-force-dark').checked === " + str(not default).lower()
@@ -220,8 +224,12 @@ def run_test(default):
wait_for_condition(
"return document.querySelector('#enable-force-dark').checked === " + str(default).lower()
)
- evaluate("document.querySelector('#force-dark-sites button').click()")
- wait_for_condition("return document.querySelector('#force-dark-sites button') === null")
+ evaluate("document.querySelector('#force-dark-settings').click()")
+ wait_for_condition(
+ "return document.querySelector('#host-settings').open && document.querySelector('#host-settings-list button') !== null"
+ )
+ evaluate("document.querySelector('#host-settings-list button').click()")
+ wait_for_condition("return document.querySelector('#host-settings-list button') === null")
switch_to(site_handle)
wait_for_condition("return matchMedia('(prefers-color-scheme: dark)').matches === " + str(default).lower())
assert_force_dark("Reset updates an already-open page", default, check_initial=False)
diff --git a/Tests/UI/Qt/TestSiteSettingsPopover.cpp b/Tests/UI/Qt/TestSiteSettingsPopover.cpp
index 89dc236bc62..68ed773f45e 100644
--- a/Tests/UI/Qt/TestSiteSettingsPopover.cpp
+++ b/Tests/UI/Qt/TestSiteSettingsPopover.cpp
@@ -12,6 +12,7 @@
#include <LibFileSystem/FileSystem.h>
#include <LibTest/TestCase.h>
#include <LibURL/Parser.h>
+#include <LibWebCommon/WebView/Utilities.h>
#include <LibWebView/Settings.h>
#include <UI/Qt/SiteSettingsPopover.h>
@@ -114,7 +115,7 @@ TEST_CASE(blob_site_uses_the_default_without_changing_its_origin_host_override)
auto url = URL::Parser::basic_parse("blob:https://example.com/1234"sv).release_value();
auto site = site_for();
site.origin = url.origin();
- site.host_for_settings = {};
+ site.host_for_settings = WebView::host_for_settings(url);
popover.set_site(move(site));
auto& toggle = force_dark_switch(popover);
EXPECT(!toggle.isEnabled());
diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cpp
index 275c8637c9b..eb5c04a55fe 100644
--- a/UI/Qt/Application.cpp
+++ b/UI/Qt/Application.cpp
@@ -2710,15 +2710,14 @@ QMenuBar* Application::create_application_menu_bar(ForBrowserWindow for_browser_
}
view_menu->addSeparator();
}
- view_menu->addMenu(create_application_menu(*view_menu, application.color_scheme_menu()));
view_menu->addAction(create_application_action(*view_menu, application.force_dark_action(), IncludeActionIcon::No));
+ view_menu->addMenu(create_application_menu(*view_menu, application.color_scheme_menu()));
view_menu->addMenu(create_application_menu(*view_menu, application.contrast_menu()));
view_menu->addMenu(create_application_menu(*view_menu, application.motion_menu()));
+ view_menu->addSeparator();
- if constexpr (show_menu_bar_option_available()) {
- view_menu->addSeparator();
+ if constexpr (show_menu_bar_option_available())
view_menu->addAction(create_application_action(*view_menu, application.toggle_menu_bar_action(), IncludeActionIcon::No));
- }
menu_bar->addMenu(bookmarks_menu());
menu_bar->addMenu(history_menu());
diff --git a/UI/Qt/ApplicationActions.cpp b/UI/Qt/ApplicationActions.cpp
index 015734e3728..d27ab114c76 100644
--- a/UI/Qt/ApplicationActions.cpp
+++ b/UI/Qt/ApplicationActions.cpp
@@ -161,10 +161,10 @@ ApplicationActions::ApplicationActions(PageOptions const& options)
m_zoom_menu->add_action(*m_reset_zoom_action);
m_force_dark_action = Action::create_checkable("Force Dark Mode"sv, ActionID::ForceDark, on_active_view([](RemoteView& view) {
- if (view.is_private() == WebView::IsPrivate::Yes || view.force_dark_host().is_empty())
+ if (view.is_private() == WebView::IsPrivate::Yes || view.current_host_for_settings().is_empty())
return;
auto& settings = Application::settings();
- settings.set_force_dark_for_host(view.force_dark_host(), !settings.force_dark_for_host(view.force_dark_host()));
+ settings.set_force_dark_for_host(view.current_host_for_settings(), !settings.force_dark_for_host(view.current_host_for_settings()));
}));
auto set_website_color_scheme = [](WebView::ThemePreference color_scheme) {
@@ -363,8 +363,8 @@ void ApplicationActions::update_force_dark_action()
{
auto& settings = Application::settings();
auto* view = active_view();
- m_force_dark_action->set_enabled(view && view->is_private() == WebView::IsPrivate::No && !view->force_dark_host().is_empty());
- m_force_dark_action->set_checked(view ? settings.force_dark_for_host(view->force_dark_host()) : settings.content_settings().enable_force_dark);
+ m_force_dark_action->set_enabled(view && view->is_private() == WebView::IsPrivate::No && !view->current_host_for_settings().is_empty());
+ m_force_dark_action->set_checked(view ? settings.force_dark_for_host(view->current_host_for_settings()) : settings.content_settings().enable_force_dark);
}
void ApplicationActions::devtools_enabled_changed(bool enabled)
diff --git a/UI/Qt/RemoteView.h b/UI/Qt/RemoteView.h
index c3e3e1a7d2f..d43ba8a6eec 100644
--- a/UI/Qt/RemoteView.h
+++ b/UI/Qt/RemoteView.h
@@ -153,7 +153,7 @@ public:
}
void enable_picture_in_picture_controls() { HubConnection::the().async_view_enable_picture_in_picture_controls(view_id()); }
void enqueue_input_event(Web::InputEvent);
- String force_dark_host() const { return m_state.force_dark_host; }
+ String current_host_for_settings() const { return m_state.host_for_settings; }
void update_interface_color_scheme() { HubConnection::the().async_view_update_interface_color_scheme(view_id()); }
void update_system_theme(Core::AnonymousBuffer const& theme) { HubConnection::the().async_view_set_system_theme(view_id(), theme); }
NonnullRefPtr<Core::Promise<ByteString>> selected_text();
diff --git a/UI/Qt/SiteSettingsPopover.cpp b/UI/Qt/SiteSettingsPopover.cpp
index dde74e5f204..2886db0fb9e 100644
--- a/UI/Qt/SiteSettingsPopover.cpp
+++ b/UI/Qt/SiteSettingsPopover.cpp
@@ -225,8 +225,8 @@ SiteSettingsPopover::SiteSettingsPopover(QWidget* parent, WebView::Settings& set
m_force_dark_switch = new PopoverSwitch(m_site_page);
m_force_dark_switch->setAccessibleName("Force dark mode on this site");
QObject::connect(m_force_dark_switch, &QCheckBox::toggled, this, [this](bool enabled) {
- if (!m_is_private && !m_force_dark_host.is_empty())
- m_settings.set_force_dark_for_host(m_force_dark_host, enabled);
+ if (!m_is_private && !m_host.is_empty())
+ m_settings.set_force_dark_for_host(m_host, enabled);
});
force_dark_row->addWidget(m_force_dark_switch);
layout->addLayout(force_dark_row);
@@ -282,7 +282,7 @@ SiteSettingsPopover::SiteSettingsPopover(QWidget* parent, WebView::Settings& set
QObject::connect(m_reset_permissions_link, &QPushButton::clicked, this, [this] {
m_settings.remove_autoplay_site_filter(m_origin);
if (!m_is_private)
- m_settings.reset_force_dark_for_host(m_force_dark_host);
+ m_settings.reset_host_setting(WebView::HostSetting::ForceDark, m_host);
update_autoplay();
if (on_reset_permissions)
on_reset_permissions();
@@ -361,7 +361,7 @@ SiteSettingsPopover::SiteSettingsPopover(QWidget* parent, WebView::Settings& set
void SiteSettingsPopover::set_site(Site site)
{
m_origin = site.origin.serialize();
- m_force_dark_host = AK::move(site.host_for_settings);
+ m_host = AK::move(site.host_for_settings);
m_is_private = site.is_private;
content_settings_changed();
m_host_label->setText(qstring_from_ak_string(site.origin.host().serialize()));
@@ -507,8 +507,8 @@ void SiteSettingsPopover::fit_to_page()
void SiteSettingsPopover::content_settings_changed()
{
QSignalBlocker blocker(m_force_dark_switch);
- m_force_dark_switch->setChecked(m_settings.force_dark_for_host(m_force_dark_host));
- m_force_dark_switch->setEnabled(!m_is_private && !m_force_dark_host.is_empty());
+ m_force_dark_switch->setChecked(m_settings.force_dark_for_host(m_host));
+ m_force_dark_switch->setEnabled(!m_is_private && !m_host.is_empty());
update_reset_link();
}
@@ -527,7 +527,7 @@ void SiteSettingsPopover::update_reset_link()
if (!m_reset_permissions_link)
return;
auto const& autoplay = m_settings.autoplay_settings();
- auto has_force_dark_choice = !m_is_private && m_settings.content_settings().force_dark_per_host.contains(m_force_dark_host);
+ auto has_force_dark_choice = !m_is_private && m_settings.content_settings().force_dark_per_host.contains(m_host);
m_reset_permissions_link->setEnabled(m_has_decided_permissions || autoplay.site_filters.contains(m_origin) || has_force_dark_choice);
}
diff --git a/UI/Qt/SiteSettingsPopover.h b/UI/Qt/SiteSettingsPopover.h
index 028e0b3505e..bbb70c78624 100644
--- a/UI/Qt/SiteSettingsPopover.h
+++ b/UI/Qt/SiteSettingsPopover.h
@@ -72,7 +72,7 @@ private:
WebView::Settings& m_settings;
String m_origin;
- String m_force_dark_host;
+ String m_host;
bool m_is_private { false };
QLabel* m_force_dark_icon { nullptr };
PopoverSwitch* m_force_dark_switch { nullptr };
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index c6b89fe6817..6b9322706a4 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -1555,7 +1555,7 @@ void Tab::show_site_settings_popover()
m_site_settings_popover->update_chrome_style(palette());
m_site_settings_popover->set_site({
.origin = AK::move(origin),
- .host_for_settings = view().force_dark_host(),
+ .host_for_settings = view().current_host_for_settings(),
.is_private = view().is_private() == WebView::IsPrivate::Yes,
.favicon = m_favicon,
.content_blocking = view().content_blocking_snapshot(),