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 base::android::ScopedJavaLocalRef<jobject> | |
20 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.
| |
21 AccountChooserInfoBarDelegateAndroid* infobar_delegate = | |
22 static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); | |
23 std::vector<base::string16> usernames; | |
24 // TODO(melandory): Federated credentials should be processed also. | |
25 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.
| |
26 usernames.push_back(password_form->username_value); | |
27 } | |
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::ProcessButton(int action, | |
36 const std::string& action_value) { | |
37 if (!owner()) | |
38 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.
| |
39 | |
40 RemoveSelf(); | |
41 } | |
42 | |
43 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env, | |
44 jobject obj, | |
45 jint credential_item, | |
46 jint credential_type) { | |
47 ChooseCredential(credential_item, credential_type); | |
48 } | |
49 | |
50 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.
| |
51 int credential_type) { | |
52 AccountChooserInfoBarDelegateAndroid* infobar_delegate = | |
53 static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate()); | |
54 infobar_delegate->ChooseCredential( | |
55 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.
| |
56 RemoveSelf(); | |
57 } | |
58 | |
59 bool RegisterAccountChooserInfoBar(JNIEnv* env) { | |
60 return RegisterNativesImpl(env); | |
61 } | |
OLD | NEW |