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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "components/autofill/core/browser/autofill_profile.h" | 44 #include "components/autofill/core/browser/autofill_profile.h" |
45 #include "components/autofill/core/browser/autofill_type.h" | 45 #include "components/autofill/core/browser/autofill_type.h" |
46 #include "components/autofill/core/browser/country_names.h" | 46 #include "components/autofill/core/browser/country_names.h" |
47 #include "components/autofill/core/browser/credit_card.h" | 47 #include "components/autofill/core/browser/credit_card.h" |
48 #include "components/autofill/core/browser/field_types.h" | 48 #include "components/autofill/core/browser/field_types.h" |
49 #include "components/autofill/core/browser/form_structure.h" | 49 #include "components/autofill/core/browser/form_structure.h" |
50 #include "components/autofill/core/browser/personal_data_manager.h" | 50 #include "components/autofill/core/browser/personal_data_manager.h" |
51 #include "components/autofill/core/browser/phone_number.h" | 51 #include "components/autofill/core/browser/phone_number.h" |
52 #include "components/autofill/core/browser/phone_number_i18n.h" | 52 #include "components/autofill/core/browser/phone_number_i18n.h" |
53 #include "components/autofill/core/browser/popup_item_ids.h" | 53 #include "components/autofill/core/browser/popup_item_ids.h" |
| 54 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" |
54 #include "components/autofill/core/browser/validation.h" | 55 #include "components/autofill/core/browser/validation.h" |
55 #include "components/autofill/core/common/autofill_clock.h" | 56 #include "components/autofill/core/common/autofill_clock.h" |
56 #include "components/autofill/core/common/autofill_constants.h" | 57 #include "components/autofill/core/common/autofill_constants.h" |
57 #include "components/autofill/core/common/autofill_data_validation.h" | 58 #include "components/autofill/core/common/autofill_data_validation.h" |
58 #include "components/autofill/core/common/autofill_pref_names.h" | 59 #include "components/autofill/core/common/autofill_pref_names.h" |
59 #include "components/autofill/core/common/autofill_util.h" | 60 #include "components/autofill/core/common/autofill_util.h" |
60 #include "components/autofill/core/common/form_data.h" | 61 #include "components/autofill/core/common/form_data.h" |
61 #include "components/autofill/core/common/form_data_predictions.h" | 62 #include "components/autofill/core/common/form_data_predictions.h" |
62 #include "components/autofill/core/common/form_field_data.h" | 63 #include "components/autofill/core/common/form_field_data.h" |
63 #include "components/autofill/core/common/password_form_fill_data.h" | 64 #include "components/autofill/core/common/password_form_fill_data.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), | 228 new AutofillMetrics::FormEventLogger(false /* is_for_credit_card */)), |
228 credit_card_form_event_logger_( | 229 credit_card_form_event_logger_( |
229 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), | 230 new AutofillMetrics::FormEventLogger(true /* is_for_credit_card */)), |
230 has_logged_autofill_enabled_(false), | 231 has_logged_autofill_enabled_(false), |
231 has_logged_address_suggestions_count_(false), | 232 has_logged_address_suggestions_count_(false), |
232 did_show_suggestions_(false), | 233 did_show_suggestions_(false), |
233 user_did_type_(false), | 234 user_did_type_(false), |
234 user_did_autofill_(false), | 235 user_did_autofill_(false), |
235 user_did_edit_autofilled_field_(false), | 236 user_did_edit_autofilled_field_(false), |
236 user_did_accept_upload_prompt_(false), | 237 user_did_accept_upload_prompt_(false), |
| 238 should_cvc_be_requested_(false), |
237 external_delegate_(NULL), | 239 external_delegate_(NULL), |
238 test_delegate_(NULL), | 240 test_delegate_(NULL), |
239 #if defined(OS_ANDROID) || defined(OS_IOS) | 241 #if defined(OS_ANDROID) || defined(OS_IOS) |
240 autofill_assistant_(this), | 242 autofill_assistant_(this), |
241 #endif | 243 #endif |
242 weak_ptr_factory_(this) { | 244 weak_ptr_factory_(this) { |
243 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { | 245 if (enable_download_manager == ENABLE_AUTOFILL_DOWNLOAD_MANAGER) { |
244 download_manager_.reset(new AutofillDownloadManager(driver, this)); | 246 download_manager_.reset(new AutofillDownloadManager(driver, this)); |
245 } | 247 } |
246 CountryNames::SetLocaleString(app_locale_); | 248 CountryNames::SetLocaleString(app_locale_); |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 const base::string16& context_token, | 1028 const base::string16& context_token, |
1027 std::unique_ptr<base::DictionaryValue> legal_message) { | 1029 std::unique_ptr<base::DictionaryValue> legal_message) { |
1028 // TODO(jdonnelly): Log duration. | 1030 // TODO(jdonnelly): Log duration. |
1029 if (result == AutofillClient::SUCCESS) { | 1031 if (result == AutofillClient::SUCCESS) { |
1030 // Do *not* call payments_client_->Prepare() here. We shouldn't send | 1032 // Do *not* call payments_client_->Prepare() here. We shouldn't send |
1031 // credentials until the user has explicitly accepted a prompt to upload. | 1033 // credentials until the user has explicitly accepted a prompt to upload. |
1032 upload_request_.context_token = context_token; | 1034 upload_request_.context_token = context_token; |
1033 user_did_accept_upload_prompt_ = false; | 1035 user_did_accept_upload_prompt_ = false; |
1034 client_->ConfirmSaveCreditCardToCloud( | 1036 client_->ConfirmSaveCreditCardToCloud( |
1035 upload_request_.card, std::move(legal_message), | 1037 upload_request_.card, std::move(legal_message), |
| 1038 should_cvc_be_requested_, |
1036 base::Bind(&AutofillManager::OnUserDidAcceptUpload, | 1039 base::Bind(&AutofillManager::OnUserDidAcceptUpload, |
1037 weak_ptr_factory_.GetWeakPtr())); | 1040 weak_ptr_factory_.GetWeakPtr())); |
1038 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData, | 1041 client_->LoadRiskData(base::Bind(&AutofillManager::OnDidGetUploadRiskData, |
1039 weak_ptr_factory_.GetWeakPtr())); | 1042 weak_ptr_factory_.GetWeakPtr())); |
1040 AutofillMetrics::LogCardUploadDecisionMetric( | 1043 AutofillMetrics::CardUploadDecisionMetric card_upload_decision_metric = |
1041 AutofillMetrics::UPLOAD_OFFERED); | 1044 should_cvc_be_requested_ ? AutofillMetrics::UPLOAD_OFFERED_NO_CVC |
1042 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_OFFERED); | 1045 : AutofillMetrics::UPLOAD_OFFERED; |
| 1046 AutofillMetrics::LogCardUploadDecisionMetric(card_upload_decision_metric); |
| 1047 LogCardUploadDecisionUkm(card_upload_decision_metric); |
1043 } else { | 1048 } else { |
1044 // If the upload details request failed, fall back to a local save. The | 1049 // If the upload details request failed, fall back to a local save. The |
1045 // reasoning here is as follows: | 1050 // reasoning here is as follows: |
1046 // - This will sometimes fail intermittently, in which case it might be | 1051 // - This will sometimes fail intermittently, in which case it might be |
1047 // better to not fall back, because sometimes offering upload and sometimes | 1052 // better to not fall back, because sometimes offering upload and sometimes |
1048 // offering local save is a poor user experience. | 1053 // offering local save is a poor user experience. |
1049 // - However, in some cases, our local configuration limiting the feature to | 1054 // - However, in some cases, our local configuration limiting the feature to |
1050 // countries that Payments is known to support will not match Payments' own | 1055 // countries that Payments is known to support will not match Payments' own |
1051 // determination of what country the user is located in. In these cases, | 1056 // determination of what country the user is located in. In these cases, |
1052 // the upload details request will consistently fail and if we don't fall | 1057 // the upload details request will consistently fail and if we don't fall |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 | 1097 |
1093 void AutofillManager::OnUnmaskVerificationResult( | 1098 void AutofillManager::OnUnmaskVerificationResult( |
1094 AutofillClient::PaymentsRpcResult result) { | 1099 AutofillClient::PaymentsRpcResult result) { |
1095 client_->OnUnmaskVerificationResult(result); | 1100 client_->OnUnmaskVerificationResult(result); |
1096 } | 1101 } |
1097 | 1102 |
1098 void AutofillManager::OnUserDidAcceptUpload() { | 1103 void AutofillManager::OnUserDidAcceptUpload() { |
1099 user_did_accept_upload_prompt_ = true; | 1104 user_did_accept_upload_prompt_ = true; |
1100 if (!upload_request_.risk_data.empty()) { | 1105 if (!upload_request_.risk_data.empty()) { |
1101 upload_request_.app_locale = app_locale_; | 1106 upload_request_.app_locale = app_locale_; |
| 1107 // If the upload request does not have card CVC, populate it with the |
| 1108 // value provided by the user: |
| 1109 if (upload_request_.cvc.empty()) { |
| 1110 DCHECK(client_->GetSaveCardBubbleController()); |
| 1111 upload_request_.cvc = |
| 1112 client_->GetSaveCardBubbleController()->GetCvcEnteredByUser(); |
| 1113 } |
1102 payments_client_->UploadCard(upload_request_); | 1114 payments_client_->UploadCard(upload_request_); |
1103 } | 1115 } |
1104 } | 1116 } |
1105 | 1117 |
1106 void AutofillManager::OnDidGetUploadRiskData(const std::string& risk_data) { | 1118 void AutofillManager::OnDidGetUploadRiskData(const std::string& risk_data) { |
1107 upload_request_.risk_data = risk_data; | 1119 upload_request_.risk_data = risk_data; |
1108 if (user_did_accept_upload_prompt_) { | 1120 if (user_did_accept_upload_prompt_) { |
1109 upload_request_.app_locale = app_locale_; | 1121 upload_request_.app_locale = app_locale_; |
| 1122 // If the upload request does not have card CVC, populate it with the |
| 1123 // value provided by the user: |
| 1124 if (upload_request_.cvc.empty()) { |
| 1125 DCHECK(client_->GetSaveCardBubbleController()); |
| 1126 upload_request_.cvc = |
| 1127 client_->GetSaveCardBubbleController()->GetCvcEnteredByUser(); |
| 1128 } |
1110 payments_client_->UploadCard(upload_request_); | 1129 payments_client_->UploadCard(upload_request_); |
1111 } | 1130 } |
1112 } | 1131 } |
1113 | 1132 |
1114 void AutofillManager::OnDidEndTextFieldEditing() { | 1133 void AutofillManager::OnDidEndTextFieldEditing() { |
1115 external_delegate_->DidEndTextFieldEditing(); | 1134 external_delegate_->DidEndTextFieldEditing(); |
1116 } | 1135 } |
1117 | 1136 |
1118 bool AutofillManager::IsAutofillEnabled() const { | 1137 bool AutofillManager::IsAutofillEnabled() const { |
1119 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); | 1138 return ::autofill::IsAutofillEnabled(client_->GetPrefs()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 upload_request_.card = *imported_credit_card; | 1211 upload_request_.card = *imported_credit_card; |
1193 | 1212 |
1194 // In order to prompt the user to upload their card, we must have both: | 1213 // In order to prompt the user to upload their card, we must have both: |
1195 // 1) Card with CVC | 1214 // 1) Card with CVC |
1196 // 2) 1+ recently-used or modified addresses that meet the client-side | 1215 // 2) 1+ recently-used or modified addresses that meet the client-side |
1197 // validation rules | 1216 // validation rules |
1198 // Here we perform both checks before returning or logging anything, | 1217 // Here we perform both checks before returning or logging anything, |
1199 // because if only one of the two is missing, it may be fixable. | 1218 // because if only one of the two is missing, it may be fixable. |
1200 | 1219 |
1201 // Check for a CVC to determine whether we can prompt the user to upload | 1220 // Check for a CVC to determine whether we can prompt the user to upload |
1202 // their card. If no CVC is present, do nothing. We could fall back to a | 1221 // their card. If no CVC is present and the experiment is off, do nothing. |
1203 // local save but we believe that sometimes offering upload and sometimes | 1222 // We could fall back to a local save but we believe that sometimes offering |
1204 // offering local save is a confusing user experience. | 1223 // upload and sometimes offering local save is a confusing user experience. |
| 1224 // If no CVC and the experiment is on, request CVC from the user in the |
| 1225 // bubble and save using the provided value. |
1205 for (const auto& field : submitted_form) { | 1226 for (const auto& field : submitted_form) { |
1206 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && | 1227 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && |
1207 IsValidCreditCardSecurityCode(field->value, | 1228 IsValidCreditCardSecurityCode(field->value, |
1208 upload_request_.card.type())) { | 1229 upload_request_.card.type())) { |
1209 upload_request_.cvc = field->value; | 1230 upload_request_.cvc = field->value; |
1210 break; | 1231 break; |
1211 } | 1232 } |
1212 } | 1233 } |
1213 | 1234 |
1214 // Upload requires that recently used or modified addresses meet the | 1235 // Upload requires that recently used or modified addresses meet the |
1215 // client-side validation rules. | 1236 // client-side validation rules. |
1216 autofill::AutofillMetrics::CardUploadDecisionMetric | 1237 autofill::AutofillMetrics::CardUploadDecisionMetric |
1217 get_profiles_decision_metric = AutofillMetrics::UPLOAD_OFFERED; | 1238 get_profiles_decision_metric = AutofillMetrics::UPLOAD_OFFERED; |
1218 std::string rappor_metric_name; | 1239 std::string rappor_metric_name; |
1219 bool get_profiles_succeeded = | 1240 bool get_profiles_succeeded = |
1220 GetProfilesForCreditCardUpload(*imported_credit_card, | 1241 GetProfilesForCreditCardUpload(*imported_credit_card, |
1221 &upload_request_.profiles, | 1242 &upload_request_.profiles, |
1222 &get_profiles_decision_metric, | 1243 &get_profiles_decision_metric, |
1223 &rappor_metric_name); | 1244 &rappor_metric_name); |
1224 | 1245 |
1225 pending_upload_request_url_ = GURL(submitted_form.source_url()); | 1246 pending_upload_request_url_ = GURL(submitted_form.source_url()); |
1226 | 1247 |
1227 // Both the CVC and address checks are done. Conform to the legacy order of | 1248 // Both the CVC and address checks are done. Conform to the legacy order of |
1228 // reporting on CVC then address. | 1249 // reporting on CVC then address. |
| 1250 should_cvc_be_requested_ = false; |
1229 if (upload_request_.cvc.empty()) { | 1251 if (upload_request_.cvc.empty()) { |
1230 AutofillMetrics::LogCardUploadDecisionMetric( | 1252 if (IsAutofillUpstreamRequestCvcIfMissingExperimentEnabled()) { |
1231 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | 1253 should_cvc_be_requested_ = true; |
1232 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | 1254 } else { |
1233 pending_upload_request_url_ = GURL(); | 1255 AutofillMetrics::LogCardUploadDecisionMetric( |
1234 CollectRapportSample(submitted_form.source_url(), | 1256 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); |
1235 "Autofill.CardUploadNotOfferedNoCvc"); | 1257 LogCardUploadDecisionUkm(AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); |
1236 return; | 1258 pending_upload_request_url_ = GURL(); |
| 1259 CollectRapportSample(submitted_form.source_url(), |
| 1260 "Autofill.CardUploadNotOfferedNoCvc"); |
| 1261 return; |
| 1262 } |
1237 } | 1263 } |
1238 if (!get_profiles_succeeded) { | 1264 if (!get_profiles_succeeded) { |
1239 DCHECK(get_profiles_decision_metric != AutofillMetrics::UPLOAD_OFFERED); | 1265 DCHECK(get_profiles_decision_metric != AutofillMetrics::UPLOAD_OFFERED); |
1240 AutofillMetrics::LogCardUploadDecisionMetric( | 1266 AutofillMetrics::LogCardUploadDecisionMetric( |
1241 get_profiles_decision_metric); | 1267 get_profiles_decision_metric); |
1242 LogCardUploadDecisionUkm(get_profiles_decision_metric); | 1268 LogCardUploadDecisionUkm(get_profiles_decision_metric); |
1243 pending_upload_request_url_ = GURL(); | 1269 pending_upload_request_url_ = GURL(); |
1244 if (!rappor_metric_name.empty()) { | 1270 if (!rappor_metric_name.empty()) { |
1245 CollectRapportSample(submitted_form.source_url(), rappor_metric_name); | 1271 CollectRapportSample(submitted_form.source_url(), rappor_metric_name); |
1246 } | 1272 } |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 } | 2224 } |
2199 #endif // ENABLE_FORM_DEBUG_DUMP | 2225 #endif // ENABLE_FORM_DEBUG_DUMP |
2200 | 2226 |
2201 void AutofillManager::LogCardUploadDecisionUkm( | 2227 void AutofillManager::LogCardUploadDecisionUkm( |
2202 AutofillMetrics::CardUploadDecisionMetric upload_decision) { | 2228 AutofillMetrics::CardUploadDecisionMetric upload_decision) { |
2203 AutofillMetrics::LogCardUploadDecisionUkm( | 2229 AutofillMetrics::LogCardUploadDecisionUkm( |
2204 client_->GetUkmService(), pending_upload_request_url_, upload_decision); | 2230 client_->GetUkmService(), pending_upload_request_url_, upload_decision); |
2205 } | 2231 } |
2206 | 2232 |
2207 } // namespace autofill | 2233 } // namespace autofill |
OLD | NEW |