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

Side by Side 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: Use the credit card number field in metrics tests, because ios single-field form fill will not requ… 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 601
602 void AutofillManager::FillOrPreviewCreditCardForm( 602 void AutofillManager::FillOrPreviewCreditCardForm(
603 AutofillDriver::RendererFormDataAction action, 603 AutofillDriver::RendererFormDataAction action,
604 int query_id, 604 int query_id,
605 const FormData& form, 605 const FormData& form,
606 const FormFieldData& field, 606 const FormFieldData& field,
607 const CreditCard& credit_card) { 607 const CreditCard& credit_card) {
608 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) { 608 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) {
609 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD && 609 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD &&
610 WillFillCreditCardNumber(form, field)) { 610 WillFillCreditCardNumber(form, field)) {
611 unmask_request_.card = credit_card;
612 unmasking_query_id_ = query_id; 611 unmasking_query_id_ = query_id;
613 unmasking_form_ = form; 612 unmasking_form_ = form;
614 unmasking_field_ = field; 613 unmasking_field_ = field;
615 payments_client_->Prepare(); 614 masked_card_ = credit_card;
616 client_->ShowUnmaskPrompt(unmask_request_.card, 615 GetOrCreateFullCardRequest()->GetFullCard(
617 AutofillClient::UNMASK_FOR_AUTOFILL, 616 masked_card_, AutofillClient::UNMASK_FOR_AUTOFILL,
618 weak_ptr_factory_.GetWeakPtr()); 617 weak_ptr_factory_.GetWeakPtr());
619 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUnmaskRiskData,
620 weak_ptr_factory_.GetWeakPtr()));
621 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); 618 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion();
622 return; 619 return;
623 } 620 }
624 credit_card_form_event_logger_->OnDidFillSuggestion(credit_card); 621 credit_card_form_event_logger_->OnDidFillSuggestion(credit_card);
625 } 622 }
626 623
627 FillOrPreviewDataModelForm(action, query_id, form, field, credit_card, 624 FillOrPreviewDataModelForm(action, query_id, form, field, credit_card,
628 true /* is_credit_card */); 625 true /* is_credit_card */,
626 base::string16() /* cvc */);
629 } 627 }
630 628
631 void AutofillManager::FillOrPreviewProfileForm( 629 void AutofillManager::FillOrPreviewProfileForm(
632 AutofillDriver::RendererFormDataAction action, 630 AutofillDriver::RendererFormDataAction action,
633 int query_id, 631 int query_id,
634 const FormData& form, 632 const FormData& form,
635 const FormFieldData& field, 633 const FormFieldData& field,
636 const AutofillProfile& profile) { 634 const AutofillProfile& profile) {
637 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) 635 if (action == AutofillDriver::FORM_DATA_ACTION_FILL)
638 address_form_event_logger_->OnDidFillSuggestion(profile); 636 address_form_event_logger_->OnDidFillSuggestion(profile);
639 637
640 FillOrPreviewDataModelForm(action, query_id, form, field, profile, 638 FillOrPreviewDataModelForm(action, query_id, form, field, profile,
641 false /* is_credit_card */); 639 false /* is_credit_card */,
640 base::string16() /* cvc */);
642 } 641 }
643 642
644 void AutofillManager::FillOrPreviewForm( 643 void AutofillManager::FillOrPreviewForm(
645 AutofillDriver::RendererFormDataAction action, 644 AutofillDriver::RendererFormDataAction action,
646 int query_id, 645 int query_id,
647 const FormData& form, 646 const FormData& form,
648 const FormFieldData& field, 647 const FormFieldData& field,
649 int unique_id) { 648 int unique_id) {
650 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) 649 if (!IsValidFormData(form) || !IsValidFormFieldData(field))
651 return; 650 return;
652 651
653 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the 652 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the
654 // PersonalDataManager to reload Mac address book entries. Thus it must come 653 // PersonalDataManager to reload Mac address book entries. Thus it must come
655 // before GetProfile or GetCreditCard. 654 // before GetProfile or GetCreditCard.
656 if (!RefreshDataModels() || !driver_->RendererIsAvailable()) 655 if (!RefreshDataModels() || !driver_->RendererIsAvailable())
657 return; 656 return;
658 657
659 const CreditCard* credit_card = nullptr; 658 const CreditCard* credit_card = nullptr;
660 const AutofillProfile* profile = nullptr; 659 const AutofillProfile* profile = nullptr;
661 if (GetCreditCard(unique_id, &credit_card)) 660 if (GetCreditCard(unique_id, &credit_card))
662 FillOrPreviewCreditCardForm(action, query_id, form, field, *credit_card); 661 FillOrPreviewCreditCardForm(action, query_id, form, field, *credit_card);
663 else if (GetProfile(unique_id, &profile)) 662 else if (GetProfile(unique_id, &profile))
664 FillOrPreviewProfileForm(action, query_id, form, field, *profile); 663 FillOrPreviewProfileForm(action, query_id, form, field, *profile);
665 } 664 }
666 665
667 void AutofillManager::FillCreditCardForm(int query_id, 666 void AutofillManager::FillCreditCardForm(int query_id,
668 const FormData& form, 667 const FormData& form,
669 const FormFieldData& field, 668 const FormFieldData& field,
670 const CreditCard& credit_card) { 669 const CreditCard& credit_card,
670 const base::string16& cvc) {
671 if (!IsValidFormData(form) || !IsValidFormFieldData(field) || 671 if (!IsValidFormData(form) || !IsValidFormFieldData(field) ||
672 !driver_->RendererIsAvailable()) { 672 !driver_->RendererIsAvailable()) {
673 return; 673 return;
674 } 674 }
675 675
676 FillOrPreviewDataModelForm(AutofillDriver::FORM_DATA_ACTION_FILL, query_id, 676 FillOrPreviewDataModelForm(AutofillDriver::FORM_DATA_ACTION_FILL, query_id,
677 form, field, credit_card, true); 677 form, field, credit_card, true, cvc);
678 } 678 }
679 679
680 void AutofillManager::OnFocusNoLongerOnForm() { 680 void AutofillManager::OnFocusNoLongerOnForm() {
681 ProcessPendingFormForUpload(); 681 ProcessPendingFormForUpload();
682 } 682 }
683 683
684 void AutofillManager::OnDidPreviewAutofillFormData() { 684 void AutofillManager::OnDidPreviewAutofillFormData() {
685 if (test_delegate_) 685 if (test_delegate_)
686 test_delegate_->DidPreviewFormData(); 686 test_delegate_->DidPreviewFormData();
687 } 687 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 personal_data_->RemoveByGUID(guid); 815 personal_data_->RemoveByGUID(guid);
816 return true; 816 return true;
817 } 817 }
818 818
819 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, 819 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name,
820 const base::string16& value) { 820 const base::string16& value) {
821 autocomplete_history_manager_->OnRemoveAutocompleteEntry(name, value); 821 autocomplete_history_manager_->OnRemoveAutocompleteEntry(name, value);
822 } 822 }
823 823
824 bool AutofillManager::IsShowingUnmaskPrompt() { 824 bool AutofillManager::IsShowingUnmaskPrompt() {
825 return unmask_request_.card.Compare(CreditCard()) != 0; 825 return full_card_request_ && full_card_request_->IsGettingFullCard();
826 } 826 }
827 827
828 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { 828 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() {
829 return form_structures_.get(); 829 return form_structures_.get();
830 } 830 }
831 831
832 payments::FullCardRequest* AutofillManager::GetOrCreateFullCardRequest() {
833 if (!full_card_request_) {
834 full_card_request_.reset(new payments::FullCardRequest(
835 client_, payments_client_.get(), personal_data_));
836 }
837
838 return full_card_request_.get();
839 }
840
832 void AutofillManager::SetTestDelegate(AutofillManagerTestDelegate* delegate) { 841 void AutofillManager::SetTestDelegate(AutofillManagerTestDelegate* delegate) {
833 test_delegate_ = delegate; 842 test_delegate_ = delegate;
834 } 843 }
835 844
836 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values, 845 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values,
837 const std::vector<base::string16>& labels) { 846 const std::vector<base::string16>& labels) {
838 if (!IsValidString16Vector(values) || 847 if (!IsValidString16Vector(values) ||
839 !IsValidString16Vector(labels) || 848 !IsValidString16Vector(labels) ||
840 values.size() != labels.size()) 849 values.size() != labels.size())
841 return; 850 return;
(...skipping 28 matching lines...) Expand all
870 client_->GetRapporService()); 879 client_->GetRapporService());
871 880
872 // Forward form structures to the password generation manager to detect 881 // Forward form structures to the password generation manager to detect
873 // account creation forms. 882 // account creation forms.
874 driver_->PropagateAutofillPredictions(queried_forms); 883 driver_->PropagateAutofillPredictions(queried_forms);
875 884
876 // If the corresponding flag is set, annotate forms with the predicted types. 885 // If the corresponding flag is set, annotate forms with the predicted types.
877 driver_->SendAutofillTypePredictionsToRenderer(queried_forms); 886 driver_->SendAutofillTypePredictionsToRenderer(queried_forms);
878 } 887 }
879 888
880 void AutofillManager::OnUnmaskResponse(const UnmaskResponse& response) {
881 unmask_request_.user_response = response;
882 if (!unmask_request_.risk_data.empty()) {
883 real_pan_request_timestamp_ = base::Time::Now();
884 payments_client_->UnmaskCard(unmask_request_);
885 }
886 }
887
888 void AutofillManager::OnUnmaskPromptClosed() {
889 payments_client_->CancelRequest();
890 driver_->RendererShouldClearPreviewedForm();
891 unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails();
892 }
893
894 IdentityProvider* AutofillManager::GetIdentityProvider() { 889 IdentityProvider* AutofillManager::GetIdentityProvider() {
895 return client_->GetIdentityProvider(); 890 return client_->GetIdentityProvider();
896 } 891 }
897 892
898 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, 893 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result,
899 const std::string& real_pan) { 894 const std::string& real_pan) {
900 AutofillMetrics::LogRealPanDuration( 895 DCHECK(full_card_request_);
901 base::Time::Now() - real_pan_request_timestamp_, result); 896 full_card_request_->OnDidGetRealPan(result, real_pan);
902 if (!real_pan.empty()) {
903 DCHECK_EQ(AutofillClient::SUCCESS, result);
904 credit_card_form_event_logger_->OnDidFillSuggestion(unmask_request_.card);
905 unmask_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD);
906 unmask_request_.card.SetNumber(base::UTF8ToUTF16(real_pan));
907 if (!unmask_request_.user_response.exp_month.empty()) {
908 unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_MONTH,
909 unmask_request_.user_response.exp_month);
910 }
911 if (!unmask_request_.user_response.exp_year.empty()) {
912 unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR,
913 unmask_request_.user_response.exp_year);
914 }
915 if (unmask_request_.user_response.should_store_pan)
916 personal_data_->UpdateServerCreditCard(unmask_request_.card);
917
918 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_,
919 unmask_request_.card);
920 }
921
922 client_->OnUnmaskVerificationResult(result);
923 } 897 }
924 898
925 void AutofillManager::OnDidGetUploadDetails( 899 void AutofillManager::OnDidGetUploadDetails(
926 AutofillClient::PaymentsRpcResult result, 900 AutofillClient::PaymentsRpcResult result,
927 const base::string16& context_token, 901 const base::string16& context_token,
928 std::unique_ptr<base::DictionaryValue> legal_message) { 902 std::unique_ptr<base::DictionaryValue> legal_message) {
929 // TODO(jdonnelly): Log duration. 903 // TODO(jdonnelly): Log duration.
930 if (result == AutofillClient::SUCCESS) { 904 if (result == AutofillClient::SUCCESS) {
931 // Do *not* call payments_client_->Prepare() here. We shouldn't send 905 // Do *not* call payments_client_->Prepare() here. We shouldn't send
932 // credentials until the user has explicitly accepted a prompt to upload. 906 // credentials until the user has explicitly accepted a prompt to upload.
(...skipping 28 matching lines...) Expand all
961 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); 935 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED);
962 } 936 }
963 } 937 }
964 938
965 void AutofillManager::OnDidUploadCard( 939 void AutofillManager::OnDidUploadCard(
966 AutofillClient::PaymentsRpcResult result) { 940 AutofillClient::PaymentsRpcResult result) {
967 // We don't do anything user-visible if the upload attempt fails. 941 // We don't do anything user-visible if the upload attempt fails.
968 // TODO(jdonnelly): Log duration. 942 // TODO(jdonnelly): Log duration.
969 } 943 }
970 944
971 void AutofillManager::OnDidGetUnmaskRiskData(const std::string& risk_data) { 945 void AutofillManager::OnFullCardDetails(const CreditCard& card,
972 unmask_request_.risk_data = risk_data; 946 const base::string16& cvc) {
973 if (!unmask_request_.user_response.cvc.empty()) { 947 credit_card_form_event_logger_->OnDidFillSuggestion(masked_card_);
974 real_pan_request_timestamp_ = base::Time::Now(); 948 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_,
975 payments_client_->UnmaskCard(unmask_request_); 949 card, cvc);
976 } 950 masked_card_ = CreditCard();
951 }
952
953 void AutofillManager::OnFullCardError() {
954 driver_->RendererShouldClearPreviewedForm();
977 } 955 }
978 956
979 void AutofillManager::OnUserDidAcceptUpload() { 957 void AutofillManager::OnUserDidAcceptUpload() {
980 user_did_accept_upload_prompt_ = true; 958 user_did_accept_upload_prompt_ = true;
981 if (!upload_request_.risk_data.empty()) { 959 if (!upload_request_.risk_data.empty()) {
982 upload_request_.app_locale = app_locale_; 960 upload_request_.app_locale = app_locale_;
983 payments_client_->UploadCard(upload_request_); 961 payments_client_->UploadCard(upload_request_);
984 } 962 }
985 } 963 }
986 964
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 address_form_event_logger_.reset( 1231 address_form_event_logger_.reset(
1254 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)); 1232 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */));
1255 credit_card_form_event_logger_.reset( 1233 credit_card_form_event_logger_.reset(
1256 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)); 1234 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */));
1257 has_logged_autofill_enabled_ = false; 1235 has_logged_autofill_enabled_ = false;
1258 has_logged_address_suggestions_count_ = false; 1236 has_logged_address_suggestions_count_ = false;
1259 did_show_suggestions_ = false; 1237 did_show_suggestions_ = false;
1260 user_did_type_ = false; 1238 user_did_type_ = false;
1261 user_did_autofill_ = false; 1239 user_did_autofill_ = false;
1262 user_did_edit_autofilled_field_ = false; 1240 user_did_edit_autofilled_field_ = false;
1263 unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails(); 1241 masked_card_ = CreditCard();
1264 unmasking_query_id_ = -1; 1242 unmasking_query_id_ = -1;
1265 unmasking_form_ = FormData(); 1243 unmasking_form_ = FormData();
1266 unmasking_field_ = FormFieldData(); 1244 unmasking_field_ = FormFieldData();
1267 forms_loaded_timestamps_.clear(); 1245 forms_loaded_timestamps_.clear();
1268 initial_interaction_timestamp_ = TimeTicks(); 1246 initial_interaction_timestamp_ = TimeTicks();
1269 external_delegate_->Reset(); 1247 external_delegate_->Reset();
1270 } 1248 }
1271 1249
1272 AutofillManager::AutofillManager(AutofillDriver* driver, 1250 AutofillManager::AutofillManager(AutofillDriver* driver,
1273 AutofillClient* client, 1251 AutofillClient* client,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 *credit_card = personal_data_->GetCreditCardByGUID(credit_card_id); 1355 *credit_card = personal_data_->GetCreditCardByGUID(credit_card_id);
1378 return !!*credit_card; 1356 return !!*credit_card;
1379 } 1357 }
1380 1358
1381 void AutofillManager::FillOrPreviewDataModelForm( 1359 void AutofillManager::FillOrPreviewDataModelForm(
1382 AutofillDriver::RendererFormDataAction action, 1360 AutofillDriver::RendererFormDataAction action,
1383 int query_id, 1361 int query_id,
1384 const FormData& form, 1362 const FormData& form,
1385 const FormFieldData& field, 1363 const FormFieldData& field,
1386 const AutofillDataModel& data_model, 1364 const AutofillDataModel& data_model,
1387 bool is_credit_card) { 1365 bool is_credit_card,
1366 const base::string16& cvc) {
1388 FormStructure* form_structure = NULL; 1367 FormStructure* form_structure = NULL;
1389 AutofillField* autofill_field = NULL; 1368 AutofillField* autofill_field = NULL;
1390 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) 1369 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
1391 return; 1370 return;
1392 1371
1393 DCHECK(form_structure); 1372 DCHECK(form_structure);
1394 DCHECK(autofill_field); 1373 DCHECK(autofill_field);
1395 1374
1396 FormData result = form; 1375 FormData result = form;
1397 1376
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 FieldTypeGroup field_group_type = cached_field->Type().group(); 1431 FieldTypeGroup field_group_type = cached_field->Type().group();
1453 1432
1454 if (field_group_type == NO_GROUP) 1433 if (field_group_type == NO_GROUP)
1455 continue; 1434 continue;
1456 1435
1457 base::string16 value = 1436 base::string16 value =
1458 data_model.GetInfo(cached_field->Type(), app_locale_); 1437 data_model.GetInfo(cached_field->Type(), app_locale_);
1459 if (is_credit_card && 1438 if (is_credit_card &&
1460 cached_field->Type().GetStorableType() == 1439 cached_field->Type().GetStorableType() ==
1461 CREDIT_CARD_VERIFICATION_CODE) { 1440 CREDIT_CARD_VERIFICATION_CODE) {
1462 // If this is |unmask_request_.card|, |unmask_request_.user_response.cvc| 1441 value = cvc;
1463 // should be non-empty and vice versa.
1464 value = unmask_request_.user_response.cvc;
1465 DCHECK_EQ(&unmask_request_.card == &data_model, !value.empty());
1466 } else if (is_credit_card && IsCreditCardExpirationType( 1442 } else if (is_credit_card && IsCreditCardExpirationType(
1467 cached_field->Type().GetStorableType()) && 1443 cached_field->Type().GetStorableType()) &&
1468 static_cast<const CreditCard*>(&data_model) 1444 static_cast<const CreditCard*>(&data_model)
1469 ->IsExpired(base::Time::Now())) { 1445 ->IsExpired(base::Time::Now())) {
1470 // Don't fill expired cards expiration date. 1446 // Don't fill expired cards expiration date.
1471 value = base::string16(); 1447 value = base::string16();
1472 } 1448 }
1473 1449
1474 // Must match ForEachMatchingFormField() in form_autofill_util.cc. 1450 // Must match ForEachMatchingFormField() in form_autofill_util.cc.
1475 // Only notify autofilling of empty fields and the field that initiated 1451 // Only notify autofilling of empty fields and the field that initiated
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 if (i > 0) 1997 if (i > 0)
2022 fputs("Next oldest form:\n", file); 1998 fputs("Next oldest form:\n", file);
2023 } 1999 }
2024 fputs("\n", file); 2000 fputs("\n", file);
2025 2001
2026 fclose(file); 2002 fclose(file);
2027 } 2003 }
2028 #endif // ENABLE_FORM_DEBUG_DUMP 2004 #endif // ENABLE_FORM_DEBUG_DUMP
2029 2005
2030 } // namespace autofill 2006 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698