summaryrefslogtreecommitdiffstats
path: root/services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs')
-rw-r--r--services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs b/services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs
new file mode 100644
index 0000000000..9d85ecfe22
--- /dev/null
+++ b/services/fxaccounts/rust-bridge/firefox-accounts-bridge/src/lib.rs
@@ -0,0 +1,41 @@
+/* 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/. */
+
+//! This crate, as its name suggests, serves as a bridge
+//! between the Javascript world (RustFxAccount.js)
+//! and the Rust world (fxa-client crate).
+//!
+//! The `bridge` module implements the `mozIFirefoxAccountsBridge`
+//! interface, which is callable from JS.
+//!
+//! The `punt` module helps running the synchronous Rust operations
+//! on a background thread pool managed by Gecko.
+
+#[macro_use]
+extern crate cstr;
+#[macro_use]
+extern crate xpcom;
+
+mod bridge;
+mod punt;
+
+use crate::bridge::Bridge;
+use nserror::{nsresult, NS_OK};
+use xpcom::{interfaces::mozIFirefoxAccountsBridge, RefPtr};
+
+// The constructor for our fxa implementation, exposed to C++. See
+// `FirefoxAccountsBridge.h` for the declaration and the wrapper we
+// register with the component manager.
+#[no_mangle]
+pub unsafe extern "C" fn NS_NewFirefoxAccountsBridge(
+ result: *mut *const mozIFirefoxAccountsBridge,
+) -> nsresult {
+ match Bridge::new() {
+ Ok(bridge) => {
+ RefPtr::new(bridge.coerce::<mozIFirefoxAccountsBridge>()).forget(&mut *result);
+ NS_OK
+ }
+ Err(err) => err.into(),
+ }
+}