From 85083fce2da7a270e324fd951b7f3d03a50aef1b Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Mon, 20 Nov 2017 14:20:39 +0100 Subject: Implement "cookie-averse document objects". See: https://html.spec.whatwg.org/multipage/dom.html#cookie-averse-document-object This resolves #196. --- dom/base/nsIDocument.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'dom/base/nsIDocument.h') diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 5b10c9914..8f35e9ba5 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -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 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; -- cgit v1.2.3