Bug 1863873 - Block ability to perform audio decoding outside of Utility on release...
[gecko.git] / dom / webauthn / WebAuthnPromiseHolder.cpp
blob60dff7f1c28269ed6b0e367a69ecec0bd5713a0e
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__);
17 NS_IMETHODIMP
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
24 // called.
25 RefPtr<nsIWebAuthnRegisterResult> result(aResult);
26 mEventTarget->Dispatch(NS_NewRunnableFunction(
27 "WebAuthnRegisterPromiseHolder::Resolve",
28 [self = RefPtr{this}, result]() {
29 self->mRegisterPromise.ResolveIfExists(result, __func__);
30 }));
31 return NS_OK;
34 NS_IMETHODIMP
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
41 // called.
42 mEventTarget->Dispatch(NS_NewRunnableFunction(
43 "WebAuthnRegisterPromiseHolder::Reject",
44 [self = RefPtr{this}, aResult]() {
45 self->mRegisterPromise.RejectIfExists(aResult, __func__);
46 }));
47 return NS_OK;
50 NS_IMPL_ISUPPORTS(WebAuthnSignPromiseHolder, nsIWebAuthnSignPromise);
52 already_AddRefed<WebAuthnSignPromise> WebAuthnSignPromiseHolder::Ensure() {
53 return mSignPromise.Ensure(__func__);
56 NS_IMETHODIMP
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
63 // called.
64 RefPtr<nsIWebAuthnSignResult> result(aResult);
65 mEventTarget->Dispatch(NS_NewRunnableFunction(
66 "WebAuthnSignPromiseHolder::Resolve", [self = RefPtr{this}, result]() {
67 self->mSignPromise.ResolveIfExists(result, __func__);
68 }));
69 return NS_OK;
72 NS_IMETHODIMP
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
79 // called.
80 mEventTarget->Dispatch(NS_NewRunnableFunction(
81 "WebAuthnSignPromiseHolder::Reject", [self = RefPtr{this}, aResult]() {
82 self->mSignPromise.RejectIfExists(aResult, __func__);
83 }));
85 return NS_OK;
88 } // namespace mozilla::dom