2021-09-13 01:00:47 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-13 21:50:05 +03:00
|
|
|
#include <AK/Vector.h>
|
2024-03-18 16:22:27 +13:00
|
|
|
#include <LibURL/URL.h>
|
2022-09-25 17:03:42 +01:00
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2024-02-11 19:48:56 +13:00
|
|
|
namespace Web::DOMURL {
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2021-09-13 21:50:05 +03:00
|
|
|
struct QueryParam {
|
2023-03-01 20:10:01 +01:00
|
|
|
String name;
|
|
|
|
String value;
|
2021-09-13 21:50:05 +03:00
|
|
|
};
|
2024-08-11 00:24:54 +12:00
|
|
|
String url_encode(Vector<QueryParam> const&, StringView encoding = "UTF-8"sv);
|
|
|
|
Vector<QueryParam> url_decode(StringView);
|
2021-09-13 21:50:05 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
class URLSearchParams : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(URLSearchParams, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(URLSearchParams);
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static GC::Ref<URLSearchParams> create(JS::Realm&, StringView);
|
|
|
|
static GC::Ref<URLSearchParams> create(JS::Realm&, Vector<QueryParam> list);
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2022-09-04 14:04:42 +02:00
|
|
|
virtual ~URLSearchParams() override;
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2023-02-23 13:32:08 +00:00
|
|
|
size_t size() const;
|
2024-08-11 00:24:54 +12:00
|
|
|
void append(String const& name, String const& value);
|
|
|
|
void delete_(String const& name, Optional<String> const& value = {});
|
2023-03-01 20:10:01 +01:00
|
|
|
Optional<String> get(String const& name);
|
2024-08-11 00:24:54 +12:00
|
|
|
Vector<String> get_all(String const& name);
|
2024-08-10 23:52:54 +12:00
|
|
|
bool has(String const& name, Optional<String> const& value = {});
|
2024-08-11 00:24:54 +12:00
|
|
|
void set(String const& name, String const& value);
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2024-08-11 00:24:54 +12:00
|
|
|
void sort();
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2024-08-11 00:24:54 +12:00
|
|
|
String to_string() const;
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2023-03-01 20:10:01 +01:00
|
|
|
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, String const&)>;
|
2021-10-31 10:03:29 -04:00
|
|
|
JS::ThrowCompletionOr<void> for_each(ForEachCallback);
|
2021-09-28 02:11:55 +03:00
|
|
|
|
2021-09-13 01:00:47 +03:00
|
|
|
private:
|
2024-02-11 19:48:56 +13:00
|
|
|
friend class DOMURL;
|
2021-09-28 02:11:55 +03:00
|
|
|
friend class URLSearchParamsIterator;
|
2021-09-14 00:10:22 +03:00
|
|
|
|
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-09-25 18:11:21 -06:00
|
|
|
URLSearchParams(JS::Realm&, Vector<QueryParam> list);
|
2022-09-04 14:04:42 +02:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-09-04 14:04:42 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-09-13 01:00:47 +03:00
|
|
|
|
2024-08-11 00:24:54 +12:00
|
|
|
void update();
|
2021-09-13 01:00:47 +03:00
|
|
|
|
|
|
|
Vector<QueryParam> m_list;
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ptr<DOMURL> m_url;
|
2021-09-13 01:00:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|