/src/serenity/Userland/Libraries/LibWeb/HTML/BroadcastChannel.cpp
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibJS/Runtime/Realm.h> |
8 | | #include <LibWeb/Bindings/BroadcastChannelPrototype.h> |
9 | | #include <LibWeb/Bindings/Intrinsics.h> |
10 | | #include <LibWeb/HTML/BroadcastChannel.h> |
11 | | #include <LibWeb/HTML/EventNames.h> |
12 | | |
13 | | namespace Web::HTML { |
14 | | |
15 | | JS_DEFINE_ALLOCATOR(BroadcastChannel); |
16 | | |
17 | | JS::NonnullGCPtr<BroadcastChannel> BroadcastChannel::construct_impl(JS::Realm& realm, FlyString const& name) |
18 | 0 | { |
19 | 0 | return realm.heap().allocate<BroadcastChannel>(realm, realm, name); |
20 | 0 | } |
21 | | |
22 | | BroadcastChannel::BroadcastChannel(JS::Realm& realm, FlyString const& name) |
23 | 0 | : DOM::EventTarget(realm) |
24 | 0 | , m_channel_name(name) |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | void BroadcastChannel::initialize(JS::Realm& realm) |
29 | 0 | { |
30 | 0 | Base::initialize(realm); |
31 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(BroadcastChannel); |
32 | 0 | } |
33 | | |
34 | | // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-name |
35 | | FlyString BroadcastChannel::name() |
36 | 0 | { |
37 | | // The name getter steps are to return this's channel name. |
38 | 0 | return m_channel_name; |
39 | 0 | } |
40 | | |
41 | | // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-close |
42 | | void BroadcastChannel::close() |
43 | 0 | { |
44 | | // The close() method steps are to set this's closed flag to true. |
45 | 0 | m_closed_flag = true; |
46 | 0 | } |
47 | | |
48 | | // https://html.spec.whatwg.org/multipage/web-messaging.html#handler-broadcastchannel-onmessage |
49 | | void BroadcastChannel::set_onmessage(WebIDL::CallbackType* event_handler) |
50 | 0 | { |
51 | 0 | set_event_handler_attribute(HTML::EventNames::message, event_handler); |
52 | 0 | } |
53 | | |
54 | | // https://html.spec.whatwg.org/multipage/web-messaging.html#handler-broadcastchannel-onmessage |
55 | | WebIDL::CallbackType* BroadcastChannel::onmessage() |
56 | 0 | { |
57 | 0 | return event_handler_attribute(HTML::EventNames::message); |
58 | 0 | } |
59 | | |
60 | | // https://html.spec.whatwg.org/multipage/web-messaging.html#handler-broadcastchannel-onmessageerror |
61 | | void BroadcastChannel::set_onmessageerror(WebIDL::CallbackType* event_handler) |
62 | 0 | { |
63 | 0 | set_event_handler_attribute(HTML::EventNames::messageerror, event_handler); |
64 | 0 | } |
65 | | |
66 | | // https://html.spec.whatwg.org/multipage/web-messaging.html#handler-broadcastchannel-onmessageerror |
67 | | WebIDL::CallbackType* BroadcastChannel::onmessageerror() |
68 | 0 | { |
69 | 0 | return event_handler_attribute(HTML::EventNames::messageerror); |
70 | 0 | } |
71 | | |
72 | | } |