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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 #include "components/autofill/core/common/autofill_data_validation.h" | 51 #include "components/autofill/core/common/autofill_data_validation.h" |
52 #include "components/autofill/core/common/autofill_pref_names.h" | 52 #include "components/autofill/core/common/autofill_pref_names.h" |
53 #include "components/autofill/core/common/autofill_switches.h" | 53 #include "components/autofill/core/common/autofill_switches.h" |
54 #include "components/autofill/core/common/autofill_util.h" | 54 #include "components/autofill/core/common/autofill_util.h" |
55 #include "components/autofill/core/common/form_data.h" | 55 #include "components/autofill/core/common/form_data.h" |
56 #include "components/autofill/core/common/form_data_predictions.h" | 56 #include "components/autofill/core/common/form_data_predictions.h" |
57 #include "components/autofill/core/common/form_field_data.h" | 57 #include "components/autofill/core/common/form_field_data.h" |
58 #include "components/autofill/core/common/password_form_fill_data.h" | 58 #include "components/autofill/core/common/password_form_fill_data.h" |
59 #include "components/pref_registry/pref_registry_syncable.h" | 59 #include "components/pref_registry/pref_registry_syncable.h" |
60 #include "components/prefs/pref_service.h" | 60 #include "components/prefs/pref_service.h" |
61 #include "components/rappor/rappor_utils.h" | |
61 #include "google_apis/gaia/identity_provider.h" | 62 #include "google_apis/gaia/identity_provider.h" |
62 #include "grit/components_strings.h" | 63 #include "grit/components_strings.h" |
63 #include "ui/base/l10n/l10n_util.h" | 64 #include "ui/base/l10n/l10n_util.h" |
64 #include "ui/gfx/geometry/rect.h" | 65 #include "ui/gfx/geometry/rect.h" |
65 #include "url/gurl.h" | 66 #include "url/gurl.h" |
66 | 67 |
67 #if defined(OS_IOS) | 68 #if defined(OS_IOS) |
68 #include "components/autofill/core/browser/autofill_field_trial_ios.h" | 69 #include "components/autofill/core/browser/autofill_field_trial_ios.h" |
69 #include "components/autofill/core/browser/keyboard_accessory_metrics_logger.h" | 70 #include "components/autofill/core/browser/keyboard_accessory_metrics_logger.h" |
70 #endif | 71 #endif |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 for (const AutofillField* field : submitted_form) { | 1070 for (const AutofillField* field : submitted_form) { |
1070 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && | 1071 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE && |
1071 base::StringToInt(field->value, &cvc)) { | 1072 base::StringToInt(field->value, &cvc)) { |
1072 upload_request_.cvc = field->value; | 1073 upload_request_.cvc = field->value; |
1073 break; | 1074 break; |
1074 } | 1075 } |
1075 } | 1076 } |
1076 if (upload_request_.cvc.empty()) { | 1077 if (upload_request_.cvc.empty()) { |
1077 AutofillMetrics::LogCardUploadDecisionMetric( | 1078 AutofillMetrics::LogCardUploadDecisionMetric( |
1078 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | 1079 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); |
1080 if (submitted_form.source_url().is_valid() && | |
Justin Donnelly
2016/06/21 15:04:54
This is a complicated bit of code that's difficult
Mathieu
2016/06/21 17:05:08
Sure, I prefer the first version.
| |
1081 client_->GetRapporService()) { | |
1082 rappor::SampleDomainAndRegistryFromGURL( | |
1083 client_->GetRapporService(), "Autofill.CardUploadNotOfferedNoCvc", | |
1084 submitted_form.source_url()); | |
1085 } | |
1079 return; | 1086 return; |
1080 } | 1087 } |
1081 | 1088 |
1082 // Upload also requires recently used or modified addresses that meet the | 1089 // Upload also requires recently used or modified addresses that meet the |
1083 // client-side validation rules. | 1090 // client-side validation rules. |
1084 if (!GetProfilesForCreditCardUpload(*imported_credit_card, | 1091 if (!GetProfilesForCreditCardUpload(*imported_credit_card, |
1085 &upload_request_.profiles)) { | 1092 &upload_request_.profiles, |
1093 submitted_form.source_url())) { | |
1086 return; | 1094 return; |
1087 } | 1095 } |
1088 | 1096 |
1089 // All required data is available, start the upload process. | 1097 // All required data is available, start the upload process. |
1090 payments_client_->GetUploadDetails(app_locale_); | 1098 payments_client_->GetUploadDetails(app_locale_); |
1091 } | 1099 } |
1092 } | 1100 } |
1093 | 1101 |
1094 bool AutofillManager::GetProfilesForCreditCardUpload( | 1102 bool AutofillManager::GetProfilesForCreditCardUpload( |
1095 const CreditCard& card, | 1103 const CreditCard& card, |
1096 std::vector<AutofillProfile>* profiles) const { | 1104 std::vector<AutofillProfile>* profiles, |
1105 const GURL& source_url) const { | |
1097 std::vector<AutofillProfile> candidate_profiles; | 1106 std::vector<AutofillProfile> candidate_profiles; |
1098 const base::Time now = base::Time::Now(); | 1107 const base::Time now = base::Time::Now(); |
1099 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); | 1108 const base::TimeDelta fifteen_minutes = base::TimeDelta::FromMinutes(15); |
1100 | 1109 |
1101 // First, collect all of the addresses used recently. | 1110 // First, collect all of the addresses used recently. |
1102 for (AutofillProfile* profile : personal_data_->GetProfiles()) { | 1111 for (AutofillProfile* profile : personal_data_->GetProfiles()) { |
1103 if ((now - profile->use_date()) < fifteen_minutes || | 1112 if ((now - profile->use_date()) < fifteen_minutes || |
1104 (now - profile->modification_date()) < fifteen_minutes) { | 1113 (now - profile->modification_date()) < fifteen_minutes) { |
1105 candidate_profiles.push_back(*profile); | 1114 candidate_profiles.push_back(*profile); |
1106 } | 1115 } |
1107 } | 1116 } |
1108 if (candidate_profiles.empty()) { | 1117 if (candidate_profiles.empty()) { |
1109 AutofillMetrics::LogCardUploadDecisionMetric( | 1118 AutofillMetrics::LogCardUploadDecisionMetric( |
1110 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); | 1119 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_ADDRESS); |
1120 if (source_url.is_valid() && client_->GetRapporService()) { | |
1121 rappor::SampleDomainAndRegistryFromGURL( | |
1122 client_->GetRapporService(), "Autofill.CardUploadNotOfferedNoAddress", | |
1123 source_url); | |
1124 } | |
1111 return false; | 1125 return false; |
1112 } | 1126 } |
1113 | 1127 |
1114 // If any of the names on the card or the addresses don't match (where | 1128 // If any of the names on the card or the addresses don't match (where |
1115 // matching is case insensitive and ignores middle initials if present), the | 1129 // matching is case insensitive and ignores middle initials if present), the |
1116 // candidate set is invalid. This matches the rules for name matching applied | 1130 // candidate set is invalid. This matches the rules for name matching applied |
1117 // server-side by Google Payments and ensures that we don't send upload | 1131 // server-side by Google Payments and ensures that we don't send upload |
1118 // requests that are guaranteed to fail. | 1132 // requests that are guaranteed to fail. |
1119 base::string16 verified_name; | 1133 base::string16 verified_name; |
1120 base::string16 card_name = | 1134 base::string16 card_name = |
1121 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); | 1135 card.GetInfo(AutofillType(CREDIT_CARD_NAME_FULL), app_locale_); |
1122 if (!card_name.empty()) { | 1136 if (!card_name.empty()) { |
1123 verified_name = RemoveMiddleInitial(card_name); | 1137 verified_name = RemoveMiddleInitial(card_name); |
1124 } | 1138 } |
1125 for (const AutofillProfile& profile : candidate_profiles) { | 1139 for (const AutofillProfile& profile : candidate_profiles) { |
1126 base::string16 address_name = | 1140 base::string16 address_name = |
1127 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); | 1141 profile.GetInfo(AutofillType(NAME_FULL), app_locale_); |
1128 if (!address_name.empty()) { | 1142 if (!address_name.empty()) { |
1129 if (verified_name.empty()) { | 1143 if (verified_name.empty()) { |
1130 verified_name = RemoveMiddleInitial(address_name); | 1144 verified_name = RemoveMiddleInitial(address_name); |
1131 } else { | 1145 } else { |
1132 // TODO(crbug.com/590307): We only use ASCII case insensitivity here | 1146 // TODO(crbug.com/590307): We only use ASCII case insensitivity here |
1133 // because the feature is launching US-only and middle initials only | 1147 // because the feature is launching US-only and middle initials only |
1134 // make sense for Western-style names anyway. As we launch in more | 1148 // make sense for Western-style names anyway. As we launch in more |
1135 // countries, we'll need to make the name comparison more sophisticated. | 1149 // countries, we'll need to make the name comparison more sophisticated. |
1136 if (!base::EqualsCaseInsensitiveASCII( | 1150 if (!base::EqualsCaseInsensitiveASCII( |
1137 verified_name, RemoveMiddleInitial(address_name))) { | 1151 verified_name, RemoveMiddleInitial(address_name))) { |
1138 AutofillMetrics::LogCardUploadDecisionMetric( | 1152 AutofillMetrics::LogCardUploadDecisionMetric( |
1139 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); | 1153 AutofillMetrics::UPLOAD_NOT_OFFERED_CONFLICTING_NAMES); |
1154 if (source_url.is_valid() && client_->GetRapporService()) { | |
1155 rappor::SampleDomainAndRegistryFromGURL( | |
1156 client_->GetRapporService(), | |
1157 "Autofill.CardUploadNotOfferedConflictingNames", source_url); | |
1158 } | |
1140 return false; | 1159 return false; |
1141 } | 1160 } |
1142 } | 1161 } |
1143 } | 1162 } |
1144 } | 1163 } |
1145 // If neither the card nor any of the addresses have a name associated with | 1164 // If neither the card nor any of the addresses have a name associated with |
1146 // them, the candidate set is invalid. | 1165 // them, the candidate set is invalid. |
1147 if (verified_name.empty()) { | 1166 if (verified_name.empty()) { |
1148 AutofillMetrics::LogCardUploadDecisionMetric( | 1167 AutofillMetrics::LogCardUploadDecisionMetric( |
1149 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME); | 1168 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_NAME); |
1169 if (source_url.is_valid() && client_->GetRapporService()) { | |
1170 rappor::SampleDomainAndRegistryFromGURL( | |
1171 client_->GetRapporService(), "Autofill.CardUploadNotOfferedNoName", | |
1172 source_url); | |
1173 } | |
1150 return false; | 1174 return false; |
1151 } | 1175 } |
1152 | 1176 |
1153 // If any of the candidate addresses have a non-empty zip that doesn't match | 1177 // If any of the candidate addresses have a non-empty zip that doesn't match |
1154 // any other non-empty zip, then the candidate set is invalid. | 1178 // any other non-empty zip, then the candidate set is invalid. |
1155 base::string16 verified_zip; | 1179 base::string16 verified_zip; |
1156 for (const AutofillProfile& profile : candidate_profiles) { | 1180 for (const AutofillProfile& profile : candidate_profiles) { |
1157 // TODO(jdonnelly): Use GetInfo instead of GetRawInfo once zip codes are | 1181 // TODO(jdonnelly): Use GetInfo instead of GetRawInfo once zip codes are |
1158 // canonicalized. See http://crbug.com/587465. | 1182 // canonicalized. See http://crbug.com/587465. |
1159 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); | 1183 base::string16 zip = profile.GetRawInfo(ADDRESS_HOME_ZIP); |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1999 if (i > 0) | 2023 if (i > 0) |
2000 fputs("Next oldest form:\n", file); | 2024 fputs("Next oldest form:\n", file); |
2001 } | 2025 } |
2002 fputs("\n", file); | 2026 fputs("\n", file); |
2003 | 2027 |
2004 fclose(file); | 2028 fclose(file); |
2005 } | 2029 } |
2006 #endif // ENABLE_FORM_DEBUG_DUMP | 2030 #endif // ENABLE_FORM_DEBUG_DUMP |
2007 | 2031 |
2008 } // namespace autofill | 2032 } // namespace autofill |
OLD | NEW |