Chromium Code Reviews| Index: chrome/browser/ui/android/infobars/autofill_cc_infobar.cc |
| diff --git a/chrome/browser/ui/android/infobars/autofill_cc_infobar.cc b/chrome/browser/ui/android/infobars/autofill_cc_infobar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0eef068e804cc7e2c95fae74e304e8b2beb7d502 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/infobars/autofill_cc_infobar.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/android/infobars/autofill_cc_infobar.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "chrome/browser/android/resource_mapper.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "components/autofill/core/browser/autofill_cc_infobar_delegate.h" |
| +#include "components/autofill/core/browser/legal_message_line.h" |
| +#include "jni/AutofillCCInfoBarDelegate_jni.h" |
| +#include "ui/gfx/android/java_bitmap.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "url/gurl.h" |
| + |
| +// InfoBarService ------------------------------------------------------------- |
| + |
| +scoped_ptr<infobars::InfoBar> InfoBarService::CreateAutofillCCInfoBar( |
| + scoped_ptr<autofill::AutofillCCInfoBarDelegate> delegate) { |
| + return make_scoped_ptr(new AutofillCCInfoBar(std::move(delegate))); |
| +} |
| + |
| +// AutofillCCInfoBar ---------------------------------------------------------- |
| + |
| +// static |
| +bool AutofillCCInfoBar::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +AutofillCCInfoBar::AutofillCCInfoBar( |
| + scoped_ptr<autofill::AutofillCCInfoBarDelegate> delegate) |
| + : ConfirmInfoBar(std::move(delegate)) {} |
| + |
| +AutofillCCInfoBar::~AutofillCCInfoBar() {} |
| + |
| +void AutofillCCInfoBar::OnLegalMessageLinkClicked(JNIEnv* env, |
| + jobject obj, |
| + jstring url) { |
| + static_cast<autofill::AutofillCCInfoBarDelegate*>(GetDelegate()) |
| + ->OnLegalMessageLinkClicked( |
| + GURL(base::android::ConvertJavaStringToUTF16(env, url))); |
| +} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| +AutofillCCInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| + base::android::ScopedJavaLocalRef<jobject> java_delegate = |
|
Justin Donnelly
2016/01/07 18:15:40
Move this to where you declare cc_delegate below s
please use gerrit instead
2016/01/08 00:07:05
Done.
|
| + Java_AutofillCCInfoBarDelegate_create(env, |
| + reinterpret_cast<intptr_t>(this)); |
| + base::android::ScopedJavaLocalRef<jstring> ok_button_text = |
| + base::android::ConvertUTF16ToJavaString( |
| + env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); |
| + base::android::ScopedJavaLocalRef<jstring> cancel_button_text = |
| + base::android::ConvertUTF16ToJavaString( |
| + env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| + |
| + ConfirmInfoBarDelegate* delegate = GetDelegate(); |
| + base::android::ScopedJavaLocalRef<jstring> message_text = |
| + base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText()); |
| + base::android::ScopedJavaLocalRef<jstring> link_text = |
| + base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText()); |
| + |
| + autofill::AutofillCCInfoBarDelegate* cc_delegate = |
| + static_cast<autofill::AutofillCCInfoBarDelegate*>(delegate); |
| + Java_AutofillCCInfoBarDelegate_addDetail( |
| + env, java_delegate.obj(), |
| + ResourceMapper::MapFromChromiumId(cc_delegate->issuer_icon_id()), |
| + base::android::ConvertUTF16ToJavaString( |
| + env, cc_delegate->card_label()).obj(), |
| + base::android::ConvertUTF16ToJavaString( |
| + env, cc_delegate->card_sub_label()).obj()); |
| + |
| + for (const auto& line : cc_delegate->legal_messages()) { |
|
gone
2016/01/08 00:08:09
Hopping back and forth across the JNI barrier can
please use gerrit instead
2016/01/12 00:47:25
I expect the outer to loop 1 time. inner: 2 times.
|
| + Java_AutofillCCInfoBarDelegate_addLegalMessageLine( |
| + env, java_delegate.obj(), |
| + base::android::ConvertUTF16ToJavaString(env, line->text()).obj()); |
| + for (const auto& link : line->links()) { |
| + Java_AutofillCCInfoBarDelegate_addLinkToLastLegalMessageLine( |
| + env, java_delegate.obj(), link.range.start(), link.range.end(), |
| + base::android::ConvertUTF8ToJavaString(env, link.url.spec()).obj()); |
| + } |
| + } |
| + |
| + ScopedJavaLocalRef<jobject> java_bitmap; |
| + if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && |
| + !delegate->GetIcon().IsEmpty()) { |
| + java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); |
| + } |
| + |
| + return Java_AutofillCCInfoBarDelegate_show( |
| + env, java_delegate.obj(), GetEnumeratedIconId(), java_bitmap.obj(), |
| + message_text.obj(), link_text.obj(), ok_button_text.obj(), |
| + cancel_button_text.obj()); |
| +} |