internal_authenticator_android.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_WEBAUTHN_ANDROID_INTERNAL_AUTHENTICATOR_ANDROID_H_
  5. #define COMPONENTS_WEBAUTHN_ANDROID_INTERNAL_AUTHENTICATOR_ANDROID_H_
  6. #include "base/android/jni_weak_ref.h"
  7. #include "components/webauthn/core/browser/internal_authenticator.h"
  8. #include "content/public/browser/global_routing_id.h"
  9. #include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
  10. namespace url {
  11. class Origin;
  12. }
  13. namespace content {
  14. class RenderFrameHost;
  15. } // namespace content
  16. // Implementation of the public InternalAuthenticator interface.
  17. // This class is meant only for trusted and internal components of Chrome to
  18. // use. The Android implementation is in
  19. // org.chromium.chrome.browser.webauth.AuthenticatorImpl.
  20. // When MakeCredential() or GetAssertion() is called, the Java implementation
  21. // passes the response through InvokeMakeCredentialResponse() and
  22. // InvokeGetAssertionResponse(), which eventually invokes the callback given by
  23. // the original caller.
  24. class InternalAuthenticatorAndroid : public webauthn::InternalAuthenticator {
  25. public:
  26. explicit InternalAuthenticatorAndroid(
  27. content::RenderFrameHost* render_frame_host);
  28. ~InternalAuthenticatorAndroid() override;
  29. // InternalAuthenticator:
  30. void SetEffectiveOrigin(const url::Origin& origin) override;
  31. void SetPaymentOptions(blink::mojom::PaymentOptionsPtr payment) override;
  32. void MakeCredential(
  33. blink::mojom::PublicKeyCredentialCreationOptionsPtr options,
  34. blink::mojom::Authenticator::MakeCredentialCallback callback) override;
  35. void GetAssertion(
  36. blink::mojom::PublicKeyCredentialRequestOptionsPtr options,
  37. blink::mojom::Authenticator::GetAssertionCallback callback) override;
  38. void IsUserVerifyingPlatformAuthenticatorAvailable(
  39. blink::mojom::Authenticator::
  40. IsUserVerifyingPlatformAuthenticatorAvailableCallback callback)
  41. override;
  42. void Cancel() override;
  43. content::RenderFrameHost* GetRenderFrameHost() override;
  44. void InvokeMakeCredentialResponse(
  45. JNIEnv* env,
  46. jint status,
  47. const base::android::JavaParamRef<jobject>& byte_buffer);
  48. void InvokeGetAssertionResponse(
  49. JNIEnv* env,
  50. jint status,
  51. const base::android::JavaParamRef<jobject>& byte_buffer);
  52. void InvokeIsUserVerifyingPlatformAuthenticatorAvailableResponse(
  53. JNIEnv* env,
  54. jboolean is_uvpaa);
  55. private:
  56. // Returns the associated AuthenticatorImpl Java object. Initializes new
  57. // instance if not done so already in order to avoid possibility of any null
  58. // pointer issues.
  59. base::android::JavaRef<jobject>& GetJavaObject();
  60. const content::GlobalRenderFrameHostId render_frame_host_id_;
  61. base::android::ScopedJavaGlobalRef<jobject> java_internal_authenticator_ref_;
  62. blink::mojom::Authenticator::MakeCredentialCallback
  63. make_credential_response_callback_;
  64. blink::mojom::Authenticator::GetAssertionCallback
  65. get_assertion_response_callback_;
  66. blink::mojom::Authenticator::
  67. IsUserVerifyingPlatformAuthenticatorAvailableCallback is_uvpaa_callback_;
  68. };
  69. #endif // COMPONENTS_WEBAUTHN_ANDROID_INTERNAL_AUTHENTICATOR_ANDROID_H_