Commit 5dbab35d authored by Jinho Bang's avatar Jinho Bang Committed by Commit Bot

Password: Fix a bug that "Touch to fill" UI doesn't work in dark mode

When switching dark mode, the application context is changed. Therefore,
existing cached object might not work. So, this patch removes the cache
related code and recreate the bridge object whenever
TouchToFillViewImpl::Show() is called.

Bug: 1146969
Change-Id: I386550b8008dc6289a0d6d2ea367e59c975fb508
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2525804Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Jinho Bang <jinho.bang@samsung.com>
Cr-Commit-Position: refs/heads/master@{#825852}
parent 0dad8387
......@@ -62,8 +62,7 @@ void TouchToFillViewImpl::Show(
const GURL& url,
IsOriginSecure is_origin_secure,
base::span<const password_manager::UiCredential> credentials) {
auto java_object = GetOrCreateJavaObject();
if (!java_object)
if (!RecreateJavaObject())
return;
// Serialize the |credentials| span into a Java array and instruct the bridge
// to show it together with |url| to the user.
......@@ -83,7 +82,7 @@ void TouchToFillViewImpl::Show(
}
Java_TouchToFillBridge_showCredentials(
env, java_object, ConvertUTF8ToJavaString(env, url.spec()),
env, java_object_internal_, ConvertUTF8ToJavaString(env, url.spec()),
is_origin_secure.value(), credential_array);
}
......@@ -109,16 +108,17 @@ void TouchToFillViewImpl::OnDismiss(JNIEnv* env) {
OnDismiss();
}
base::android::ScopedJavaGlobalRef<jobject>
TouchToFillViewImpl::GetOrCreateJavaObject() {
if (java_object_internal_) {
return java_object_internal_;
}
bool TouchToFillViewImpl::RecreateJavaObject() {
if (controller_->GetNativeView() == nullptr ||
controller_->GetNativeView()->GetWindowAndroid() == nullptr) {
return nullptr; // No window attached (yet or anymore).
return false; // No window attached (yet or anymore).
}
if (java_object_internal_) {
Java_TouchToFillBridge_destroy(AttachCurrentThread(),
java_object_internal_);
}
return java_object_internal_ = Java_TouchToFillBridge_create(
AttachCurrentThread(), reinterpret_cast<intptr_t>(this),
controller_->GetNativeView()->GetWindowAndroid()->GetJavaObject());
java_object_internal_ = Java_TouchToFillBridge_create(
AttachCurrentThread(), reinterpret_cast<intptr_t>(this),
controller_->GetNativeView()->GetWindowAndroid()->GetJavaObject());
return !!java_object_internal_;
}
......@@ -38,11 +38,10 @@ class TouchToFillViewImpl : public TouchToFillView {
void OnDismiss(JNIEnv* env);
private:
// Returns either the fully initialized java counterpart of this bridge or
// a is_null() reference if the creation failed. By using this method, the
// bridge will try to recreate the java object if it failed previously (e.g.
// because there was no native window available).
base::android::ScopedJavaGlobalRef<jobject> GetOrCreateJavaObject();
// Returns either true if the java counterpart of this bridge is initialized
// successfully or false if the creation failed. This method will recreate the
// java object whenever Show() is called.
bool RecreateJavaObject();
TouchToFillController* controller_ = nullptr;
base::android::ScopedJavaGlobalRef<jobject> java_object_internal_;
......
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