/* * Copyright (c) 2021, Idan Horowitz * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::URL { struct QueryParam { String name; String value; }; String url_encode(Vector const&, AK::URL::PercentEncodeSet); Vector url_decode(StringView); class URLSearchParams : public Bindings::Wrappable , public RefCounted { public: using WrapperType = Bindings::URLSearchParamsWrapper; static NonnullRefPtr create(Vector list) { return adopt_ref(*new URLSearchParams(move(list))); } static DOM::ExceptionOr> create_with_global_object(Bindings::WindowObject&, Variant>, OrderedHashMap, String> const& init); void append(String const& name, String const& value); void delete_(String const& name); String get(String const& name); Vector get_all(String const& name); bool has(String const& name); void set(String const& name, String const& value); void sort(); String to_string() const; using ForEachCallback = Function(String const&, String const&)>; JS::ThrowCompletionOr for_each(ForEachCallback); private: friend class URL; friend class URLSearchParamsIterator; explicit URLSearchParams(Vector list) : m_list(move(list)) {}; void update(); Vector m_list; WeakPtr m_url; }; } namespace Web::Bindings { URLSearchParamsWrapper* wrap(JS::GlobalObject&, URL::URLSearchParams&); }