From dc6fb43d261beaf0899b2e4cd53589275b28cf76 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 24 Sep 2022 00:29:45 +0100 Subject: [PATCH] LibWeb: Add referrer policy to Fetch::Infrastructure::Request The enum is in its own directory and namespace as there's a standalone spec for it, that will later also house AOs. - https://w3c.github.io/webappsec-referrer-policy/ - https://www.w3.org/TR/referrer-policy/ --- .../Fetch/Infrastructure/HTTP/Requests.h | 6 ++++- Userland/Libraries/LibWeb/Forward.h | 4 ++++ .../LibWeb/ReferrerPolicy/ReferrerPolicy.h | 23 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h index cb92d96ff2..3ac271c361 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h @@ -257,6 +257,9 @@ public: [[nodiscard]] ReferrerType const& referrer() const { return m_referrer; } void set_referrer(ReferrerType referrer) { m_referrer = move(referrer); } + [[nodiscard]] Optional const& referrer_policy() const { return m_referrer_policy; } + void set_referrer_policy(Optional 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; } @@ -364,7 +367,8 @@ private: ReferrerType m_referrer { Referrer::Client }; // https://fetch.spec.whatwg.org/#concept-request-referrer-policy - // FIXME: A request has an associated referrer policy, which is a referrer policy. Unless stated otherwise it is the empty string. + // A request has an associated referrer policy, which is a referrer policy. Unless stated otherwise it is the empty string. + Optional m_referrer_policy; // 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 stated otherwise, it is "no-cors". diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 3345a23fbb..8971d486f6 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -357,6 +357,10 @@ namespace Web::Platform { class Timer; } +namespace Web::ReferrerPolicy { +enum class ReferrerPolicy; +} + namespace Web::RequestIdleCallback { class IdleDeadline; } diff --git a/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h b/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h new file mode 100644 index 0000000000..4598cdc9b2 --- /dev/null +++ b/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Web::ReferrerPolicy { + +// https://w3c.github.io/webappsec-referrer-policy/#enumdef-referrerpolicy +enum class ReferrerPolicy { + NoReferrer, + NoReferrerWhenDowngrade, + SameOrigin, + Origin, + StrictOrigin, + OriginWhenCrossOrigin, + StrictOriginWhenCrossOrigin, + UnsafeURL, +}; + +}