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_profile.h" | 5 #include "components/autofill/core/browser/autofill_profile.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "components/autofill/core/common/form_field_data.h" | 26 #include "components/autofill/core/common/form_field_data.h" |
| 27 #include "grit/component_strings.h" | 27 #include "grit/component_strings.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 | 29 |
| 30 namespace autofill { | 30 namespace autofill { |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Like |AutofillType::GetEquivalentFieldType()|, but also returns |NAME_FULL| | 33 // Like |AutofillType::GetEquivalentFieldType()|, but also returns |NAME_FULL| |
| 34 // for first, middle, and last name field types. | 34 // for first, middle, and last name field types. |
| 35 NativeFieldType GetEquivalentFieldTypeCollapsingNames(NativeFieldType type) { | 35 NativeFieldType GetEquivalentFieldTypeCollapsingNames(NativeFieldType type) { |
| 36 if (type == NAME_FIRST || type == NAME_MIDDLE || type == NAME_LAST || | 36 NativeFieldType equivalent_type = |
| 37 type == NAME_MIDDLE_INITIAL) | 37 AutofillType(type).GetEquivalentNativeType(); |
|
Evan Stade
2013/08/05 18:47:24
this fn seems a little bit hoop-jumpy. Would it be
Ilya Sherman
2013/08/06 05:05:39
It's not quite the same unless we also check for N
Evan Stade
2013/08/06 18:39:59
I think the original way is fine now that I unders
Ilya Sherman
2013/08/06 23:04:56
Done.
| |
| 38 | |
| 39 if (AutofillType(equivalent_type).group() == NAME) | |
| 38 return NAME_FULL; | 40 return NAME_FULL; |
| 39 | 41 |
| 40 return AutofillType::GetEquivalentFieldType(type); | 42 return equivalent_type; |
| 41 } | 43 } |
| 42 | 44 |
| 43 // Fills |distinguishing_fields| with a list of fields to use when creating | 45 // Fills |distinguishing_fields| with a list of fields to use when creating |
| 44 // labels that can help to distinguish between two profiles. Draws fields from | 46 // labels that can help to distinguish between two profiles. Draws fields from |
| 45 // |suggested_fields| if it is non-NULL; otherwise returns a default list. | 47 // |suggested_fields| if it is non-NULL; otherwise returns a default list. |
| 46 // If |suggested_fields| is non-NULL, does not include |excluded_field| in the | 48 // If |suggested_fields| is non-NULL, does not include |excluded_field| in the |
| 47 // list. Otherwise, |excluded_field| is ignored, and should be set to | 49 // list. Otherwise, |excluded_field| is ignored, and should be set to |
| 48 // |UNKNOWN_TYPE| by convention. The resulting list of fields is sorted in | 50 // |UNKNOWN_TYPE| by convention. The resulting list of fields is sorted in |
| 49 // decreasing order of importance. | 51 // decreasing order of importance. |
| 50 void GetFieldsForDistinguishingProfiles( | 52 void GetFieldsForDistinguishingProfiles( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 accumulate += ASCIIToUTF16(" "); | 119 accumulate += ASCIIToUTF16(" "); |
| 118 accumulate += values[i]; | 120 accumulate += values[i]; |
| 119 } | 121 } |
| 120 return accumulate; | 122 return accumulate; |
| 121 } | 123 } |
| 122 | 124 |
| 123 base::string16 GetFormGroupInfo(const FormGroup& form_group, | 125 base::string16 GetFormGroupInfo(const FormGroup& form_group, |
| 124 const AutofillType& type, | 126 const AutofillType& type, |
| 125 const std::string& app_locale) { | 127 const std::string& app_locale) { |
| 126 return app_locale.empty() ? | 128 return app_locale.empty() ? |
| 127 form_group.GetRawInfo(type.native_type()) : | 129 form_group.GetRawInfo(type.GetEquivalentNativeType()) : |
| 128 form_group.GetInfo(type, app_locale); | 130 form_group.GetInfo(type, app_locale); |
| 129 } | 131 } |
| 130 | 132 |
| 131 template <class T> | 133 template <class T> |
| 132 void CopyValuesToItems(NativeFieldType type, | 134 void CopyValuesToItems(NativeFieldType type, |
| 133 const std::vector<base::string16>& values, | 135 const std::vector<base::string16>& values, |
| 134 std::vector<T>* form_group_items, | 136 std::vector<T>* form_group_items, |
| 135 const T& prototype) { | 137 const T& prototype) { |
| 136 form_group_items->resize(values.size(), prototype); | 138 form_group_items->resize(values.size(), prototype); |
| 137 for (size_t i = 0; i < form_group_items->size(); ++i) { | 139 for (size_t i = 0; i < form_group_items->size(); ++i) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 void AutofillProfile::GetMatchingTypes( | 270 void AutofillProfile::GetMatchingTypes( |
| 269 const base::string16& text, | 271 const base::string16& text, |
| 270 const std::string& app_locale, | 272 const std::string& app_locale, |
| 271 NativeFieldTypeSet* matching_types) const { | 273 NativeFieldTypeSet* matching_types) const { |
| 272 FormGroupList info = FormGroups(); | 274 FormGroupList info = FormGroups(); |
| 273 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) | 275 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) |
| 274 (*it)->GetMatchingTypes(text, app_locale, matching_types); | 276 (*it)->GetMatchingTypes(text, app_locale, matching_types); |
| 275 } | 277 } |
| 276 | 278 |
| 277 base::string16 AutofillProfile::GetRawInfo(NativeFieldType type) const { | 279 base::string16 AutofillProfile::GetRawInfo(NativeFieldType type) const { |
| 278 NativeFieldType return_type = AutofillType::GetEquivalentFieldType(type); | 280 const FormGroup* form_group = FormGroupForType(AutofillType(type)); |
| 279 const FormGroup* form_group = FormGroupForType(AutofillType(return_type)); | |
| 280 if (!form_group) | 281 if (!form_group) |
| 281 return base::string16(); | 282 return base::string16(); |
| 282 | 283 |
| 283 return form_group->GetRawInfo(return_type); | 284 return form_group->GetRawInfo(type); |
| 284 } | 285 } |
| 285 | 286 |
| 286 void AutofillProfile::SetRawInfo(NativeFieldType type, | 287 void AutofillProfile::SetRawInfo(NativeFieldType type, |
| 287 const base::string16& value) { | 288 const base::string16& value) { |
| 288 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); | 289 FormGroup* form_group = MutableFormGroupForType(AutofillType(type)); |
| 289 if (form_group) | 290 if (form_group) |
| 290 form_group->SetRawInfo(type, CollapseWhitespace(value, false)); | 291 form_group->SetRawInfo(type, CollapseWhitespace(value, false)); |
| 291 } | 292 } |
| 292 | 293 |
| 293 base::string16 AutofillProfile::GetInfo(const AutofillType& type, | 294 base::string16 AutofillProfile::GetInfo(const AutofillType& type, |
| 294 const std::string& app_locale) const { | 295 const std::string& app_locale) const { |
| 295 NativeFieldType return_type = | 296 const FormGroup* form_group = FormGroupForType(type); |
| 296 AutofillType::GetEquivalentFieldType(type.native_type()); | |
| 297 const FormGroup* form_group = FormGroupForType(AutofillType(return_type)); | |
| 298 if (!form_group) | 297 if (!form_group) |
| 299 return base::string16(); | 298 return base::string16(); |
| 300 | 299 |
| 301 return form_group->GetInfo(AutofillType(return_type), app_locale); | 300 return form_group->GetInfo(type, app_locale); |
| 302 } | 301 } |
| 303 | 302 |
| 304 bool AutofillProfile::SetInfo(const AutofillType& type, | 303 bool AutofillProfile::SetInfo(const AutofillType& type, |
| 305 const base::string16& value, | 304 const base::string16& value, |
| 306 const std::string& app_locale) { | 305 const std::string& app_locale) { |
| 307 FormGroup* form_group = MutableFormGroupForType(type); | 306 FormGroup* form_group = MutableFormGroupForType(type); |
| 308 if (!form_group) | 307 if (!form_group) |
| 309 return false; | 308 return false; |
| 310 | 309 |
| 311 return | 310 return |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 } | 355 } |
| 357 | 356 |
| 358 void AutofillProfile::FillFormField(const AutofillField& field, | 357 void AutofillProfile::FillFormField(const AutofillField& field, |
| 359 size_t variant, | 358 size_t variant, |
| 360 const std::string& app_locale, | 359 const std::string& app_locale, |
| 361 FormFieldData* field_data) const { | 360 FormFieldData* field_data) const { |
| 362 AutofillType type = field.Type(); | 361 AutofillType type = field.Type(); |
| 363 DCHECK_NE(CREDIT_CARD, type.group()); | 362 DCHECK_NE(CREDIT_CARD, type.group()); |
| 364 DCHECK(field_data); | 363 DCHECK(field_data); |
| 365 | 364 |
| 366 if (type.native_type() == PHONE_HOME_NUMBER || | 365 if (type.GetEquivalentNativeType() == PHONE_HOME_NUMBER) { |
| 367 type.native_type() == PHONE_BILLING_NUMBER) { | |
| 368 FillPhoneNumberField(field, variant, app_locale, field_data); | 366 FillPhoneNumberField(field, variant, app_locale, field_data); |
| 369 } else if (field_data->form_control_type == "select-one") { | 367 } else if (field_data->form_control_type == "select-one") { |
| 370 FillSelectControl(type, app_locale, field_data); | 368 FillSelectControl(type, app_locale, field_data); |
| 371 } else { | 369 } else { |
| 372 std::vector<base::string16> values; | 370 std::vector<base::string16> values; |
| 373 GetMultiInfo(type, app_locale, &values); | 371 GetMultiInfo(type, app_locale, &values); |
| 374 if (variant >= values.size()) { | 372 if (variant >= values.size()) { |
| 375 // If the variant is unavailable, bail. This case is reachable, for | 373 // If the variant is unavailable, bail. This case is reachable, for |
| 376 // example if Sync updates a profile during the filling process. | 374 // example if Sync updates a profile during the filling process. |
| 377 return; | 375 return; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) | 899 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)) |
| 902 << " " | 900 << " " |
| 903 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) | 901 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)) |
| 904 << " " | 902 << " " |
| 905 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 903 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 906 << " " | 904 << " " |
| 907 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 905 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 908 } | 906 } |
| 909 | 907 |
| 910 } // namespace autofill | 908 } // namespace autofill |
| OLD | NEW |