rework effective tld service interface, fix normalization bugs and improve error propagation. b=368989, r=biesi, sr=dveditz

git-svn-id: svn://10.0.0.236/trunk@238135 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dwitte%stanford.edu
2007-10-25 08:14:27 +00:00
parent 888830c4fd
commit c66b74a11b
6 changed files with 291 additions and 104 deletions

View File

@@ -1703,30 +1703,21 @@ nsHTMLDocument::SetDomain(const nsAString& aDomain)
nsAutoString current;
if (NS_FAILED(GetDomain(current)))
return NS_ERROR_FAILURE;
PRBool ok = PR_FALSE;
if (current.Equals(aDomain)) {
ok = PR_TRUE;
} else if (aDomain.Length() < current.Length()) {
nsAutoString suffix;
current.Right(suffix, aDomain.Length());
PRUnichar c = current.CharAt(current.Length() - aDomain.Length() - 1);
if (suffix.Equals(aDomain, nsCaseInsensitiveStringComparator()) &&
(c == '.')) {
// Using only a TLD is forbidden (bug 368700)
nsCOMPtr<nsIEffectiveTLDService> tldService =
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
if (!tldService)
return NS_ERROR_NOT_AVAILABLE;
PRBool ok = current.Equals(aDomain);
if (current.Length() > aDomain.Length() &&
StringEndsWith(current, aDomain, nsCaseInsensitiveStringComparator()) &&
current.CharAt(current.Length() - aDomain.Length() - 1) == '.') {
// Using only a TLD is forbidden (bug 368700)
nsCOMPtr<nsIEffectiveTLDService> tldService =
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
if (!tldService)
return NS_ERROR_NOT_AVAILABLE;
NS_ConvertUTF16toUTF8 str(aDomain);
PRUint32 tldLength;
nsresult rv = tldService->GetEffectiveTLDLength(str, &tldLength);
if (NS_FAILED(rv))
return rv;
if (tldLength < str.Length())
ok = PR_TRUE;
}
// try to get the base domain; if this works, we're ok
NS_ConvertUTF16toUTF8 str(aDomain);
nsCAutoString etld;
nsresult rv = tldService->GetBaseDomainFromHost(str, 0, etld);
ok = NS_SUCCEEDED(rv);
}
if (!ok) {
// Error: illegal domain