| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { | 52 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { |
| 53 return RegisterNativesImpl(env); | 53 return RegisterNativesImpl(env); |
| 54 } | 54 } |
| 55 | 55 |
| 56 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} | 56 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} |
| 57 | 57 |
| 58 void PasswordGenerationPopupViewAndroid::Show() { | 58 void PasswordGenerationPopupViewAndroid::Show() { |
| 59 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 60 ui::ViewAndroid* view_android = controller_->container_view(); | 59 ui::ViewAndroid* view_android = controller_->container_view(); |
| 61 | 60 |
| 62 DCHECK(view_android); | 61 DCHECK(view_android); |
| 63 | 62 |
| 63 popup_ = view_android->AcquireAnchorView(); |
| 64 const ScopedJavaLocalRef<jobject> view = popup_.view(); |
| 65 if (view.is_null()) |
| 66 return; |
| 67 JNIEnv* env = base::android::AttachCurrentThread(); |
| 64 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( | 68 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( |
| 65 env, reinterpret_cast<intptr_t>(this), | 69 env, view.obj(), reinterpret_cast<intptr_t>(this), |
| 66 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 70 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 67 view_android->GetViewAndroidDelegate().obj())); | |
| 68 | 71 |
| 69 UpdateBoundsAndRedrawPopup(); | 72 UpdateBoundsAndRedrawPopup(); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void PasswordGenerationPopupViewAndroid::Hide() { | 75 void PasswordGenerationPopupViewAndroid::Hide() { |
| 73 controller_ = NULL; | 76 controller_ = NULL; |
| 74 JNIEnv* env = base::android::AttachCurrentThread(); | 77 JNIEnv* env = base::android::AttachCurrentThread(); |
| 75 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); | 78 if (!java_object_.is_null()) { |
| 79 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); |
| 80 } else { |
| 81 // Hide() should delete |this| either via Java dismiss or directly. |
| 82 delete this; |
| 83 } |
| 76 } | 84 } |
| 77 | 85 |
| 78 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { | 86 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { |
| 79 static const int kUnusedSize = 0; | 87 static const int kUnusedSize = 0; |
| 80 return gfx::Size(kUnusedSize, kUnusedSize); | 88 return gfx::Size(kUnusedSize, kUnusedSize); |
| 81 } | 89 } |
| 82 | 90 |
| 83 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 91 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 92 if (java_object_.is_null()) |
| 93 return; |
| 94 |
| 95 const ScopedJavaLocalRef<jobject> view = popup_.view(); |
| 96 if (view.is_null()) |
| 97 return; |
| 98 |
| 99 ui::ViewAndroid* view_android = controller_->container_view(); |
| 100 |
| 101 DCHECK(view_android); |
| 102 view_android->SetAnchorRect(view, controller_->element_bounds()); |
| 84 JNIEnv* env = base::android::AttachCurrentThread(); | 103 JNIEnv* env = base::android::AttachCurrentThread(); |
| 85 Java_PasswordGenerationPopupBridge_setAnchorRect( | |
| 86 env, | |
| 87 java_object_.obj(), | |
| 88 controller_->element_bounds().x(), | |
| 89 controller_->element_bounds().y(), | |
| 90 controller_->element_bounds().width(), | |
| 91 controller_->element_bounds().height()); | |
| 92 | |
| 93 ScopedJavaLocalRef<jstring> password = | 104 ScopedJavaLocalRef<jstring> password = |
| 94 base::android::ConvertUTF16ToJavaString(env, controller_->password()); | 105 base::android::ConvertUTF16ToJavaString(env, controller_->password()); |
| 95 ScopedJavaLocalRef<jstring> suggestion = | 106 ScopedJavaLocalRef<jstring> suggestion = |
| 96 base::android::ConvertUTF16ToJavaString( | 107 base::android::ConvertUTF16ToJavaString( |
| 97 env, controller_->SuggestedText()); | 108 env, controller_->SuggestedText()); |
| 98 ScopedJavaLocalRef<jstring> help = | 109 ScopedJavaLocalRef<jstring> help = |
| 99 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); | 110 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); |
| 100 | 111 |
| 101 Java_PasswordGenerationPopupBridge_show( | 112 Java_PasswordGenerationPopupBridge_show( |
| 102 env, | 113 env, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 118 return false; | 129 return false; |
| 119 } | 130 } |
| 120 | 131 |
| 121 // static | 132 // static |
| 122 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( | 133 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( |
| 123 PasswordGenerationPopupController* controller) { | 134 PasswordGenerationPopupController* controller) { |
| 124 return new PasswordGenerationPopupViewAndroid(controller); | 135 return new PasswordGenerationPopupViewAndroid(controller); |
| 125 } | 136 } |
| 126 | 137 |
| 127 } // namespace autofill | 138 } // namespace autofill |
| OLD | NEW |