mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 19:57:45 +03:00
LibWeb: Implement 'Strip url for use as a referrer' AO
This commit is contained in:
parent
6c1a9b28f1
commit
1e5cac9e9c
Notes:
sideshowbarker
2024-07-17 18:46:30 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/1e5cac9e9c Pull-request: https://github.com/SerenityOS/serenity/pull/15795 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/davidot ✅
@ -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
|
||||
|
@ -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…
Reference in New Issue
Block a user