Procházet zdrojové kódy

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.
Linus Groh před 3 roky
rodič
revize
5e8bfb5efc
1 změnil soubory, kde provedl 24 přidání a 0 odebrání
  1. 24 0
      Userland/Libraries/LibWeb/Origin.h

+ 24 - 0
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); }