MessageChannel.h 985 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/PlatformObject.h>
  8. #include <LibWeb/Forward.h>
  9. namespace Web::HTML {
  10. // https://html.spec.whatwg.org/multipage/web-messaging.html#message-channels
  11. class MessageChannel final : public Bindings::PlatformObject {
  12. WEB_PLATFORM_OBJECT(MessageChannel, Bindings::PlatformObject);
  13. JS_DECLARE_ALLOCATOR(MessageChannel);
  14. public:
  15. static WebIDL::ExceptionOr<JS::NonnullGCPtr<MessageChannel>> construct_impl(JS::Realm&);
  16. virtual ~MessageChannel() override;
  17. MessagePort* port1();
  18. MessagePort const* port1() const;
  19. MessagePort* port2();
  20. MessagePort const* port2() const;
  21. private:
  22. explicit MessageChannel(JS::Realm&);
  23. virtual void initialize(JS::Realm&) override;
  24. virtual void visit_edges(Cell::Visitor&) override;
  25. JS::GCPtr<MessagePort> m_port1;
  26. JS::GCPtr<MessagePort> m_port2;
  27. };
  28. }