blink_message_port_adapter.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_CAST_MESSAGE_PORT_BLINK_MESSAGE_PORT_ADAPTER_H_
  5. #define COMPONENTS_CAST_MESSAGE_PORT_BLINK_MESSAGE_PORT_ADAPTER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/strings/string_piece.h"
  9. #include "components/cast/message_port/message_port.h"
  10. #include "third_party/blink/public/common/messaging/web_message_port.h"
  11. namespace cast_api_bindings {
  12. // Adapts between blink::WebMessagePort and the port type created by
  13. // cast_api_bindings::CreatePlatformMessagePortPair. Some Javascript engines
  14. // specifically use blink::WebMessagePort internally but need
  15. // cast_api_bindings::MessagePort(s) to communicate with Cast bindings.
  16. class BlinkMessagePortAdapter {
  17. public:
  18. BlinkMessagePortAdapter() = delete;
  19. // Adapts a |client| blink port to the port type created by
  20. // CreatePlatformMessagePortPair, which is returned.
  21. static std::unique_ptr<MessagePort> ToClientPlatformMessagePort(
  22. blink::WebMessagePort&& client);
  23. // Adapts a |server| port of the type created by CreatePlatformMessagePortPair
  24. // to a blink port, which is returned.
  25. static blink::WebMessagePort FromServerPlatformMessagePort(
  26. std::unique_ptr<MessagePort> server);
  27. };
  28. } // namespace cast_api_bindings
  29. #endif // COMPONENTS_CAST_MESSAGE_PORT_BLINK_MESSAGE_PORT_ADAPTER_H_