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

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

Issue 861103002: Credentials chooser UI for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
(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 "base/android/jni_string.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/password_manager/account_chooser_infobar_delegate_andro id.h"
12 #include "components/password_manager/content/common/credential_manager_types.h"
13 #include "content/public/browser/web_contents.h"
14 #include "jni/AccountChooserInfoBar_jni.h"
15
16 // static
17 void AccountChooserInfoBarDelegateAndroid::Create(
18 content::WebContents* web_contents,
19 ManagePasswordsUIController* ui_controller) {
20 InfoBarService::FromWebContents(web_contents)
21 ->AddInfoBar(make_scoped_ptr(new AccountChooserInfoBar(make_scoped_ptr(
22 new AccountChooserInfoBarDelegateAndroid(ui_controller)))));
23 }
24
25 AccountChooserInfoBar::AccountChooserInfoBar(
26 scoped_ptr<AccountChooserInfoBarDelegateAndroid> delegate)
27 : InfoBarAndroid(delegate.Pass()) {
28 }
29
30 base::android::ScopedJavaLocalRef<jobject>
31 AccountChooserInfoBar::CreateRenderInfoBar(JNIEnv* env) {
32 AccountChooserInfoBarDelegateAndroid* infobar_delegate =
33 static_cast<AccountChooserInfoBarDelegateAndroid*>(delegate());
34 std::vector<base::string16> usernames;
35 // TODO(melandory): Federated credentials should be processed also.
36 for (auto password_form : infobar_delegate->local_credentials_forms()) {
37 usernames.push_back(password_form->username_value);
38 }
39 base::android::ScopedJavaLocalRef<jobjectArray> java_usernames =
40 base::android::ToJavaArrayOfStrings(env, usernames);
41 return Java_AccountChooserInfoBar_show(env, reinterpret_cast<intptr_t>(this),
42 GetEnumeratedIconId(),
43 java_usernames.obj());
44 }
45
46 void AccountChooserInfoBar::ProcessButton(int action,
47 const std::string& action_value) {
48 if (!owner())
49 return;
50
51 RemoveSelf();
52 }
53
54 void AccountChooserInfoBar::OnCredentialClicked(JNIEnv* env,
55 jobject obj,
56 jint credential_item,
57 jint credential_type) {
58 ChooseCredential(credential_item, credential_type);
59 }
60
61 void AccountChooserInfoBar::ChooseCredential(int credential_item,
62 int credential_type) {
63 AccountChooserInfoBarDelegateAndroid* delegate = GetDelegate();
64 delegate->choose_credential(
65 credential_item, (password_manager::CredentialType)credential_type);
66 RemoveSelf();
67 }
68
69 bool RegisterAccountChooserInfoBar(JNIEnv* env) {
70 return RegisterNativesImpl(env);
71 }
72
73 AccountChooserInfoBarDelegateAndroid* AccountChooserInfoBar::GetDelegate() {
74 return delegate()->AsAccountChooserInfoBarDelegateAndroid();
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698