PublicSuffixSoup.cpp [plain text]
#include "config.h"
#include "PublicSuffix.h"
#if ENABLE(PUBLIC_SUFFIX_LIST)
#include <libsoup/soup.h>
#include <wtf/glib/GUniquePtr.h>
namespace WebCore {
bool isPublicSuffix(const String& domain)
{
if (domain.isEmpty())
return false;
return soup_tld_domain_is_public_suffix(domain.convertToASCIILowercase().utf8().data());
}
String topPrivatelyControlledDomain(const String& domain)
{
if (domain.isEmpty())
return String();
if (!domain.isAllASCII())
return domain;
String lowercaseDomain = domain.convertToASCIILowercase();
if (lowercaseDomain == "localhost")
return lowercaseDomain;
CString domainUTF8 = lowercaseDomain.utf8();
unsigned position = 0;
while (domainUTF8.data()[position] == '.')
position++;
if (position == domainUTF8.length())
return String();
GUniqueOutPtr<GError> error;
if (const char* baseDomain = soup_tld_get_base_domain(domainUTF8.data() + position, &error.outPtr()))
return String::fromUTF8(baseDomain);
if (g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_INVALID_HOSTNAME) || g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS) || g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_NO_BASE_DOMAIN))
return String();
if (g_error_matches(error.get(), SOUP_TLD_ERROR, SOUP_TLD_ERROR_IS_IP_ADDRESS))
return domain;
ASSERT_NOT_REACHED();
return String();
}
}
#endif // ENABLE(PUBLIC_SUFFIX_LIST)