diff --git a/Base/res/ladybird/default-config/BrowserAutoplayAllowlist.txt b/Base/res/ladybird/default-config/BrowserAutoplayAllowlist.txt deleted file mode 100644 index 1596b5587cd..00000000000 --- a/Base/res/ladybird/default-config/BrowserAutoplayAllowlist.txt +++ /dev/null @@ -1 +0,0 @@ -file:// diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp index 98edefc2e51..1e7816f96db 100644 --- a/Libraries/LibWebView/ViewImplementation.cpp +++ b/Libraries/LibWebView/ViewImplementation.cpp @@ -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 save_screenshot(Gfx::ShareableBitmap const& bitmap) { if (!bitmap.is_valid()) diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h index 5bd697d0e1b..c4adec69815 100644 --- a/Libraries/LibWebView/ViewImplementation.h +++ b/Libraries/LibWebView/ViewImplementation.h @@ -28,11 +28,12 @@ #include #include #include +#include #include 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 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; diff --git a/Meta/gn/secondary/Ladybird/BUILD.gn b/Meta/gn/secondary/Ladybird/BUILD.gn index 7b0ab6724bf..2debfeb6019 100644 --- a/Meta/gn/secondary/Ladybird/BUILD.gn +++ b/Meta/gn/secondary/Ladybird/BUILD.gn @@ -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", ] diff --git a/Services/WebContent/main.cpp b/Services/WebContent/main.cpp index 6cc618b2871..857a28914e1 100644 --- a/Services/WebContent/main.cpp +++ b/Services/WebContent/main.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -50,7 +49,6 @@ #endif static ErrorOr load_content_filters(StringView config_path); -static ErrorOr load_autoplay_allowlist(StringView config_path); static ErrorOr initialize_resource_loader(GC::Heap&, int request_server_socket); static ErrorOr initialize_image_decoder(int image_decoder_socket); static ErrorOr reinitialize_image_decoder(IPC::File const& image_decoder_socket); @@ -212,10 +210,6 @@ ErrorOr 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, "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 load_content_filters(StringView config_path) return {}; } -static ErrorOr 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 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 initialize_resource_loader(GC::Heap& heap, int request_server_socket) { static_assert(IsSame, "Need to handle other IPC transports here"); diff --git a/UI/AppKit/Application/ApplicationDelegate.mm b/UI/AppKit/Application/ApplicationDelegate.mm index c79a02c8c7a..1c328bbcec3 100644 --- a/UI/AppKit/Application/ApplicationDelegate.mm +++ b/UI/AppKit/Application/ApplicationDelegate.mm @@ -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]; diff --git a/UI/AppKit/Interface/LadybirdWebView.h b/UI/AppKit/Interface/LadybirdWebView.h index 96c3d280251..aef3553bcd8 100644 --- a/UI/AppKit/Interface/LadybirdWebView.h +++ b/UI/AppKit/Interface/LadybirdWebView.h @@ -88,8 +88,6 @@ - (void)debugRequest:(ByteString const&)request argument:(ByteString const&)argument; -- (void)setEnableAutoplay:(BOOL)enabled; - - (void)viewSource; @end diff --git a/UI/AppKit/Interface/LadybirdWebView.mm b/UI/AppKit/Interface/LadybirdWebView.mm index 0cccff0292e..24c50c71414 100644 --- a/UI/AppKit/Interface/LadybirdWebView.mm +++ b/UI/AppKit/Interface/LadybirdWebView.mm @@ -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(); diff --git a/UI/AppKit/Interface/LadybirdWebViewBridge.cpp b/UI/AppKit/Interface/LadybirdWebViewBridge.cpp index c25c31553e5..ddf2e00041a 100644 --- a/UI/AppKit/Interface/LadybirdWebViewBridge.cpp +++ b/UI/AppKit/Interface/LadybirdWebViewBridge.cpp @@ -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() { Gfx::Bitmap* bitmap = nullptr; diff --git a/UI/AppKit/Interface/LadybirdWebViewBridge.h b/UI/AppKit/Interface/LadybirdWebViewBridge.h index 2d9f418192d..0e243c454e3 100644 --- a/UI/AppKit/Interface/LadybirdWebViewBridge.h +++ b/UI/AppKit/Interface/LadybirdWebViewBridge.h @@ -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; diff --git a/UI/AppKit/Interface/TabController.h b/UI/AppKit/Interface/TabController.h index 1464ae60776..5ec71b95b55 100644 --- a/UI/AppKit/Interface/TabController.h +++ b/UI/AppKit/Interface/TabController.h @@ -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; diff --git a/UI/AppKit/Interface/TabController.mm b/UI/AppKit/Interface/TabController.mm index b6f0e36164c..176b743519d 100644 --- a/UI/AppKit/Interface/TabController.mm +++ b/UI/AppKit/Interface/TabController.mm @@ -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; diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp index d790f0d7909..92598063f78 100644 --- a/UI/Qt/BrowserWindow.cpp +++ b/UI/Qt/BrowserWindow.cpp @@ -104,12 +104,6 @@ BrowserWindow::BrowserWindow(Vector 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 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); } diff --git a/UI/Qt/Settings.cpp b/UI/Qt/Settings.cpp index 4126da6270d..f8734de3376 100644 --- a/UI/Qt/Settings.cpp +++ b/UI/Qt/Settings.cpp @@ -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(); diff --git a/UI/Qt/Settings.h b/UI/Qt/Settings.h index 520dbac5470..d8919cd5a7a 100644 --- a/UI/Qt/Settings.h +++ b/UI/Qt/Settings.h @@ -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(); diff --git a/UI/Qt/SettingsDialog.cpp b/UI/Qt/SettingsDialog.cpp index f69cb1aec28..4e16aa56451 100644 --- a/UI/Qt/SettingsDialog.cpp +++ b/UI/Qt/SettingsDialog.cpp @@ -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); diff --git a/UI/Qt/SettingsDialog.h b/UI/Qt/SettingsDialog.h index 461dd23e71d..1532fea7698 100644 --- a/UI/Qt/SettingsDialog.h +++ b/UI/Qt/SettingsDialog.h @@ -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 }; }; } diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp index 730c34d599a..f2b17076ab8 100644 --- a/UI/Qt/Tab.cpp +++ b/UI/Qt/Tab.cpp @@ -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); -} - } diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.h index 133213830f8..ef2ddf6f4ac 100644 --- a/UI/Qt/Tab.h +++ b/UI/Qt/Tab.h @@ -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); } diff --git a/UI/cmake/ResourceFiles.cmake b/UI/cmake/ResourceFiles.cmake index 2ea86e801d2..2bad6de510a 100644 --- a/UI/cmake/ResourceFiles.cmake +++ b/UI/cmake/ResourceFiles.cmake @@ -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/")