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

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: Removing avatar URL Created 5 years, 9 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"
8 #include "base/android/jni_array.h"
9 #include "chrome/browser/infobars/infobar_service.h" 7 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro id.h" 8 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro id.h"
9 #include "chrome/browser/password_manager/password_form_android_utils.h"
11 #include "components/password_manager/content/common/credential_manager_types.h" 10 #include "components/password_manager/content/common/credential_manager_types.h"
12 #include "jni/AccountChooserInfoBar_jni.h" 11 #include "jni/AccountChooserInfoBar_jni.h"
13 12
13 namespace {
14
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) {
newt (away) 2015/03/17 06:04:18 nit: be consistent with your naming. Either would
melandory 2015/03/17 13:05:33 Done.
22 ScopedJavaLocalRef<jobject> java_credential = CreateNativeCredential(
23 env, *password_form, index, static_cast<int>(type));
24 env->SetObjectArrayElement(java_credentials_array.obj(), index,
25 java_credential.obj());
26 index++;
27 }
28 return java_credentials_array;
29 }
30
31 }; // namespace
32
14 AccountChooserInfoBar::AccountChooserInfoBar( 33 AccountChooserInfoBar::AccountChooserInfoBar(
15 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate) 34 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate)
16 : InfoBarAndroid(delegate.Pass()) { 35 : InfoBarAndroid(delegate.Pass()) {
17 } 36 }
18 37
19 AccountChooserInfoBar::~AccountChooserInfoBar() { 38 AccountChooserInfoBar::~AccountChooserInfoBar() {
20 } 39 }
21 40
22 base::android::ScopedJavaLocalRef<jobject> 41 base::android::ScopedJavaLocalRef<jobject>
23 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) { 42 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) {
24 std::vector<base::string16> usernames; 43 size_t credential_array_size =
25 // TODO(melandory): Federated credentials should be processed also. 44 GetDelegate()->local_credentials_forms().size() +
26 for (auto password_form : GetDelegate()->local_credentials_forms()) 45 GetDelegate()->federated_credentials_forms().size();
27 usernames.push_back(password_form->username_value); 46 ScopedJavaLocalRef<jobjectArray> java_credentials_array =
28 base::android::ScopedJavaLocalRef<jobjectArray> java_usernames = 47 CreateNativeCredentialArray(env, credential_array_size);
29 base::android::ToJavaArrayOfStrings(env, usernames); 48 AddElementsToJavaCredentialArray(
49 env, java_credentials_array, GetDelegate()->local_credentials_forms(),
50 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL);
51 AddElementsToJavaCredentialArray(
52 env, java_credentials_array, GetDelegate()->federated_credentials_forms(),
53 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED);
30 return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this), 54 return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this),
31 GetEnumeratedIconId(), 55 GetEnumeratedIconId(),
32 java_usernames.obj()); 56 java_credentials_array.obj());
33 } 57 }
34 58
35 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, 59 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env,
36 jobject obj, 60 jobject obj,
37 jint credential_item, 61 jint credential_item,
38 jint credential_type) { 62 jint credential_type) {
39 GetDelegate()->ChooseCredential( 63 GetDelegate()->ChooseCredential(
40 credential_item, 64 credential_item,
41 static_cast<password_manager::CredentialType>(credential_type)); 65 static_cast<password_manager::CredentialType>(credential_type));
42 RemoveSelf(); 66 RemoveSelf();
43 } 67 }
44 68
45 void AccountChooserInfoBar::ProcessButton(int action, 69 void AccountChooserInfoBar::ProcessButton(int action,
46 const std::string& action_value) { 70 const std::string& action_value) {
47 if (!owner()) 71 if (!owner())
48 return; // We're closing; don't call anything, it might access the owner. 72 return; // We're closing; don't call anything, it might access the owner.
49 GetDelegate()->ChooseCredential( 73 GetDelegate()->ChooseCredential(
50 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); 74 -1, password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY);
51 RemoveSelf(); 75 RemoveSelf();
52 } 76 }
53 77
54 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() { 78 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() {
55 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); 79 return static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate());
56 } 80 }
57 81
58 bool RegisterAccountChooserInfoBar(JNIEnv* env) { 82 bool RegisterAccountChooserInfoBar(JNIEnv* env) {
59 return RegisterNativesImpl(env); 83 return RegisterNativesImpl(env);
60 } 84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698