summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-js/UniFFICallbacks.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/uniffi-js/UniFFICallbacks.h
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-js/UniFFICallbacks.h')
-rw-r--r--toolkit/components/uniffi-js/UniFFICallbacks.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/toolkit/components/uniffi-js/UniFFICallbacks.h b/toolkit/components/uniffi-js/UniFFICallbacks.h
new file mode 100644
index 0000000000..34faeda6a2
--- /dev/null
+++ b/toolkit/components/uniffi-js/UniFFICallbacks.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_UniFFICallbacks_h
+#define mozilla_UniFFICallbacks_h
+
+#include "mozilla/StaticPtr.h"
+#include "mozilla/dom/UniFFIRust.h"
+#include "mozilla/dom/UniFFIScaffolding.h"
+
+namespace mozilla::uniffi {
+
+/**
+ * UniFFI-generated scaffolding function to initialize a callback interface
+ *
+ * The Rust code expests us to pass it a ForeignCallback entrypoint for each
+ * callback interface.
+ */
+typedef void (*CallbackInitFunc)(ForeignCallback, RustCallStatus*);
+
+/**
+ * All the information needed to handle a callback interface.
+ *
+ * The generated code includes a function that maps interface ids to one of
+ * these structs
+ */
+struct CallbackInterfaceInfo {
+ // Human-friendly name
+ const char* mName;
+ // JS handler
+ StaticRefPtr<dom::UniFFICallbackHandler>* mHandler;
+ // Handler function, defined in the generated C++ code
+ ForeignCallback mForeignCallback;
+ // Init function, defined in the generated Rust scaffolding. mForeignCallback
+ // should be passed to this.
+ CallbackInitFunc mInitForeignCallback;
+};
+
+Maybe<CallbackInterfaceInfo> UniFFIGetCallbackInterfaceInfo(
+ uint64_t aInterfaceId);
+
+#ifdef MOZ_UNIFFI_FIXTURES
+Maybe<CallbackInterfaceInfo> UniFFIFixturesGetCallbackInterfaceInfo(
+ uint64_t aInterfaceId);
+#endif
+
+/**
+ * Register the JS handler for a callback interface
+ */
+void RegisterCallbackHandler(uint64_t aInterfaceId,
+ dom::UniFFICallbackHandler& aCallbackHandler,
+ ErrorResult& aError);
+
+/**
+ * Deregister the JS handler for a callback interface
+ */
+void DeregisterCallbackHandler(uint64_t aInterfaceId, ErrorResult& aError);
+
+/**
+ * Queue a UniFFI callback interface function to run at some point
+ *
+ * This function is for fire-and-forget callbacks where the caller doesn't care
+ * about the return value and doesn't want to wait for the call to finish. A
+ * good use case for this is logging.
+ */
+MOZ_CAN_RUN_SCRIPT
+void QueueCallback(size_t aInterfaceId, uint64_t aHandle, uint32_t aMethod,
+ RustBuffer aArgs);
+
+} // namespace mozilla::uniffi
+
+#endif // mozilla_UniFFICallbacks_h