summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-17 13:55:42 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-18 16:30:02 +0200
commit1ffd533ea27f43807d12a44605ea0a0de9436174 (patch)
tree5314a1e164dd744b96185a9c1378bf7b63d9e858
parentfed2606591c457587a4b5d80ce94ee8f70fc8787 (diff)
downloadserenity-1ffd533ea27f43807d12a44605ea0a0de9436174.zip
Ladybird: Propagate autoplay settings to the WebContent process
-rw-r--r--Ladybird/WebContent/main.cpp35
-rw-r--r--Ladybird/cmake/AndroidExtras.cmake7
-rw-r--r--Ladybird/cmake/InstallRules.cmake1
3 files changed, 42 insertions, 1 deletions
diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp
index abcc8c7e85..cbe2a32c4d 100644
--- a/Ladybird/WebContent/main.cpp
+++ b/Ladybird/WebContent/main.cpp
@@ -24,6 +24,7 @@
#include <LibWeb/Loader/ContentFilter.h>
#include <LibWeb/Loader/FrameLoader.h>
#include <LibWeb/Loader/ResourceLoader.h>
+#include <LibWeb/PermissionsPolicy/AutoplayAllowlist.h>
#include <LibWeb/WebSockets/WebSocket.h>
#include <QGuiApplication>
#include <QSocketNotifier>
@@ -33,6 +34,7 @@
#include <WebContent/WebDriverConnection.h>
static ErrorOr<void> load_content_filters();
+static ErrorOr<void> load_autoplay_allowlist();
extern DeprecatedString s_serenity_resource_root;
@@ -85,6 +87,10 @@ 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();
+ if (maybe_autoplay_allowlist_error.is_error())
+ dbgln("Failed to load autoplay allowlist: {}", maybe_autoplay_allowlist_error.error());
+
int webcontent_fd_passing_socket { -1 };
Core::ArgsParser args_parser;
@@ -126,3 +132,32 @@ static ErrorOr<void> load_content_filters()
}
return {};
}
+
+static ErrorOr<void> load_autoplay_allowlist()
+{
+ auto file_or_error = Core::File::open(TRY(String::formatted("{}/home/anon/.config/BrowserAutoplayAllowlist.txt", s_serenity_resource_root)), Core::File::OpenMode::Read);
+ if (file_or_error.is_error())
+ file_or_error = Core::File::open(TRY(String::formatted("{}/res/ladybird/BrowserAutoplayAllowlist.txt", s_serenity_resource_root)), Core::File::OpenMode::Read);
+ if (file_or_error.is_error())
+ return file_or_error.release_error();
+
+ auto file = file_or_error.release_value();
+ auto allowlist = TRY(Core::BufferedFile::create(move(file)));
+ auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
+
+ 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 {};
+}
diff --git a/Ladybird/cmake/AndroidExtras.cmake b/Ladybird/cmake/AndroidExtras.cmake
index 923098f424..c1f39e7342 100644
--- a/Ladybird/cmake/AndroidExtras.cmake
+++ b/Ladybird/cmake/AndroidExtras.cmake
@@ -49,12 +49,17 @@ copy_res_folder(emoji)
copy_res_folder(themes)
copy_res_folder(color-palettes)
copy_res_folder(cursor-themes)
+add_custom_target(copy-autoplay-allowlist
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ "${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserAutoplayAllowlist.txt"
+ "asset-bundle/res/ladybird/BrowserAutoplayAllowlist.txt"
+)
add_custom_target(copy-content-filters
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt"
"asset-bundle/res/ladybird/BrowserContentFilters.txt"
)
-add_dependencies(archive-assets copy-content-filters)
+add_dependencies(archive-assets copy-autoplay-allowlist copy-content-filters)
add_custom_target(copy-assets COMMAND ${CMAKE_COMMAND} -E copy_if_different ladybird-assets.tar.gz "${CMAKE_SOURCE_DIR}/android/assets")
add_dependencies(copy-assets archive-assets)
add_dependencies(ladybird copy-assets)
diff --git a/Ladybird/cmake/InstallRules.cmake b/Ladybird/cmake/InstallRules.cmake
index 5bfbdafb11..ea134c82ad 100644
--- a/Ladybird/cmake/InstallRules.cmake
+++ b/Ladybird/cmake/InstallRules.cmake
@@ -81,6 +81,7 @@ install(DIRECTORY
)
install(FILES
+ "${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserAutoplayAllowlist.txt"
"${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt"
DESTINATION "${CMAKE_INSTALL_DATADIR}/res/ladybird"
COMPONENT ladybird_Runtime