mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 05:44:58 +00:00
LibWeb: Consistently use the EmptyString state of ReferrerPolicy
We previously used an empty optional to denote that a ReferrerPolicy is in the default empty string state. However, later additions added an explicit EmptyString state. This patch moves all users to the explicit state, and stops using `Optional<ReferrerPolicy>` everywhere except for when an option not being passed from JavaScript has meaning.
This commit is contained in:
parent
637f2f2ed6
commit
c79bac70f4
12 changed files with 23 additions and 24 deletions
|
@ -23,11 +23,11 @@ namespace Web::Fetch {
|
|||
// - Fetch has use-cases beyond its JS interface, so having to refer to the 'Bindings' namespace
|
||||
// constantly is irritating.
|
||||
|
||||
Optional<ReferrerPolicy::ReferrerPolicy> from_bindings_enum(Bindings::ReferrerPolicy referrer_policy)
|
||||
ReferrerPolicy::ReferrerPolicy from_bindings_enum(Bindings::ReferrerPolicy referrer_policy)
|
||||
{
|
||||
switch (referrer_policy) {
|
||||
case Bindings::ReferrerPolicy::Empty:
|
||||
return {};
|
||||
return ReferrerPolicy::ReferrerPolicy::EmptyString;
|
||||
case Bindings::ReferrerPolicy::NoReferrer:
|
||||
return ReferrerPolicy::ReferrerPolicy::NoReferrer;
|
||||
case Bindings::ReferrerPolicy::NoReferrerWhenDowngrade:
|
||||
|
@ -113,11 +113,11 @@ Infrastructure::Request::RedirectMode from_bindings_enum(Bindings::RequestRedire
|
|||
}
|
||||
}
|
||||
|
||||
Bindings::ReferrerPolicy to_bindings_enum(Optional<ReferrerPolicy::ReferrerPolicy> const& referrer_policy)
|
||||
Bindings::ReferrerPolicy to_bindings_enum(ReferrerPolicy::ReferrerPolicy referrer_policy)
|
||||
{
|
||||
if (!referrer_policy.has_value())
|
||||
switch (referrer_policy) {
|
||||
case ReferrerPolicy::ReferrerPolicy::EmptyString:
|
||||
return Bindings::ReferrerPolicy::Empty;
|
||||
switch (*referrer_policy) {
|
||||
case ReferrerPolicy::ReferrerPolicy::NoReferrer:
|
||||
return Bindings::ReferrerPolicy::NoReferrer;
|
||||
case ReferrerPolicy::ReferrerPolicy::NoReferrerWhenDowngrade:
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
|
||||
namespace Web::Fetch {
|
||||
|
||||
[[nodiscard]] Optional<ReferrerPolicy::ReferrerPolicy> from_bindings_enum(Bindings::ReferrerPolicy);
|
||||
[[nodiscard]] ReferrerPolicy::ReferrerPolicy from_bindings_enum(Bindings::ReferrerPolicy);
|
||||
[[nodiscard]] Infrastructure::Request::Mode from_bindings_enum(Bindings::RequestMode);
|
||||
[[nodiscard]] Infrastructure::Request::CredentialsMode from_bindings_enum(Bindings::RequestCredentials);
|
||||
[[nodiscard]] Infrastructure::Request::CacheMode from_bindings_enum(Bindings::RequestCache);
|
||||
[[nodiscard]] Infrastructure::Request::RedirectMode from_bindings_enum(Bindings::RequestRedirect);
|
||||
|
||||
[[nodiscard]] Bindings::ReferrerPolicy to_bindings_enum(Optional<ReferrerPolicy::ReferrerPolicy> const&);
|
||||
[[nodiscard]] Bindings::ReferrerPolicy to_bindings_enum(ReferrerPolicy::ReferrerPolicy);
|
||||
[[nodiscard]] Bindings::RequestDestination to_bindings_enum(Optional<Infrastructure::Request::Destination> const&);
|
||||
[[nodiscard]] Bindings::RequestMode to_bindings_enum(Infrastructure::Request::Mode);
|
||||
[[nodiscard]] Bindings::RequestCredentials to_bindings_enum(Infrastructure::Request::CredentialsMode);
|
||||
|
|
|
@ -236,7 +236,7 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
|
|||
|
||||
// 8. If request’s referrer policy is the empty string, then set request’s referrer policy to request’s policy
|
||||
// container’s referrer policy.
|
||||
if (!request->referrer_policy().has_value()) {
|
||||
if (request->referrer_policy() == ReferrerPolicy::ReferrerPolicy::EmptyString) {
|
||||
VERIFY(request->policy_container().has<HTML::PolicyContainer>());
|
||||
request->set_referrer_policy(request->policy_container().get<HTML::PolicyContainer>().referrer_policy);
|
||||
}
|
||||
|
|
|
@ -309,8 +309,8 @@ ErrorOr<void> Request::add_origin_header()
|
|||
// 3. Otherwise, if request’s method is neither `GET` nor `HEAD`, then:
|
||||
else if (!StringView { m_method }.is_one_of("GET"sv, "HEAD"sv)) {
|
||||
// 1. If request’s mode is not "cors", then switch on request’s referrer policy:
|
||||
if (m_mode != Mode::CORS && m_referrer_policy.has_value()) {
|
||||
switch (*m_referrer_policy) {
|
||||
if (m_mode != Mode::CORS) {
|
||||
switch (m_referrer_policy) {
|
||||
// -> "no-referrer"
|
||||
case ReferrerPolicy::ReferrerPolicy::NoReferrer:
|
||||
// Set serializedOrigin to `null`.
|
||||
|
|
|
@ -273,8 +273,8 @@ public:
|
|||
[[nodiscard]] ReferrerType const& referrer() const { return m_referrer; }
|
||||
void set_referrer(ReferrerType referrer) { m_referrer = move(referrer); }
|
||||
|
||||
[[nodiscard]] Optional<ReferrerPolicy::ReferrerPolicy> const& referrer_policy() const { return m_referrer_policy; }
|
||||
void set_referrer_policy(Optional<ReferrerPolicy::ReferrerPolicy> referrer_policy) { m_referrer_policy = move(referrer_policy); }
|
||||
[[nodiscard]] ReferrerPolicy::ReferrerPolicy const& referrer_policy() const { return m_referrer_policy; }
|
||||
void set_referrer_policy(ReferrerPolicy::ReferrerPolicy referrer_policy) { m_referrer_policy = move(referrer_policy); }
|
||||
|
||||
[[nodiscard]] ResponseTainting response_tainting() const { return m_response_tainting; }
|
||||
void set_response_tainting(ResponseTainting response_tainting) { m_response_tainting = response_tainting; }
|
||||
|
@ -420,7 +420,7 @@ private:
|
|||
// https://fetch.spec.whatwg.org/#concept-request-referrer-policy
|
||||
// A request has an associated referrer policy, which is a referrer policy. Unless stated otherwise it is the empty
|
||||
// string.
|
||||
Optional<ReferrerPolicy::ReferrerPolicy> m_referrer_policy;
|
||||
ReferrerPolicy::ReferrerPolicy m_referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString };
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-request-mode
|
||||
// A request has an associated mode, which is "same-origin", "cors", "no-cors", "navigate", or "websocket". Unless
|
||||
|
|
|
@ -559,7 +559,7 @@ after_step_7:
|
|||
request->set_initiator(Fetch::Infrastructure::Request::Initiator::ImageSet);
|
||||
|
||||
// 21. Set request's referrer policy to the current state of the element's referrerpolicy attribute.
|
||||
request->set_referrer_policy(ReferrerPolicy::from_string(get_attribute_value(HTML::AttributeNames::referrerpolicy)));
|
||||
request->set_referrer_policy(ReferrerPolicy::from_string(get_attribute_value(HTML::AttributeNames::referrerpolicy)).value_or(ReferrerPolicy::ReferrerPolicy::EmptyString));
|
||||
|
||||
// FIXME: 22. Set request's priority to the current state of the element's fetchpriority attribute.
|
||||
|
||||
|
@ -774,7 +774,7 @@ void HTMLImageElement::react_to_changes_in_the_environment()
|
|||
request->set_initiator(Fetch::Infrastructure::Request::Initiator::ImageSet);
|
||||
|
||||
// 3. Set request's referrer policy to the current state of the element's referrerpolicy attribute.
|
||||
request->set_referrer_policy(ReferrerPolicy::from_string(get_attribute_value(HTML::AttributeNames::referrerpolicy)));
|
||||
request->set_referrer_policy(ReferrerPolicy::from_string(get_attribute_value(HTML::AttributeNames::referrerpolicy)).value_or(ReferrerPolicy::ReferrerPolicy::EmptyString));
|
||||
|
||||
// FIXME: 4. Set request's priority to the current state of the element's fetchpriority attribute.
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ private:
|
|||
CORSSettingAttribute crossorigin { CORSSettingAttribute::NoCORS };
|
||||
// referrer policy (default the empty string)
|
||||
// A referrer policy
|
||||
Optional<ReferrerPolicy::ReferrerPolicy> referrer_policy {};
|
||||
ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString };
|
||||
// FIXME: source set (default null)
|
||||
// Null or a source set
|
||||
// base URL
|
||||
|
|
|
@ -54,10 +54,7 @@ void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String
|
|||
if (name == HTML::AttributeNames::crossorigin) {
|
||||
m_crossorigin = cors_setting_attribute_from_keyword(value);
|
||||
} else if (name == HTML::AttributeNames::referrerpolicy) {
|
||||
if (!value.has_value())
|
||||
m_referrer_policy.clear();
|
||||
else
|
||||
m_referrer_policy = ReferrerPolicy::from_string(*value);
|
||||
m_referrer_policy = ReferrerPolicy::from_string(value.value_or(""_string)).value_or(ReferrerPolicy::ReferrerPolicy::EmptyString);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ private:
|
|||
CORSSettingAttribute m_crossorigin { CORSSettingAttribute::NoCORS };
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#attr-script-referrerpolicy
|
||||
Optional<ReferrerPolicy::ReferrerPolicy> m_referrer_policy;
|
||||
ReferrerPolicy::ReferrerPolicy m_referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString };
|
||||
|
||||
bool m_failed_to_load { false };
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ struct ScriptFetchOptions {
|
|||
Fetch::Infrastructure::Request::CredentialsMode credentials_mode { Fetch::Infrastructure::Request::CredentialsMode::SameOrigin };
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-referrer-policy
|
||||
Optional<ReferrerPolicy::ReferrerPolicy> referrer_policy;
|
||||
ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::ReferrerPolicy::EmptyString };
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-fetch-options-render-blocking
|
||||
bool render_blocking { false };
|
||||
|
|
|
@ -82,8 +82,8 @@ Optional<URL> determine_requests_referrer(Fetch::Infrastructure::Request const&
|
|||
|
||||
// 8. Execute the statements corresponding to the value of policy:
|
||||
// Note: If request’s referrer policy is the empty string, Fetch will not call into this algorithm.
|
||||
VERIFY(policy.has_value());
|
||||
switch (*policy) {
|
||||
VERIFY(policy != ReferrerPolicy::EmptyString);
|
||||
switch (policy) {
|
||||
// "no-referrer"
|
||||
case ReferrerPolicy::NoReferrer:
|
||||
// Return no referrer
|
||||
|
|
|
@ -35,6 +35,8 @@ StringView to_string(ReferrerPolicy referrer_policy)
|
|||
|
||||
Optional<ReferrerPolicy> from_string(StringView string)
|
||||
{
|
||||
if (string.is_empty())
|
||||
return ReferrerPolicy::EmptyString;
|
||||
if (string.equals_ignoring_ascii_case("no-referrer"sv))
|
||||
return ReferrerPolicy::NoReferrer;
|
||||
if (string.equals_ignoring_ascii_case("no-referrer-when-downgrade"sv))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue