diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/webauthn/WebAuthnPromiseHolder.h | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/webauthn/WebAuthnPromiseHolder.h')
-rw-r--r-- | dom/webauthn/WebAuthnPromiseHolder.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/dom/webauthn/WebAuthnPromiseHolder.h b/dom/webauthn/WebAuthnPromiseHolder.h new file mode 100644 index 0000000000..ca70fedb14 --- /dev/null +++ b/dom/webauthn/WebAuthnPromiseHolder.h @@ -0,0 +1,69 @@ +/* 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_dom_WebAuthnPromiseHolder_h +#define mozilla_dom_WebAuthnPromiseHolder_h + +#include "mozilla/MozPromise.h" +#include "nsIWebAuthnResult.h" +#include "nsIWebAuthnPromise.h" +#include "nsIThread.h" + +namespace mozilla::dom { + +/* + * WebAuthnRegisterPromiseHolder and WebAuthnSignPromiseHolder wrap a + * MozPromiseHolder with an XPCOM interface that allows the contained promise + * to be resolved, rejected, or disconnected safely from any thread. + * + * Calls to Resolve(), Reject(), and Disconnect() are dispatched to the serial + * event target with wich the promise holder was initialized. At most one of + * these calls will be processed; the first call to reach the event target + * wins. Once the promise is initialized with Ensure() the program MUST call + * at least one of Resolve(), Reject(), or Disconnect(). + */ + +using WebAuthnRegisterPromise = + MozPromise<RefPtr<nsIWebAuthnRegisterResult>, nsresult, true>; + +using WebAuthnSignPromise = + MozPromise<RefPtr<nsIWebAuthnSignResult>, nsresult, true>; + +class WebAuthnRegisterPromiseHolder final : public nsIWebAuthnRegisterPromise { + public: + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSIWEBAUTHNREGISTERPROMISE + + explicit WebAuthnRegisterPromiseHolder(nsISerialEventTarget* aEventTarget) + : mEventTarget(aEventTarget) {} + + already_AddRefed<WebAuthnRegisterPromise> Ensure(); + + private: + ~WebAuthnRegisterPromiseHolder() = default; + + nsCOMPtr<nsISerialEventTarget> mEventTarget; + MozPromiseHolder<WebAuthnRegisterPromise> mRegisterPromise; +}; + +class WebAuthnSignPromiseHolder final : public nsIWebAuthnSignPromise { + public: + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSIWEBAUTHNSIGNPROMISE + + explicit WebAuthnSignPromiseHolder(nsISerialEventTarget* aEventTarget) + : mEventTarget(aEventTarget) {} + + already_AddRefed<WebAuthnSignPromise> Ensure(); + + private: + ~WebAuthnSignPromiseHolder() = default; + + nsCOMPtr<nsISerialEventTarget> mEventTarget; + MozPromiseHolder<WebAuthnSignPromise> mSignPromise; +}; + +} // namespace mozilla::dom + +#endif // mozilla_dom_WebAuthnPromiseHolder_h |