summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/ReferrerPolicy/ReferrerPolicy.cpp
blob: 51309409c59c78c1412a883c5dc07a9c34a969d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 {};
}

}