Chromium Code Reviews| Index: chrome/browser/ui/android/infobars/autofill_assist_infobar.cc |
| diff --git a/chrome/browser/ui/android/infobars/autofill_assist_infobar.cc b/chrome/browser/ui/android/infobars/autofill_assist_infobar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..679025babc7f3b951b4246e1e3dfef2da3784452 |
| --- /dev/null |
| +++ b/chrome/browser/ui/android/infobars/autofill_assist_infobar.cc |
| @@ -0,0 +1,78 @@ |
| +// 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_assist_infobar.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/android/resource_mapper.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| +#include "components/autofill/core/browser/autofill_assist_infobar_delegate_mobile.h" |
| +#include "components/autofill/core/browser/autofill_assist_infobar_mobile.h" |
| +#include "jni/AutofillAssistInfoBar_jni.h" |
| +#include "ui/gfx/android/java_bitmap.h" |
| +#include "ui/gfx/image/image.h" |
| +#include "url/gurl.h" |
| + |
| +namespace autofill { |
| + |
| +std::unique_ptr<infobars::InfoBar> CreateAssistInfoBar( |
|
please use gerrit instead
2016/07/27 17:02:26
Should we put a comment here akin to "Declared in
Mathieu
2016/07/27 21:35:52
Done.
|
| + std::unique_ptr<AutofillAssistInfoBarDelegateMobile> delegate) { |
| + return base::WrapUnique(new AutofillAssistInfoBar(std::move(delegate))); |
| +} |
| + |
| +} // namespace autofill |
| + |
| +AutofillAssistInfoBar::AutofillAssistInfoBar( |
| + std::unique_ptr<autofill::AutofillAssistInfoBarDelegateMobile> delegate) |
| + : ConfirmInfoBar(std::move(delegate)) {} |
| + |
| +AutofillAssistInfoBar::~AutofillAssistInfoBar() {} |
| + |
| +// static |
| +bool AutofillAssistInfoBar::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +base::android::ScopedJavaLocalRef<jobject> |
| +AutofillAssistInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| + autofill::AutofillAssistInfoBarDelegateMobile* delegate = GetAssistDelegate(); |
|
please use gerrit instead
2016/07/27 17:02:26
This function is called only once, so you can remo
Mathieu
2016/07/27 21:35:52
Done.
|
| + ScopedJavaLocalRef<jobject> java_bitmap; |
| + if (delegate->GetIconId() == infobars::InfoBarDelegate::kNoIconID && |
| + !delegate->GetIcon().IsEmpty()) { |
| + java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); |
| + } |
| + |
| + base::android::ScopedJavaLocalRef<jobject> java_delegate = |
| + Java_AutofillAssistInfoBar_create( |
| + env, reinterpret_cast<intptr_t>(this), GetEnumeratedIconId(), |
| + java_bitmap.obj(), base::android::ConvertUTF16ToJavaString( |
| + env, delegate->GetMessageText()) |
| + .obj(), |
| + base::android::ConvertUTF16ToJavaString( |
| + env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)) |
| + .obj(), |
| + base::android::ConvertUTF16ToJavaString( |
| + env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_CANCEL)) |
| + .obj()); |
| + |
| + Java_AutofillAssistInfoBar_addDetail( |
| + env, java_delegate.obj(), |
| + ResourceMapper::MapFromChromiumId(delegate->issuer_icon_id()), |
| + base::android::ConvertUTF16ToJavaString(env, delegate->card_label()) |
| + .obj(), |
| + base::android::ConvertUTF16ToJavaString(env, delegate->card_sub_label()) |
| + .obj()); |
| + |
| + return java_delegate; |
| +} |
| + |
| +autofill::AutofillAssistInfoBarDelegateMobile* |
| +AutofillAssistInfoBar::GetAssistDelegate() { |
|
please use gerrit instead
2016/07/27 17:02:26
Can be removed.
Mathieu
2016/07/27 21:35:52
Acknowledged.
|
| + return static_cast<autofill::AutofillAssistInfoBarDelegateMobile*>( |
| + GetDelegate()); |
| +} |