diff --git a/Libraries/LibURL/CMakeLists.txt b/Libraries/LibURL/CMakeLists.txt index b40b60d5368..2edcded7413 100644 --- a/Libraries/LibURL/CMakeLists.txt +++ b/Libraries/LibURL/CMakeLists.txt @@ -1,8 +1,12 @@ +include(public_suffix) + set(SOURCES Origin.cpp Parser.cpp URL.cpp + ${PUBLIC_SUFFIX_SOURCES} ) serenity_lib(LibURL url) target_link_libraries(LibURL PRIVATE LibUnicode LibTextCodec) +target_compile_definitions(LibURL PRIVATE ENABLE_PUBLIC_SUFFIX=$) diff --git a/Libraries/LibURL/URL.cpp b/Libraries/LibURL/URL.cpp index 061009dcf8f..ba96886c857 100644 --- a/Libraries/LibURL/URL.cpp +++ b/Libraries/LibURL/URL.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Max Wipfli + * Copyright (c) 2024, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,6 +15,10 @@ #include #include +#if defined(ENABLE_PUBLIC_SUFFIX) +# include +#endif + namespace URL { // FIXME: It could make sense to force users of URL to use URL::Parser::basic_parse() explicitly instead of using a constructor. @@ -498,4 +503,22 @@ ByteString percent_decode(StringView input) return builder.to_byte_string(); } +bool is_public_suffix([[maybe_unused]] StringView host) +{ +#if defined(ENABLE_PUBLIC_SUFFIX) + return PublicSuffixData::the()->is_public_suffix(host); +#else + return false; +#endif +} + +Optional get_public_suffix([[maybe_unused]] StringView host) +{ +#if defined(ENABLE_PUBLIC_SUFFIX) + return MUST(PublicSuffixData::the()->get_public_suffix(host)); +#else + return {}; +#endif +} + } diff --git a/Libraries/LibURL/URL.h b/Libraries/LibURL/URL.h index bc17a362062..cb111dcc660 100644 --- a/Libraries/LibURL/URL.h +++ b/Libraries/LibURL/URL.h @@ -199,6 +199,9 @@ URL create_with_url_or_path(ByteString const&); URL create_with_file_scheme(ByteString const& path, ByteString const& fragment = {}, ByteString const& hostname = {}); URL create_with_data(StringView mime_type, StringView payload, bool is_base64 = false); +bool is_public_suffix(StringView host); +Optional get_public_suffix(StringView host); + } template<> diff --git a/Libraries/LibWebView/CMakeLists.txt b/Libraries/LibWebView/CMakeLists.txt index 88df9a4efc5..e62a04c7400 100644 --- a/Libraries/LibWebView/CMakeLists.txt +++ b/Libraries/LibWebView/CMakeLists.txt @@ -1,5 +1,4 @@ include(fontconfig) -include(public_suffix) set(SOURCES Application.cpp @@ -21,7 +20,6 @@ set(SOURCES Utilities.cpp ViewImplementation.cpp WebContentClient.cpp - ${PUBLIC_SUFFIX_SOURCES} ) if (APPLE) @@ -74,7 +72,6 @@ set(GENERATED_SOURCES serenity_lib(LibWebView webview) target_link_libraries(LibWebView PRIVATE LibCore LibFileSystem LibGfx LibImageDecoderClient LibIPC LibRequests LibJS LibWeb LibUnicode LibURL LibSyntax) -target_compile_definitions(LibWebView PRIVATE ENABLE_PUBLIC_SUFFIX=$) if (APPLE) target_link_libraries(LibWebView PRIVATE LibThreading) diff --git a/Libraries/LibWebView/CookieJar.cpp b/Libraries/LibWebView/CookieJar.cpp index 1a0f83f2fa1..9203c78ebac 100644 --- a/Libraries/LibWebView/CookieJar.cpp +++ b/Libraries/LibWebView/CookieJar.cpp @@ -14,7 +14,6 @@ #include #include #include -#include namespace WebView { @@ -335,7 +334,7 @@ void CookieJar::store_cookie(Web::Cookie::ParsedCookie const& parsed_cookie, con } // 9. If the user agent is configured to reject "public suffixes" and the domain-attribute is a public suffix: - if (is_public_suffix(domain_attribute)) { + if (URL::is_public_suffix(domain_attribute)) { // 1. If the domain-attribute is identical to the canonicalized request-host: if (domain_attribute == canonicalized_domain) { // 1. Let the domain-attribute be the empty string. diff --git a/Libraries/LibWebView/URL.cpp b/Libraries/LibWebView/URL.cpp index 9968ebeaffc..ef0117c38bc 100644 --- a/Libraries/LibWebView/URL.cpp +++ b/Libraries/LibWebView/URL.cpp @@ -6,34 +6,11 @@ */ #include -#include #include #include -#if defined(ENABLE_PUBLIC_SUFFIX) -# include -#endif - namespace WebView { -bool is_public_suffix([[maybe_unused]] StringView host) -{ -#if defined(ENABLE_PUBLIC_SUFFIX) - return PublicSuffixData::the()->is_public_suffix(host); -#else - return false; -#endif -} - -Optional get_public_suffix([[maybe_unused]] StringView host) -{ -#if defined(ENABLE_PUBLIC_SUFFIX) - return MUST(PublicSuffixData::the()->get_public_suffix(host)); -#else - return {}; -#endif -} - Optional sanitize_url(StringView url, Optional search_engine, AppendTLD append_tld) { if (FileSystem::exists(url.trim_whitespace())) { @@ -111,7 +88,7 @@ static URLParts break_web_url_into_parts(URL::URL const& url, StringView url_str domain = url_without_scheme; } - auto public_suffix = get_public_suffix(domain); + auto public_suffix = URL::get_public_suffix(domain); if (!public_suffix.has_value() || !domain.ends_with(*public_suffix)) return { scheme, domain, remainder }; diff --git a/Libraries/LibWebView/URL.h b/Libraries/LibWebView/URL.h index 0145c63a667..aa617019e14 100644 --- a/Libraries/LibWebView/URL.h +++ b/Libraries/LibWebView/URL.h @@ -12,9 +12,6 @@ namespace WebView { -bool is_public_suffix(StringView host); -Optional get_public_suffix(StringView host); - enum class AppendTLD { No, Yes, diff --git a/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt index 53c0ab668c8..5ad6e3858bf 100644 --- a/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt +++ b/Meta/Lagom/Tools/CodeGenerators/CMakeLists.txt @@ -1,4 +1,4 @@ add_subdirectory(IPCCompiler) add_subdirectory(LibTextCodec) +add_subdirectory(LibURL) add_subdirectory(LibWeb) -add_subdirectory(LibWebView) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWebView/CMakeLists.txt b/Meta/Lagom/Tools/CodeGenerators/LibURL/CMakeLists.txt similarity index 100% rename from Meta/Lagom/Tools/CodeGenerators/LibWebView/CMakeLists.txt rename to Meta/Lagom/Tools/CodeGenerators/LibURL/CMakeLists.txt diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWebView/GeneratePublicSuffixData.cpp b/Meta/Lagom/Tools/CodeGenerators/LibURL/GeneratePublicSuffixData.cpp similarity index 98% rename from Meta/Lagom/Tools/CodeGenerators/LibWebView/GeneratePublicSuffixData.cpp rename to Meta/Lagom/Tools/CodeGenerators/LibURL/GeneratePublicSuffixData.cpp index 90fac0d4f09..ef3e363cb8a 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWebView/GeneratePublicSuffixData.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibURL/GeneratePublicSuffixData.cpp @@ -56,7 +56,7 @@ ErrorOr generate_header_file(Core::InputBufferedFile&, Core::File& file) #include #include -namespace WebView { +namespace URL { class PublicSuffixData { protected: @@ -96,9 +96,9 @@ ErrorOr generate_implementation_file(Core::InputBufferedFile& input, Core: generator.append(R"~~~( #include #include -#include +#include -namespace WebView { +namespace URL { static constexpr auto s_public_suffixes = Array {)~~~");