diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp
index e01ebe76e4b1..7cb4482ac23b 100644
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -4037,84 +4037,32 @@ return
NS_OK
;
}
-NS_IMETHODIMP
-nsHTMLDocument
-:
-:
-SetDomain
-(
-const
-nsAString
-&
-aDomain
-)
-{
-ErrorResult
-rv
-;
-SetDomain
-(
-aDomain
-rv
-)
-;
-return
-rv
-.
-StealNSResult
-(
-)
-;
-}
-void
+already_AddRefed
+<
+nsIURI
+>
nsHTMLDocument
:
:
-SetDomain
+CreateInheritingURIForHost
(
const
-nsAString
-&
-aDomain
-ErrorResult
-&
-rv
-)
-{
-if
-(
-mSandboxFlags
+nsACString
&
-SANDBOXED_DOMAIN
+aHostString
)
{
-rv
-.
-Throw
-(
-NS_ERROR_DOM_SECURITY_ERR
-)
-;
-return
-;
-}
if
(
-aDomain
+aHostString
.
IsEmpty
(
)
)
{
-rv
-.
-Throw
-(
-NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN
-)
-;
return
+nullptr
;
}
nsCOMPtr
@@ -4133,14 +4081,8 @@ if
uri
)
{
-rv
-.
-Throw
-(
-NS_ERROR_FAILURE
-)
-;
return
+nullptr
;
}
nsCOMPtr
@@ -4150,7 +4092,7 @@ nsIURI
newURI
;
nsresult
-rv2
+rv
=
uri
-
@@ -4167,21 +4109,15 @@ if
(
NS_FAILED
(
-rv2
+rv
)
)
{
-rv
-.
-Throw
-(
-rv2
-)
-;
return
+nullptr
;
}
-rv2
+rv
=
newURI
-
@@ -4197,93 +4133,94 @@ if
(
NS_FAILED
(
-rv2
+rv
)
)
{
-rv
-.
-Throw
-(
-rv2
-)
-;
return
+nullptr
;
}
-rv2
+rv
=
newURI
-
>
SetHostAndPort
(
-NS_ConvertUTF16toUTF8
-(
-aDomain
-)
+aHostString
)
;
if
(
NS_FAILED
(
-rv2
+rv
)
)
{
-rv
+return
+nullptr
+;
+}
+return
+newURI
.
-Throw
+forget
(
-rv2
)
;
-return
-;
}
-nsAutoCString
-current
-domain
-;
-if
-(
-NS_FAILED
-(
-uri
--
+already_AddRefed
+<
+nsIURI
>
-GetAsciiHost
+nsHTMLDocument
+:
+:
+RegistrableDomainSuffixOfInternal
(
-current
-)
-)
+const
+nsAString
+&
+aNewDomain
+nsIURI
+*
+aOrigHost
)
-current
-.
-Truncate
+{
+nsAutoCString
+domain
+=
+NS_ConvertUTF16toUTF8
(
+aNewDomain
)
;
+nsAutoCString
+current
+;
if
(
NS_FAILED
(
-newURI
+aOrigHost
-
>
GetAsciiHost
(
-domain
+current
)
)
)
-domain
+{
+current
.
Truncate
(
)
;
+}
bool
ok
=
@@ -4358,14 +4295,8 @@ if
tldService
)
{
-rv
-.
-Throw
-(
-NS_ERROR_NOT_AVAILABLE
-)
-;
return
+nullptr
;
}
nsAutoCString
@@ -4380,7 +4311,7 @@ tldService
>
GetBaseDomain
(
-uri
+aOrigHost
0
currentBaseDomain
)
@@ -4450,6 +4381,217 @@ if
ok
)
{
+return
+nullptr
+;
+}
+return
+CreateInheritingURIForHost
+(
+domain
+)
+;
+}
+bool
+nsHTMLDocument
+:
+:
+IsRegistrableDomainSuffixOfOrEqualTo
+(
+const
+nsAString
+&
+aHostSuffixString
+const
+nsACString
+&
+aOrigHost
+)
+{
+if
+(
+aHostSuffixString
+.
+IsEmpty
+(
+)
+)
+{
+return
+false
+;
+}
+nsCOMPtr
+<
+nsIURI
+>
+origURI
+=
+CreateInheritingURIForHost
+(
+aOrigHost
+)
+;
+if
+(
+!
+origURI
+)
+{
+return
+false
+;
+}
+nsCOMPtr
+<
+nsIURI
+>
+newURI
+=
+RegistrableDomainSuffixOfInternal
+(
+aHostSuffixString
+origURI
+)
+;
+if
+(
+!
+newURI
+)
+{
+return
+false
+;
+}
+return
+true
+;
+}
+NS_IMETHODIMP
+nsHTMLDocument
+:
+:
+SetDomain
+(
+const
+nsAString
+&
+aDomain
+)
+{
+ErrorResult
+rv
+;
+SetDomain
+(
+aDomain
+rv
+)
+;
+return
+rv
+.
+StealNSResult
+(
+)
+;
+}
+void
+nsHTMLDocument
+:
+:
+SetDomain
+(
+const
+nsAString
+&
+aDomain
+ErrorResult
+&
+rv
+)
+{
+if
+(
+mSandboxFlags
+&
+SANDBOXED_DOMAIN
+)
+{
+rv
+.
+Throw
+(
+NS_ERROR_DOM_SECURITY_ERR
+)
+;
+return
+;
+}
+if
+(
+aDomain
+.
+IsEmpty
+(
+)
+)
+{
+rv
+.
+Throw
+(
+NS_ERROR_DOM_BAD_DOCUMENT_DOMAIN
+)
+;
+return
+;
+}
+nsCOMPtr
+<
+nsIURI
+>
+uri
+=
+GetDomainURI
+(
+)
+;
+if
+(
+!
+uri
+)
+{
+rv
+.
+Throw
+(
+NS_ERROR_FAILURE
+)
+;
+return
+;
+}
+nsCOMPtr
+<
+nsIURI
+>
+newURI
+=
+RegistrableDomainSuffixOfInternal
+(
+aDomain
+uri
+)
+;
+if
+(
+!
+newURI
+)
+{
rv
.
Throw
diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h
index 3c6db7a1393f..fec0fa74295e 100644
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -680,6 +680,19 @@ ErrorResult
rv
)
;
+bool
+IsRegistrableDomainSuffixOfOrEqualTo
+(
+const
+nsAString
+&
+aHostSuffixString
+const
+nsACString
+&
+aOrigHost
+)
+;
void
GetCookie
(
@@ -1362,6 +1375,33 @@ GetDomainURI
(
)
;
+already_AddRefed
+<
+nsIURI
+>
+CreateInheritingURIForHost
+(
+const
+nsACString
+&
+aHostString
+)
+;
+already_AddRefed
+<
+nsIURI
+>
+RegistrableDomainSuffixOfInternal
+(
+const
+nsAString
+&
+aHostSuffixString
+nsIURI
+*
+aOrigHost
+)
+;
nsresult
WriteCommon
(