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( ...@@ -62,8 +62,7 @@ void TouchToFillViewImpl::Show(
const GURL& url, const GURL& url,
IsOriginSecure is_origin_secure, IsOriginSecure is_origin_secure,
base::span<const password_manager::UiCredential> credentials) { base::span<const password_manager::UiCredential> credentials) {
auto java_object = GetOrCreateJavaObject(); if (!RecreateJavaObject())
if (!java_object)
return; return;
// Serialize the |credentials| span into a Java array and instruct the bridge // Serialize the |credentials| span into a Java array and instruct the bridge
// to show it together with |url| to the user. // to show it together with |url| to the user.
...@@ -83,7 +82,7 @@ void TouchToFillViewImpl::Show( ...@@ -83,7 +82,7 @@ void TouchToFillViewImpl::Show(
} }
Java_TouchToFillBridge_showCredentials( Java_TouchToFillBridge_showCredentials(
env, java_object, ConvertUTF8ToJavaString(env, url.spec()), env, java_object_internal_, ConvertUTF8ToJavaString(env, url.spec()),
is_origin_secure.value(), credential_array); is_origin_secure.value(), credential_array);
} }
...@@ -109,16 +108,17 @@ void TouchToFillViewImpl::OnDismiss(JNIEnv* env) { ...@@ -109,16 +108,17 @@ void TouchToFillViewImpl::OnDismiss(JNIEnv* env) {
OnDismiss(); OnDismiss();
} }
base::android::ScopedJavaGlobalRef<jobject> bool TouchToFillViewImpl::RecreateJavaObject() {
TouchToFillViewImpl::GetOrCreateJavaObject() {
if (java_object_internal_) {
return java_object_internal_;
}
if (controller_->GetNativeView() == nullptr || if (controller_->GetNativeView() == nullptr ||
controller_->GetNativeView()->GetWindowAndroid() == 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( java_object_internal_ = Java_TouchToFillBridge_create(
AttachCurrentThread(), reinterpret_cast<intptr_t>(this), AttachCurrentThread(), reinterpret_cast<intptr_t>(this),
controller_->GetNativeView()->GetWindowAndroid()->GetJavaObject()); controller_->GetNativeView()->GetWindowAndroid()->GetJavaObject());
return !!java_object_internal_;
} }
...@@ -38,11 +38,10 @@ class TouchToFillViewImpl : public TouchToFillView { ...@@ -38,11 +38,10 @@ class TouchToFillViewImpl : public TouchToFillView {
void OnDismiss(JNIEnv* env); void OnDismiss(JNIEnv* env);
private: private:
// Returns either the fully initialized java counterpart of this bridge or // Returns either true if the java counterpart of this bridge is initialized
// a is_null() reference if the creation failed. By using this method, the // successfully or false if the creation failed. This method will recreate the
// bridge will try to recreate the java object if it failed previously (e.g. // java object whenever Show() is called.
// because there was no native window available). bool RecreateJavaObject();
base::android::ScopedJavaGlobalRef<jobject> GetOrCreateJavaObject();
TouchToFillController* controller_ = nullptr; TouchToFillController* controller_ = nullptr;
base::android::ScopedJavaGlobalRef<jobject> java_object_internal_; 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