OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 labels->swap(labels_copy); | 112 labels->swap(labels_copy); |
113 icons->swap(icons_copy); | 113 icons->swap(icons_copy); |
114 unique_ids->swap(unique_ids_copy); | 114 unique_ids->swap(unique_ids_copy); |
115 } | 115 } |
116 | 116 |
117 // Precondition: |form_structure| and |form| should correspond to the same | 117 // Precondition: |form_structure| and |form| should correspond to the same |
118 // logical form. Returns true if any field in the given |section| within |form| | 118 // logical form. Returns true if any field in the given |section| within |form| |
119 // is auto-filled. | 119 // is auto-filled. |
120 bool SectionIsAutofilled(const FormStructure& form_structure, | 120 bool SectionIsAutofilled(const FormStructure& form_structure, |
121 const FormData& form, | 121 const FormData& form, |
122 const string16& section) { | 122 const std::string& section) { |
123 DCHECK_EQ(form_structure.field_count(), form.fields.size()); | 123 DCHECK_EQ(form_structure.field_count(), form.fields.size()); |
124 for (size_t i = 0; i < form_structure.field_count(); ++i) { | 124 for (size_t i = 0; i < form_structure.field_count(); ++i) { |
125 if (form_structure.field(i)->section() == section && | 125 if (form_structure.field(i)->section() == section && |
126 form.fields[i].is_autofilled) { | 126 form.fields[i].is_autofilled) { |
127 return true; | 127 return true; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 return false; | 131 return false; |
132 } | 132 } |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 } | 1227 } |
1228 } | 1228 } |
1229 } | 1229 } |
1230 | 1230 |
1231 void AutofillManager::FillCreditCardFormField(const CreditCard& credit_card, | 1231 void AutofillManager::FillCreditCardFormField(const CreditCard& credit_card, |
1232 AutofillFieldType type, | 1232 AutofillFieldType type, |
1233 FormFieldData* field) { | 1233 FormFieldData* field) { |
1234 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(type).group()); | 1234 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(type).group()); |
1235 DCHECK(field); | 1235 DCHECK(field); |
1236 | 1236 |
1237 if (field->form_control_type == ASCIIToUTF16("select-one")) { | 1237 if (field->form_control_type == "select-one") { |
1238 autofill::FillSelectControl(credit_card, type, field); | 1238 autofill::FillSelectControl(credit_card, type, field); |
1239 } else if (field->form_control_type == ASCIIToUTF16("month")) { | 1239 } else if (field->form_control_type == "month") { |
1240 // HTML5 input="month" consists of year-month. | 1240 // HTML5 input="month" consists of year-month. |
1241 string16 year = | 1241 string16 year = |
1242 credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 1242 credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
1243 string16 month = credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_MONTH); | 1243 string16 month = credit_card.GetCanonicalizedInfo(CREDIT_CARD_EXP_MONTH); |
1244 if (!year.empty() && !month.empty()) { | 1244 if (!year.empty() && !month.empty()) { |
1245 // Fill the value only if |credit_card| includes both year and month | 1245 // Fill the value only if |credit_card| includes both year and month |
1246 // information. | 1246 // information. |
1247 field->value = year + ASCIIToUTF16("-") + month; | 1247 field->value = year + ASCIIToUTF16("-") + month; |
1248 } | 1248 } |
1249 } else { | 1249 } else { |
1250 field->value = credit_card.GetCanonicalizedInfo(type); | 1250 field->value = credit_card.GetCanonicalizedInfo(type); |
1251 } | 1251 } |
1252 } | 1252 } |
1253 | 1253 |
1254 void AutofillManager::FillFormField(const AutofillProfile& profile, | 1254 void AutofillManager::FillFormField(const AutofillProfile& profile, |
1255 const AutofillField& cached_field, | 1255 const AutofillField& cached_field, |
1256 size_t variant, | 1256 size_t variant, |
1257 FormFieldData* field) { | 1257 FormFieldData* field) { |
1258 AutofillFieldType type = cached_field.type(); | 1258 AutofillFieldType type = cached_field.type(); |
1259 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); | 1259 DCHECK_NE(AutofillType::CREDIT_CARD, AutofillType(type).group()); |
1260 DCHECK(field); | 1260 DCHECK(field); |
1261 | 1261 |
1262 if (type == PHONE_HOME_NUMBER) { | 1262 if (type == PHONE_HOME_NUMBER) { |
1263 FillPhoneNumberField(profile, cached_field, variant, field); | 1263 FillPhoneNumberField(profile, cached_field, variant, field); |
1264 } else { | 1264 } else { |
1265 if (field->form_control_type == ASCIIToUTF16("select-one")) { | 1265 if (field->form_control_type == "select-one") { |
1266 autofill::FillSelectControl(profile, type, field); | 1266 autofill::FillSelectControl(profile, type, field); |
1267 } else { | 1267 } else { |
1268 std::vector<string16> values; | 1268 std::vector<string16> values; |
1269 profile.GetCanonicalizedMultiInfo(type, &values); | 1269 profile.GetCanonicalizedMultiInfo(type, &values); |
1270 if (variant >= values.size()) { | 1270 if (variant >= values.size()) { |
1271 // If the variant is unavailable, bail. This case is reachable, for | 1271 // If the variant is unavailable, bail. This case is reachable, for |
1272 // example if Sync updates a profile during the filling process. | 1272 // example if Sync updates a profile during the filling process. |
1273 return; | 1273 return; |
1274 } | 1274 } |
1275 | 1275 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 *profile_guid = IDToGUID(profile_id); | 1400 *profile_guid = IDToGUID(profile_id); |
1401 } | 1401 } |
1402 | 1402 |
1403 void AutofillManager::UpdateInitialInteractionTimestamp( | 1403 void AutofillManager::UpdateInitialInteractionTimestamp( |
1404 const TimeTicks& interaction_timestamp) { | 1404 const TimeTicks& interaction_timestamp) { |
1405 if (initial_interaction_timestamp_.is_null() || | 1405 if (initial_interaction_timestamp_.is_null() || |
1406 interaction_timestamp < initial_interaction_timestamp_) { | 1406 interaction_timestamp < initial_interaction_timestamp_) { |
1407 initial_interaction_timestamp_ = interaction_timestamp; | 1407 initial_interaction_timestamp_ = interaction_timestamp; |
1408 } | 1408 } |
1409 } | 1409 } |
OLD | NEW |