LibWebView+WebContent+UI: Migrate to the new autoplay settings

This removes the old autoplay allowlist file in favor of the new site
setting. We still support the command-line flag to enable autoplay
globally, as this is needed for WPT.
This commit is contained in:
Timothy Flynn 2025-03-29 08:19:00 -04:00
parent 42691cb80b
commit 94041a28de
20 changed files with 17 additions and 137 deletions

View file

@ -262,15 +262,6 @@ void ViewImplementation::set_enable_do_not_track(bool enable)
client().async_set_enable_do_not_track(page_id(), enable);
}
void ViewImplementation::set_enable_autoplay(bool enable)
{
if (enable) {
client().async_set_autoplay_allowed_on_all_websites(page_id());
} else {
client().async_set_autoplay_allowlist(page_id(), {});
}
}
ByteString ViewImplementation::selected_text()
{
return client().get_selected_text(page_id());
@ -612,6 +603,8 @@ void ViewImplementation::initialize_client(CreateNewClient create_new_client)
if (auto const& user_agent_preset = Application::web_content_options().user_agent_preset; user_agent_preset.has_value())
client().async_debug_request(m_client_state.page_index, "spoof-user-agent"sv, *user_agents.get(*user_agent_preset));
autoplay_settings_changed();
}
void ViewImplementation::handle_web_content_process_crash(LoadErrorPage load_error_page)
@ -659,6 +652,17 @@ void ViewImplementation::handle_web_content_process_crash(LoadErrorPage load_err
}
}
void ViewImplementation::autoplay_settings_changed()
{
auto const& autoplay_settings = Application::settings().autoplay_settings();
auto const& web_content_options = Application::web_content_options();
if (autoplay_settings.enabled_globally || web_content_options.enable_autoplay == EnableAutoplay::Yes)
client().async_set_autoplay_allowed_on_all_websites(page_id());
else
client().async_set_autoplay_allowlist(page_id(), autoplay_settings.site_filters.values());
}
static ErrorOr<LexicalPath> save_screenshot(Gfx::ShareableBitmap const& bitmap)
{
if (!bitmap.is_valid())

View file

@ -28,11 +28,12 @@
#include <LibWebView/DOMNodeProperties.h>
#include <LibWebView/Forward.h>
#include <LibWebView/PageInfo.h>
#include <LibWebView/Settings.h>
#include <LibWebView/WebContentClient.h>
namespace WebView {
class ViewImplementation {
class ViewImplementation : public SettingsObserver {
public:
virtual ~ViewImplementation();
@ -83,8 +84,6 @@ public:
void set_enable_do_not_track(bool);
void set_enable_autoplay(bool);
ByteString selected_text();
Optional<String> selected_text_with_whitespace_collapsed();
void select_all();
@ -265,6 +264,8 @@ protected:
};
void handle_web_content_process_crash(LoadErrorPage = LoadErrorPage::Yes);
virtual void autoplay_settings_changed() override;
struct SharedBitmap {
i32 id { -1 };
Web::DevicePixelSize last_painted_size;

View file

@ -284,7 +284,6 @@ web_templates = [
cacert = [ "$root_build_dir/cacert.pem" ]
config_resources = [
"//Base/res/ladybird/default-config/BrowserAutoplayAllowlist.txt",
"//Base/res/ladybird/default-config/BrowserContentFilters.txt",
"//Base/res/ladybird/default-config/bookmarks.json",
]

View file

@ -25,7 +25,6 @@
#include <LibWeb/Loader/GeneratedPagesLoader.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
#include <LibWeb/Platform/AudioCodecPluginAgnostic.h>
#include <LibWeb/Platform/EventLoopPluginSerenity.h>
#include <LibWebView/Plugins/FontPlugin.h>
@ -50,7 +49,6 @@
#endif
static ErrorOr<void> load_content_filters(StringView config_path);
static ErrorOr<void> load_autoplay_allowlist(StringView config_path);
static ErrorOr<void> initialize_resource_loader(GC::Heap&, int request_server_socket);
static ErrorOr<void> initialize_image_decoder(int image_decoder_socket);
static ErrorOr<void> reinitialize_image_decoder(IPC::File const& image_decoder_socket);
@ -212,10 +210,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (maybe_content_filter_error.is_error())
dbgln("Failed to load content filters: {}", maybe_content_filter_error.error());
auto maybe_autoplay_allowlist_error = load_autoplay_allowlist(config_path);
if (maybe_autoplay_allowlist_error.is_error())
dbgln("Failed to load autoplay allowlist: {}", maybe_autoplay_allowlist_error.error());
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Need to handle other IPC transports here");
auto webcontent_socket = TRY(Core::take_over_socket_from_system_server("WebContent"sv));
@ -254,30 +248,6 @@ static ErrorOr<void> load_content_filters(StringView config_path)
return {};
}
static ErrorOr<void> load_autoplay_allowlist(StringView config_path)
{
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
auto file = TRY(Core::File::open(ByteString::formatted("{}/BrowserAutoplayAllowlist.txt", config_path), Core::File::OpenMode::Read));
auto allowlist = TRY(Core::InputBufferedFile::create(move(file)));
Vector<String> origins;
while (TRY(allowlist->can_read_line())) {
auto line = TRY(allowlist->read_line(buffer));
if (line.is_empty())
continue;
auto domain = TRY(String::from_utf8(line));
TRY(origins.try_append(move(domain)));
}
auto& autoplay_allowlist = Web::PermissionsPolicy::AutoplayAllowlist::the();
TRY(autoplay_allowlist.enable_for_origins(origins));
return {};
}
ErrorOr<void> initialize_resource_loader(GC::Heap& heap, int request_server_socket)
{
static_assert(IsSame<IPC::Transport, IPC::TransportSocket>, "Need to handle other IPC transports here");

View file

@ -39,7 +39,6 @@
- (NSMenuItem*)createFileMenu;
- (NSMenuItem*)createEditMenu;
- (NSMenuItem*)createViewMenu;
- (NSMenuItem*)createSettingsMenu;
- (NSMenuItem*)createHistoryMenu;
- (NSMenuItem*)createInspectMenu;
- (NSMenuItem*)createDebugMenu;
@ -59,7 +58,6 @@
[[NSApp mainMenu] addItem:[self createFileMenu]];
[[NSApp mainMenu] addItem:[self createEditMenu]];
[[NSApp mainMenu] addItem:[self createViewMenu]];
[[NSApp mainMenu] addItem:[self createSettingsMenu]];
[[NSApp mainMenu] addItem:[self createHistoryMenu]];
[[NSApp mainMenu] addItem:[self createInspectMenu]];
[[NSApp mainMenu] addItem:[self createDebugMenu]];
@ -577,19 +575,6 @@
return menu;
}
- (NSMenuItem*)createSettingsMenu
{
auto* menu = [[NSMenuItem alloc] init];
auto* submenu = [[NSMenu alloc] initWithTitle:@"Settings"];
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Enable Autoplay"
action:@selector(toggleAutoplay:)
keyEquivalent:@""]];
[menu setSubmenu:submenu];
return menu;
}
- (NSMenuItem*)createHistoryMenu
{
auto* menu = [[NSMenuItem alloc] init];

View file

@ -88,8 +88,6 @@
- (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument;
- (void)setEnableAutoplay:(BOOL)enabled;
- (void)viewSource;
@end

View file

@ -275,11 +275,6 @@ struct HideCursor {
m_web_view_bridge->debug_request(request, argument);
}
- (void)setEnableAutoplay:(BOOL)enabled
{
m_web_view_bridge->set_enable_autoplay(enabled);
}
- (void)viewSource
{
m_web_view_bridge->get_source();

View file

@ -93,11 +93,6 @@ void WebViewBridge::enqueue_input_event(Web::KeyEvent event)
ViewImplementation::enqueue_input_event(move(event));
}
void WebViewBridge::set_enable_autoplay(bool enabled)
{
ViewImplementation::set_enable_autoplay(enabled);
}
Optional<WebViewBridge::Paintable> WebViewBridge::paintable()
{
Gfx::Bitmap* bitmap = nullptr;

View file

@ -41,8 +41,6 @@ public:
void enqueue_input_event(Web::DragEvent);
void enqueue_input_event(Web::KeyEvent);
void set_enable_autoplay(bool enabled);
struct Paintable {
Gfx::Bitmap& bitmap;
Gfx::IntSize bitmap_size;

View file

@ -17,7 +17,6 @@ struct TabSettings {
BOOL should_show_line_box_borders { NO };
BOOL scripting_enabled { YES };
BOOL block_popups { YES };
BOOL autoplay_enabled { NO };
BOOL same_origin_policy_enabled { NO };
ByteString user_agent_name { "Disabled"sv };
ByteString navigator_compatibility_mode { "chrome"sv };
@ -49,7 +48,6 @@ struct TabSettings {
- (void)setPopupBlocking:(BOOL)block_popups;
- (void)setScripting:(BOOL)enabled;
- (void)setAutoplay:(BOOL)enabled;
- (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument;
- (void)focusLocationToolbarItem;

View file

@ -102,7 +102,6 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
m_settings = {
.scripting_enabled = WebView::Application::browser_options().disable_scripting == WebView::DisableScripting::Yes ? NO : YES,
.block_popups = WebView::Application::browser_options().allow_popups == WebView::AllowPopups::Yes ? NO : YES,
.autoplay_enabled = WebView::Application::web_content_options().enable_autoplay == WebView::EnableAutoplay::Yes ? YES : NO,
};
if (auto const& user_agent_preset = WebView::Application::web_content_options().user_agent_preset; user_agent_preset.has_value())
@ -165,7 +164,6 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
{
[self setPopupBlocking:m_settings.block_popups];
[self setScripting:m_settings.scripting_enabled];
[self setAutoplay:m_settings.autoplay_enabled];
}
- (void)zoomIn:(id)sender
@ -392,17 +390,6 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
[self debugRequest:"block-pop-ups" argument:block_popups ? "on" : "off"];
}
- (void)toggleAutoplay:(id)sender
{
m_settings.autoplay_enabled = !m_settings.autoplay_enabled;
[self setAutoplay:m_settings.autoplay_enabled];
}
- (void)setAutoplay:(BOOL)enabled
{
[[[self tab] web_view] setEnableAutoplay:m_settings.autoplay_enabled];
}
- (void)toggleSameOriginPolicy:(id)sender
{
m_settings.same_origin_policy_enabled = !m_settings.same_origin_policy_enabled;
@ -646,8 +633,6 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
[item setState:(m_settings.user_agent_name == [[item title] UTF8String]) ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(setNavigatorCompatibilityMode:)) {
[item setState:(m_settings.navigator_compatibility_mode == [[[item title] lowercaseString] UTF8String]) ? NSControlStateValueOn : NSControlStateValueOff];
} else if ([item action] == @selector(toggleAutoplay:)) {
[item setState:m_settings.autoplay_enabled ? NSControlStateValueOn : NSControlStateValueOff];
}
return YES;

View file

@ -104,12 +104,6 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
});
});
QObject::connect(Settings::the(), &Settings::enable_autoplay_changed, this, [this](bool enable) {
for_each_tab([enable](auto& tab) {
tab.set_enable_autoplay(enable);
});
});
QObject::connect(Settings::the(), &Settings::preferred_languages_changed, this, [this](QStringList languages) {
Vector<String> preferred_languages;
preferred_languages.ensure_capacity(languages.length());
@ -881,7 +875,6 @@ void BrowserWindow::initialize_tab(Tab* tab)
tab->set_preferred_languages(preferred_languages);
tab->set_navigator_compatibility_mode(navigator_compatibility_mode());
tab->set_enable_do_not_track(Settings::the()->enable_do_not_track());
tab->set_enable_autoplay(WebView::Application::web_content_options().enable_autoplay == WebView::EnableAutoplay::Yes || Settings::the()->enable_autoplay());
tab->view().set_preferred_color_scheme(m_preferred_color_scheme);
}

View file

@ -100,17 +100,6 @@ void Settings::set_enable_do_not_track(bool enable)
emit enable_do_not_track_changed(enable);
}
bool Settings::enable_autoplay()
{
return m_qsettings->value("enable_autoplay", false).toBool();
}
void Settings::set_enable_autoplay(bool enable)
{
m_qsettings->setValue("enable_autoplay", enable);
emit enable_autoplay_changed(enable);
}
bool Settings::show_menubar()
{
return m_qsettings->value("show_menubar", false).toBool();

View file

@ -57,9 +57,6 @@ public:
bool enable_do_not_track();
void set_enable_do_not_track(bool enable);
bool enable_autoplay();
void set_enable_autoplay(bool enable);
bool show_menubar();
void set_show_menubar(bool show_menubar);
@ -67,7 +64,6 @@ signals:
void show_menubar_changed(bool show_menubar);
void preferred_languages_changed(QStringList const& languages);
void enable_do_not_track_changed(bool enable);
void enable_autoplay_changed(bool enable);
protected:
Settings();

View file

@ -49,28 +49,12 @@ SettingsDialog::SettingsDialog(QMainWindow* window)
Settings::the()->set_enable_do_not_track(state == Qt::Checked);
});
m_enable_autoplay = new QCheckBox(this);
if (WebView::Application::web_content_options().enable_autoplay == WebView::EnableAutoplay::Yes) {
m_enable_autoplay->setChecked(true);
} else {
m_enable_autoplay->setChecked(Settings::the()->enable_autoplay());
}
#if (QT_VERSION > QT_VERSION_CHECK(6, 7, 0))
QObject::connect(m_enable_autoplay, &QCheckBox::checkStateChanged, this, [&](int state) {
#else
QObject::connect(m_enable_autoplay, &QCheckBox::stateChanged, this, [&](int state) {
#endif
Settings::the()->set_enable_autoplay(state == Qt::Checked);
});
setup_autocomplete_engine();
m_layout->addRow(new QLabel("Preferred Language(s)", this), m_preferred_languages);
m_layout->addRow(new QLabel("Enable Autocomplete", this), m_enable_autocomplete);
m_layout->addRow(new QLabel("Autocomplete Engine", this), m_autocomplete_engine_dropdown);
m_layout->addRow(new QLabel("Send web sites a \"Do Not Track\" request", this), m_enable_do_not_track);
m_layout->addRow(new QLabel("Enable autoplay on all websites", this), m_enable_autoplay);
setWindowTitle("Settings");
setLayout(m_layout);

View file

@ -31,7 +31,6 @@ private:
QCheckBox* m_enable_autocomplete { nullptr };
QPushButton* m_autocomplete_engine_dropdown { nullptr };
QCheckBox* m_enable_do_not_track { nullptr };
QCheckBox* m_enable_autoplay { nullptr };
};
}

View file

@ -948,9 +948,4 @@ void Tab::set_enable_do_not_track(bool enable)
m_view->set_enable_do_not_track(enable);
}
void Tab::set_enable_autoplay(bool enable)
{
m_view->set_enable_autoplay(enable);
}
}

View file

@ -92,8 +92,6 @@ public:
void set_enable_do_not_track(bool);
void set_enable_autoplay(bool);
bool url_is_hidden() const { return m_location_edit->url_is_hidden(); }
void set_url_is_hidden(bool url_is_hidden) { m_location_edit->set_url_is_hidden(url_is_hidden); }

View file

@ -89,7 +89,6 @@ list(TRANSFORM THEMES PREPEND "${LADYBIRD_SOURCE_DIR}/Base/res/themes/")
set(CONFIG_RESOURCES
bookmarks.json
BrowserAutoplayAllowlist.txt
BrowserContentFilters.txt
)
list(TRANSFORM CONFIG_RESOURCES PREPEND "${LADYBIRD_SOURCE_DIR}/Base/res/ladybird/default-config/")