MessageChannel.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <LibWeb/Bindings/Wrappable.h>
  9. #include <LibWeb/DOM/EventTarget.h>
  10. #include <LibWeb/Forward.h>
  11. #include <LibWeb/HTML/Window.h>
  12. namespace Web::HTML {
  13. // https://html.spec.whatwg.org/multipage/web-messaging.html#message-channels
  14. class MessageChannel final
  15. : public RefCounted<MessageChannel>
  16. , public Bindings::Wrappable {
  17. public:
  18. using WrapperType = Bindings::MessageChannelWrapper;
  19. using RefCounted::ref;
  20. using RefCounted::unref;
  21. static NonnullRefPtr<MessageChannel> create_with_global_object(Bindings::WindowObject&)
  22. {
  23. return adopt_ref(*new MessageChannel());
  24. }
  25. virtual ~MessageChannel() override;
  26. MessagePort* port1() { return m_port1; }
  27. MessagePort const* port1() const { return m_port1; }
  28. MessagePort* port2() { return m_port2; }
  29. MessagePort const* port2() const { return m_port2; }
  30. private:
  31. MessageChannel();
  32. RefPtr<MessagePort> m_port1;
  33. RefPtr<MessagePort> m_port2;
  34. };
  35. }