mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +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: https://github.com/LadybirdBrowser/ladybird/commit/2e64e0b8367 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)
|
||||
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>>());
|
||||
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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 (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"
|
||||
|
@ -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
|
||||
|
|
|
@ -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".
|
||||
// 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 origin’s host matches one of the CIDR notations 127.0.0.0/8 or ::1/128 [RFC4632], return "Potentially Trustworthy".
|
||||
|
|
Loading…
Add table
Reference in a new issue