mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
LibWeb: Implement 'Strip url for use as a referrer' AO
This commit is contained in:
parent
6c1a9b28f1
commit
1e5cac9e9c
3 changed files with 68 additions and 0 deletions
|
@ -377,6 +377,7 @@ set(SOURCES
|
||||||
Platform/ImageCodecPlugin.cpp
|
Platform/ImageCodecPlugin.cpp
|
||||||
Platform/Timer.cpp
|
Platform/Timer.cpp
|
||||||
Platform/TimerSerenity.cpp
|
Platform/TimerSerenity.cpp
|
||||||
|
ReferrerPolicy/AbstractOperations.cpp
|
||||||
RequestIdleCallback/IdleDeadline.cpp
|
RequestIdleCallback/IdleDeadline.cpp
|
||||||
ResizeObserver/ResizeObserver.cpp
|
ResizeObserver/ResizeObserver.cpp
|
||||||
SecureContexts/AbstractOperations.cpp
|
SecureContexts/AbstractOperations.cpp
|
||||||
|
|
|
@ -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 url’s scheme is a local scheme, then return no referrer.
|
||||||
|
if (Fetch::Infrastructure::LOCAL_SCHEMES.span().contains_slow(url->scheme()))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 3. Set url’s username to the empty string.
|
||||||
|
url->set_username(""sv);
|
||||||
|
|
||||||
|
// 4. Set url’s password to the empty string.
|
||||||
|
url->set_password(""sv);
|
||||||
|
|
||||||
|
// 5. Set url’s fragment to null.
|
||||||
|
url->set_fragment({});
|
||||||
|
|
||||||
|
// 6. If the origin-only flag is true, then:
|
||||||
|
if (origin_only == OriginOnly::Yes) {
|
||||||
|
// 1. Set url’s path to « the empty string ».
|
||||||
|
url->set_paths({ ""sv });
|
||||||
|
|
||||||
|
// 2. Set url’s query to null.
|
||||||
|
url->set_query({});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. Return url.
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue