Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 // work if the delegate has a pointer to the AutofillManager, but | 237 // work if the delegate has a pointer to the AutofillManager, but |
| 238 // future directions may not need such a pointer. | 238 // future directions may not need such a pointer. |
| 239 external_delegate_ = delegate; | 239 external_delegate_ = delegate; |
| 240 autocomplete_history_manager_->SetExternalDelegate(delegate); | 240 autocomplete_history_manager_->SetExternalDelegate(delegate); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void AutofillManager::ShowAutofillSettings() { | 243 void AutofillManager::ShowAutofillSettings() { |
| 244 client_->ShowAutofillSettings(); | 244 client_->ShowAutofillSettings(); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void AutofillManager::UnmaskCardForPayment(const CreditCard& maybe_masked_card, | |
| 248 const UnmaskCallback& callback) { | |
| 249 if (unmask_callback_) { | |
| 250 callback.Run(false, maybe_masked_card, maybe_masked_card, base::string16()); | |
| 251 return; | |
| 252 } | |
| 253 | |
| 254 unmask_callback_.reset(new UnmaskCallback(callback)); | |
| 255 unmask_request_.card = maybe_masked_card; | |
| 256 bool is_masked = | |
| 257 maybe_masked_card.record_type() == CreditCard::MASKED_SERVER_CARD; | |
| 258 | |
| 259 if (is_masked) | |
| 260 payments_client_->Prepare(); | |
| 261 | |
| 262 client_->ShowUnmaskPrompt(unmask_request_.card, | |
|
Mathieu
2016/04/19 13:24:25
can you mention why we're calling ShowUnmaskPrompt
| |
| 263 weak_ptr_factory_.GetWeakPtr()); | |
| 264 | |
| 265 if (is_masked) { | |
| 266 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUnmaskRiskData, | |
| 267 weak_ptr_factory_.GetWeakPtr())); | |
| 268 } | |
| 269 } | |
| 270 | |
| 247 bool AutofillManager::ShouldShowScanCreditCard(const FormData& form, | 271 bool AutofillManager::ShouldShowScanCreditCard(const FormData& form, |
| 248 const FormFieldData& field) { | 272 const FormFieldData& field) { |
| 249 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 273 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 250 switches::kDisableCreditCardScan)) { | 274 switches::kDisableCreditCardScan)) { |
| 251 return false; | 275 return false; |
| 252 } | 276 } |
| 253 | 277 |
| 254 if (base::FieldTrialList::FindFullName("CreditCardScan") == "Control" && | 278 if (base::FieldTrialList::FindFullName("CreditCardScan") == "Control" && |
| 255 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 279 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 256 switches::kEnableCreditCardScan)) { | 280 switches::kEnableCreditCardScan)) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 600 | 624 |
| 601 void AutofillManager::FillOrPreviewCreditCardForm( | 625 void AutofillManager::FillOrPreviewCreditCardForm( |
| 602 AutofillDriver::RendererFormDataAction action, | 626 AutofillDriver::RendererFormDataAction action, |
| 603 int query_id, | 627 int query_id, |
| 604 const FormData& form, | 628 const FormData& form, |
| 605 const FormFieldData& field, | 629 const FormFieldData& field, |
| 606 const CreditCard& credit_card) { | 630 const CreditCard& credit_card) { |
| 607 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) { | 631 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) { |
| 608 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD && | 632 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD && |
| 609 WillFillCreditCardNumber(form, field)) { | 633 WillFillCreditCardNumber(form, field)) { |
| 610 unmask_request_.card = credit_card; | |
| 611 unmasking_query_id_ = query_id; | 634 unmasking_query_id_ = query_id; |
| 612 unmasking_form_ = form; | 635 unmasking_form_ = form; |
| 613 unmasking_field_ = field; | 636 unmasking_field_ = field; |
| 614 payments_client_->Prepare(); | 637 UnmaskCardForPayment(credit_card, |
| 615 client_->ShowUnmaskPrompt(unmask_request_.card, | 638 base::Bind(&AutofillManager::OnCardUnmasked, |
| 616 weak_ptr_factory_.GetWeakPtr()); | 639 weak_ptr_factory_.GetWeakPtr())); |
| 617 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUnmaskRiskData, | |
| 618 weak_ptr_factory_.GetWeakPtr())); | |
| 619 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); | 640 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); |
| 620 return; | 641 return; |
| 621 } | 642 } |
| 622 credit_card_form_event_logger_->OnDidFillSuggestion(credit_card); | 643 credit_card_form_event_logger_->OnDidFillSuggestion(credit_card); |
| 623 } | 644 } |
| 624 | 645 |
| 625 FillOrPreviewDataModelForm(action, query_id, form, field, credit_card, | 646 FillOrPreviewDataModelForm(action, query_id, form, field, credit_card, |
| 626 true /* is_credit_card */); | 647 true /* is_credit_card */); |
| 627 } | 648 } |
| 628 | 649 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 869 | 890 |
| 870 // Forward form structures to the password generation manager to detect | 891 // Forward form structures to the password generation manager to detect |
| 871 // account creation forms. | 892 // account creation forms. |
| 872 driver_->PropagateAutofillPredictions(queried_forms); | 893 driver_->PropagateAutofillPredictions(queried_forms); |
| 873 | 894 |
| 874 // If the corresponding flag is set, annotate forms with the predicted types. | 895 // If the corresponding flag is set, annotate forms with the predicted types. |
| 875 driver_->SendAutofillTypePredictionsToRenderer(queried_forms); | 896 driver_->SendAutofillTypePredictionsToRenderer(queried_forms); |
| 876 } | 897 } |
| 877 | 898 |
| 878 void AutofillManager::OnUnmaskResponse(const UnmaskResponse& response) { | 899 void AutofillManager::OnUnmaskResponse(const UnmaskResponse& response) { |
| 900 DCHECK(unmask_callback_); | |
| 901 | |
| 902 if (unmask_request_.card.record_type() != CreditCard::MASKED_SERVER_CARD) { | |
| 903 unmask_callback_->Run(true, unmask_request_.card, unmask_request_.card, | |
| 904 response.cvc); | |
| 905 unmask_callback_.reset(); | |
| 906 client_->OnUnmaskVerificationResult(AutofillClient::SUCCESS); | |
| 907 return; | |
| 908 } | |
| 909 | |
| 879 unmask_request_.user_response = response; | 910 unmask_request_.user_response = response; |
| 880 if (!unmask_request_.risk_data.empty()) { | 911 if (!unmask_request_.risk_data.empty()) { |
| 881 real_pan_request_timestamp_ = base::Time::Now(); | 912 real_pan_request_timestamp_ = base::Time::Now(); |
| 882 payments_client_->UnmaskCard(unmask_request_); | 913 payments_client_->UnmaskCard(unmask_request_); |
| 883 } | 914 } |
| 884 } | 915 } |
| 885 | 916 |
| 886 void AutofillManager::OnUnmaskPromptClosed() { | 917 void AutofillManager::OnUnmaskPromptClosed() { |
| 918 if (unmask_callback_) { | |
| 919 unmask_callback_->Run(false, unmask_request_.card, unmask_request_.card, | |
| 920 base::string16()); | |
| 921 unmask_callback_.reset(); | |
| 922 } | |
| 887 payments_client_->CancelRequest(); | 923 payments_client_->CancelRequest(); |
| 888 driver_->RendererShouldClearPreviewedForm(); | |
| 889 unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails(); | 924 unmask_request_ = payments::PaymentsClient::UnmaskRequestDetails(); |
| 890 } | 925 } |
| 891 | 926 |
| 892 IdentityProvider* AutofillManager::GetIdentityProvider() { | 927 IdentityProvider* AutofillManager::GetIdentityProvider() { |
| 893 return client_->GetIdentityProvider(); | 928 return client_->GetIdentityProvider(); |
| 894 } | 929 } |
| 895 | 930 |
| 896 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, | 931 void AutofillManager::OnDidGetRealPan(AutofillClient::PaymentsRpcResult result, |
| 897 const std::string& real_pan) { | 932 const std::string& real_pan) { |
| 933 DCHECK(unmask_callback_); | |
| 898 AutofillMetrics::LogRealPanDuration( | 934 AutofillMetrics::LogRealPanDuration( |
| 899 base::Time::Now() - real_pan_request_timestamp_, result); | 935 base::Time::Now() - real_pan_request_timestamp_, result); |
| 936 CreditCard original = unmask_request_.card; | |
| 900 if (!real_pan.empty()) { | 937 if (!real_pan.empty()) { |
| 901 DCHECK_EQ(AutofillClient::SUCCESS, result); | 938 DCHECK_EQ(AutofillClient::SUCCESS, result); |
| 902 credit_card_form_event_logger_->OnDidFillSuggestion(unmask_request_.card); | |
| 903 unmask_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD); | 939 unmask_request_.card.set_record_type(CreditCard::FULL_SERVER_CARD); |
| 904 unmask_request_.card.SetNumber(base::UTF8ToUTF16(real_pan)); | 940 unmask_request_.card.SetNumber(base::UTF8ToUTF16(real_pan)); |
| 905 if (!unmask_request_.user_response.exp_month.empty()) { | 941 if (!unmask_request_.user_response.exp_month.empty()) { |
| 906 unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_MONTH, | 942 unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_MONTH, |
| 907 unmask_request_.user_response.exp_month); | 943 unmask_request_.user_response.exp_month); |
| 908 } | 944 } |
| 909 if (!unmask_request_.user_response.exp_year.empty()) { | 945 if (!unmask_request_.user_response.exp_year.empty()) { |
| 910 unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 946 unmask_request_.card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 911 unmask_request_.user_response.exp_year); | 947 unmask_request_.user_response.exp_year); |
| 912 } | 948 } |
| 913 if (unmask_request_.user_response.should_store_pan) | 949 if (unmask_request_.user_response.should_store_pan) |
| 914 personal_data_->UpdateServerCreditCard(unmask_request_.card); | 950 personal_data_->UpdateServerCreditCard(unmask_request_.card); |
| 951 } | |
| 915 | 952 |
| 916 FillCreditCardForm(unmasking_query_id_, unmasking_form_, unmasking_field_, | 953 unmask_callback_->Run(!real_pan.empty() && result == AutofillClient::SUCCESS, |
| 917 unmask_request_.card); | 954 original, unmask_request_.card, |
| 918 } | 955 unmask_request_.user_response.cvc); |
| 956 unmask_callback_.reset(); | |
| 919 | 957 |
| 920 client_->OnUnmaskVerificationResult(result); | 958 client_->OnUnmaskVerificationResult(result); |
| 921 } | 959 } |
| 922 | 960 |
| 923 void AutofillManager::OnDidGetUploadDetails( | 961 void AutofillManager::OnDidGetUploadDetails( |
| 924 AutofillClient::PaymentsRpcResult result, | 962 AutofillClient::PaymentsRpcResult result, |
| 925 const base::string16& context_token, | 963 const base::string16& context_token, |
| 926 std::unique_ptr<base::DictionaryValue> legal_message) { | 964 std::unique_ptr<base::DictionaryValue> legal_message) { |
| 927 // TODO(jdonnelly): Log duration. | 965 // TODO(jdonnelly): Log duration. |
| 928 if (result == AutofillClient::SUCCESS) { | 966 if (result == AutofillClient::SUCCESS) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 959 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); | 997 AutofillMetrics::UPLOAD_NOT_OFFERED_GET_UPLOAD_DETAILS_FAILED); |
| 960 } | 998 } |
| 961 } | 999 } |
| 962 | 1000 |
| 963 void AutofillManager::OnDidUploadCard( | 1001 void AutofillManager::OnDidUploadCard( |
| 964 AutofillClient::PaymentsRpcResult result) { | 1002 AutofillClient::PaymentsRpcResult result) { |
| 965 // We don't do anything user-visible if the upload attempt fails. | 1003 // We don't do anything user-visible if the upload attempt fails. |
| 966 // TODO(jdonnelly): Log duration. | 1004 // TODO(jdonnelly): Log duration. |
| 967 } | 1005 } |
| 968 | 1006 |
| 1007 void AutofillManager::OnCardUnmasked(bool success, | |
| 1008 const CreditCard& original_card, | |
| 1009 const CreditCard& unmasked_card, | |
| 1010 const base::string16& unused_cvc) { | |
| 1011 if (success) { | |
| 1012 credit_card_form_event_logger_->OnDidFillSuggestion(original_card); | |
| 1013 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
| |
| 1014 unmasked_card); | |
| 1015 } else { | |
| 1016 driver_->RendererShouldClearPreviewedForm(); | |
| 1017 } | |
| 1018 } | |
| 1019 | |
| 969 void AutofillManager::OnDidGetUnmaskRiskData(const std::string& risk_data) { | 1020 void AutofillManager::OnDidGetUnmaskRiskData(const std::string& risk_data) { |
| 970 unmask_request_.risk_data = risk_data; | 1021 unmask_request_.risk_data = risk_data; |
| 971 if (!unmask_request_.user_response.cvc.empty()) { | 1022 if (!unmask_request_.user_response.cvc.empty()) { |
| 972 real_pan_request_timestamp_ = base::Time::Now(); | 1023 real_pan_request_timestamp_ = base::Time::Now(); |
| 973 payments_client_->UnmaskCard(unmask_request_); | 1024 payments_client_->UnmaskCard(unmask_request_); |
| 974 } | 1025 } |
| 975 } | 1026 } |
| 976 | 1027 |
| 977 void AutofillManager::OnUserDidAcceptUpload() { | 1028 void AutofillManager::OnUserDidAcceptUpload() { |
| 978 user_did_accept_upload_prompt_ = true; | 1029 user_did_accept_upload_prompt_ = true; |
| (...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2017 if (i > 0) | 2068 if (i > 0) |
| 2018 fputs("Next oldest form:\n", file); | 2069 fputs("Next oldest form:\n", file); |
| 2019 } | 2070 } |
| 2020 fputs("\n", file); | 2071 fputs("\n", file); |
| 2021 | 2072 |
| 2022 fclose(file); | 2073 fclose(file); |
| 2023 } | 2074 } |
| 2024 #endif // ENABLE_FORM_DEBUG_DUMP | 2075 #endif // ENABLE_FORM_DEBUG_DUMP |
| 2025 | 2076 |
| 2026 } // namespace autofill | 2077 } // namespace autofill |
| OLD | NEW |