OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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/update_password_infobar.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" |
| 12 #include "components/password_manager/core/common/credential_manager_types.h" |
| 13 #include "jni/UpdatePasswordInfoBar_jni.h" |
| 14 |
| 15 UpdatePasswordInfoBar::UpdatePasswordInfoBar( |
| 16 scoped_ptr<UpdatePasswordInfoBarDelegate> delegate) |
| 17 : ConfirmInfoBar(std::move(delegate)) {} |
| 18 |
| 19 UpdatePasswordInfoBar::~UpdatePasswordInfoBar() {} |
| 20 |
| 21 base::android::ScopedJavaLocalRef<jobject> |
| 22 UpdatePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| 23 using base::android::ConvertUTF16ToJavaString; |
| 24 using base::android::ScopedJavaLocalRef; |
| 25 UpdatePasswordInfoBarDelegate* update_password_delegate = |
| 26 static_cast<UpdatePasswordInfoBarDelegate*>(delegate()); |
| 27 ScopedJavaLocalRef<jstring> ok_button_text = ConvertUTF16ToJavaString( |
| 28 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 29 ScopedJavaLocalRef<jstring> cancel_button_text = ConvertUTF16ToJavaString( |
| 30 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 31 ScopedJavaLocalRef<jstring> branding_text = |
| 32 ConvertUTF16ToJavaString(env, update_password_delegate->branding()); |
| 33 |
| 34 std::vector<base::string16> usernames; |
| 35 if (update_password_delegate->ShowMultipleAccounts()) { |
| 36 for (auto password_form : update_password_delegate->GetCurrentForms()) { |
| 37 usernames.push_back(password_form->username_value); |
| 38 } |
| 39 } else { |
| 40 usernames.push_back( |
| 41 update_password_delegate->GetUsernameForOneAccountCase()); |
| 42 } |
| 43 |
| 44 base::android::ScopedJavaLocalRef<jobjectArray> java_usernames = |
| 45 base::android::ToJavaArrayOfStrings(env, usernames); |
| 46 return Java_UpdatePasswordInfoBar_show( |
| 47 env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(), |
| 48 java_usernames.obj(), ok_button_text.obj(), cancel_button_text.obj(), |
| 49 branding_text.obj(), update_password_delegate->ShowMultipleAccounts(), |
| 50 update_password_delegate->is_smartlock_branding_enabled()); |
| 51 } |
| 52 |
| 53 void UpdatePasswordInfoBar::OnLinkClicked(JNIEnv* env, |
| 54 const JavaParamRef<jobject>& obj) { |
| 55 GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB); |
| 56 } |
| 57 |
| 58 void UpdatePasswordInfoBar::OnUpdateClicked(JNIEnv* env, |
| 59 jobject obj, |
| 60 jint form_id) { |
| 61 UpdatePasswordInfoBarDelegate* update_password_delegate = |
| 62 static_cast<UpdatePasswordInfoBarDelegate*>(delegate()); |
| 63 update_password_delegate->UpdatePasswordInternal(form_id); |
| 64 RemoveSelf(); |
| 65 } |
| 66 |
| 67 bool UpdatePasswordInfoBar::Register(JNIEnv* env) { |
| 68 return RegisterNativesImpl(env); |
| 69 } |
| 70 |
| 71 scoped_ptr<infobars::InfoBar> CreateUpdatePasswordInfoBar( |
| 72 scoped_ptr<UpdatePasswordInfoBarDelegate> delegate) { |
| 73 return make_scoped_ptr(new UpdatePasswordInfoBar(std::move(delegate))); |
| 74 } |
OLD | NEW |