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.
4
5#include "chrome/browser/ui/android/infobars/save_password_infobar.h"
6
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"
12
13// SavePasswordInfoBarDelegate-------------------------------------------------
14
15// static
16scoped_ptr<infobars::InfoBar> SavePasswordInfoBarDelegate::CreateInfoBar(
17    scoped_ptr<SavePasswordInfoBarDelegate> delegate) {
18  return scoped_ptr<infobars::InfoBar>(
19      new SavePasswordInfoBar(delegate.Pass()));
20}
21
22// SavePasswordInfoBar --------------------------------------------------------
23
24SavePasswordInfoBar::SavePasswordInfoBar(
25    scoped_ptr<SavePasswordInfoBarDelegate> delegate)
26    : ConfirmInfoBar(delegate.PassAs<ConfirmInfoBarDelegate>()),
27      java_save_password_delegate_() {
28}
29
30SavePasswordInfoBar::~SavePasswordInfoBar() {
31}
32
33void SavePasswordInfoBar::SetUseAdditionalAuthentication(
34    JNIEnv* env,
35    jobject obj,
36    bool use_additional_authentication) {
37  GetDelegate()->SetUseAdditionalPasswordAuthentication(
38      use_additional_authentication);
39}
40
41base::android::ScopedJavaLocalRef<jobject>
42    SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
43  java_save_password_delegate_.Reset(
44      Java_SavePasswordInfoBarDelegate_create(env));
45  base::android::ScopedJavaLocalRef<jstring> ok_button_text =
46      base::android::ConvertUTF16ToJavaString(
47          env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK));
48  base::android::ScopedJavaLocalRef<jstring> cancel_button_text =
49      base::android::ConvertUTF16ToJavaString(
50          env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL));
51  SavePasswordInfoBarDelegate* delegate = GetDelegate();
52  base::android::ScopedJavaLocalRef<jstring> message_text =
53      base::android::ConvertUTF16ToJavaString(
54          env, reinterpret_cast<ConfirmInfoBarDelegate*>(
55              delegate)->GetMessageText());
56
57  return Java_SavePasswordInfoBarDelegate_showSavePasswordInfoBar(
58      env,
59      java_save_password_delegate_.obj(),
60      reinterpret_cast<intptr_t>(this),
61      GetEnumeratedIconId(),
62      message_text.obj(),
63      ok_button_text.obj(),
64      cancel_button_text.obj());
65}
66
67SavePasswordInfoBarDelegate* SavePasswordInfoBar::GetDelegate() {
68  return static_cast<SavePasswordInfoBarDelegate*>(delegate());
69}
70
71
72// Native JNI methods ---------------------------------------------------------
73
74bool RegisterSavePasswordInfoBar(JNIEnv* env) {
75  return RegisterNativesImpl(env);
76}
77