diff options
author | Linus Groh <mail@linusgroh.de> | 2022-02-14 21:59:47 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-15 01:31:03 +0100 |
commit | 5e8bfb5efc0e4b8cdffd2ecbf0239916a6d3d69d (patch) | |
tree | 4579358d54c4022f67b5cd431d0c4a29943a965b | |
parent | 6d0e6e381166607808dba4bcbbdf3ac7185c5a73 (diff) | |
download | serenity-5e8bfb5efc0e4b8cdffd2ecbf0239916a6d3d69d.zip |
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.
-rw-r--r-- | Userland/Libraries/LibWeb/Origin.h | 24 |
1 files changed, 24 insertions, 0 deletions
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); } |