Add binary format support to CefMessageRouter (fixes #3502)

This commit is contained in:
Nik Pavlov
2023-10-25 18:20:55 +00:00
committed by Marshall Greenblatt
parent 1b74ac5124
commit 44323082b1
34 changed files with 2218 additions and 534 deletions

View File

@@ -219,6 +219,38 @@ struct CefMessageRouterConfig {
size_t message_size_threshold;
};
///
/// This class acts as a container for managing binary data. It retains
/// references to the underlying backing store, ensuring it is valid as long as
/// the CefBinaryBuffer exists. This allows efficient, zero-copy access to data
/// received from another process.
///
/// This class is not designed to be thread-safe, and it is the user's
/// responsibility to synchronize access from multiple threads to ensure data
/// integrity.
///
class CefBinaryBuffer : public CefBaseRefCounted {
public:
///
/// Returns the read-only pointer to the memory. Returns nullptr if
/// |GetSize()| returns zero. The returned pointer is only valid for the life
/// span of this object.
///
virtual const void* GetData() const = 0;
///
/// Returns the writable pointer to the memory. Returns nullptr if
/// |GetSize()| returns zero. The returned pointer is only valid for the life
/// span of this object.
///
virtual void* GetData() = 0;
///
/// Returns the size of the data.
///
virtual size_t GetSize() const = 0;
};
///
/// Implements the browser side of query routing. The methods of this class may
/// be called on any browser process thread unless otherwise indicated.
@@ -238,10 +270,17 @@ class CefMessageRouterBrowserSide
public:
///
/// Notify the associated JavaScript onSuccess callback that the query has
/// completed successfully with the specified |response|.
/// completed successfully with the specified string |response|.
///
virtual void Success(const CefString& response) = 0;
///
/// Notify the associated JavaScript onSuccess callback that the query has
/// completed successfully with binary data. A |data| pointer to the binary
/// data can be nullptr only if the |size| is 0.
///
virtual void Success(const void* data, size_t size) = 0;
///
/// Notify the associated JavaScript onFailure callback that the query has
/// failed with the specified |error_code| and |error_message|.
@@ -276,6 +315,25 @@ class CefMessageRouterBrowserSide
return false;
}
///
/// Executed when a new query is received. |query_id| uniquely identifies
/// the query for the life span of the router. Return true to handle the
/// query or false to propagate the query to other registered handlers, if
/// any. If no handlers return true from this method then the query will be
/// automatically canceled with an error code of -1 delivered to the
/// JavaScript onFailure callback. If this method returns true then a
/// Callback method must be executed either in this method or asynchronously
/// to complete the query.
///
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64_t query_id,
CefRefPtr<const CefBinaryBuffer> request,
bool persistent,
CefRefPtr<Callback> callback) {
return false;
}
///
/// Executed when a query has been canceled either explicitly using the
/// JavaScript cancel function or implicitly due to browser destruction,