Commit 57797bb0 authored by sczs's avatar sczs Committed by Commit Bot

Adds UpdateAndAccept to SaveCardInfobarDelegateMobile

- UpdateAndAccept takes a cardholderName, expirationMonth and
expirationYear as parameters and sends this to the
RunSaveCardPromptCallback.

- Updates SaveCardManager to support the new editing functionality on
iOS so the Username and Date FixFlows are not presented.

Change-Id: Ie26130431c9d3ffec79078fccbe81f329661e1f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893827
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#732300}
parent 5730bedc
......@@ -10,7 +10,6 @@
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/common/autofill_constants.h"
......@@ -68,7 +67,8 @@ AutofillSaveCardInfoBarDelegateMobile::AutofillSaveCardInfoBarDelegateMobile(
AutofillSaveCardInfoBarDelegateMobile::
~AutofillSaveCardInfoBarDelegateMobile() {
if (!had_user_interaction_) {
RunSaveCardPromptCallbackWithUserDecision(AutofillClient::IGNORED);
RunSaveCardPromptCallback(AutofillClient::IGNORED,
/*user_provided_details=*/{});
LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
}
}
......@@ -141,12 +141,14 @@ bool AutofillSaveCardInfoBarDelegateMobile::ShouldExpire(
}
void AutofillSaveCardInfoBarDelegateMobile::InfoBarDismissed() {
RunSaveCardPromptCallbackWithUserDecision(AutofillClient::DECLINED);
RunSaveCardPromptCallback(AutofillClient::DECLINED,
/*user_provided_details=*/{});
LogUserAction(AutofillMetrics::INFOBAR_DENIED);
}
bool AutofillSaveCardInfoBarDelegateMobile::Cancel() {
RunSaveCardPromptCallbackWithUserDecision(AutofillClient::DECLINED);
RunSaveCardPromptCallback(AutofillClient::DECLINED,
/*user_provided_details=*/{});
LogUserAction(AutofillMetrics::INFOBAR_DENIED);
return true;
}
......@@ -178,18 +180,36 @@ base::string16 AutofillSaveCardInfoBarDelegateMobile::GetButtonLabel(
}
bool AutofillSaveCardInfoBarDelegateMobile::Accept() {
RunSaveCardPromptCallbackWithUserDecision(AutofillClient::ACCEPTED);
RunSaveCardPromptCallback(AutofillClient::ACCEPTED,
/*user_provided_details=*/{});
LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
return true;
}
void AutofillSaveCardInfoBarDelegateMobile::
RunSaveCardPromptCallbackWithUserDecision(
AutofillClient::SaveCardOfferUserDecision user_decision) {
if (upload_)
std::move(upload_save_card_prompt_callback_).Run(user_decision, {});
else
#if defined(OS_IOS)
bool AutofillSaveCardInfoBarDelegateMobile::UpdateAndAccept(
base::string16 cardholder_name,
base::string16 expiration_date_month,
base::string16 expiration_date_year) {
AutofillClient::UserProvidedCardDetails user_provided_details;
user_provided_details.cardholder_name = cardholder_name;
user_provided_details.expiration_date_month = expiration_date_month;
user_provided_details.expiration_date_year = expiration_date_year;
RunSaveCardPromptCallback(AutofillClient::ACCEPTED, user_provided_details);
LogUserAction(AutofillMetrics::INFOBAR_ACCEPTED);
return true;
}
#endif // defined(OS_IOS)
void AutofillSaveCardInfoBarDelegateMobile::RunSaveCardPromptCallback(
AutofillClient::SaveCardOfferUserDecision user_decision,
AutofillClient::UserProvidedCardDetails user_provided_details) {
if (upload_) {
std::move(upload_save_card_prompt_callback_)
.Run(user_decision, user_provided_details);
} else {
std::move(local_save_card_prompt_callback_).Run(user_decision);
}
}
void AutofillSaveCardInfoBarDelegateMobile::LogUserAction(
......
......@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_metrics.h"
#include "components/autofill/core/browser/payments/legal_message_line.h"
......@@ -78,11 +79,25 @@ class AutofillSaveCardInfoBarDelegateMobile : public ConfirmInfoBarDelegate {
bool Accept() override;
bool Cancel() override;
#if defined(OS_IOS)
// Updates and then saves the card using |cardholder_name|,
// |expiration_date_month| and |expiration_date_year|, which were provided
// as part of the iOS save card Infobar dialog.
bool UpdateAndAccept(base::string16 cardholder_name,
base::string16 expiration_date_month,
base::string16 expiration_date_year);
#endif // defined(OS_IOS)
private:
// Runs the appropriate local or upload save callback with the given
// |user_decision|.
void RunSaveCardPromptCallbackWithUserDecision(
AutofillClient::SaveCardOfferUserDecision user_decision);
// |user_decision|, using the |user_provided_details|. If
// |user_provided_details| is empty then the current Card values will be used.
// The cardholder name and expiration date portions of
// |user_provided_details| are handled separately, so if either of them are
// empty the current Card values will be used.
void RunSaveCardPromptCallback(
AutofillClient::SaveCardOfferUserDecision user_decision,
AutofillClient::UserProvidedCardDetails user_provided_details);
void LogUserAction(AutofillMetrics::InfoBarMetric user_action);
......
......@@ -43,6 +43,7 @@
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/infobars/core/infobar_feature.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "url/gurl.h"
......@@ -218,6 +219,20 @@ void CreditCardSaveManager::AttemptToOfferCardUploadSave(
should_request_expiration_date_from_user_ = true;
}
#if defined(OS_IOS)
if ((base::FeatureList::IsEnabled(
features::kAutofillSaveCardInfobarEditSupport) &&
base::FeatureList::IsEnabled(kIOSInfobarUIReboot))) {
// iOS's new credit card save dialog requires the user to enter both
// cardholder name and expiration date before saving. Regardless of what
// Chrome thought it needed to do before, disable both of the previous
// standalone fix flows, and let the new save dialog handle their combined
// case.
should_request_name_from_user_ = false;
should_request_expiration_date_from_user_ = false;
}
#endif // defined(OS_IOS)
// The cardholder name and expiration date fix flows cannot both be
// active at the same time. If they are, abort offering upload.
// If user is signed in and has Wallet Sync Transport enabled but we still
......@@ -766,6 +781,18 @@ int CreditCardSaveManager::GetDetectedValues() const {
detected_values |= DetectedValue::USER_PROVIDED_NAME;
}
// On iOS if the new Infobar UI is enabled, it won't be possible to save the
// card unless the user provides both a valid cardholder name and expiration
// date.
#if defined(OS_IOS)
if ((base::FeatureList::IsEnabled(
features::kAutofillSaveCardInfobarEditSupport) &&
base::FeatureList::IsEnabled(kIOSInfobarUIReboot))) {
detected_values |= DetectedValue::USER_PROVIDED_NAME;
detected_values |= DetectedValue::USER_PROVIDED_EXPIRATION_DATE;
}
#endif // defined(OS_IOS)
return detected_values;
}
......@@ -829,7 +856,17 @@ void CreditCardSaveManager::OnUserDidAcceptUploadHelper(
// that it is possible a name already existed on the card if conflicting names
// were found, which this intentionally overwrites.)
if (!user_provided_card_details.cardholder_name.empty()) {
#if defined(OS_IOS)
// On iOS if the new Infobar UI is enabled, cardholder name was provided by
// the user, but not through the fix flow triggered via
// |should_request_name_from_user_|.
DCHECK(should_request_name_from_user_ ||
(base::FeatureList::IsEnabled(
autofill::features::kAutofillSaveCardInfobarEditSupport) &&
base::FeatureList::IsEnabled(kIOSInfobarUIReboot)));
#else
DCHECK(should_request_name_from_user_);
#endif
upload_request_.card.SetInfo(CREDIT_CARD_NAME_FULL,
user_provided_card_details.cardholder_name,
app_locale_);
......@@ -840,7 +877,17 @@ void CreditCardSaveManager::OnUserDidAcceptUploadHelper(
// the expiration date on |upload_request_.card| with the selected date.
if (!user_provided_card_details.expiration_date_month.empty() &&
!user_provided_card_details.expiration_date_year.empty()) {
#if defined(OS_IOS)
// On iOS if the new Infobar UI is enabled, expiration date was provided by
// the user, but not through the fix flow triggered via
// |should_request_expiration_date_from_user_|.
DCHECK(should_request_expiration_date_from_user_ ||
(base::FeatureList::IsEnabled(
autofill::features::kAutofillSaveCardInfobarEditSupport) &&
base::FeatureList::IsEnabled(kIOSInfobarUIReboot)));
#else
DCHECK(should_request_expiration_date_from_user_);
#endif
upload_request_.card.SetInfo(
CREDIT_CARD_EXP_MONTH, user_provided_card_details.expiration_date_month,
app_locale_);
......
......@@ -38,6 +38,16 @@
autofill::AutofillSaveCardInfoBarDelegateMobile* saveCardInfoBarDelegate;
// YES if the Infobar has been Accepted.
@property(nonatomic, assign) BOOL infobarAccepted;
// TODO(crbug.com/1014652): Move these to future Mediator since these properties
// don't belong in the Coordinator. Cardholder Name to be saved by
// |saveCardInfoBarDelegate|.
@property(nonatomic, copy) NSString* cardholderName;
// Card Expiration month to be saved by |saveCardInfoBarDelegate|.
@property(nonatomic, copy) NSString* expirationMonth;
// Card Expiration year to be saved by |saveCardInfoBarDelegate|.
@property(nonatomic, copy) NSString* expirationYear;
@end
@implementation InfobarSaveCardCoordinator
......@@ -67,6 +77,7 @@
initWithDelegate:self
presentsModal:self.hasBadge
type:InfobarType::kInfobarTypeSaveCard];
[self.bannerViewController
setButtonText:self.saveCardInfoBarDelegate->upload()
? l10n_util::GetNSString(
......@@ -82,6 +93,13 @@
self.saveCardInfoBarDelegate->card_label())];
self.bannerViewController.iconImage =
[UIImage imageNamed:@"infobar_save_card_icon"];
self.cardholderName = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->cardholder_name());
self.expirationMonth = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->expiration_date_month());
self.expirationYear = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->expiration_date_year());
}
}
......@@ -115,7 +133,13 @@
return;
}
// Ignore the Accept() return value since it always returns YES.
self.saveCardInfoBarDelegate->Accept();
DCHECK(self.cardholderName);
DCHECK(self.expirationMonth);
DCHECK(self.expirationYear);
self.saveCardInfoBarDelegate->UpdateAndAccept(
base::SysNSStringToUTF16(self.cardholderName),
base::SysNSStringToUTF16(self.expirationMonth),
base::SysNSStringToUTF16(self.expirationYear));
self.infobarAccepted = YES;
}
......@@ -164,12 +188,9 @@
stringWithFormat:@"•••• %@",
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate
->card_last_four_digits())];
self.modalViewController.cardholderName =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->cardholder_name());
self.modalViewController.expirationMonth = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->expiration_date_month());
self.modalViewController.expirationYear = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->expiration_date_year());
self.modalViewController.cardholderName = self.cardholderName;
self.modalViewController.expirationMonth = self.expirationMonth;
self.modalViewController.expirationYear = self.expirationYear;
self.modalViewController.currentCardSaved = !self.infobarAccepted;
self.modalViewController.legalMessages = [self legalMessagesForModal];
if ((base::FeatureList::IsEnabled(
......@@ -210,8 +231,9 @@
- (void)saveCardWithCardholderName:(NSString*)cardholderName
expirationMonth:(NSString*)month
expirationYear:(NSString*)year {
// TODO(crbug.com/1014652): Once editing is supported send these parameters to
// the Delegate for saving.
self.cardholderName = cardholderName;
self.expirationMonth = month;
self.expirationYear = year;
[self modalInfobarButtonWasAccepted:self];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment