Chromium Code Reviews| OLD | NEW |
|---|---|
| (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( | |
| 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()) | |
| 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<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.
| |
| 51 Java_AutofillCCInfoBarDelegate_create(env, | |
| 52 reinterpret_cast<intptr_t>(this)); | |
| 53 base::android::ScopedJavaLocalRef<jstring> ok_button_text = | |
| 54 base::android::ConvertUTF16ToJavaString( | |
| 55 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); | |
| 56 base::android::ScopedJavaLocalRef<jstring> cancel_button_text = | |
| 57 base::android::ConvertUTF16ToJavaString( | |
| 58 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | |
| 59 | |
| 60 ConfirmInfoBarDelegate* delegate = GetDelegate(); | |
| 61 base::android::ScopedJavaLocalRef<jstring> message_text = | |
| 62 base::android::ConvertUTF16ToJavaString(env, delegate->GetMessageText()); | |
| 63 base::android::ScopedJavaLocalRef<jstring> link_text = | |
| 64 base::android::ConvertUTF16ToJavaString(env, delegate->GetLinkText()); | |
| 65 | |
| 66 autofill::AutofillCCInfoBarDelegate* cc_delegate = | |
| 67 static_cast<autofill::AutofillCCInfoBarDelegate*>(delegate); | |
| 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()) { | |
|
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.
| |
| 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 } | |
| OLD | NEW |