LibURL: Migrate Origin scheme from ByteString to String

This commit is contained in:
Sam Atkins 2024-11-27 16:18:42 +00:00 committed by Andreas Kling
commit 2e64e0b836
Notes: github-actions[bot] 2024-11-30 11:23:49 +00:00
6 changed files with 10 additions and 13 deletions

View file

@ -104,7 +104,7 @@ ErrorOr<URL::Origin> decode(Decoder& decoder)
if (is_opaque) if (is_opaque)
return URL::Origin {}; return URL::Origin {};
auto scheme = TRY(decoder.decode<ByteString>()); auto scheme = TRY(decoder.decode<Optional<String>>());
auto host = TRY(decoder.decode<URL::Host>()); auto host = TRY(decoder.decode<URL::Host>());
auto port = TRY(decoder.decode<Optional<u16>>()); auto port = TRY(decoder.decode<Optional<u16>>());

View file

@ -123,7 +123,7 @@ ErrorOr<void> encode(Encoder& encoder, URL::Origin const& origin)
TRY(encoder.encode(true)); TRY(encoder.encode(true));
} else { } else {
TRY(encoder.encode(false)); TRY(encoder.encode(false));
TRY(encoder.encode<ByteString>(origin.scheme())); TRY(encoder.encode(origin.scheme()));
TRY(encoder.encode(origin.host())); TRY(encoder.encode(origin.host()));
TRY(encoder.encode(origin.port())); TRY(encoder.encode(origin.port()));
} }

View file

@ -18,7 +18,7 @@ String Origin::serialize() const
// 2. Otherwise, let result be origin's scheme. // 2. Otherwise, let result be origin's scheme.
StringBuilder result; StringBuilder result;
result.append(scheme()); result.append(scheme().value_or(String {}));
// 3. Append "://" to result. // 3. Append "://" to result.
result.append("://"sv); result.append("://"sv);
@ -45,7 +45,7 @@ unsigned Traits<URL::Origin>::hash(URL::Origin const& origin)
if (origin.is_opaque()) if (origin.is_opaque())
return 0; return 0;
unsigned hash = origin.scheme().hash(); unsigned hash = origin.scheme().value_or(String {}).hash();
if (origin.port().has_value()) if (origin.port().has_value())
hash = pair_int_hash(hash, *origin.port()); hash = pair_int_hash(hash, *origin.port());

View file

@ -15,7 +15,7 @@ namespace URL {
class Origin { class Origin {
public: public:
Origin() = default; Origin() = default;
Origin(Optional<ByteString> const& scheme, Host const& host, Optional<u16> port) Origin(Optional<String> const& scheme, Host const& host, Optional<u16> port)
: m_state(State { : m_state(State {
.scheme = scheme, .scheme = scheme,
.host = host, .host = host,
@ -27,10 +27,7 @@ public:
// https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque // https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque
bool is_opaque() const { return !m_state.has_value(); } bool is_opaque() const { return !m_state.has_value(); }
StringView scheme() const Optional<String> const& scheme() const { return m_state->scheme; }
{
return m_state->scheme.map([](auto& str) { return str.view(); }).value_or(StringView {});
}
Host const& host() const { return m_state->host; } Host const& host() const { return m_state->host; }
Optional<u16> port() const { return m_state->port; } Optional<u16> port() const { return m_state->port; }
@ -97,7 +94,7 @@ public:
private: private:
struct State { struct State {
Optional<ByteString> scheme; Optional<String> scheme;
Host host; Host host;
Optional<u16> port; Optional<u16> port;
}; };

View file

@ -392,7 +392,7 @@ Origin URL::origin() const
// -> "wss" // -> "wss"
if (scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) { if (scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) {
// Return the tuple origin (urls scheme, urls host, urls port, null). // Return the tuple origin (urls scheme, urls host, urls port, null).
return Origin(scheme().to_byte_string(), host().value(), port()); return Origin(scheme(), host().value(), port());
} }
// -> "file" // -> "file"
@ -400,7 +400,7 @@ Origin URL::origin() const
if (scheme() == "file"sv || scheme() == "resource"sv) { if (scheme() == "file"sv || scheme() == "resource"sv) {
// Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin. // Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
// Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages. // Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
return Origin(scheme().to_byte_string(), String {}, {}); return Origin(scheme(), String {}, {});
} }
// -> Otherwise // -> Otherwise

View file

@ -24,7 +24,7 @@ Trustworthiness is_origin_potentially_trustworthy(URL::Origin const& origin)
// 3. If origins scheme is either "https" or "wss", return "Potentially Trustworthy". // 3. If origins scheme is either "https" or "wss", return "Potentially Trustworthy".
// Note: This is meant to be analog to the a priori authenticated URL concept in [MIX]. // Note: This is meant to be analog to the a priori authenticated URL concept in [MIX].
if (origin.scheme().is_one_of("https"sv, "wss"sv)) if (auto& scheme = origin.scheme(); scheme.has_value() && scheme->is_one_of("https"sv, "wss"sv))
return Trustworthiness::PotentiallyTrustworthy; return Trustworthiness::PotentiallyTrustworthy;
// 4. If origins host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy". // 4. If origins host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".