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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..413f590915844b154aeac6b8d9804a1e9de0e139 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/infobars/account_chooser_infobar.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#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 "components/password_manager/content/common/credential_manager_types.h" |
| +#include "jni/AccountChooserInfoBar_jni.h" |
| + |
| +namespace { |
| + |
| +void NotifyDelegateAboutChoosenCredential( |
|
Peter Kasting
2015/02/18 21:44:17
Nit: "Choosen" isn't a word. Why not just call th
melandory
2015/02/19 13:38:01
I'll remove this function, because with GetDelegat
|
| + infobars::InfoBarDelegate* delegate, |
| + int credential_item, |
| + password_manager::CredentialType credential_type) { |
| + AccountChooserInfoBarDelegateAndroid* infobar_delegate = |
| + static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate); |
|
Peter Kasting
2015/02/18 21:44:17
Nit: You do this twice in this file. If you defin
melandory
2015/02/19 13:38:01
Done.
|
| + infobar_delegate->ChooseCredential(credential_item, credential_type); |
| +} |
| + |
| +} // namespace |
| + |
| +AccountChooserInfoBar::AccountChooserInfoBar( |
| + scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) |
| + : InfoBarAndroid(delegate.Pass()) { |
| +} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| +AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| + AccountChooserInfoBarDelegateAndroid* infobar_delegate = |
| + static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); |
| + std::vector<base::string16> usernames; |
| + // TODO(melandory): Federated credentials should be processed also. |
| + for (auto password_form : infobar_delegate->local_credentials_forms()) |
| + usernames.push_back(password_form->username_value); |
| + base::android::ScopedJavaLocalRef<jobjectArray> java_usernames = |
| + base::android::ToJavaArrayOfStrings(env, usernames); |
| + return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this), |
| + GetEnumeratedIconId(), |
| + java_usernames.obj()); |
| +} |
| + |
| +void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, |
| + jobject obj, |
| + jint credential_item, |
| + jint credential_type) { |
| + NotifyDelegateAboutChoosenCredential( |
| + delegate(), credential_item, |
| + static_cast<password_manager::CredentialType>(credential_type)); |
| + RemoveSelf(); |
| +} |
| + |
| +void AccountChooserInfoBar::ProcessButton(int action, |
| + const std::string& action_value) { |
| + // We're closing; don't call anything, it might access |
| + // the owner. |
|
Peter Kasting
2015/02/18 21:44:17
Nit: This comment can all fit on one line, and sho
melandory
2015/02/19 13:38:01
Done.
|
| + if (!owner()) |
| + return; |
| + NotifyDelegateAboutChoosenCredential( |
| + delegate(), -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); |
| + RemoveSelf(); |
| +} |
| + |
| +bool RegisterAccountChooserInfoBar(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |