Move Document::domainIsRegisterable to SecurityOrigin::isMatchingRegistrableDomainSuffix
[WebKit-https.git] / Source / WebCore / page / SecurityOrigin.cpp
index ddcc7d2..7b7cf2c 100644 (file)
@@ -30,6 +30,7 @@
 #include "SecurityOrigin.h"
 
 #include "BlobURL.h"
+#include "OriginAccessEntry.h"
 #include "SchemeRegistry.h"
 #include "SecurityPolicy.h"
 #include "TextEncoding.h"
@@ -432,6 +433,27 @@ bool SecurityOrigin::isSameOriginAs(const SecurityOrigin& other) const
     return isSameSchemeHostPort(other);
 }
 
+bool SecurityOrigin::isMatchingRegistrableDomainSuffix(const String& domainSuffix, bool treatIPAddressAsDomain) const
+{
+    if (domainSuffix.isEmpty())
+        return false;
+
+    auto ipAddressSetting = treatIPAddressAsDomain ? OriginAccessEntry::TreatIPAddressAsDomain : OriginAccessEntry::TreatIPAddressAsIPAddress;
+    OriginAccessEntry accessEntry { protocol(), domainSuffix, OriginAccessEntry::AllowSubdomains, ipAddressSetting };
+    if (!accessEntry.matchesOrigin(*this))
+        return false;
+
+    // Always return true if it is an exact match.
+    if (domainSuffix.length() == host().length())
+        return true;
+
+#if ENABLE(PUBLIC_SUFFIX_LIST)
+    return !isPublicSuffix(domainSuffix);
+#else
+    return true;
+#endif
+}
+
 void SecurityOrigin::grantLoadLocalResources()
 {
     // Granting privileges to some, but not all, documents in a SecurityOrigin