Commit b85cc232 authored by Manas Verma's avatar Manas Verma Committed by Commit Bot

[AF Auth] Fix failing opt-in flow

This CL creates the JavaRef for AuthenticatorImpl when request is made,
rather than in constructor.

Bug: 949269
Change-Id: I43244cafde4f2e98d69caa7adfe347ee1334af5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314030
Commit-Queue: Manas Verma <manasverma@google.com>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#792818}
parent 6db73ca9
...@@ -29,12 +29,10 @@ InternalAuthenticatorAndroid::InternalAuthenticatorAndroid( ...@@ -29,12 +29,10 @@ InternalAuthenticatorAndroid::InternalAuthenticatorAndroid(
content::RenderFrameHost* render_frame_host) content::RenderFrameHost* render_frame_host)
: render_frame_host_(render_frame_host) { : render_frame_host_(render_frame_host) {
DCHECK(render_frame_host_); DCHECK(render_frame_host_);
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> local_ref = Java_AuthenticatorImpl_create( java_authenticator_impl_ref_ = Java_AuthenticatorImpl_create(
env, reinterpret_cast<intptr_t>(this), env, reinterpret_cast<intptr_t>(this),
render_frame_host_->GetJavaRenderFrameHost()); render_frame_host_->GetJavaRenderFrameHost());
java_authenticator_impl_ref_ = JavaObjectWeakGlobalRef(env, local_ref);
} }
InternalAuthenticatorAndroid::~InternalAuthenticatorAndroid() { InternalAuthenticatorAndroid::~InternalAuthenticatorAndroid() {
...@@ -47,9 +45,8 @@ InternalAuthenticatorAndroid::~InternalAuthenticatorAndroid() { ...@@ -47,9 +45,8 @@ InternalAuthenticatorAndroid::~InternalAuthenticatorAndroid() {
void InternalAuthenticatorAndroid::SetEffectiveOrigin( void InternalAuthenticatorAndroid::SetEffectiveOrigin(
const url::Origin& origin) { const url::Origin& origin) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_authenticator_impl_ref_.get(env); JavaRef<jobject>& obj = GetJavaObject();
if (obj.is_null()) DCHECK(!obj.is_null());
return;
Java_AuthenticatorImpl_setEffectiveOrigin(env, obj, Java_AuthenticatorImpl_setEffectiveOrigin(env, obj,
origin.CreateJavaObject()); origin.CreateJavaObject());
...@@ -59,18 +56,15 @@ void InternalAuthenticatorAndroid::MakeCredential( ...@@ -59,18 +56,15 @@ void InternalAuthenticatorAndroid::MakeCredential(
blink::mojom::PublicKeyCredentialCreationOptionsPtr options, blink::mojom::PublicKeyCredentialCreationOptionsPtr options,
blink::mojom::Authenticator::MakeCredentialCallback callback) { blink::mojom::Authenticator::MakeCredentialCallback callback) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_authenticator_impl_ref_.get(env); JavaRef<jobject>& obj = GetJavaObject();
if (obj.is_null()) DCHECK(!obj.is_null());
return;
make_credential_response_callback_ = std::move(callback); make_credential_response_callback_ = std::move(callback);
std::vector<uint8_t> byte_vector = std::vector<uint8_t> byte_vector =
blink::mojom::PublicKeyCredentialCreationOptions::Serialize(&options); blink::mojom::PublicKeyCredentialCreationOptions::Serialize(&options);
base::android::ScopedJavaLocalRef<jobject> byte_buffer = ScopedJavaLocalRef<jobject> byte_buffer = ScopedJavaLocalRef<jobject>(
base::android::ScopedJavaLocalRef<jobject>( env, env->NewDirectByteBuffer(byte_vector.data(), byte_vector.size()));
env,
env->NewDirectByteBuffer(byte_vector.data(), byte_vector.size()));
Java_AuthenticatorImpl_makeCredentialBridge(env, obj, byte_buffer); Java_AuthenticatorImpl_makeCredentialBridge(env, obj, byte_buffer);
} }
...@@ -79,18 +73,15 @@ void InternalAuthenticatorAndroid::GetAssertion( ...@@ -79,18 +73,15 @@ void InternalAuthenticatorAndroid::GetAssertion(
blink::mojom::PublicKeyCredentialRequestOptionsPtr options, blink::mojom::PublicKeyCredentialRequestOptionsPtr options,
blink::mojom::Authenticator::GetAssertionCallback callback) { blink::mojom::Authenticator::GetAssertionCallback callback) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_authenticator_impl_ref_.get(env); JavaRef<jobject>& obj = GetJavaObject();
if (obj.is_null()) DCHECK(!obj.is_null());
return;
get_assertion_response_callback_ = std::move(callback); get_assertion_response_callback_ = std::move(callback);
std::vector<uint8_t> byte_vector = std::vector<uint8_t> byte_vector =
blink::mojom::PublicKeyCredentialRequestOptions::Serialize(&options); blink::mojom::PublicKeyCredentialRequestOptions::Serialize(&options);
base::android::ScopedJavaLocalRef<jobject> byte_buffer = ScopedJavaLocalRef<jobject> byte_buffer = ScopedJavaLocalRef<jobject>(
base::android::ScopedJavaLocalRef<jobject>( env, env->NewDirectByteBuffer(byte_vector.data(), byte_vector.size()));
env,
env->NewDirectByteBuffer(byte_vector.data(), byte_vector.size()));
Java_AuthenticatorImpl_getAssertionBridge(env, obj, byte_buffer); Java_AuthenticatorImpl_getAssertionBridge(env, obj, byte_buffer);
} }
...@@ -100,9 +91,8 @@ void InternalAuthenticatorAndroid:: ...@@ -100,9 +91,8 @@ void InternalAuthenticatorAndroid::
blink::mojom::Authenticator:: blink::mojom::Authenticator::
IsUserVerifyingPlatformAuthenticatorAvailableCallback callback) { IsUserVerifyingPlatformAuthenticatorAvailableCallback callback) {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_authenticator_impl_ref_.get(env); JavaRef<jobject>& obj = GetJavaObject();
if (obj.is_null()) DCHECK(!obj.is_null());
return;
is_uvpaa_callback_ = std::move(callback); is_uvpaa_callback_ = std::move(callback);
Java_AuthenticatorImpl_isUserVerifyingPlatformAuthenticatorAvailableBridge( Java_AuthenticatorImpl_isUserVerifyingPlatformAuthenticatorAvailableBridge(
...@@ -111,9 +101,8 @@ void InternalAuthenticatorAndroid:: ...@@ -111,9 +101,8 @@ void InternalAuthenticatorAndroid::
void InternalAuthenticatorAndroid::Cancel() { void InternalAuthenticatorAndroid::Cancel() {
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_authenticator_impl_ref_.get(env); JavaRef<jobject>& obj = GetJavaObject();
if (obj.is_null()) DCHECK(!obj.is_null());
return;
Java_AuthenticatorImpl_cancel(env, obj); Java_AuthenticatorImpl_cancel(env, obj);
} }
...@@ -162,3 +151,13 @@ void InternalAuthenticatorAndroid:: ...@@ -162,3 +151,13 @@ void InternalAuthenticatorAndroid::
jboolean is_uvpaa) { jboolean is_uvpaa) {
std::move(is_uvpaa_callback_).Run(static_cast<bool>(is_uvpaa)); std::move(is_uvpaa_callback_).Run(static_cast<bool>(is_uvpaa));
} }
JavaRef<jobject>& InternalAuthenticatorAndroid::GetJavaObject() {
if (java_authenticator_impl_ref_.is_null()) {
JNIEnv* env = AttachCurrentThread();
java_authenticator_impl_ref_ = Java_AuthenticatorImpl_create(
env, reinterpret_cast<intptr_t>(this),
render_frame_host_->GetJavaRenderFrameHost());
}
return java_authenticator_impl_ref_;
}
...@@ -61,7 +61,12 @@ class InternalAuthenticatorAndroid : public autofill::InternalAuthenticator { ...@@ -61,7 +61,12 @@ class InternalAuthenticatorAndroid : public autofill::InternalAuthenticator {
jboolean is_uvpaa); jboolean is_uvpaa);
private: private:
JavaObjectWeakGlobalRef java_authenticator_impl_ref_; // Returns the associated AuthenticatorImpl Java object. Initializes new
// instance if not done so already in order to avoid possibility of any null
// pointer issues.
base::android::JavaRef<jobject>& GetJavaObject();
base::android::ScopedJavaGlobalRef<jobject> java_authenticator_impl_ref_;
content::RenderFrameHost* render_frame_host_; content::RenderFrameHost* render_frame_host_;
blink::mojom::Authenticator::MakeCredentialCallback blink::mojom::Authenticator::MakeCredentialCallback
make_credential_response_callback_; make_credential_response_callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment