1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/AppShutdown.h"
6 #include "WebAuthnPromiseHolder.h"
8 namespace mozilla::dom
{
10 NS_IMPL_ISUPPORTS(WebAuthnRegisterPromiseHolder
, nsIWebAuthnRegisterPromise
);
12 already_AddRefed
<WebAuthnRegisterPromise
>
13 WebAuthnRegisterPromiseHolder::Ensure() {
14 return mRegisterPromise
.Ensure(__func__
);
18 WebAuthnRegisterPromiseHolder::Resolve(nsIWebAuthnRegisterResult
* aResult
) {
19 if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads
)) {
20 return NS_ERROR_ILLEGAL_DURING_SHUTDOWN
;
23 // Resolve the promise on its owning thread if Disconnect() has not been
25 RefPtr
<nsIWebAuthnRegisterResult
> result(aResult
);
26 mEventTarget
->Dispatch(NS_NewRunnableFunction(
27 "WebAuthnRegisterPromiseHolder::Resolve",
28 [self
= RefPtr
{this}, result
]() {
29 self
->mRegisterPromise
.ResolveIfExists(result
, __func__
);
35 WebAuthnRegisterPromiseHolder::Reject(nsresult aResult
) {
36 if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads
)) {
37 return NS_ERROR_ILLEGAL_DURING_SHUTDOWN
;
40 // Reject the promise on its owning thread if Disconnect() has not been
42 mEventTarget
->Dispatch(NS_NewRunnableFunction(
43 "WebAuthnRegisterPromiseHolder::Reject",
44 [self
= RefPtr
{this}, aResult
]() {
45 self
->mRegisterPromise
.RejectIfExists(aResult
, __func__
);
50 NS_IMPL_ISUPPORTS(WebAuthnSignPromiseHolder
, nsIWebAuthnSignPromise
);
52 already_AddRefed
<WebAuthnSignPromise
> WebAuthnSignPromiseHolder::Ensure() {
53 return mSignPromise
.Ensure(__func__
);
57 WebAuthnSignPromiseHolder::Resolve(nsIWebAuthnSignResult
* aResult
) {
58 if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads
)) {
59 return NS_ERROR_ILLEGAL_DURING_SHUTDOWN
;
62 // Resolve the promise on its owning thread if Disconnect() has not been
64 RefPtr
<nsIWebAuthnSignResult
> result(aResult
);
65 mEventTarget
->Dispatch(NS_NewRunnableFunction(
66 "WebAuthnSignPromiseHolder::Resolve", [self
= RefPtr
{this}, result
]() {
67 self
->mSignPromise
.ResolveIfExists(result
, __func__
);
73 WebAuthnSignPromiseHolder::Reject(nsresult aResult
) {
74 if (AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads
)) {
75 return NS_ERROR_ILLEGAL_DURING_SHUTDOWN
;
78 // Reject the promise on its owning thread if Disconnect() has not been
80 mEventTarget
->Dispatch(NS_NewRunnableFunction(
81 "WebAuthnSignPromiseHolder::Reject", [self
= RefPtr
{this}, aResult
]() {
82 self
->mSignPromise
.RejectIfExists(aResult
, __func__
);
88 } // namespace mozilla::dom