2021-04-24 08:54:24 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2026-02-16 11:28:08 -03:00
|
|
|
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
|
2021-04-24 08:54:24 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-03-05 06:33:56 -03:00
|
|
|
#include <AK/FlyString.h>
|
2026-05-20 15:58:46 -03:00
|
|
|
#include <LibGC/RootVector.h>
|
2021-04-24 08:54:24 -03:00
|
|
|
#include <LibWeb/DOM/Event.h>
|
2025-07-19 23:35:33 -03:00
|
|
|
#include <LibWeb/Export.h>
|
2021-04-24 08:54:24 -03:00
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
2023-11-06 17:11:58 -03:00
|
|
|
// FIXME: Include ServiceWorker
|
2026-03-16 14:36:36 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/comms.html#messageeventsource
|
2026-05-20 15:58:46 -03:00
|
|
|
using MessageEventSource = Variant<GC::Ref<WindowProxy>, GC::Ref<MessagePort>>;
|
|
|
|
|
using NullableMessageEventSource = Variant<GC::Ref<WindowProxy>, GC::Ref<MessagePort>, Empty>;
|
2023-11-06 17:11:58 -03:00
|
|
|
|
2026-03-16 14:36:36 -03:00
|
|
|
// https://html.spec.whatwg.org/multipage/comms.html#messageevent
|
2025-07-19 23:35:33 -03:00
|
|
|
class WEB_API MessageEvent : public DOM::Event {
|
2022-08-28 08:42:07 -03:00
|
|
|
WEB_PLATFORM_OBJECT(MessageEvent, DOM::Event);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(MessageEvent);
|
2022-08-08 17:29:40 -03:00
|
|
|
|
2021-04-24 08:54:24 -03:00
|
|
|
public:
|
2026-05-20 15:58:46 -03:00
|
|
|
[[nodiscard]] static GC::Ref<MessageEvent> create(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const&);
|
2026-05-01 14:01:23 -03:00
|
|
|
[[nodiscard]] static GC::Ref<MessageEvent> create(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const&, URL::Origin const&);
|
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<MessageEvent>> construct_impl(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const&);
|
2021-04-24 08:54:24 -03:00
|
|
|
|
2026-05-01 14:01:23 -03:00
|
|
|
MessageEvent(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const& event_init);
|
|
|
|
|
MessageEvent(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const& event_init, URL::Origin const&);
|
2022-08-08 17:29:40 -03:00
|
|
|
virtual ~MessageEvent() override;
|
2021-04-24 08:54:24 -03:00
|
|
|
|
2022-08-08 17:29:40 -03:00
|
|
|
JS::Value data() const { return m_data; }
|
2026-03-17 02:55:56 -03:00
|
|
|
String origin() const;
|
2023-03-05 06:33:56 -03:00
|
|
|
String const& last_event_id() const { return m_last_event_id; }
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<JS::Object> ports() const;
|
2026-02-16 11:28:08 -03:00
|
|
|
|
2026-02-17 11:57:03 -03:00
|
|
|
NullableMessageEventSource source() const;
|
2021-04-24 08:54:24 -03:00
|
|
|
|
2025-12-07 10:19:54 -03:00
|
|
|
virtual Optional<URL::Origin> extract_an_origin() const override;
|
|
|
|
|
|
2026-05-20 15:58:46 -03:00
|
|
|
void init_message_event(String const& type, bool bubbles, bool cancelable, JS::Value data, String const& origin, String const& last_event_id, NullableMessageEventSource source, GC::RootVector<GC::Ref<MessagePort>> const& ports);
|
2024-07-09 15:43:51 -03:00
|
|
|
|
2022-08-08 17:29:40 -03:00
|
|
|
private:
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2022-08-08 17:29:40 -03:00
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
2021-04-24 08:54:24 -03:00
|
|
|
|
2026-05-01 14:01:23 -03:00
|
|
|
MessageEvent(JS::Realm&, FlyString const& event_name, Bindings::MessageEventInit const& event_init, Variant<URL::Origin, String, Empty>);
|
2026-02-16 11:28:08 -03:00
|
|
|
|
2022-08-08 17:29:40 -03:00
|
|
|
JS::Value m_data;
|
2026-03-17 02:55:56 -03:00
|
|
|
|
|
|
|
|
// https://html.spec.whatwg.org/multipage/comms.html#concept-messageevent-origin
|
|
|
|
|
// Each MessageEvent has an origin (an origin, a string, or null), initially null.
|
|
|
|
|
Variant<URL::Origin, String, Empty> m_origin;
|
|
|
|
|
|
2023-03-05 06:33:56 -03:00
|
|
|
String m_last_event_id;
|
2026-05-20 15:58:46 -03:00
|
|
|
NullableMessageEventSource m_source;
|
2024-11-14 12:01:23 -03:00
|
|
|
Vector<GC::Ref<JS::Object>> m_ports;
|
|
|
|
|
mutable GC::Ptr<JS::Array> m_ports_array;
|
2021-04-24 08:54:24 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|