Bladeren bron

LibWebView: Wrap retrieving public suffix data in a helper

This lets outside callers use this API but primarily is to fix the build
when the ENABLE_PUBLIC_SUFFIX_DOWNLOAD CMake option is disabled.
Timothy Flynn 1 jaar geleden
bovenliggende
commit
ae3e0d97b5
2 gewijzigde bestanden met toevoegingen van 11 en 4 verwijderingen
  1. 9 4
      Userland/Libraries/LibWebView/URL.cpp
  2. 2 0
      Userland/Libraries/LibWebView/URL.h

+ 9 - 4
Userland/Libraries/LibWebView/URL.cpp

@@ -26,7 +26,6 @@ static Optional<URL> query_public_suffix_list(StringView url_string)
     if (!url.is_valid())
         return {};
 
-#if defined(ENABLE_PUBLIC_SUFFIX)
     if (url.host().has<URL::IPv4Address>() || url.host().has<URL::IPv6Address>())
         return url;
 
@@ -36,7 +35,7 @@ static Optional<URL> query_public_suffix_list(StringView url_string)
     if (url.host().has<String>()) {
         auto const& host = url.host().get<String>();
 
-        if (auto public_suffix = MUST(PublicSuffixData::the()->get_public_suffix(host)); public_suffix.has_value())
+        if (auto public_suffix = get_public_suffix(host); public_suffix.has_value())
             return url;
 
         if (host.ends_with_bytes(".local"sv) || host.ends_with_bytes("localhost"sv))
@@ -44,8 +43,14 @@ static Optional<URL> query_public_suffix_list(StringView url_string)
     }
 
     return {};
+}
+
+Optional<String> get_public_suffix([[maybe_unused]] StringView host)
+{
+#if defined(ENABLE_PUBLIC_SUFFIX)
+    return MUST(PublicSuffixData::the()->get_public_suffix(host));
 #else
-    return url;
+    return {};
 #endif
 }
 
@@ -95,7 +100,7 @@ static URLParts break_web_url_into_parts(URL const& url, StringView url_string)
 {
     auto host = MUST(url.serialized_host());
 
-    auto public_suffix = MUST(PublicSuffixData::the()->get_public_suffix(host));
+    auto public_suffix = get_public_suffix(host);
     if (!public_suffix.has_value())
         return {};
 

+ 2 - 0
Userland/Libraries/LibWebView/URL.h

@@ -12,6 +12,8 @@
 
 namespace WebView {
 
+Optional<String> get_public_suffix(StringView host);
+
 enum class AppendTLD {
     No,
     Yes,