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/. */
5 #ifndef mozilla_dom_WebAuthnService_h_
6 #define mozilla_dom_WebAuthnService_h_
8 #include "nsIWebAuthnService.h"
9 #include "AuthrsBridge_ffi.h"
11 #ifdef MOZ_WIDGET_ANDROID
12 # include "AndroidWebAuthnService.h"
16 # include "MacOSWebAuthnService.h"
20 # include "WinWebAuthnService.h"
23 namespace mozilla::dom
{
25 already_AddRefed
<nsIWebAuthnService
> NewWebAuthnService();
27 class WebAuthnService final
: public nsIWebAuthnService
{
29 NS_DECL_THREADSAFE_ISUPPORTS
30 NS_DECL_NSIWEBAUTHNSERVICE
33 Unused
<< authrs_service_constructor(getter_AddRefs(mAuthrsService
));
35 if (WinWebAuthnService::AreWebAuthNApisAvailable()) {
36 mPlatformService
= new WinWebAuthnService();
38 mPlatformService
= mAuthrsService
;
40 #elif defined(MOZ_WIDGET_ANDROID)
41 mPlatformService
= new AndroidWebAuthnService();
42 #elif defined(XP_MACOSX)
43 if (__builtin_available(macos
13.3, *)) {
44 mPlatformService
= NewMacOSWebAuthnServiceIfAvailable();
46 if (!mPlatformService
) {
47 mPlatformService
= mAuthrsService
;
50 mPlatformService
= mAuthrsService
;
55 ~WebAuthnService() = default;
57 nsIWebAuthnService
* DefaultService() {
58 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
59 return mAuthrsService
;
61 return mPlatformService
;
64 nsIWebAuthnService
* AuthrsService() { return mAuthrsService
; }
66 nsCOMPtr
<nsIWebAuthnService
> mAuthrsService
;
67 nsCOMPtr
<nsIWebAuthnService
> mPlatformService
;
70 } // namespace mozilla::dom
72 #endif // mozilla_dom_WebAuthnService_h_