LibWeb: Implement 'Strip url for use as a referrer' AO

This commit is contained in:
Linus Groh 2022-10-13 19:10:27 +02:00
parent 6c1a9b28f1
commit 1e5cac9e9c
Notes: sideshowbarker 2024-07-17 18:46:30 +09:00
3 changed files with 68 additions and 0 deletions

View File

@ -377,6 +377,7 @@ set(SOURCES
Platform/ImageCodecPlugin.cpp
Platform/Timer.cpp
Platform/TimerSerenity.cpp
ReferrerPolicy/AbstractOperations.cpp
RequestIdleCallback/IdleDeadline.cpp
ResizeObserver/ResizeObserver.cpp
SecureContexts/AbstractOperations.cpp

View File

@ -0,0 +1,47 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/URL.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Fetch/Infrastructure/URL.h>
#include <LibWeb/ReferrerPolicy/AbstractOperations.h>
#include <LibWeb/URL/URL.h>
namespace Web::ReferrerPolicy {
Optional<AK::URL> strip_url_for_use_as_referrer(Optional<AK::URL> url, OriginOnly origin_only)
{
// 1. If url is null, return no referrer.
if (!url.has_value())
return {};
// 2. If urls scheme is a local scheme, then return no referrer.
if (Fetch::Infrastructure::LOCAL_SCHEMES.span().contains_slow(url->scheme()))
return {};
// 3. Set urls username to the empty string.
url->set_username(""sv);
// 4. Set urls password to the empty string.
url->set_password(""sv);
// 5. Set urls fragment to null.
url->set_fragment({});
// 6. If the origin-only flag is true, then:
if (origin_only == OriginOnly::Yes) {
// 1. Set urls path to « the empty string ».
url->set_paths({ ""sv });
// 2. Set urls query to null.
url->set_query({});
}
// 7. Return url.
return url;
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
namespace Web::ReferrerPolicy {
enum class OriginOnly {
Yes,
No,
};
Optional<AK::URL> strip_url_for_use_as_referrer(Optional<AK::URL>, OriginOnly origin_only = OriginOnly::No);
}