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

@ -201,7 +201,7 @@ SerializedPolicy Policy::serialize() const
.directives = move(serialized_directives),
.disposition = m_disposition,
.source = m_source,
.self_origin = m_self_origin,
.self_origin = m_self_origin.value(),
.pre_parsed_policy_string = m_pre_parsed_policy_string,
};
}

View file

@ -45,7 +45,7 @@ public:
[[nodiscard]] Vector<GC::Ref<Directives::Directive>> const& directives() const { return m_directives; }
[[nodiscard]] Disposition disposition() const { return m_disposition; }
[[nodiscard]] Source source() const { return m_source; }
[[nodiscard]] URL::Origin const& self_origin() const { return m_self_origin; }
[[nodiscard]] URL::Origin const& self_origin() const { return m_self_origin.value(); }
[[nodiscard]] String const& pre_parsed_policy_string(Badge<Violation>) const { return m_pre_parsed_policy_string; }
[[nodiscard]] bool contains_directive_with_name(StringView name) const;
@ -81,7 +81,7 @@ private:
// Spec Note: This is needed to facilitate the 'self' checks of local scheme documents/workers that have inherited
// their policy but have an opaque origin. Most of the time this will simply be the environment settings
// objects origin.
URL::Origin m_self_origin;
Optional<URL::Origin> m_self_origin;
// This is used for reporting which policy was violated. It's not exactly specified, only linking to an ABNF grammar
// definition. WebKit and Blink return the original string that was parsed, whereas Firefox seems to try and return

View file

@ -25,15 +25,13 @@ ErrorOr<void> encode(Encoder& encoder, Web::ContentSecurityPolicy::SerializedPol
template<>
ErrorOr<Web::ContentSecurityPolicy::SerializedPolicy> decode(Decoder& decoder)
{
Web::ContentSecurityPolicy::SerializedPolicy serialized_policy {};
serialized_policy.directives = TRY(decoder.decode<Vector<Web::ContentSecurityPolicy::Directives::SerializedDirective>>());
serialized_policy.disposition = TRY(decoder.decode<Web::ContentSecurityPolicy::Policy::Disposition>());
serialized_policy.source = TRY(decoder.decode<Web::ContentSecurityPolicy::Policy::Source>());
serialized_policy.self_origin = TRY(decoder.decode<URL::Origin>());
serialized_policy.pre_parsed_policy_string = TRY(decoder.decode<String>());
return serialized_policy;
return Web::ContentSecurityPolicy::SerializedPolicy {
.directives = TRY(decoder.decode<Vector<Web::ContentSecurityPolicy::Directives::SerializedDirective>>()),
.disposition = TRY(decoder.decode<Web::ContentSecurityPolicy::Policy::Disposition>()),
.source = TRY(decoder.decode<Web::ContentSecurityPolicy::Policy::Source>()),
.self_origin = TRY(decoder.decode<URL::Origin>()),
.pre_parsed_policy_string = TRY(decoder.decode<String>()),
};
}
}