Index: chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBarDelegate.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBarDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBarDelegate.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5ef7c635e94d4167d16099bed9736dc3e83db95e |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/infobar/AutofillCCInfoBarDelegate.java |
@@ -0,0 +1,114 @@ |
+// 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. |
+ |
+package org.chromium.chrome.browser.infobar; |
+ |
+import android.graphics.Bitmap; |
+ |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.chrome.browser.ResourceId; |
+ |
+import java.util.LinkedList; |
+ |
+/** |
+ * Provides JNI methods for saving credit card information. |
+ */ |
+public class AutofillCCInfoBarDelegate implements AutofillCCInfoBar.LegalMessageLinkClickDelegate { |
gone
2016/01/08 00:08:09
This class should just be merged into the Autofill
please use gerrit instead
2016/01/12 00:47:25
Done.
|
+ private long mNativeAutofillCCInfoBar; |
+ private LinkedList<AutofillCCInfoBar.CardDetail> mCardDetails = |
gone
2016/01/08 00:08:09
private final?
please use gerrit instead
2016/01/12 00:47:25
Done.
|
+ new LinkedList<AutofillCCInfoBar.CardDetail>(); |
+ private LinkedList<AutofillCCInfoBar.LegalMessageLine> mLegalMessageLines = |
+ new LinkedList<AutofillCCInfoBar.LegalMessageLine>(); |
+ |
+ private AutofillCCInfoBarDelegate(long nativeAutofillCCInfoBar) { |
+ mNativeAutofillCCInfoBar = nativeAutofillCCInfoBar; |
+ } |
+ |
+ /** |
+ * Creates and returns a new instance of the delegate. Should be called first. |
gone
2016/01/08 00:08:09
nit: newlines between the function description and
please use gerrit instead
2016/01/12 00:47:25
Done.
|
+ * @param nativeAutofillCCInfoBar The pointer to the native object for callbacks. |
+ * @return A new instance of the delegate. |
+ */ |
+ @CalledByNative |
+ private static AutofillCCInfoBarDelegate create(long nativeAutofillCCInfoBar) { |
+ return new AutofillCCInfoBarDelegate(nativeAutofillCCInfoBar); |
+ } |
+ |
+ /** |
+ * Adds information to the infobar about the credit card that will be saved. Should be called |
+ * before {@link #show()}. |
+ * @param enumeratedIconId ID corresponding to the icon that will be shown for this credit card. |
+ * The ID must have been mapped using the ResourceMapper class before |
+ * passing it to this function. |
+ * @param label The credit card label, for example "***1234". |
+ * @param subLabel The credit card sub-label, for example "Exp: 06/17". |
+ */ |
+ @CalledByNative |
+ private void addDetail(int enumeratedIconId, String label, String subLabel) { |
+ AutofillCCInfoBar.CardDetail detail = new AutofillCCInfoBar.CardDetail(); |
gone
2016/01/08 00:08:09
Should probably add constructors to each of the Au
please use gerrit instead
2016/01/12 00:47:25
Done.
|
+ detail.issuerIconDrawableId = ResourceId.mapToDrawableId(enumeratedIconId); |
+ detail.label = label; |
+ detail.subLabel = subLabel; |
+ mCardDetails.add(detail); |
+ } |
+ |
+ /** |
+ * Adds a line of legal message plain text to the infobar. Should be called before {@link |
+ * #show()}. |
+ * @param text The legal message plain text. |
+ */ |
+ @CalledByNative |
+ private void addLegalMessageLine(String text) { |
+ AutofillCCInfoBar.LegalMessageLine line = new AutofillCCInfoBar.LegalMessageLine(); |
+ line.text = text; |
+ line.links = new LinkedList<AutofillCCInfoBar.LegalMessageLine.Link>(); |
+ mLegalMessageLines.add(line); |
+ } |
+ |
+ /** |
+ * Marks up the last added line of legal message text with a link. Should be called before |
+ * {@link #show()}. |
+ * @param start The inclusive offset of the start of the link in the text. |
+ * @param end The exclusive offset of the end of the link in the text. |
+ * @param url The URL to open when the link is clicked. |
+ */ |
+ @CalledByNative |
+ private void addLinkToLastLegalMessageLine(int start, int end, String url) { |
+ AutofillCCInfoBar.LegalMessageLine.Link link = |
+ new AutofillCCInfoBar.LegalMessageLine.Link(); |
+ link.start = start; |
+ link.end = end; |
+ link.url = url; |
+ mLegalMessageLines.getLast().links.add(link); |
+ } |
+ |
+ /** |
+ * Creates an infobar for saving a credit card. Should be called last. |
+ * @param enumeratedIconId ID corresponding to the icon that will be shown for the InfoBar. |
+ * The ID must have been mapped using the ResourceMapper class before |
+ * passing it to this function. |
+ * @param iconBitmap Bitmap to use if there is no equivalent Java resource for enumeratedIconId. |
+ * @param message Message to display to the user indicating what the InfoBar is for. |
+ * @param linkText Link text to display in addition to the message. |
+ * @param buttonOk String to display on the OK button. |
+ * @param buttonCancel String to display on the Cancel button. |
+ */ |
+ @CalledByNative |
+ private InfoBar show(int enumeratedIconId, Bitmap iconBitmap, String message, String linkText, |
+ String buttonOk, String buttonCancel) { |
+ return new AutofillCCInfoBar(ResourceId.mapToDrawableId(enumeratedIconId), iconBitmap, |
+ message, linkText, mCardDetails, mLegalMessageLines, buttonOk, buttonCancel, this); |
+ } |
+ |
+ /** |
+ * {@see org.chromium.chrome.browser.infobar.AutofillCCInfoBar.LegalMessageLinkClickDelegate |
+ * #onLegalMessageLinkClicked(String url)} |
+ */ |
gone
2016/01/08 00:08:09
nit: You generally don't need to add a javadoc if
please use gerrit instead
2016/01/12 00:47:25
Done.
|
+ @Override |
+ public void onLegalMessageLinkClicked(String url) { |
+ nativeOnLegalMessageLinkClicked(mNativeAutofillCCInfoBar, url); |
+ } |
+ |
+ private native void nativeOnLegalMessageLinkClicked(long nativeAutofillCCInfoBar, String url); |
gone
2016/01/08 00:08:09
There's some extra convoluted routing going on her
please use gerrit instead
2016/01/12 00:47:25
Done.
|
+} |