OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/android/infobars/account_chooser_infobar.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro
id.h" |
| 11 #include "components/password_manager/content/common/credential_manager_types.h" |
| 12 #include "jni/AccountChooserInfoBar_jni.h" |
| 13 |
| 14 AccountChooserInfoBar::AccountChooserInfoBar( |
| 15 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) |
| 16 : InfoBarAndroid(delegate.Pass()) { |
| 17 } |
| 18 |
| 19 AccountChooserInfoBar::~AccountChooserInfoBar() { |
| 20 } |
| 21 |
| 22 base::android::ScopedJavaLocalRef<jobject> |
| 23 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| 24 std::vector<base::string16> usernames; |
| 25 // TODO(melandory): Federated credentials should be processed also. |
| 26 for (auto password_form : GetDelegate()->local_credentials_forms()) |
| 27 usernames.push_back(password_form->username_value); |
| 28 base::android::ScopedJavaLocalRef<jobjectArray> java_usernames = |
| 29 base::android::ToJavaArrayOfStrings(env, usernames); |
| 30 return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this), |
| 31 GetEnumeratedIconId(), |
| 32 java_usernames.obj()); |
| 33 } |
| 34 |
| 35 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, |
| 36 jobject obj, |
| 37 jint credential_item, |
| 38 jint credential_type) { |
| 39 GetDelegate()->ChooseCredential( |
| 40 credential_item, |
| 41 static_cast<password_manager::CredentialType>(credential_type)); |
| 42 RemoveSelf(); |
| 43 } |
| 44 |
| 45 void AccountChooserInfoBar::ProcessButton(int action, |
| 46 const std::string& action_value) { |
| 47 if (!owner()) |
| 48 return; // We're closing; don't call anything, it might access the owner. |
| 49 GetDelegate()->ChooseCredential( |
| 50 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); |
| 51 RemoveSelf(); |
| 52 } |
| 53 |
| 54 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() { |
| 55 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); |
| 56 } |
| 57 |
| 58 bool RegisterAccountChooserInfoBar(JNIEnv* env) { |
| 59 return RegisterNativesImpl(env); |
| 60 } |
OLD | NEW |