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..051c2faf14043ed913ef1a964434e95974d1f18e |
--- /dev/null |
+++ b/chrome/browser/ui/android/infobars/account_chooser_infobar.cc |
@@ -0,0 +1,61 @@ |
+// 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" |
+ |
+AccountChooserInfoBar::AccountChooserInfoBar( |
+ scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) |
+ : InfoBarAndroid(delegate.Pass()) { |
+} |
+ |
+base::android::ScopedJavaLocalRef<jobject> |
+AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
Peter Kasting
2015/02/18 00:23:05
Function definition order must match declaration o
melandory
2015/02/18 21:15:34
Done.
|
+ 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()) { |
Peter Kasting
2015/02/18 00:23:05
Nit: No {} (you don't put it on one-line condition
melandory
2015/02/18 21:15:34
Done.
|
+ 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::ProcessButton(int action, |
+ const std::string& action_value) { |
+ if (!owner()) |
+ return; |
Peter Kasting
2015/02/18 00:23:05
Nit: For clarity, add: "// We're closing; don't ca
melandory
2015/02/18 21:15:34
Done.
|
+ |
+ RemoveSelf(); |
+} |
+ |
+void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, |
+ jobject obj, |
+ jint credential_item, |
+ jint credential_type) { |
+ ChooseCredential(credential_item, credential_type); |
+} |
+ |
+void AccountChooserInfoBar::ChooseCredential(int credential_item, |
Peter Kasting
2015/02/18 00:23:05
Why do we have this helper for just one caller? W
melandory
2015/02/18 21:15:34
Done.
|
+ int credential_type) { |
+ AccountChooserInfoBarDelegateAndroid* infobar_delegate = |
+ static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); |
+ infobar_delegate->ChooseCredential( |
+ credential_item, (password_manager::CredentialType)credential_type); |
Peter Kasting
2015/02/18 00:23:05
No C-style casts, please
melandory
2015/02/18 21:15:34
Done.
|
+ RemoveSelf(); |
+} |
+ |
+bool RegisterAccountChooserInfoBar(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |