SavePasswordInfoBar::SavePasswordInfoBar(
    scoped_ptr<SavePasswordInfoBarDelegate> delegate)
    : ConfirmInfoBar(delegate.Pass()) {
}

SavePasswordInfoBar::~SavePasswordInfoBar() {
}

base::android::ScopedJavaLocalRef<jobject>
SavePasswordInfoBar::CreateRenderInfoBar(JNIEnv* env) {
  using base::android::ConvertUTF16ToJavaString;
  using base::android::ScopedJavaLocalRef;
  SavePasswordInfoBarDelegate* save_password_delegate =
      static_cast<SavePasswordInfoBarDelegate*>(delegate());
  ScopedJavaLocalRef<jstring> ok_button_text = ConvertUTF16ToJavaString(
      env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK));
  ScopedJavaLocalRef<jstring> cancel_button_text = ConvertUTF16ToJavaString(
      env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL));
  ScopedJavaLocalRef<jstring> message_text = ConvertUTF16ToJavaString(
      env, save_password_delegate->GetMessageText());

  return Java_SavePasswordInfoBar_show(
      env, GetEnumeratedIconId(), message_text.obj(),
      save_password_delegate->title_link_range().start(),
      save_password_delegate->title_link_range().end(), ok_button_text.obj(),
      cancel_button_text.obj(), save_password_delegate->ShouldShowMoreButton());
}

void SavePasswordInfoBar::OnLinkClicked(JNIEnv* env, jobject obj) {
  GetDelegate()->LinkClicked(NEW_FOREGROUND_TAB);
}

bool SavePasswordInfoBar::Register(JNIEnv* env) {
  return RegisterNativesImpl(env);
}

scoped_ptr<infobars::InfoBar> CreateSavePasswordInfoBar(
    scoped_ptr<SavePasswordInfoBarDelegate> delegate) {
  return make_scoped_ptr(new SavePasswordInfoBar(delegate.Pass()));
}
