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