Implement "cookie-averse document objects".

See: https://html.spec.whatwg.org/multipage/dom.html#cookie-averse-document-object
This resolves #196.
This commit is contained in:
wolfbeast 2017-11-20 14:20:39 +01:00 • committed by Roy Tam
commit 3df0152d88
3 changed files with 43 additions and 0 deletions

View file

@ -1923,6 +1923,34 @@ public:
return mMarkedCCGeneration;
}
/**
* Returns whether this document is cookie-averse. See
* https://html.spec.whatwg.org/multipage/dom.html#cookie-averse-document-object
*/
bool IsCookieAverse() const
{
// If we are a document that "has no browsing context."
if (!GetInnerWindow()) {
return true;
}
// If we are a document "whose URL's scheme is not a network scheme."
// NB: Explicitly allow file: URIs to store cookies.
nsCOMPtr<nsIURI> codebaseURI;
NodePrincipal()->GetURI(getter_AddRefs(codebaseURI));
if (!codebaseURI) {
return true;
}
nsAutoCString scheme;
codebaseURI->GetScheme(scheme);
return !scheme.EqualsLiteral("http") &&
!scheme.EqualsLiteral("https") &&
!scheme.EqualsLiteral("ftp") &&
!scheme.EqualsLiteral("file");
}
bool IsLoadedAsData()
{
return mLoadedAsData;