| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/android/autofill/password_generation_popup_view_andr
oid.h" | 5 #include "chrome/browser/ui/android/autofill/password_generation_popup_view_andr
oid.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 // static | 54 // static |
| 55 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { | 55 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { |
| 56 return RegisterNativesImpl(env); | 56 return RegisterNativesImpl(env); |
| 57 } | 57 } |
| 58 | 58 |
| 59 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} | 59 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} |
| 60 | 60 |
| 61 void PasswordGenerationPopupViewAndroid::Show() { | 61 void PasswordGenerationPopupViewAndroid::Show() { |
| 62 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 63 ui::ViewAndroid* view_android = controller_->container_view(); | 62 ui::ViewAndroid* view_android = controller_->container_view(); |
| 64 | 63 |
| 65 DCHECK(view_android); | 64 DCHECK(view_android); |
| 66 | 65 |
| 66 popup_ = view_android->AcquireAnchorView(); |
| 67 const ScopedJavaLocalRef<jobject> view = popup_.view(); |
| 68 if (view.is_null()) |
| 69 return; |
| 70 JNIEnv* env = base::android::AttachCurrentThread(); |
| 67 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( | 71 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( |
| 68 env, reinterpret_cast<intptr_t>(this), | 72 env, view.obj(), reinterpret_cast<intptr_t>(this), |
| 69 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 73 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 70 view_android->GetViewAndroidDelegate().obj())); | |
| 71 | 74 |
| 72 UpdateBoundsAndRedrawPopup(); | 75 UpdateBoundsAndRedrawPopup(); |
| 73 } | 76 } |
| 74 | 77 |
| 75 void PasswordGenerationPopupViewAndroid::Hide() { | 78 void PasswordGenerationPopupViewAndroid::Hide() { |
| 76 controller_ = NULL; | 79 controller_ = NULL; |
| 77 JNIEnv* env = base::android::AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
| 78 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); | 81 if (!java_object_.is_null()) { |
| 82 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); |
| 83 } else { |
| 84 // Hide() should delete |this| either via Java dismiss or directly. |
| 85 delete this; |
| 86 } |
| 79 } | 87 } |
| 80 | 88 |
| 81 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { | 89 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { |
| 82 static const int kUnusedSize = 0; | 90 static const int kUnusedSize = 0; |
| 83 return gfx::Size(kUnusedSize, kUnusedSize); | 91 return gfx::Size(kUnusedSize, kUnusedSize); |
| 84 } | 92 } |
| 85 | 93 |
| 86 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 94 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 95 if (java_object_.is_null()) |
| 96 return; |
| 97 |
| 98 const ScopedJavaLocalRef<jobject> view = popup_.view(); |
| 99 if (view.is_null()) |
| 100 return; |
| 101 |
| 102 ui::ViewAndroid* view_android = controller_->container_view(); |
| 103 |
| 104 DCHECK(view_android); |
| 105 view_android->SetAnchorRect(view, controller_->element_bounds()); |
| 87 JNIEnv* env = base::android::AttachCurrentThread(); | 106 JNIEnv* env = base::android::AttachCurrentThread(); |
| 88 Java_PasswordGenerationPopupBridge_setAnchorRect( | |
| 89 env, | |
| 90 java_object_.obj(), | |
| 91 controller_->element_bounds().x(), | |
| 92 controller_->element_bounds().y(), | |
| 93 controller_->element_bounds().width(), | |
| 94 controller_->element_bounds().height()); | |
| 95 | |
| 96 ScopedJavaLocalRef<jstring> password = | 107 ScopedJavaLocalRef<jstring> password = |
| 97 base::android::ConvertUTF16ToJavaString(env, controller_->password()); | 108 base::android::ConvertUTF16ToJavaString(env, controller_->password()); |
| 98 ScopedJavaLocalRef<jstring> suggestion = | 109 ScopedJavaLocalRef<jstring> suggestion = |
| 99 base::android::ConvertUTF16ToJavaString( | 110 base::android::ConvertUTF16ToJavaString( |
| 100 env, controller_->SuggestedText()); | 111 env, controller_->SuggestedText()); |
| 101 ScopedJavaLocalRef<jstring> help = | 112 ScopedJavaLocalRef<jstring> help = |
| 102 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); | 113 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); |
| 103 | 114 |
| 104 Java_PasswordGenerationPopupBridge_show( | 115 Java_PasswordGenerationPopupBridge_show( |
| 105 env, | 116 env, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 121 return false; | 132 return false; |
| 122 } | 133 } |
| 123 | 134 |
| 124 // static | 135 // static |
| 125 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( | 136 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( |
| 126 PasswordGenerationPopupController* controller) { | 137 PasswordGenerationPopupController* controller) { |
| 127 return new PasswordGenerationPopupViewAndroid(controller); | 138 return new PasswordGenerationPopupViewAndroid(controller); |
| 128 } | 139 } |
| 129 | 140 |
| 130 } // namespace autofill | 141 } // namespace autofill |
| OLD | NEW |