| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill_popup_view_android.h" | 5 #include "chrome/browser/ui/android/autofill/autofill_popup_view_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "chrome/browser/ui/android/window_android_helper.h" | 9 #include "chrome/browser/ui/android/window_android_helper.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 controller_->element_bounds().x(), | 48 controller_->element_bounds().x(), |
| 49 controller_->element_bounds().y(), | 49 controller_->element_bounds().y(), |
| 50 controller_->element_bounds().width(), | 50 controller_->element_bounds().width(), |
| 51 controller_->element_bounds().height()); | 51 controller_->element_bounds().height()); |
| 52 | 52 |
| 53 // We need an array of AutofillSuggestion. | 53 // We need an array of AutofillSuggestion. |
| 54 ScopedJavaLocalRef<jclass> autofill_suggestion_clazz = | 54 ScopedJavaLocalRef<jclass> autofill_suggestion_clazz = |
| 55 base::android::GetClass(env, | 55 base::android::GetClass(env, |
| 56 "org/chromium/chrome/browser/autofill/AutofillSuggestion"); | 56 "org/chromium/chrome/browser/autofill/AutofillSuggestion"); |
| 57 ScopedJavaLocalRef<jobjectArray> data_array(env, | 57 ScopedJavaLocalRef<jobjectArray> data_array(env, |
| 58 env->NewObjectArray(controller_->autofill_values().size(), | 58 env->NewObjectArray(controller_->names().size(), |
| 59 autofill_suggestion_clazz.obj(), NULL)); | 59 autofill_suggestion_clazz.obj(), NULL)); |
| 60 base::android::CheckException(env); | 60 base::android::CheckException(env); |
| 61 for (size_t i = 0; i < controller_->autofill_values().size(); ++i) { | 61 for (size_t i = 0; i < controller_->names().size(); ++i) { |
| 62 ScopedJavaLocalRef<jstring> value = | 62 ScopedJavaLocalRef<jstring> name = |
| 63 base::android::ConvertUTF16ToJavaString( | 63 base::android::ConvertUTF16ToJavaString( |
| 64 env, controller_->autofill_values()[i]); | 64 env, controller_->names()[i]); |
| 65 ScopedJavaLocalRef<jstring> label = | 65 ScopedJavaLocalRef<jstring> subtext = |
| 66 base::android::ConvertUTF16ToJavaString( | 66 base::android::ConvertUTF16ToJavaString( |
| 67 env, controller_->autofill_labels()[i]); | 67 env, controller_->subtexts()[i]); |
| 68 int unique_id = controller_->autofill_unique_ids()[i]; | 68 int identifier = controller_->identifiers()[i]; |
| 69 ScopedJavaLocalRef<jobject> data = | 69 ScopedJavaLocalRef<jobject> data = |
| 70 Java_AutofillPopupGlue_createAutofillSuggestion(env, | 70 Java_AutofillPopupGlue_createAutofillSuggestion(env, |
| 71 value.obj(), | 71 name.obj(), |
| 72 label.obj(), | 72 subtext.obj(), |
| 73 unique_id); | 73 identifier); |
| 74 env->SetObjectArrayElement(data_array.obj(), i, data.obj()); | 74 env->SetObjectArrayElement(data_array.obj(), i, data.obj()); |
| 75 base::android::CheckException(env); | 75 base::android::CheckException(env); |
| 76 } | 76 } |
| 77 | 77 |
| 78 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj()); | 78 Java_AutofillPopupGlue_show(env, java_object_.obj(), data_array.obj()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, | 81 void AutofillPopupViewAndroid::SuggestionSelected(JNIEnv* env, |
| 82 jobject obj, | 82 jobject obj, |
| 83 jint list_index, | 83 jint list_index, |
| 84 jstring value, | 84 jstring /*name*/, |
| 85 jint unique_id) { | 85 jint /*identifier*/) { |
| 86 string16 value_utf16 = base::android::ConvertJavaStringToUTF16(env, value); | 86 controller_->AcceptSuggestion(list_index); |
| 87 controller_->AcceptAutofillSuggestion(value_utf16, | |
| 88 unique_id, | |
| 89 list_index); | |
| 90 } | 87 } |
| 91 | 88 |
| 92 void AutofillPopupViewAndroid::Dismissed(JNIEnv* env, jobject obj) { | 89 void AutofillPopupViewAndroid::Dismissed(JNIEnv* env, jobject obj) { |
| 93 delete this; | 90 delete this; |
| 94 } | 91 } |
| 95 | 92 |
| 96 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} | 93 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} |
| 97 | 94 |
| 98 // static | 95 // static |
| 99 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { | 96 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { |
| 100 return RegisterNativesImpl(env); | 97 return RegisterNativesImpl(env); |
| 101 } | 98 } |
| 102 | 99 |
| 103 // static | 100 // static |
| 104 AutofillPopupView* AutofillPopupView::Create( | 101 AutofillPopupView* AutofillPopupView::Create( |
| 105 AutofillPopupController* controller) { | 102 AutofillPopupController* controller) { |
| 106 return new AutofillPopupViewAndroid(controller); | 103 return new AutofillPopupViewAndroid(controller); |
| 107 } | 104 } |
| OLD | NEW |