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