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 committed by Tim Ledbetter
parent 223b04f087
commit ed265b568d
Notes: github-actions[bot] 2025-03-30 15:20:08 +00:00
20 changed files with 17 additions and 137 deletions

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/")