2021-04-24 13:54:24 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2021-04-24 13:54:24 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-03-05 10:33:56 +01:00
|
|
|
#include <AK/FlyString.h>
|
2021-04-24 13:54:24 +02:00
|
|
|
#include <LibWeb/DOM/Event.h>
|
2025-07-19 19:35:33 -07:00
|
|
|
#include <LibWeb/Export.h>
|
2021-04-24 13:54:24 +02:00
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
2023-11-06 20:11:58 +00:00
|
|
|
// FIXME: Include ServiceWorker
|
2024-11-15 04:01:23 +13:00
|
|
|
using MessageEventSource = Variant<GC::Root<WindowProxy>, GC::Root<MessagePort>>;
|
2023-11-06 20:11:58 +00:00
|
|
|
|
2021-10-01 18:39:03 +03:00
|
|
|
struct MessageEventInit : public DOM::EventInit {
|
|
|
|
JS::Value data { JS::js_null() };
|
2023-11-06 21:14:31 +00:00
|
|
|
String origin {};
|
|
|
|
String last_event_id {};
|
2023-11-06 20:11:58 +00:00
|
|
|
Optional<MessageEventSource> source;
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Root<MessagePort>> ports;
|
2021-10-01 18:39:03 +03:00
|
|
|
};
|
|
|
|
|
2025-07-19 19:35:33 -07:00
|
|
|
class WEB_API MessageEvent : public DOM::Event {
|
2022-08-28 13:42:07 +02:00
|
|
|
WEB_PLATFORM_OBJECT(MessageEvent, DOM::Event);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(MessageEvent);
|
2022-08-08 22:29:40 +02:00
|
|
|
|
2021-04-24 13:54:24 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<MessageEvent> create(JS::Realm&, FlyString const& event_name, MessageEventInit const& = {});
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<MessageEvent>> construct_impl(JS::Realm&, FlyString const& event_name, MessageEventInit const&);
|
2021-04-24 13:54:24 +02:00
|
|
|
|
2023-03-05 10:33:56 +01:00
|
|
|
MessageEvent(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init);
|
2022-08-08 22:29:40 +02:00
|
|
|
virtual ~MessageEvent() override;
|
2021-04-24 13:54:24 +02:00
|
|
|
|
2022-08-08 22:29:40 +02:00
|
|
|
JS::Value data() const { return m_data; }
|
2023-03-05 10:33:56 +01:00
|
|
|
String const& origin() const { return m_origin; }
|
|
|
|
String const& last_event_id() const { return m_last_event_id; }
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<JS::Object> ports() const;
|
|
|
|
Variant<GC::Root<WindowProxy>, GC::Root<MessagePort>, Empty> source() const;
|
2021-04-24 13:54:24 +02:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
void init_message_event(String const& type, bool bubbles, bool cancelable, JS::Value data, String const& origin, String const& last_event_id, Optional<MessageEventSource> source, Vector<GC::Root<MessagePort>> const& ports);
|
2024-07-09 19:43:51 +01:00
|
|
|
|
2022-08-08 22:29:40 +02:00
|
|
|
private:
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-08 22:29:40 +02:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-04-24 13:54:24 +02:00
|
|
|
|
2022-08-08 22:29:40 +02:00
|
|
|
JS::Value m_data;
|
2023-03-05 10:33:56 +01:00
|
|
|
String m_origin;
|
|
|
|
String m_last_event_id;
|
2023-11-06 20:11:58 +00:00
|
|
|
Optional<MessageEventSource> m_source;
|
2024-11-15 04:01:23 +13:00
|
|
|
Vector<GC::Ref<JS::Object>> m_ports;
|
|
|
|
mutable GC::Ptr<JS::Array> m_ports_array;
|
2021-04-24 13:54:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|