mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibURL: Migrate Origin scheme from ByteString to String
This commit is contained in:
parent
7f7f6e490b
commit
2e64e0b836
Notes:
github-actions[bot]
2024-11-30 11:23:49 +00:00
Author: https://github.com/AtkinsSJ
Commit: 2e64e0b836
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2610
Reviewed-by: https://github.com/shannonbooth ✅
6 changed files with 10 additions and 13 deletions
|
@ -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>>());
|
||||||
|
|
||||||
|
|
|
@ -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()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 (url’s scheme, url’s host, url’s port, null).
|
// Return the tuple origin (url’s scheme, url’s host, url’s 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
|
||||||
|
|
|
@ -24,7 +24,7 @@ Trustworthiness is_origin_potentially_trustworthy(URL::Origin const& origin)
|
||||||
|
|
||||||
// 3. If origin’s scheme is either "https" or "wss", return "Potentially Trustworthy".
|
// 3. If origin’s 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 origin’s host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".
|
// 4. If origin’s host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue