From 5e8bfb5efc0e4b8cdffd2ecbf0239916a6d3d69d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Mon, 14 Feb 2022 21:59:47 +0000 Subject: [PATCH] LibWeb: Implement Origin's "same origin-domain" concept Check of domains is left as a FIXME as our Origin class doesn't support those yet. --- Userland/Libraries/LibWeb/Origin.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Userland/Libraries/LibWeb/Origin.h b/Userland/Libraries/LibWeb/Origin.h index aa19f36aa1..d40555efa6 100644 --- a/Userland/Libraries/LibWeb/Origin.h +++ b/Userland/Libraries/LibWeb/Origin.h @@ -42,6 +42,30 @@ public: && port() == other.port(); } + // https://html.spec.whatwg.org/multipage/origin.html#same-origin-domain + bool is_same_origin_domain(Origin const& other) const + { + // 1. If A and B are the same opaque origin, then return true. + if (is_opaque() && other.is_opaque()) + return true; + + // 2. If A and B are both tuple origins, run these substeps: + if (!is_opaque() && !other.is_opaque()) { + // 1. If A and B's schemes are identical, and their domains are identical and non-null, then return true. + // FIXME: Check domains once supported. + if (protocol() == other.protocol()) + return true; + + // 2. Otherwise, if A and B are same origin and their domains are identical and null, then return true. + // FIXME: Check domains once supported. + if (is_same_origin(other)) + return true; + } + + // 3. Return false. + return false; + } + bool operator==(Origin const& other) const { return is_same_origin(other); } bool operator!=(Origin const& other) const { return !is_same_origin(other); }