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

Side by Side 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: Addressed Justin's nits. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/autofill_cc_infobar.h"
6
7 #include <utility>
8
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "chrome/browser/android/resource_mapper.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "components/autofill/core/browser/autofill_cc_infobar_delegate.h"
14 #include "components/autofill/core/browser/legal_message_line.h"
15 #include "jni/AutofillCCInfoBarDelegate_jni.h"
16 #include "ui/gfx/android/java_bitmap.h"
17 #include "ui/gfx/image/image.h"
18 #include "url/gurl.h"
19
20 // InfoBarService -------------------------------------------------------------
21
22 scoped_ptr<infobars::InfoBar> InfoBarService::CreateAutofillCCInfoBar(
23 scoped_ptr<autofill::AutofillCCInfoBarDelegate> delegate) {
24 return make_scoped_ptr(new AutofillCCInfoBar(std::move(delegate)));
25 }
26
27 // AutofillCCInfoBar ----------------------------------------------------------
28
29 // static
30 bool AutofillCCInfoBar::Register(JNIEnv* env) {
31 return RegisterNativesImpl(env);
32 }
33
34 AutofillCCInfoBar::AutofillCCInfoBar(
Evan Stade 2016/01/08 03:14:12 s/CC/Cc
please use gerrit instead 2016/01/12 00:47:25 Renamed to AutofillSaveCardInfoBar instead.
35 scoped_ptr<autofill::AutofillCCInfoBarDelegate> delegate)
36 : ConfirmInfoBar(std::move(delegate)) {}
37
38 AutofillCCInfoBar::~AutofillCCInfoBar() {}
39
40 void AutofillCCInfoBar::OnLegalMessageLinkClicked(JNIEnv* env,
41 jobject obj,
42 jstring url) {
43 static_cast<autofill::AutofillCCInfoBarDelegate*>(GetDelegate())
Peter Kasting 2016/01/08 00:34:31 You call GetDelegate() twice in this class, and bo
please use gerrit instead 2016/01/12 00:47:25 Done.
44 ->OnLegalMessageLinkClicked(
45 GURL(base::android::ConvertJavaStringToUTF16(env, url)));
46 }
47
48 base::android::ScopedJavaLocalRef<jobject>
49 AutofillCCInfoBar::CreateRenderInfoBar(JNIEnv* env) {
50 base::android::ScopedJavaLocalRef<jstring> ok_button_text =
51 base::android::ConvertUTF16ToJavaString(
52 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK));
53 base::android::ScopedJavaLocalRef<jstring> cancel_button_text =
54 base::android::ConvertUTF16ToJavaString(
55 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL));
56
57 ConfirmInfoBarDelegate* delegate = GetDelegate();
58 base::android::ScopedJavaLocalRef<jstring> message_text =
59 base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText());
60 base::android::ScopedJavaLocalRef<jstring> link_text =
61 base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText());
62
63 autofill::AutofillCCInfoBarDelegate* cc_delegate =
64 static_cast<autofill::AutofillCCInfoBarDelegate*>(delegate);
65 base::android::ScopedJavaLocalRef<jobject> java_delegate =
66 Java_AutofillCCInfoBarDelegate_create(env,
67 reinterpret_cast<intptr_t>(this));
68 Java_AutofillCCInfoBarDelegate_addDetail(
69 env, java_delegate.obj(),
70 ResourceMapper::MapFromChromiumId(cc_delegate->issuer_icon_id()),
71 base::android::ConvertUTF16ToJavaString(
72 env, cc_delegate->card_label()).obj(),
73 base::android::ConvertUTF16ToJavaString(
74 env, cc_delegate->card_sub_label()).obj());
75
76 for (const auto& line : cc_delegate->legal_messages()) {
77 Java_AutofillCCInfoBarDelegate_addLegalMessageLine(
78 env, java_delegate.obj(),
79 base::android::ConvertUTF16ToJavaString(env, line->text()).obj());
80 for (const auto& link : line->links()) {
81 Java_AutofillCCInfoBarDelegate_addLinkToLastLegalMessageLine(
82 env, java_delegate.obj(), link.range.start(), link.range.end(),
83 base::android::ConvertUTF8ToJavaString(env, link.url.spec()).obj());
84 }
85 }
86
87 ScopedJavaLocalRef<jobject> java_bitmap;
88 if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID &&
89 !delegate->GetIcon().IsEmpty()) {
90 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap());
91 }
92
93 return Java_AutofillCCInfoBarDelegate_show(
94 env, java_delegate.obj(), GetEnumeratedIconId(), java_bitmap.obj(),
95 message_text.obj(), link_text.obj(), ok_button_text.obj(),
96 cancel_button_text.obj());
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698