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
parent 7f7f6e490b
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)
return URL::Origin {};
auto scheme = TRY(decoder.decode<ByteString>());
auto scheme = TRY(decoder.decode<Optional<String>>());
auto host = TRY(decoder.decode<URL::Host>());
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));
} else {
TRY(encoder.encode(false));
TRY(encoder.encode<ByteString>(origin.scheme()));
TRY(encoder.encode(origin.scheme()));
TRY(encoder.encode(origin.host()));
TRY(encoder.encode(origin.port()));
}

View file

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

View file

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

View file

@ -392,7 +392,7 @@ Origin URL::origin() const
// -> "wss"
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 Origin(scheme().to_byte_string(), host().value(), port());
return Origin(scheme(), host().value(), port());
}
// -> "file"
@ -400,7 +400,7 @@ Origin URL::origin() const
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.
// 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

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".
// 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;
// 4. If origins host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".