Populate the item tag if offer is present

Currently we're populating the item tag only for the autofill popup.
We'll populate for the autofill keyboard accessory as a follow up after
implementing the UI for the keyboard accessory.

(cherry picked from commit fd364bbd477c56a8efa246e6ed7b6ef90e74d0fc)

Bug: 1093057
Change-Id: I909569e16ccaced0bc3dde01e0f03d9de3204706
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436862
Commit-Queue: Siddharth Shah <[email protected]>
Reviewed-by: Jared Saul <[email protected]>
Reviewed-by: sebsg <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#812964}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2453337
Reviewed-by: Siddharth Shah <[email protected]>
Cr-Commit-Position: refs/branch-heads/4280@{#63}
Cr-Branched-From: ea420fb963f9658c9969b6513c56b8f47efa1a2a-refs/heads/master@{#812852}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
index 51d94e65..7910154 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/autofill/AutofillPopupBridge.java
@@ -170,11 +170,11 @@
      */
     @CalledByNative
     private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
-            String label, String sublabel, int iconId, boolean isIconAtStart,
+            String label, String sublabel, String itemTag, int iconId, boolean isIconAtStart,
             int suggestionId, boolean isDeletable, boolean isLabelMultiline, boolean isLabelBold) {
         int drawableId = iconId == 0 ? DropdownItem.NO_ICON : iconId;
-        array[index] = new AutofillSuggestion(label, sublabel, /*itemTag= */ "", drawableId,
-                isIconAtStart, suggestionId, isDeletable, isLabelMultiline, isLabelBold);
+        array[index] = new AutofillSuggestion(label, sublabel, itemTag, drawableId, isIconAtStart,
+                suggestionId, isDeletable, isLabelMultiline, isLabelBold);
     }
 
     @NativeMethods
diff --git a/chrome/browser/ui/android/autofill/autofill_popup_view_android.cc b/chrome/browser/ui/android/autofill/autofill_popup_view_android.cc
index f819a73b..d332043 100644
--- a/chrome/browser/ui/android/autofill/autofill_popup_view_android.cc
+++ b/chrome/browser/ui/android/autofill/autofill_popup_view_android.cc
@@ -18,6 +18,7 @@
 #include "chrome/browser/ui/autofill/autofill_popup_controller_utils.h"
 #include "components/autofill/core/browser/ui/popup_item_ids.h"
 #include "components/autofill/core/browser/ui/suggestion.h"
+#include "components/autofill/core/common/autofill_payments_features.h"
 #include "components/autofill/core/common/autofill_util.h"
 #include "components/security_state/core/security_state.h"
 #include "ui/android/view_android.h"
@@ -94,8 +95,15 @@
             POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE ||
         suggestion.frontend_id == POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO ||
         suggestion.frontend_id == POPUP_ITEM_ID_MIXED_FORM_MESSAGE;
+    // Set the offer title to display as the item tag.
+    ScopedJavaLocalRef<jstring> item_tag =
+        base::android::ConvertUTF16ToJavaString(
+            env, base::FeatureList::IsEnabled(
+                     features::kAutofillEnableOffersInDownstream)
+                     ? suggestion.offer_label
+                     : base::string16());
     Java_AutofillPopupBridge_addToAutofillSuggestionArray(
-        env, data_array, i, value, label, android_icon_id,
+        env, data_array, i, value, label, item_tag, android_icon_id,
         /*icon_at_start=*/false, suggestion.frontend_id, is_deletable,
         is_label_multiline, /*isLabelBold*/ false);
   }