LibURL+LibWeb: Make URL::Origin default constructor private

Instead, porting over all users to use the newly created
Origin::create_opaque factory function. This also requires porting
over some users of Origin to avoid default construction.
This commit is contained in:
Shannon Booth 2025-06-15 19:08:58 +12:00 committed by Jelle Raaijmakers
commit e0d7278820
Notes: github-actions[bot] 2025-06-17 18:55:18 +00:00
16 changed files with 70 additions and 66 deletions

View file

@ -10,6 +10,12 @@
namespace URL {
// FIXME: This should be generating a unique origin identifer that can be used for equality checks.
Origin Origin::create_opaque()
{
return Origin {};
}
// https://html.spec.whatwg.org/multipage/browsers.html#same-site
bool Origin::is_same_site(Origin const& other) const
{

View file

@ -15,10 +15,6 @@ namespace URL {
class Origin {
public:
// FIXME: This should be generating a unique origin identifer that can be used for equality checks.
// Probably we should remove the default constructor, and instead expose this as a factory method.
Origin() = default;
Origin(Optional<String> const& scheme, Host const& host, Optional<u16> port)
: m_state(State {
.scheme = scheme,
@ -28,6 +24,8 @@ public:
{
}
static Origin create_opaque();
// https://html.spec.whatwg.org/multipage/origin.html#concept-origin-opaque
bool is_opaque() const { return !m_state.has_value(); }
@ -102,6 +100,8 @@ public:
bool operator==(Origin const& other) const { return is_same_origin(other); }
private:
Origin() = default;
struct State {
Optional<String> scheme;
Host host;

View file

@ -345,14 +345,14 @@ Origin URL::origin() const
// 3. If pathURL is failure, then return a new opaque origin.
if (!path_url.has_value())
return Origin {};
return Origin::create_opaque();
// 4. If pathURLs scheme is "http", "https", or "file", then return pathURLs origin.
if (path_url->scheme().is_one_of("http"sv, "https"sv, "file"sv))
return path_url->origin();
// 5. Return a new opaque origin.
return Origin {};
return Origin::create_opaque();
}
// -> "ftp"
@ -375,7 +375,7 @@ Origin URL::origin() const
// -> Otherwise
// Return a new opaque origin.
return Origin {};
return Origin::create_opaque();
}
bool URL::equals(URL const& other, ExcludeFragment exclude_fragments) const