Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/browser/ui/android/infobars/account_chooser_infobar.cc

Issue 925593006: Pass all info to account chooser infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java_cpp_enum
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/infobars/account_chooser_infobar.h" 5 #include "chrome/browser/ui/android/infobars/account_chooser_infobar.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro id.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" 11 #include "components/password_manager/content/common/credential_manager_types.h"
12 #include "jni/AccountChooserInfoBar_jni.h" 12 #include "jni/AccountChooserInfoBar_jni.h"
13 13
14 namespace {
15 ScopedJavaLocalRef<jobjectArray> AddElementsToJavaCredentialArray(
16 JNIEnv* env,
17 ScopedJavaLocalRef<jobjectArray> java_credentials_array,
18 const ScopedVector<autofill::PasswordForm>& credentials_forms,
19 password_manager::CredentialType type) {
20 int index = 0;
21 for (auto password_form : credentials_forms) {
22 ScopedJavaLocalRef<jobject> java_credential =
23 password_form->createNativeCredential(env, index,
24 static_cast<int>(type));
25 env->SetObjectArrayElement(java_credentials_array.obj(), index,
26 java_credential.obj());
27 index++;
28 }
29 return java_credentials_array;
30 }
31
32 }; // namespace
33
14 AccountChooserInfoBar::AccountChooserInfoBar( 34 AccountChooserInfoBar::AccountChooserInfoBar(
15 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) 35 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate)
16 : InfoBarAndroid(delegate.Pass()) { 36 : InfoBarAndroid(delegate.Pass()) {
17 } 37 }
18 38
19 AccountChooserInfoBar::~AccountChooserInfoBar() { 39 AccountChooserInfoBar::~AccountChooserInfoBar() {
20 } 40 }
21 41
22 base::android::ScopedJavaLocalRef<jobject> 42 base::android::ScopedJavaLocalRef<jobject>
23 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { 43 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) {
24 std::vector<base::string16> usernames; 44 size_t credential_array_size =
25 // TODO(melandory): Federated credentials should be processed also. 45 GetDelegate()->local_credentials_forms().size() +
26 for (auto password_form : GetDelegate()->local_credentials_forms()) 46 GetDelegate()->federated_credentials_forms().size();
27 usernames.push_back(password_form->username_value); 47 ScopedJavaLocalRef<jobjectArray> java_credentials_array =
28 base::android::ScopedJavaLocalRef<jobjectArray> java_usernames = 48 autofill::CreateNativeCredentialArray(env, credential_array_size);
29 base::android::ToJavaArrayOfStrings(env, usernames); 49 AddElementsToJavaCredentialArray(
50 env, java_credentials_array, GetDelegate()->local_credentials_forms(),
51 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL);
52 AddElementsToJavaCredentialArray(
53 env, java_credentials_array, GetDelegate()->federated_credentials_forms(),
54 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED);
30 return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this), 55 return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this),
31 GetEnumeratedIconId(), 56 GetEnumeratedIconId(),
32 java_usernames.obj()); 57 java_credentials_array.obj());
33 } 58 }
34 59
35 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, 60 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env,
36 jobject obj, 61 jobject obj,
37 jint credential_item, 62 jint credential_item,
38 jint credential_type) { 63 jint credential_type) {
39 GetDelegate()->ChooseCredential( 64 GetDelegate()->ChooseCredential(
40 credential_item, 65 credential_item,
41 static_cast<password_manager::CredentialType>(credential_type)); 66 static_cast<password_manager::CredentialType>(credential_type));
42 RemoveSelf(); 67 RemoveSelf();
43 } 68 }
44 69
45 void AccountChooserInfoBar::ProcessButton(int action, 70 void AccountChooserInfoBar::ProcessButton(int action,
46 const std::string& action_value) { 71 const std::string& action_value) {
47 if (!owner()) 72 if (!owner())
48 return; // We're closing; don't call anything, it might access the owner. 73 return; // We're closing; don't call anything, it might access the owner.
49 GetDelegate()->ChooseCredential( 74 GetDelegate()->ChooseCredential(
50 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); 75 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY);
51 RemoveSelf(); 76 RemoveSelf();
52 } 77 }
53 78
54 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() { 79 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() {
55 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); 80 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate());
56 } 81 }
57 82
58 bool RegisterAccountChooserInfoBar(JNIEnv* env) { 83 bool RegisterAccountChooserInfoBar(JNIEnv* env) {
59 return RegisterNativesImpl(env); 84 return RegisterNativesImpl(env);
60 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698