1 // Copyright 2014 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.
5 #include "chrome/browser/ui/android/infobars/save_password_infobar.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/logging.h"
10 #include "chrome/browser/android/resource_mapper.h"
11 #include "jni/SavePasswordInfoBarDelegate_jni.h"
13 // SavePasswordInfoBarDelegate-------------------------------------------------
16 scoped_ptr<InfoBar> SavePasswordInfoBarDelegate::CreateInfoBar(
17 scoped_ptr<SavePasswordInfoBarDelegate> delegate) {
18 return scoped_ptr<InfoBar>(new SavePasswordInfoBar(delegate.Pass()));
21 // SavePasswordInfoBar --------------------------------------------------------
23 SavePasswordInfoBar::SavePasswordInfoBar(
24 scoped_ptr<SavePasswordInfoBarDelegate> delegate)
25 : ConfirmInfoBar(delegate.PassAs<ConfirmInfoBarDelegate>()),
26 java_save_password_delegate_() {
29 SavePasswordInfoBar::~SavePasswordInfoBar() {
32 void SavePasswordInfoBar::SetUseAdditionalAuthentication(
35 bool use_additional_authentication) {
36 GetDelegate()->SetUseAdditionalPasswordAuthentication(
37 use_additional_authentication);
40 base::android::ScopedJavaLocalRef<jobject>
41 SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
42 java_save_password_delegate_.Reset(
43 Java_SavePasswordInfoBarDelegate_create(env));
44 base::android::ScopedJavaLocalRef<jstring> ok_button_text =
45 base::android::ConvertUTF16ToJavaString(
46 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK));
47 base::android::ScopedJavaLocalRef<jstring> cancel_button_text =
48 base::android::ConvertUTF16ToJavaString(
49 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL));
50 SavePasswordInfoBarDelegate* delegate = GetDelegate();
51 base::android::ScopedJavaLocalRef<jstring> message_text =
52 base::android::ConvertUTF16ToJavaString(
53 env, reinterpret_cast<ConfirmInfoBarDelegate*>(
54 delegate)->GetMessageText());
56 return Java_SavePasswordInfoBarDelegate_showSavePasswordInfoBar(
58 java_save_password_delegate_.obj(),
59 reinterpret_cast<intptr_t>(this),
60 GetEnumeratedIconId(),
63 cancel_button_text.obj());
66 SavePasswordInfoBarDelegate* SavePasswordInfoBar::GetDelegate() {
67 return static_cast<SavePasswordInfoBarDelegate*>(delegate());
71 // Native JNI methods ---------------------------------------------------------
73 bool RegisterSavePasswordInfoBar(JNIEnv* env) {
74 return RegisterNativesImpl(env);