2023-02-03 23:50:05 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibWeb/Bindings/FormDataPrototype.h>
|
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
#include <LibWeb/HTML/HTMLFormElement.h>
|
|
|
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
2023-08-28 18:38:05 +03:00
|
|
|
#include <LibWeb/XHR/FormDataEntry.h>
|
2023-02-03 23:50:05 +03:00
|
|
|
|
|
|
|
namespace Web::XHR {
|
|
|
|
|
|
|
|
// https://xhr.spec.whatwg.org/#interface-formdata
|
|
|
|
class FormData : public Bindings::PlatformObject {
|
|
|
|
WEB_PLATFORM_OBJECT(FormData, Bindings::PlatformObject);
|
2023-11-19 21:47:52 +03:00
|
|
|
JS_DECLARE_ALLOCATOR(FormData);
|
2023-02-03 23:50:05 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~FormData() override;
|
|
|
|
|
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> construct_impl(JS::Realm&, Optional<JS::NonnullGCPtr<HTML::HTMLFormElement>> form = {});
|
2023-02-17 21:57:58 +03:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<FormData>> construct_impl(JS::Realm&, Vector<FormDataEntry> entry_list);
|
2023-02-03 23:50:05 +03:00
|
|
|
|
2023-02-17 21:57:58 +03:00
|
|
|
WebIDL::ExceptionOr<void> append(String const& name, String const& value);
|
|
|
|
WebIDL::ExceptionOr<void> append(String const& name, JS::NonnullGCPtr<FileAPI::Blob> const& blob_value, Optional<String> const& filename = {});
|
|
|
|
void delete_(String const& name);
|
|
|
|
Variant<JS::Handle<FileAPI::File>, String, Empty> get(String const& name);
|
|
|
|
WebIDL::ExceptionOr<Vector<FormDataEntryValue>> get_all(String const& name);
|
|
|
|
bool has(String const& name);
|
|
|
|
WebIDL::ExceptionOr<void> set(String const& name, String const& value);
|
|
|
|
WebIDL::ExceptionOr<void> set(String const& name, JS::NonnullGCPtr<FileAPI::Blob> const& blob_value, Optional<String> const& filename = {});
|
2023-02-03 23:50:05 +03:00
|
|
|
|
2023-04-04 23:34:47 +03:00
|
|
|
Vector<FormDataEntry> const& entry_list() const { return m_entry_list; }
|
|
|
|
|
2023-03-05 19:29:11 +03:00
|
|
|
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, FormDataEntryValue const&)>;
|
|
|
|
JS::ThrowCompletionOr<void> for_each(ForEachCallback);
|
|
|
|
|
2023-02-03 23:50:05 +03:00
|
|
|
private:
|
2023-03-05 19:29:11 +03:00
|
|
|
friend class FormDataIterator;
|
|
|
|
|
2023-02-17 21:57:58 +03:00
|
|
|
explicit FormData(JS::Realm&, Vector<FormDataEntry> entry_list = {});
|
2023-02-03 23:50:05 +03:00
|
|
|
|
2023-08-07 09:41:28 +03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-02-03 23:50:05 +03:00
|
|
|
|
|
|
|
WebIDL::ExceptionOr<void> append_impl(String const& name, Variant<JS::NonnullGCPtr<FileAPI::Blob>, String> const& value, Optional<String> const& filename = {});
|
|
|
|
WebIDL::ExceptionOr<void> set_impl(String const& name, Variant<JS::NonnullGCPtr<FileAPI::Blob>, String> const& value, Optional<String> const& filename = {});
|
|
|
|
|
2023-02-17 21:57:58 +03:00
|
|
|
Vector<FormDataEntry> m_entry_list;
|
2023-02-03 23:50:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|