Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6615)

Unified Diff: chrome/browser/ui/android/infobars/autofill_cc_infobar.cc

Issue 1540423004: Add card details and legal message to Android save credit card infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Edits Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
+}

Powered by Google App Engine
This is Rietveld 408576698