diff --git a/Libraries/LibIPC/Decoder.cpp b/Libraries/LibIPC/Decoder.cpp index 85445722e4..a27168e253 100644 --- a/Libraries/LibIPC/Decoder.cpp +++ b/Libraries/LibIPC/Decoder.cpp @@ -136,8 +136,9 @@ ErrorOr decode(Decoder& decoder) { auto is_opaque = TRY(decoder.decode()); if (is_opaque) { - auto nonce = TRY(decoder.decode()); - return URL::Origin { nonce }; + auto nonce = TRY(decoder.decode()); + auto type = TRY(decoder.decode()); + return URL::Origin { URL::Origin::OpaqueData { nonce, type } }; } auto scheme = TRY(decoder.decode>()); diff --git a/Libraries/LibIPC/Encoder.cpp b/Libraries/LibIPC/Encoder.cpp index aeb3772560..56f6f74cf4 100644 --- a/Libraries/LibIPC/Encoder.cpp +++ b/Libraries/LibIPC/Encoder.cpp @@ -149,7 +149,8 @@ ErrorOr encode(Encoder& encoder, URL::Origin const& origin) { if (origin.is_opaque()) { TRY(encoder.encode(true)); - TRY(encoder.encode(origin.nonce())); + TRY(encoder.encode(origin.opaque_data().nonce)); + TRY(encoder.encode(origin.opaque_data().type)); } else { TRY(encoder.encode(false)); TRY(encoder.encode(origin.scheme())); diff --git a/Libraries/LibURL/Origin.cpp b/Libraries/LibURL/Origin.cpp index 80ef0094fb..725a485485 100644 --- a/Libraries/LibURL/Origin.cpp +++ b/Libraries/LibURL/Origin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025, Shannon Booth + * Copyright (c) 2024-2026, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,9 +11,9 @@ namespace URL { -Origin Origin::create_opaque() +Origin Origin::create_opaque(OpaqueData::Type type) { - return Origin { AK::get_random() }; + return Origin { OpaqueData { get_random(), type } }; } // https://html.spec.whatwg.org/multipage/browsers.html#same-site @@ -67,8 +67,8 @@ namespace AK { unsigned Traits::hash(URL::Origin const& origin) { if (origin.is_opaque()) { - auto const& nonce = origin.nonce(); - // Random data, so the first u32 is as good as hashing the entire thing. + auto const& nonce = origin.opaque_data().nonce; + // Random data, so the first u32 of the nonce is as good as hashing the entire thing. return (static_cast(nonce[0]) << 24) | (static_cast(nonce[1]) << 16) | (static_cast(nonce[2]) << 8) diff --git a/Libraries/LibURL/Origin.h b/Libraries/LibURL/Origin.h index 6428f8b742..70cc40ef53 100644 --- a/Libraries/LibURL/Origin.h +++ b/Libraries/LibURL/Origin.h @@ -17,14 +17,23 @@ namespace URL { // https://html.spec.whatwg.org/multipage/browsers.html#concept-origin class Origin { public: - using Nonce = Array; + struct OpaqueData { + enum class Type : u8 { + Standard, + File + }; + using Nonce = Array; - explicit Origin(Nonce nonce) - : m_state(move(nonce)) + Nonce nonce; + Type type; + }; + + explicit Origin(OpaqueData opaque_data) + : m_state(opaque_data) { } - static Origin create_opaque(); + static Origin create_opaque(OpaqueData::Type = OpaqueData::Type::Standard); Origin(Optional const& scheme, Host const& host, Optional port, Optional domain = {}) : m_state(Tuple { @@ -37,21 +46,21 @@ public: } // https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque - bool is_opaque() const { return m_state.has(); } + bool is_opaque() const { return m_state.has(); } Optional const& scheme() const { return m_state.get().scheme; } Host const& host() const { return m_state.get().host; } Optional port() const { return m_state.get().port; } Optional domain() const { return m_state.get().domain; } - Nonce const& nonce() const { return m_state.get(); } + OpaqueData const& opaque_data() const { return m_state.get(); } // https://html.spec.whatwg.org/multipage/origin.html#same-origin bool is_same_origin(Origin const& other) const { // 1. If A and B are the same opaque origin, then return true. if (is_opaque() && other.is_opaque()) - return nonce() == other.nonce(); + return opaque_data().nonce == other.opaque_data().nonce; // 2. If A and B are both tuple origins and their schemes, hosts, and port are identical, then return true. if (!is_opaque() && !other.is_opaque() @@ -70,7 +79,7 @@ public: { // 1. If A and B are the same opaque origin, then return true. if (is_opaque() && other.is_opaque()) - return nonce() == other.nonce(); + return opaque_data().nonce == other.opaque_data().nonce; // 2. If A and B are both tuple origins, run these substeps: if (!is_opaque() && !other.is_opaque()) { @@ -110,7 +119,7 @@ public: return Host { tuple.domain.value() }; // 3. Return origin's host. - return m_state.get().host; + return tuple.host; } bool operator==(Origin const& other) const { return is_same_origin(other); } @@ -123,7 +132,7 @@ private: Optional domain; }; - Variant m_state; + Variant m_state; }; } diff --git a/Libraries/LibURL/Site.cpp b/Libraries/LibURL/Site.cpp index d3985849e4..da8b2f9bf5 100644 --- a/Libraries/LibURL/Site.cpp +++ b/Libraries/LibURL/Site.cpp @@ -37,7 +37,7 @@ bool Site::is_same_site(Site const& other) const // 1. If A and B are the same opaque origin, then return true. // NOTE: Origins in sites are always opaque. if (m_value.has() && other.m_value.has()) - return m_value.get().nonce() == other.m_value.get().nonce(); + return m_value.get().opaque_data().nonce == other.m_value.get().opaque_data().nonce; // 2. If A or B is an opaque origin, then return false. if (m_value.has() || other.m_value.has())