Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Unified Diff: components/autofill/core/browser/autofill_manager.cc

Issue 1899893002: Card unmasking without form filling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_manager.cc
diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc
index ea4c155b95a449c7ed10a19e9755d9580b4c07d5..c6ff80e0a8605834ba2b3940a682edfc4df6052e 100644
--- a/components/autofill/core/browser/autofill_manager.cc
+++ b/components/autofill/core/browser/autofill_manager.cc
@@ -244,6 +244,30 @@ void AutofillManager::ShowAutofillSettings() {
client_->ShowAutofillSettings();
}
+void AutofillManager::UnmaskCardForPayment(const CreditCard& maybe_masked_card,
+ const UnmaskCallback& callback) {
+ if (unmask_callback_) {
+ callback.Run(false, maybe_masked_card, maybe_masked_card, base::string16());
+ return;
+ }
+
+ unmask_callback_.reset(new UnmaskCallback(callback));
+ unmask_request_.card = maybe_masked_card;
+ bool is_masked =
+ maybe_masked_card.record_type() == CreditCard::MASKED_SERVER_CARD;
+
+ if (is_masked)
+ payments_client_->Prepare();
+
+ client_->ShowUnmaskPrompt(unmask_request_.card,
Mathieu 2016/04/19 13:24:25 can you mention why we're calling ShowUnmaskPrompt
+ weak_ptr_factory_.GetWeakPtr());
+
+ if (is_masked) {
+ client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUnmaskRiskData,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+}
+
bool AutofillManager::ShouldShowScanCreditCard(const FormData& form,
const FormFieldData& field) {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
@@ -607,15 +631,12 @@ void AutofillManager::FillOrPreviewCreditCardForm(
if (action == AutofillDriver::FORM_DATA_ACTION_FILL) {
if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD &&
WillFillCreditCardNumber(form, field)) {
- unmask_request_.card = credit_card;
unmasking_query_id_ = query_id;
unmasking_form_ = form;
unmasking_field_ = field;
- payments_client_->Prepare();
- client_->ShowUnmaskPrompt(unmask_request_.card,
- weak_ptr_factory_.GetWeakPtr());
- client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUnmaskRiskData,
- weak_ptr_factory_.GetWeakPtr()));
+ UnmaskCardForPayment(credit_card,
+ base::Bind(&AutofillManager::OnCardUnmasked,
+ weak_ptr_factory_.GetWeakPtr()));
credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion();
return;
}
@@ -876,6 +897,16 @@ void AutofillManager::OnLoadedServerPredictions(
}
void AutofillManager::OnUnmaskResponse(const UnmaskResponse& response) {
+ DCHECK(unmask_callback_);
+
+ if (unmask_request_.card.record_type() != CreditCard::MASKED_SERVER_CARD) {
+ unmask_callback_->Run(true, unmask_request_.card, unmask_request_.card,
+ response.cvc);
+ unmask_callback_.reset();
+ client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS);
+ return;
+ }
+
unmask_request_.user_response = response;
if (!unmask_request_.risk_data.empty()) {
real_pan_request_timestamp_ = base::Time::Now();
@@ -884,8 +915,12 @@ void AutofillManager::OnUnmaskResponse(const UnmaskResponse& response) {
}
void AutofillManager::OnUnmaskPromptClosed() {
+ if (unmask_callback_) {
+ unmask_callback_->Run(false, unmask_request_.card, unmask_request_.card,
+ base::string16());
+ unmask_callback_.reset();
+ }
payments_client_->CancelRequest();
- driver_->RendererShouldClearPreviewedForm();
unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails();
}
@@ -895,11 +930,12 @@ IdentityProvider* AutofillManager::GetIdentityProvider() {
void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result,
const std::string& real_pan) {
+ DCHECK(unmask_callback_);
AutofillMetrics::LogRealPanDuration(
base::Time::Now() - real_pan_request_timestamp_, result);
+ CreditCard original = unmask_request_.card;
if (!real_pan.empty()) {
DCHECK_EQ(AutofillClient::SUCCESS, result);
- credit_card_form_event_logger_->OnDidFillSuggestion(unmask_request_.card);
unmask_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD);
unmask_request_.card.SetNumber(base::UTF8ToUTF16(real_pan));
if (!unmask_request_.user_response.exp_month.empty()) {
@@ -912,11 +948,13 @@ void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result,
}
if (unmask_request_.user_response.should_store_pan)
personal_data_->UpdateServerCreditCard(unmask_request_.card);
-
- FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_,
- unmask_request_.card);
}
+ unmask_callback_->Run(!real_pan.empty() && result == AutofillClient::SUCCESS,
+ original, unmask_request_.card,
+ unmask_request_.user_response.cvc);
+ unmask_callback_.reset();
+
client_->OnUnmaskVerificationResult(result);
}
@@ -966,6 +1004,19 @@ void AutofillManager::OnDidUploadCard(
// TODO(jdonnelly): Log duration.
}
+void AutofillManager::OnCardUnmasked(bool success,
+ const CreditCard& original_card,
+ const CreditCard& unmasked_card,
+ const base::string16& unused_cvc) {
+ if (success) {
+ credit_card_form_event_logger_->OnDidFillSuggestion(original_card);
+ FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_,
Mathieu 2016/04/19 13:24:24 curious, if the CVC is unused here, where is it ta
+ unmasked_card);
+ } else {
+ driver_->RendererShouldClearPreviewedForm();
+ }
+}
+
void AutofillManager::OnDidGetUnmaskRiskData(const std::string& risk_data) {
unmask_request_.risk_data = risk_data;
if (!unmask_request_.user_response.cvc.empty()) {

Powered by Google App Engine
This is Rietveld 408576698