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.
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 "jni/SavePasswordInfoBar_jni.h"
11 SavePasswordInfoBar::SavePasswordInfoBar(
12 scoped_ptr
<SavePasswordInfoBarDelegate
> delegate
)
13 : ConfirmInfoBar(delegate
.Pass()) {
16 SavePasswordInfoBar::~SavePasswordInfoBar() {
19 base::android::ScopedJavaLocalRef
<jobject
>
20 SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv
* env
) {
21 using base::android::ConvertUTF16ToJavaString
;
22 using base::android::ScopedJavaLocalRef
;
23 SavePasswordInfoBarDelegate
* save_password_delegate
=
24 static_cast<SavePasswordInfoBarDelegate
*>(delegate());
25 ScopedJavaLocalRef
<jstring
> ok_button_text
= ConvertUTF16ToJavaString(
26 env
, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK
));
27 ScopedJavaLocalRef
<jstring
> cancel_button_text
= ConvertUTF16ToJavaString(
28 env
, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL
));
29 ScopedJavaLocalRef
<jstring
> message_text
= ConvertUTF16ToJavaString(
30 env
, save_password_delegate
->GetMessageText());
31 ScopedJavaLocalRef
<jstring
> first_run_experience_message
=
32 ConvertUTF16ToJavaString(
33 env
, save_password_delegate
->GetFirstRunExperienceMessage());
35 return Java_SavePasswordInfoBar_show(
36 env
, GetEnumeratedIconId(), message_text
.obj(),
37 save_password_delegate
->message_link_range().start(),
38 save_password_delegate
->message_link_range().end(), ok_button_text
.obj(),
39 cancel_button_text
.obj(), first_run_experience_message
.obj());
42 void SavePasswordInfoBar::OnLinkClicked(JNIEnv
* env
, jobject obj
) {
43 GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB
);
46 bool SavePasswordInfoBar::Register(JNIEnv
* env
) {
47 return RegisterNativesImpl(env
);
50 scoped_ptr
<infobars::InfoBar
> CreateSavePasswordInfoBar(
51 scoped_ptr
<SavePasswordInfoBarDelegate
> delegate
) {
52 return make_scoped_ptr(new SavePasswordInfoBar(delegate
.Pass()));