Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / webauthn / AndroidWebAuthnService.h
blobab48be486733c940ef5ff8cc2345ad95133a747d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_AndroidWebAuthnService_h_
8 #define mozilla_dom_AndroidWebAuthnService_h_
10 #include "mozilla/java/WebAuthnTokenManagerNatives.h"
11 #include "nsIWebAuthnService.h"
13 namespace mozilla {
15 namespace dom {
17 // Collected from
18 // https://developers.google.com/android/reference/com/google/android/gms/fido/fido2/api/common/ErrorCode
19 constexpr auto kSecurityError = u"SECURITY_ERR"_ns;
20 constexpr auto kConstraintError = u"CONSTRAINT_ERR"_ns;
21 constexpr auto kNotSupportedError = u"NOT_SUPPORTED_ERR"_ns;
22 constexpr auto kInvalidStateError = u"INVALID_STATE_ERR"_ns;
23 constexpr auto kNotAllowedError = u"NOT_ALLOWED_ERR"_ns;
24 constexpr auto kAbortError = u"ABORT_ERR"_ns;
25 constexpr auto kEncodingError = u"ENCODING_ERR"_ns;
26 constexpr auto kDataError = u"DATA_ERR"_ns;
27 constexpr auto kTimeoutError = u"TIMEOUT_ERR"_ns;
28 constexpr auto kNetworkError = u"NETWORK_ERR"_ns;
29 constexpr auto kUnknownError = u"UNKNOWN_ERR"_ns;
31 class AndroidWebAuthnError {
32 public:
33 explicit AndroidWebAuthnError(const nsAString& aErrorCode)
34 : mErrorCode(aErrorCode) {}
36 nsresult GetError() const {
37 if (mErrorCode.Equals(kSecurityError)) {
38 return NS_ERROR_DOM_SECURITY_ERR;
39 } else if (mErrorCode.Equals(kConstraintError)) {
40 // TODO: The message is right, but it's not about indexeddb.
41 // See https://heycam.github.io/webidl/#constrainterror
42 return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
43 } else if (mErrorCode.Equals(kNotSupportedError)) {
44 return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
45 } else if (mErrorCode.Equals(kInvalidStateError)) {
46 return NS_ERROR_DOM_INVALID_STATE_ERR;
47 } else if (mErrorCode.Equals(kNotAllowedError)) {
48 return NS_ERROR_DOM_NOT_ALLOWED_ERR;
49 } else if (mErrorCode.Equals(kEncodingError)) {
50 return NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR;
51 } else if (mErrorCode.Equals(kDataError)) {
52 return NS_ERROR_DOM_DATA_ERR;
53 } else if (mErrorCode.Equals(kTimeoutError)) {
54 return NS_ERROR_DOM_TIMEOUT_ERR;
55 } else if (mErrorCode.Equals(kNetworkError)) {
56 return NS_ERROR_DOM_NETWORK_ERR;
57 } else if (mErrorCode.Equals(kAbortError)) {
58 return NS_ERROR_DOM_ABORT_ERR;
59 } else if (mErrorCode.Equals(kUnknownError)) {
60 return NS_ERROR_DOM_UNKNOWN_ERR;
61 } else {
62 __android_log_print(ANDROID_LOG_ERROR, "Gecko",
63 "RegisterAbort unknown code: %s",
64 NS_ConvertUTF16toUTF8(mErrorCode).get());
65 return NS_ERROR_DOM_UNKNOWN_ERR;
69 private:
70 const nsString mErrorCode;
73 class AndroidWebAuthnService final : public nsIWebAuthnService {
74 public:
75 NS_DECL_THREADSAFE_ISUPPORTS
76 NS_DECL_NSIWEBAUTHNSERVICE
78 AndroidWebAuthnService() = default;
80 private:
81 ~AndroidWebAuthnService() = default;
83 // The Android FIDO2 API doesn't accept the credProps extension. However, the
84 // appropriate value for CredentialPropertiesOutput.rk can be determined
85 // entirely from the input, so we cache it here until mRegisterPromise
86 // resolves.
87 Maybe<bool> mRegisterCredPropsRk;
90 } // namespace dom
91 } // namespace mozilla
93 #endif // mozilla_dom_AndroidWebAuthnService_h_