frontend_channel.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2020 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 CRDTP_FRONTEND_CHANNEL_H_
  5. #define CRDTP_FRONTEND_CHANNEL_H_
  6. #include <cstdint>
  7. #include <memory>
  8. #include "export.h"
  9. #include "serializable.h"
  10. #include "span.h"
  11. namespace crdtp {
  12. // =============================================================================
  13. // FrontendChannel - For sending notifications and responses to protocol clients
  14. // =============================================================================
  15. class CRDTP_EXPORT FrontendChannel {
  16. public:
  17. virtual ~FrontendChannel() = default;
  18. // Sends protocol responses and notifications. The |call_id| parameter is
  19. // seemingly redundant because it's also included in the message, but
  20. // responses may be sent from an untrusted source to a trusted process (e.g.
  21. // from Chromium's renderer (blink) to the browser process), which needs
  22. // to be able to match the response to an earlier request without parsing the
  23. // messsage.
  24. virtual void SendProtocolResponse(int call_id,
  25. std::unique_ptr<Serializable> message) = 0;
  26. virtual void SendProtocolNotification(
  27. std::unique_ptr<Serializable> message) = 0;
  28. // FallThrough indicates that |message| should be handled in another layer.
  29. // Usually this means the layer responding to the message didn't handle it,
  30. // but in some cases messages are handled by multiple layers (e.g. both
  31. // the embedder and the content layer in Chromium).
  32. virtual void FallThrough(int call_id,
  33. span<uint8_t> method,
  34. span<uint8_t> message) = 0;
  35. // Session implementations may queue notifications for performance or
  36. // other considerations; this is a hook for domain handlers to manually flush.
  37. virtual void FlushProtocolNotifications() = 0;
  38. };
  39. } // namespace crdtp
  40. #endif // CRDTP_FRONTEND_CHANNEL_H_