Chromium Code Reviews| Index: chrome/browser/ui/android/infobars/account_chooser_infobar.cc |
| diff --git a/chrome/browser/ui/android/infobars/account_chooser_infobar.cc b/chrome/browser/ui/android/infobars/account_chooser_infobar.cc |
| index 00fa5fdb2cf895dfdc51cfe1dc9797a9f41135b2..f9ee85059bc974d07315ba42059a3f7efbacab81 100644 |
| --- a/chrome/browser/ui/android/infobars/account_chooser_infobar.cc |
| +++ b/chrome/browser/ui/android/infobars/account_chooser_infobar.cc |
| @@ -4,13 +4,32 @@ |
| #include "chrome/browser/ui/android/infobars/account_chooser_infobar.h" |
| -#include "base/android/jni_android.h" |
| -#include "base/android/jni_array.h" |
| #include "chrome/browser/infobars/infobar_service.h" |
| #include "chrome/browser/password_manager/account_chooser_infobar_delegate_android.h" |
| +#include "chrome/browser/password_manager/password_form_android_utils.h" |
| #include "components/password_manager/content/common/credential_manager_types.h" |
| #include "jni/AccountChooserInfoBar_jni.h" |
| +namespace { |
| + |
| +ScopedJavaLocalRef<jobjectArray> AddElementsToJavaCredentialArray( |
| + JNIEnv* env, |
| + ScopedJavaLocalRef<jobjectArray> java_credentials_array, |
| + const ScopedVector<autofill::PasswordForm>& credentials_forms, |
| + password_manager::CredentialType type) { |
| + int index = 0; |
| + for (auto password_form : credentials_forms) { |
|
newt (away)
2015/03/17 06:04:18
nit: be consistent with your naming. Either would
melandory
2015/03/17 13:05:33
Done.
|
| + ScopedJavaLocalRef<jobject> java_credential = CreateNativeCredential( |
| + env, *password_form, index, static_cast<int>(type)); |
| + env->SetObjectArrayElement(java_credentials_array.obj(), index, |
| + java_credential.obj()); |
| + index++; |
| + } |
| + return java_credentials_array; |
| +} |
| + |
| +}; // namespace |
| + |
| AccountChooserInfoBar::AccountChooserInfoBar( |
| scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) |
| : InfoBarAndroid(delegate.Pass()) { |
| @@ -21,15 +40,20 @@ AccountChooserInfoBar::~AccountChooserInfoBar() { |
| base::android::ScopedJavaLocalRef<jobject> |
| AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| - std::vector<base::string16> usernames; |
| - // TODO(melandory): Federated credentials should be processed also. |
| - for (auto password_form : GetDelegate()->local_credentials_forms()) |
| - usernames.push_back(password_form->username_value); |
| - base::android::ScopedJavaLocalRef<jobjectArray> java_usernames = |
| - base::android::ToJavaArrayOfStrings(env, usernames); |
| + size_t credential_array_size = |
| + GetDelegate()->local_credentials_forms().size() + |
| + GetDelegate()->federated_credentials_forms().size(); |
| + ScopedJavaLocalRef<jobjectArray> java_credentials_array = |
| + CreateNativeCredentialArray(env, credential_array_size); |
| + AddElementsToJavaCredentialArray( |
| + env, java_credentials_array, GetDelegate()->local_credentials_forms(), |
| + password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
| + AddElementsToJavaCredentialArray( |
| + env, java_credentials_array, GetDelegate()->federated_credentials_forms(), |
| + password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this), |
| GetEnumeratedIconId(), |
| - java_usernames.obj()); |
| + java_credentials_array.obj()); |
| } |
| void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, |