1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

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.
This commit is contained in:
Linus Groh 2022-02-14 21:59:47 +00:00 committed by Andreas Kling
parent 6d0e6e3811
commit 5e8bfb5efc

View file

@ -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); }