URLSearchParams.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/URL.h>
  8. #include <AK/Vector.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. namespace Web::URL {
  11. struct QueryParam {
  12. String name;
  13. String value;
  14. };
  15. ErrorOr<String> url_encode(Vector<QueryParam> const&, AK::URL::PercentEncodeSet);
  16. ErrorOr<Vector<QueryParam>> url_decode(StringView);
  17. class URLSearchParams : public Bindings::PlatformObject {
  18. WEB_PLATFORM_OBJECT(URLSearchParams, Bindings::PlatformObject);
  19. public:
  20. static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> create(JS::Realm&, Vector<QueryParam> list);
  21. static WebIDL::ExceptionOr<JS::NonnullGCPtr<URLSearchParams>> construct_impl(JS::Realm&, Variant<Vector<Vector<String>>, OrderedHashMap<String, String>, String> const& init);
  22. virtual ~URLSearchParams() override;
  23. size_t size() const;
  24. WebIDL::ExceptionOr<void> append(String const& name, String const& value);
  25. WebIDL::ExceptionOr<void> delete_(String const& name);
  26. Optional<String> get(String const& name);
  27. WebIDL::ExceptionOr<Vector<String>> get_all(String const& name);
  28. bool has(String const& name);
  29. WebIDL::ExceptionOr<void> set(String const& name, String const& value);
  30. WebIDL::ExceptionOr<void> sort();
  31. WebIDL::ExceptionOr<String> to_string() const;
  32. using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, String const&)>;
  33. JS::ThrowCompletionOr<void> for_each(ForEachCallback);
  34. private:
  35. friend class URL;
  36. friend class URLSearchParamsIterator;
  37. URLSearchParams(JS::Realm&, Vector<QueryParam> list);
  38. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  39. virtual void visit_edges(Cell::Visitor&) override;
  40. WebIDL::ExceptionOr<void> update();
  41. Vector<QueryParam> m_list;
  42. JS::GCPtr<URL> m_url;
  43. };
  44. }