| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/update_password_infobar.h" | 5 #include "chrome/browser/ui/android/infobars/update_password_infobar.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "chrome/browser/password_manager/update_password_infobar_delegate_andro
id.h" | 12 #include "chrome/browser/password_manager/update_password_infobar_delegate_andro
id.h" |
| 13 #include "components/password_manager/core/common/credential_manager_types.h" | 13 #include "components/password_manager/core/common/credential_manager_types.h" |
| 14 #include "jni/UpdatePasswordInfoBar_jni.h" | 14 #include "jni/UpdatePasswordInfoBar_jni.h" |
| 15 | 15 |
| 16 using base::android::JavaParamRef; | 16 using base::android::JavaParamRef; |
| 17 | 17 |
| 18 UpdatePasswordInfoBar::UpdatePasswordInfoBar( | 18 UpdatePasswordInfoBar::UpdatePasswordInfoBar( |
| 19 std::unique_ptr<UpdatePasswordInfoBarDelegate> delegate) | 19 std::unique_ptr<UpdatePasswordInfoBarDelegate> delegate) |
| 20 : ConfirmInfoBar(std::move(delegate)) {} | 20 : ConfirmInfoBar(std::move(delegate)) {} |
| 21 | 21 |
| 22 UpdatePasswordInfoBar::~UpdatePasswordInfoBar() {} | 22 UpdatePasswordInfoBar::~UpdatePasswordInfoBar() {} |
| 23 | 23 |
| 24 int UpdatePasswordInfoBar::GetIdOfSelectedUsername() const { | 24 int UpdatePasswordInfoBar::GetIdOfSelectedUsername() const { |
| 25 return Java_UpdatePasswordInfoBar_getSelectedUsername( | 25 return Java_UpdatePasswordInfoBar_getSelectedUsername( |
| 26 base::android::AttachCurrentThread(), java_infobar_.obj()); | 26 base::android::AttachCurrentThread(), java_infobar_); |
| 27 } | 27 } |
| 28 | 28 |
| 29 base::android::ScopedJavaLocalRef<jobject> | 29 base::android::ScopedJavaLocalRef<jobject> |
| 30 UpdatePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) { | 30 UpdatePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| 31 using base::android::ConvertUTF16ToJavaString; | 31 using base::android::ConvertUTF16ToJavaString; |
| 32 using base::android::ScopedJavaLocalRef; | 32 using base::android::ScopedJavaLocalRef; |
| 33 UpdatePasswordInfoBarDelegate* update_password_delegate = | 33 UpdatePasswordInfoBarDelegate* update_password_delegate = |
| 34 static_cast<UpdatePasswordInfoBarDelegate*>(delegate()); | 34 static_cast<UpdatePasswordInfoBarDelegate*>(delegate()); |
| 35 ScopedJavaLocalRef<jstring> ok_button_text = ConvertUTF16ToJavaString( | 35 ScopedJavaLocalRef<jstring> ok_button_text = ConvertUTF16ToJavaString( |
| 36 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); | 36 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 37 ScopedJavaLocalRef<jstring> cancel_button_text = ConvertUTF16ToJavaString( | 37 ScopedJavaLocalRef<jstring> cancel_button_text = ConvertUTF16ToJavaString( |
| 38 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 38 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 39 ScopedJavaLocalRef<jstring> branding_text = | 39 ScopedJavaLocalRef<jstring> branding_text = |
| 40 ConvertUTF16ToJavaString(env, update_password_delegate->GetBranding()); | 40 ConvertUTF16ToJavaString(env, update_password_delegate->GetBranding()); |
| 41 | 41 |
| 42 std::vector<base::string16> usernames; | 42 std::vector<base::string16> usernames; |
| 43 if (update_password_delegate->ShowMultipleAccounts()) { | 43 if (update_password_delegate->ShowMultipleAccounts()) { |
| 44 for (auto* password_form : update_password_delegate->GetCurrentForms()) | 44 for (auto* password_form : update_password_delegate->GetCurrentForms()) |
| 45 usernames.push_back(password_form->username_value); | 45 usernames.push_back(password_form->username_value); |
| 46 } else { | 46 } else { |
| 47 usernames.push_back( | 47 usernames.push_back( |
| 48 update_password_delegate->get_username_for_single_account()); | 48 update_password_delegate->get_username_for_single_account()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 base::android::ScopedJavaLocalRef<jobject> infobar; | 51 base::android::ScopedJavaLocalRef<jobject> infobar; |
| 52 infobar.Reset(Java_UpdatePasswordInfoBar_show( | 52 infobar.Reset(Java_UpdatePasswordInfoBar_show( |
| 53 env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(), | 53 env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(), |
| 54 base::android::ToJavaArrayOfStrings(env, usernames).obj(), | 54 base::android::ToJavaArrayOfStrings(env, usernames), ok_button_text, |
| 55 ok_button_text.obj(), cancel_button_text.obj(), branding_text.obj(), | 55 cancel_button_text, branding_text, |
| 56 update_password_delegate->ShowMultipleAccounts(), | 56 update_password_delegate->ShowMultipleAccounts(), |
| 57 update_password_delegate->is_smartlock_branding_enabled())); | 57 update_password_delegate->is_smartlock_branding_enabled())); |
| 58 | 58 |
| 59 java_infobar_.Reset(env, infobar.obj()); | 59 java_infobar_.Reset(env, infobar.obj()); |
| 60 return infobar; | 60 return infobar; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void UpdatePasswordInfoBar::OnLinkClicked(JNIEnv* env, | 63 void UpdatePasswordInfoBar::OnLinkClicked(JNIEnv* env, |
| 64 const JavaParamRef<jobject>& obj) { | 64 const JavaParamRef<jobject>& obj) { |
| 65 GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB); | 65 GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB); |
| 66 } | 66 } |
| OLD | NEW |