diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-19 22:12:31 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-19 22:34:44 +0200 |
commit | 95559c427704b00ea3b7adbd7df44f4ba53f50f9 (patch) | |
tree | 622ad62ca20404c4da9b67c658348cacc6cc41bf /Userland/Libraries/LibWeb/HTML/MessageChannel.h | |
parent | c7aa32b90fda6f3720f99bd3368576982a635e9c (diff) | |
download | serenity-95559c427704b00ea3b7adbd7df44f4ba53f50f9.zip |
LibWeb: Implement basic support for MessageChannel and MessagePort
This patch adds a basic initial implementation of these API's.
Since LibWeb currently doesn't support workers, this implementation of
messaging doesn't bother with serializing and deserializing messages.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/MessageChannel.h')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/MessageChannel.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/MessageChannel.h b/Userland/Libraries/LibWeb/HTML/MessageChannel.h new file mode 100644 index 0000000000..9abe9b91d1 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/MessageChannel.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021, Andreas Kling <kling@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/RefCounted.h> +#include <LibWeb/Bindings/Wrappable.h> +#include <LibWeb/DOM/EventTarget.h> +#include <LibWeb/DOM/Window.h> +#include <LibWeb/Forward.h> + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/web-messaging.html#message-channels +class MessageChannel final + : public RefCounted<MessageChannel> + , public Bindings::Wrappable { +public: + using WrapperType = Bindings::MessageChannelWrapper; + + using RefCounted::ref; + using RefCounted::unref; + + static NonnullRefPtr<MessageChannel> create_with_global_object(Bindings::WindowObject& global_object) + { + return adopt_ref(*new MessageChannel(global_object)); + } + + virtual ~MessageChannel() override; + + MessagePort* port1() { return m_port1; } + MessagePort const* port1() const { return m_port1; } + + MessagePort* port2() { return m_port2; } + MessagePort const* port2() const { return m_port2; } + +private: + explicit MessageChannel(Bindings::WindowObject&); + + RefPtr<MessagePort> m_port1; + RefPtr<MessagePort> m_port2; +}; + +} |