summaryrefslogtreecommitdiff
path: root/dom/base/nsIDocument.h
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2017-11-20 14:20:39 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-08 21:02:09 +0100
commit85083fce2da7a270e324fd951b7f3d03a50aef1b (patch)
treed278950db54b32faa9dded6e46dd475f904d3030 /dom/base/nsIDocument.h
parentef720ec2507fafcb67b5ef1a1ef34a2aae5b5868 (diff)
downloaduxp-85083fce2da7a270e324fd951b7f3d03a50aef1b.tar.gz
Implement "cookie-averse document objects".
See: https://html.spec.whatwg.org/multipage/dom.html#cookie-averse-document-object This resolves #196.
Diffstat (limited to 'dom/base/nsIDocument.h')
-rw-r--r--dom/base/nsIDocument.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h
index 5b10c9914c..8f35e9ba5f 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<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;