ladybird/Libraries/LibWeb/HTML/BroadcastChannel.h
Shannon Booth e565e3c557
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
LibWeb: Implement BroadcastChannel.postMessage
The repository being in static storage is a bit of a hodgepodge, but in
line with how our current storage partitioning is done. We should
eventually move this, along with other across browsing context APIs to a
proper location at a later stage. But for now, this makes progress on
the meat of the BroadcastChannel API.
2024-11-23 16:43:55 +01:00

48 lines
1.3 KiB
C++

/*
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
*
* 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);
GC_DECLARE_ALLOCATOR(BroadcastChannel);
public:
[[nodiscard]] static GC::Ref<BroadcastChannel> construct_impl(JS::Realm&, FlyString const& name);
// 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;
}
WebIDL::ExceptionOr<void> post_message(JS::Value message);
void close();
void set_onmessage(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> onmessage();
void set_onmessageerror(GC::Ptr<WebIDL::CallbackType>);
GC::Ptr<WebIDL::CallbackType> onmessageerror();
private:
BroadcastChannel(JS::Realm&, FlyString const& name);
virtual void initialize(JS::Realm&) override;
bool is_eligible_for_messaging() const;
FlyString m_channel_name;
bool m_closed_flag { false };
};
}