Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / android / infobars / save_password_infobar.cc
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
16 scoped_ptr<InfoBar> SavePasswordInfoBarDelegate::CreateInfoBar(
17     scoped_ptr<SavePasswordInfoBarDelegate> delegate) {
18   return scoped_ptr<InfoBar>(new SavePasswordInfoBar(delegate.Pass()));
19 }
20
21 // SavePasswordInfoBar --------------------------------------------------------
22
23 SavePasswordInfoBar::SavePasswordInfoBar(
24     scoped_ptr<SavePasswordInfoBarDelegate> delegate)
25     : ConfirmInfoBar(delegate.PassAs<ConfirmInfoBarDelegate>()),
26       java_save_password_delegate_() {
27 }
28
29 SavePasswordInfoBar::~SavePasswordInfoBar() {
30 }
31
32 void SavePasswordInfoBar::SetUseAdditionalAuthentication(
33     JNIEnv* env,
34     jobject obj,
35     bool use_additional_authentication) {
36   GetDelegate()->SetUseAdditionalPasswordAuthentication(
37       use_additional_authentication);
38 }
39
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());
55
56   return Java_SavePasswordInfoBarDelegate_showSavePasswordInfoBar(
57       env,
58       java_save_password_delegate_.obj(),
59       reinterpret_cast<intptr_t>(this),
60       GetEnumeratedIconId(),
61       message_text.obj(),
62       ok_button_text.obj(),
63       cancel_button_text.obj());
64 }
65
66 SavePasswordInfoBarDelegate* SavePasswordInfoBar::GetDelegate() {
67   return static_cast<SavePasswordInfoBarDelegate*>(delegate());
68 }
69
70
71 // Native JNI methods ---------------------------------------------------------
72
73 bool RegisterSavePasswordInfoBar(JNIEnv* env) {
74   return RegisterNativesImpl(env);
75 }