tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebAuthnPromiseHolder.h (2268B)


      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
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef mozilla_dom_WebAuthnPromiseHolder_h
      6 #define mozilla_dom_WebAuthnPromiseHolder_h
      7 
      8 #include "mozilla/MozPromise.h"
      9 #include "nsIThread.h"
     10 #include "nsIWebAuthnPromise.h"
     11 #include "nsIWebAuthnResult.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 /*
     16 * WebAuthnRegisterPromiseHolder and WebAuthnSignPromiseHolder wrap a
     17 * MozPromiseHolder with an XPCOM interface that allows the contained promise
     18 * to be resolved, rejected, or disconnected safely from any thread.
     19 *
     20 * Calls to Resolve(), Reject(), and Disconnect() are dispatched to the serial
     21 * event target with wich the promise holder was initialized. At most one of
     22 * these calls will be processed; the first call to reach the event target
     23 * wins. Once the promise is initialized with Ensure() the program MUST call
     24 * at least one of Resolve(), Reject(), or Disconnect().
     25 */
     26 
     27 using WebAuthnRegisterPromise =
     28    MozPromise<RefPtr<nsIWebAuthnRegisterResult>, nsresult, true>;
     29 
     30 using WebAuthnSignPromise =
     31    MozPromise<RefPtr<nsIWebAuthnSignResult>, nsresult, true>;
     32 
     33 class WebAuthnRegisterPromiseHolder final : public nsIWebAuthnRegisterPromise {
     34 public:
     35  NS_DECL_THREADSAFE_ISUPPORTS
     36  NS_DECL_NSIWEBAUTHNREGISTERPROMISE
     37 
     38  explicit WebAuthnRegisterPromiseHolder(nsISerialEventTarget* aEventTarget)
     39      : mEventTarget(aEventTarget) {}
     40 
     41  already_AddRefed<WebAuthnRegisterPromise> Ensure();
     42 
     43 private:
     44  ~WebAuthnRegisterPromiseHolder() = default;
     45 
     46  nsCOMPtr<nsISerialEventTarget> mEventTarget;
     47  MozPromiseHolder<WebAuthnRegisterPromise> mRegisterPromise;
     48 };
     49 
     50 class WebAuthnSignPromiseHolder final : public nsIWebAuthnSignPromise {
     51 public:
     52  NS_DECL_THREADSAFE_ISUPPORTS
     53  NS_DECL_NSIWEBAUTHNSIGNPROMISE
     54 
     55  explicit WebAuthnSignPromiseHolder(nsISerialEventTarget* aEventTarget)
     56      : mEventTarget(aEventTarget) {}
     57 
     58  already_AddRefed<WebAuthnSignPromise> Ensure();
     59 
     60 private:
     61  ~WebAuthnSignPromiseHolder() = default;
     62 
     63  nsCOMPtr<nsISerialEventTarget> mEventTarget;
     64  MozPromiseHolder<WebAuthnSignPromise> mSignPromise;
     65 };
     66 
     67 }  // namespace mozilla::dom
     68 
     69 #endif  // mozilla_dom_WebAuthnPromiseHolder_h