2024-07-13 14:51:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
2024-11-23 20:45:26 +13:00
|
|
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
2024-07-13 14:51:28 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibWeb/DOM/EventTarget.h>
|
|
|
|
|
|
|
|
namespace Web::HTML {
|
|
|
|
|
|
|
|
class BroadcastChannel final : public DOM::EventTarget {
|
|
|
|
WEB_PLATFORM_OBJECT(BroadcastChannel, DOM::EventTarget);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(BroadcastChannel);
|
2024-07-13 14:51:28 +01:00
|
|
|
|
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
[[nodiscard]] static GC::Ref<BroadcastChannel> construct_impl(JS::Realm&, FlyString const& name);
|
2024-07-13 14:51:28 +01:00
|
|
|
|
2024-11-23 16:26:03 +13:00
|
|
|
// https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-name
|
|
|
|
FlyString const& name() const
|
|
|
|
{
|
|
|
|
// The name getter steps are to return this's channel name.
|
|
|
|
return m_channel_name;
|
|
|
|
}
|
2024-07-13 14:51:28 +01:00
|
|
|
|
2024-11-23 20:45:26 +13:00
|
|
|
WebIDL::ExceptionOr<void> post_message(JS::Value message);
|
|
|
|
|
2024-07-13 14:51:28 +01:00
|
|
|
void close();
|
|
|
|
|
2024-11-23 16:26:03 +13:00
|
|
|
void set_onmessage(GC::Ptr<WebIDL::CallbackType>);
|
|
|
|
GC::Ptr<WebIDL::CallbackType> onmessage();
|
|
|
|
void set_onmessageerror(GC::Ptr<WebIDL::CallbackType>);
|
|
|
|
GC::Ptr<WebIDL::CallbackType> onmessageerror();
|
2024-07-13 14:51:28 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
BroadcastChannel(JS::Realm&, FlyString const& name);
|
|
|
|
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
|
2024-11-23 20:45:26 +13:00
|
|
|
bool is_eligible_for_messaging() const;
|
|
|
|
|
2024-07-13 14:51:28 +01:00
|
|
|
FlyString m_channel_name;
|
|
|
|
bool m_closed_flag { false };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|