mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
WebContent: Load {allow,block}lists from Ladybird's config directory
This commit is contained in:
parent
b61b1374f0
commit
be147ae122
Notes:
sideshowbarker
2024-07-18 02:44:10 +09:00
Author: https://github.com/circl-lastname Commit: https://github.com/LadybirdBrowser/ladybird/commit/be147ae122a Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/672
@ -80,6 +80,10 @@ ErrorOr<NonnullRefPtr<WebView::WebContentClient>> launch_web_content_process(
|
||||
web_content_options.executable_path.to_byte_string(),
|
||||
};
|
||||
|
||||
if (web_content_options.config_path.has_value()) {
|
||||
arguments.append("--config-path"sv);
|
||||
arguments.append(web_content_options.config_path.value());
|
||||
}
|
||||
if (web_content_options.is_layout_test_mode == Ladybird::IsLayoutTestMode::Yes)
|
||||
arguments.append("--layout-test-mode"sv);
|
||||
if (web_content_options.use_lagom_networking == Ladybird::UseLagomNetworking::Yes)
|
||||
|
@ -175,6 +175,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
Ladybird::WebContentOptions web_content_options {
|
||||
.command_line = MUST(command_line_builder.to_string()),
|
||||
.executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))),
|
||||
.config_path = Ladybird::Settings::the()->directory(),
|
||||
.enable_callgrind_profiling = enable_callgrind_profiling ? Ladybird::EnableCallgrindProfiling::Yes : Ladybird::EnableCallgrindProfiling::No,
|
||||
.enable_skia_painting = use_skia_painting ? Ladybird::EnableSkiaPainting::Yes : Ladybird::EnableSkiaPainting::No,
|
||||
.use_lagom_networking = enable_qt_networking ? Ladybird::UseLagomNetworking::No : Ladybird::UseLagomNetworking::Yes,
|
||||
|
@ -58,6 +58,7 @@ enum class ExposeInternalsObject {
|
||||
struct WebContentOptions {
|
||||
String command_line;
|
||||
String executable_path;
|
||||
Optional<ByteString> config_path {};
|
||||
EnableCallgrindProfiling enable_callgrind_profiling { EnableCallgrindProfiling::No };
|
||||
EnableSkiaPainting enable_skia_painting { EnableSkiaPainting::No };
|
||||
IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No };
|
||||
|
@ -46,8 +46,8 @@
|
||||
# include <LibCore/Platform/ProcessStatisticsMach.h>
|
||||
#endif
|
||||
|
||||
static ErrorOr<void> load_content_filters();
|
||||
static ErrorOr<void> load_autoplay_allowlist();
|
||||
static ErrorOr<void> load_content_filters(StringView config_path);
|
||||
static ErrorOr<void> load_autoplay_allowlist(StringView config_path);
|
||||
static ErrorOr<void> initialize_lagom_networking(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);
|
||||
@ -92,6 +92,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
|
||||
StringView command_line {};
|
||||
StringView executable_path {};
|
||||
auto config_path = ByteString::formatted("{}/ladybird/default-config", s_serenity_resource_root);
|
||||
StringView mach_server_name {};
|
||||
Vector<ByteString> certificates;
|
||||
int request_server_socket { -1 };
|
||||
@ -108,6 +109,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(command_line, "Chrome process command line", "command-line", 0, "command_line");
|
||||
args_parser.add_option(executable_path, "Chrome process executable path", "executable-path", 0, "executable_path");
|
||||
args_parser.add_option(config_path, "Ladybird configuration path", "config-path", 0, "config_path");
|
||||
args_parser.add_option(request_server_socket, "File descriptor of the socket for the RequestServer connection", "request-server-socket", 'r', "request_server_socket");
|
||||
args_parser.add_option(image_decoder_socket, "File descriptor of the socket for the ImageDecoder connection", "image-decoder-socket", 'i', "image_decoder_socket");
|
||||
args_parser.add_option(is_layout_test_mode, "Is layout test mode", "layout-test-mode");
|
||||
@ -173,11 +175,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
Web::WebIDL::g_enable_idl_tracing = true;
|
||||
}
|
||||
|
||||
auto maybe_content_filter_error = load_content_filters();
|
||||
auto maybe_content_filter_error = load_content_filters(config_path);
|
||||
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();
|
||||
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());
|
||||
|
||||
@ -193,12 +195,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
return event_loop.exec();
|
||||
}
|
||||
|
||||
static ErrorOr<void> load_content_filters()
|
||||
static ErrorOr<void> load_content_filters(StringView config_path)
|
||||
{
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
|
||||
|
||||
auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/default-config/BrowserContentFilters.txt"sv));
|
||||
auto ad_filter_list = TRY(InputBufferedSeekable<FixedMemoryStream>::create(make<FixedMemoryStream>(resource->data())));
|
||||
auto file = TRY(Core::File::open(ByteString::formatted("{}/BrowserContentFilters.txt", config_path), Core::File::OpenMode::Read));
|
||||
auto ad_filter_list = TRY(Core::InputBufferedFile::create(move(file)));
|
||||
|
||||
Vector<String> patterns;
|
||||
|
||||
@ -217,12 +219,12 @@ static ErrorOr<void> load_content_filters()
|
||||
return {};
|
||||
}
|
||||
|
||||
static ErrorOr<void> load_autoplay_allowlist()
|
||||
static ErrorOr<void> load_autoplay_allowlist(StringView config_path)
|
||||
{
|
||||
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
|
||||
|
||||
auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/default-config/BrowserAutoplayAllowlist.txt"sv));
|
||||
auto allowlist = TRY(InputBufferedSeekable<FixedMemoryStream>::create(make<FixedMemoryStream>(resource->data())));
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user