diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-29 12:46:50 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-31 11:36:41 +0100 |
commit | 88d64fcb553fa2c95b0153649d5fcc1db99d75f8 (patch) | |
tree | 6a514eda26dc0e0f28449a18c99f28bc075a0adb /Userland/Libraries/LibWeb/ReferrerPolicy | |
parent | 0c19d3aa588a039f2f22953a703f1e66384e65ce (diff) | |
download | serenity-88d64fcb553fa2c95b0153649d5fcc1db99d75f8.zip |
LibWeb: Add HTMLAnchorElement.referrerPolicy property
Diffstat (limited to 'Userland/Libraries/LibWeb/ReferrerPolicy')
-rw-r--r-- | Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.cpp | 55 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h | 6 |
2 files changed, 61 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.cpp b/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.cpp new file mode 100644 index 0000000000..51309409c5 --- /dev/null +++ b/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/ReferrerPolicy/ReferrerPolicy.h> + +namespace Web::ReferrerPolicy { + +StringView to_string(ReferrerPolicy referrer_policy) +{ + switch (referrer_policy) { + case ReferrerPolicy::NoReferrer: + return "no-referrer"sv; + case ReferrerPolicy::NoReferrerWhenDowngrade: + return "no-referrer-when-downgrade"sv; + case ReferrerPolicy::SameOrigin: + return "same-origin"sv; + case ReferrerPolicy::Origin: + return "origin"sv; + case ReferrerPolicy::StrictOrigin: + return "strict-origin"sv; + case ReferrerPolicy::OriginWhenCrossOrigin: + return "origin-when-cross-origin"sv; + case ReferrerPolicy::StrictOriginWhenCrossOrigin: + return "strict-origin-when-cross-origin"sv; + case ReferrerPolicy::UnsafeURL: + return "unsafe-url"sv; + } + VERIFY_NOT_REACHED(); +} + +Optional<ReferrerPolicy> from_string(StringView string) +{ + if (string.equals_ignoring_ascii_case("no-referrer"sv)) + return ReferrerPolicy::NoReferrer; + if (string.equals_ignoring_ascii_case("no-referrer-when-downgrade"sv)) + return ReferrerPolicy::NoReferrerWhenDowngrade; + if (string.equals_ignoring_ascii_case("same-origin"sv)) + return ReferrerPolicy::SameOrigin; + if (string.equals_ignoring_ascii_case("origin"sv)) + return ReferrerPolicy::Origin; + if (string.equals_ignoring_ascii_case("strict-origin"sv)) + return ReferrerPolicy::StrictOrigin; + if (string.equals_ignoring_ascii_case("origin-when-cross-origin"sv)) + return ReferrerPolicy::OriginWhenCrossOrigin; + if (string.equals_ignoring_ascii_case("strict-origin-when-cross-origin"sv)) + return ReferrerPolicy::StrictOriginWhenCrossOrigin; + if (string.equals_ignoring_ascii_case("unsafe-url"sv)) + return ReferrerPolicy::UnsafeURL; + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h b/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h index dc440e33d2..6679272e3d 100644 --- a/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h +++ b/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.h @@ -6,6 +6,9 @@ #pragma once +#include <AK/Optional.h> +#include <AK/StringView.h> + namespace Web::ReferrerPolicy { // https://w3c.github.io/webappsec-referrer-policy/#enumdef-referrerpolicy @@ -24,4 +27,7 @@ enum class ReferrerPolicy { // The default referrer policy is "strict-origin-when-cross-origin". constexpr auto DEFAULT_REFERRER_POLICY = ReferrerPolicy::StrictOriginWhenCrossOrigin; +StringView to_string(ReferrerPolicy); +Optional<ReferrerPolicy> from_string(StringView); + } |