/src/serenity/Userland/Libraries/LibWeb/HTML/MessageEvent.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com> |
3 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/FlyString.h> |
11 | | #include <LibWeb/DOM/Event.h> |
12 | | |
13 | | namespace Web::HTML { |
14 | | |
15 | | // FIXME: Include ServiceWorker |
16 | | using MessageEventSource = Variant<JS::Handle<WindowProxy>, JS::Handle<MessagePort>>; |
17 | | |
18 | | struct MessageEventInit : public DOM::EventInit { |
19 | | JS::Value data { JS::js_null() }; |
20 | | String origin {}; |
21 | | String last_event_id {}; |
22 | | Optional<MessageEventSource> source; |
23 | | Vector<JS::Handle<MessagePort>> ports; |
24 | | }; |
25 | | |
26 | | class MessageEvent : public DOM::Event { |
27 | | WEB_PLATFORM_OBJECT(MessageEvent, DOM::Event); |
28 | | JS_DECLARE_ALLOCATOR(MessageEvent); |
29 | | |
30 | | public: |
31 | | [[nodiscard]] static JS::NonnullGCPtr<MessageEvent> create(JS::Realm&, FlyString const& event_name, MessageEventInit const& = {}); |
32 | | static WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageEvent>> construct_impl(JS::Realm&, FlyString const& event_name, MessageEventInit const&); |
33 | | |
34 | | MessageEvent(JS::Realm&, FlyString const& event_name, MessageEventInit const& event_init); |
35 | | virtual ~MessageEvent() override; |
36 | | |
37 | 0 | JS::Value data() const { return m_data; } |
38 | 0 | String const& origin() const { return m_origin; } |
39 | 0 | String const& last_event_id() const { return m_last_event_id; } |
40 | | JS::NonnullGCPtr<JS::Object> ports() const; |
41 | | Variant<JS::Handle<WindowProxy>, JS::Handle<MessagePort>, Empty> source() const; |
42 | | |
43 | | 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<JS::Handle<MessagePort>> const& ports); |
44 | | |
45 | | private: |
46 | | virtual void initialize(JS::Realm&) override; |
47 | | virtual void visit_edges(Cell::Visitor&) override; |
48 | | |
49 | | JS::Value m_data; |
50 | | String m_origin; |
51 | | String m_last_event_id; |
52 | | Optional<MessageEventSource> m_source; |
53 | | Vector<JS::NonnullGCPtr<JS::Object>> m_ports; |
54 | | mutable JS::GCPtr<JS::Array> m_ports_array; |
55 | | }; |
56 | | |
57 | | } |