Chromium Code Reviews| Index: components/autofill/core/browser/form_structure.cc |
| diff --git a/components/autofill/core/browser/form_structure.cc b/components/autofill/core/browser/form_structure.cc |
| index 3f0cb59bda7bd5483462c5e7a9e4789fc141f59d..d6b50d6bbee8d1da454609f8acf55d60a5b09a50 100644 |
| --- a/components/autofill/core/browser/form_structure.cc |
| +++ b/components/autofill/core/browser/form_structure.cc |
| @@ -57,8 +57,8 @@ const char kXMLElementFieldAssignments[] = "fieldassignments"; |
| const char kXMLElementField[] = "field"; |
| const char kXMLElementFields[] = "fields"; |
| const char kXMLElementForm[] = "form"; |
| -const char kBillingSection[] = "billing"; |
| -const char kShippingSection[] = "shipping"; |
| +const char kBillingMode[] = "billing"; |
| +const char kShippingMode[] = "shipping"; |
| // Stip away >= 5 consecutive digits. |
| const char kIgnorePatternInFieldName[] = "\\d{5,}+"; |
| @@ -165,23 +165,22 @@ bool IsContactTypeHint(const std::string& token) { |
| // Returns |true| iff the |token| is a type hint appropriate for a field of the |
| // given |field_type|, as specified in the implementation section of |
| // http://is.gd/whatwg_autocomplete |
| -// TODO(isherman): This should use HTML field types, not native ones. |
| bool ContactTypeHintMatchesFieldType(const std::string& token, |
| - NativeFieldType field_type) { |
| + HtmlFieldType field_type) { |
| // The "home" and "work" type hints are only appropriate for email and phone |
| // number field types. |
| if (token == "home" || token == "work") { |
| - return field_type == EMAIL_ADDRESS || |
| - (field_type >= PHONE_HOME_NUMBER && |
| - field_type <= PHONE_HOME_WHOLE_NUMBER); |
| + return field_type == HTML_TYPE_EMAIL || |
| + (field_type >= HTML_TYPE_TEL && |
| + field_type <= HTML_TYPE_TEL_LOCAL_SUFFIX); |
| } |
| // The "mobile" type hint is only appropriate for phone number field types. |
| // Note that "fax" and "pager" are intentionally ignored, as Chrome does not |
| // support filling either type of information. |
| if (token == "mobile") { |
| - return field_type >= PHONE_HOME_NUMBER && |
| - field_type <= PHONE_HOME_WHOLE_NUMBER; |
| + return field_type >= HTML_TYPE_TEL && |
| + field_type <= HTML_TYPE_TEL_LOCAL_SUFFIX; |
| } |
| return false; |
| @@ -191,104 +190,106 @@ bool ContactTypeHintMatchesFieldType(const std::string& token, |
| // |autocomplete_type|, if there is one, in the context of the given |field|. |
| // Chrome Autofill supports a subset of the field types listed at |
| // http://is.gd/whatwg_autocomplete |
| -// TODO(isherman): This should use HTML field types, not native ones. |
| -NativeFieldType FieldTypeFromAutocompleteType( |
| +HtmlFieldType FieldTypeFromAutocompleteType( |
|
Evan Stade
2013/08/05 18:47:24
maybe you should rename this to FieldTypeFromAutoc
Ilya Sherman
2013/08/06 05:05:39
Done.
|
| const std::string& autocomplete_type, |
| const AutofillField& field) { |
| if (autocomplete_type == "name") |
| - return NAME_FULL; |
| + return HTML_TYPE_NAME; |
| if (autocomplete_type == "given-name") |
| - return NAME_FIRST; |
| + return HTML_TYPE_GIVEN_NAME; |
| if (autocomplete_type == "additional-name") { |
| if (field.max_length == 1) |
| - return NAME_MIDDLE_INITIAL; |
| + return HTML_TYPE_ADDITIONAL_NAME_INITIAL; |
| else |
| - return NAME_MIDDLE; |
| + return HTML_TYPE_ADDITIONAL_NAME; |
| } |
| if (autocomplete_type == "family-name") |
| - return NAME_LAST; |
| - |
| - if (autocomplete_type == "honorific-suffix") |
| - return NAME_SUFFIX; |
| + return HTML_TYPE_FAMILY_NAME; |
| if (autocomplete_type == "organization") |
| - return COMPANY_NAME; |
| + return HTML_TYPE_ORGANIZATION; |
| + |
| + if (autocomplete_type == "street-address") |
| + return HTML_TYPE_STREET_ADDRESS; |
| if (autocomplete_type == "address-line1") |
| - return ADDRESS_HOME_LINE1; |
| + return HTML_TYPE_ADDRESS_LINE1; |
| if (autocomplete_type == "address-line2") |
| - return ADDRESS_HOME_LINE2; |
| + return HTML_TYPE_ADDRESS_LINE2; |
| if (autocomplete_type == "locality") |
| - return ADDRESS_HOME_CITY; |
| + return HTML_TYPE_LOCALITY; |
| if (autocomplete_type == "region") |
| - return ADDRESS_HOME_STATE; |
| + return HTML_TYPE_REGION; |
| if (autocomplete_type == "country") |
| - return ADDRESS_HOME_COUNTRY; |
| + return HTML_TYPE_COUNTRY_CODE; |
| + |
| + if (autocomplete_type == "country-name") |
| + return HTML_TYPE_COUNTRY_NAME; |
| if (autocomplete_type == "postal-code") |
| - return ADDRESS_HOME_ZIP; |
| + return HTML_TYPE_POSTAL_CODE; |
| if (autocomplete_type == "cc-name") |
| - return CREDIT_CARD_NAME; |
| + return HTML_TYPE_CREDIT_CARD_NAME; |
| if (autocomplete_type == "cc-number") |
| - return CREDIT_CARD_NUMBER; |
| + return HTML_TYPE_CREDIT_CARD_NUMBER; |
| if (autocomplete_type == "cc-exp") { |
| if (field.max_length == 5) |
| - return CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
| + return HTML_TYPE_CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; |
| else |
| - return CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR; |
| + return HTML_TYPE_CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR; |
| } |
| if (autocomplete_type == "cc-exp-month") |
| - return CREDIT_CARD_EXP_MONTH; |
| + return HTML_TYPE_CREDIT_CARD_EXP_MONTH; |
| if (autocomplete_type == "cc-exp-year") { |
| if (field.max_length == 2) |
| - return CREDIT_CARD_EXP_2_DIGIT_YEAR; |
| + return HTML_TYPE_CREDIT_CARD_EXP_2_DIGIT_YEAR; |
| else |
| - return CREDIT_CARD_EXP_4_DIGIT_YEAR; |
| + return HTML_TYPE_CREDIT_CARD_EXP_4_DIGIT_YEAR; |
| } |
| if (autocomplete_type == "cc-csc") |
| - return CREDIT_CARD_VERIFICATION_CODE; |
| + return HTML_TYPE_CREDIT_CARD_VERIFICATION_CODE; |
| if (autocomplete_type == "cc-type") |
| - return CREDIT_CARD_TYPE; |
| + return HTML_TYPE_CREDIT_CARD_TYPE; |
| if (autocomplete_type == "tel") |
| - return PHONE_HOME_WHOLE_NUMBER; |
| + return HTML_TYPE_TEL; |
| if (autocomplete_type == "tel-country-code") |
| - return PHONE_HOME_COUNTRY_CODE; |
| + return HTML_TYPE_TEL_COUNTRY_CODE; |
| if (autocomplete_type == "tel-national") |
| - return PHONE_HOME_CITY_AND_NUMBER; |
| + return HTML_TYPE_TEL_NATIONAL; |
| if (autocomplete_type == "tel-area-code") |
| - return PHONE_HOME_CITY_CODE; |
| + return HTML_TYPE_TEL_AREA_CODE; |
| if (autocomplete_type == "tel-local") |
| - return PHONE_HOME_NUMBER; |
| + return HTML_TYPE_TEL_LOCAL; |
| if (autocomplete_type == "tel-local-prefix") |
| - return PHONE_HOME_NUMBER; |
| + return HTML_TYPE_TEL_LOCAL_PREFIX; |
| if (autocomplete_type == "tel-local-suffix") |
| - return PHONE_HOME_NUMBER; |
| + return HTML_TYPE_TEL_LOCAL_SUFFIX; |
| if (autocomplete_type == "email") |
| - return EMAIL_ADDRESS; |
| + return HTML_TYPE_EMAIL; |
| - return UNKNOWN_TYPE; |
| + return HTML_TYPE_UNKNOWN; |
| } |
| std::string StripDigitsIfRequired(const base::string16& input) { |
| @@ -377,8 +378,7 @@ void FormStructure::DetermineHeuristicTypes( |
| // autocomplete type hint, don't try to apply other heuristics to match fields |
| // in this form. |
| bool has_author_specified_sections; |
| - ParseFieldTypesFromAutocompleteAttributes(PARSE_FOR_AUTOFILL, |
| - &has_author_specified_types_, |
| + ParseFieldTypesFromAutocompleteAttributes(&has_author_specified_types_, |
| &has_author_specified_sections); |
| if (!has_author_specified_types_) { |
| @@ -607,7 +607,7 @@ void FormStructure::ParseQueryResponse( |
| heuristics_detected_fillable_field = true; |
| (*field)->set_server_type(current_info->field_type); |
| - if (heuristic_type != (*field)->Type().native_type()) |
| + if (heuristic_type != (*field)->Type().GetEquivalentNativeType()) |
| query_response_overrode_heuristics = true; |
| // Copy default value into the field if available. |
| @@ -659,11 +659,10 @@ void FormStructure::GetFieldTypePredictions( |
| FormFieldDataPredictions annotated_field; |
| annotated_field.signature = (*field)->FieldSignature(); |
| annotated_field.heuristic_type = |
| - AutofillType::FieldTypeToString((*field)->heuristic_type()); |
| + AutofillType((*field)->heuristic_type()).ToString(); |
| annotated_field.server_type = |
| - AutofillType::FieldTypeToString((*field)->server_type()); |
| - annotated_field.overall_type = |
| - AutofillType::FieldTypeToString((*field)->Type().native_type()); |
| + AutofillType((*field)->server_type()).ToString(); |
| + annotated_field.overall_type = (*field)->Type().ToString(); |
| form.fields.push_back(annotated_field); |
| } |
| @@ -832,10 +831,12 @@ void FormStructure::LogQualityMetrics( |
| // digits) number is almost always identical to the whole phone number. |
| // TODO(isherman): Improve this logic once we add support for |
| // international numbers. |
| - if (*it == PHONE_HOME_CITY_AND_NUMBER) |
| + if (*it == PHONE_HOME_CITY_AND_NUMBER) { |
| collapsed_field_types.insert(PHONE_HOME_WHOLE_NUMBER); |
| - else |
| - collapsed_field_types.insert(AutofillType::GetEquivalentFieldType(*it)); |
| + } else { |
| + collapsed_field_types.insert( |
| + AutofillType(*it).GetEquivalentNativeType()); |
| + } |
| } |
| // Capture the field's type, if it is unambiguous. |
| @@ -843,9 +844,11 @@ void FormStructure::LogQualityMetrics( |
| if (collapsed_field_types.size() == 1) |
| field_type = *collapsed_field_types.begin(); |
| - NativeFieldType heuristic_type = field->heuristic_type(); |
| - NativeFieldType server_type = field->server_type(); |
| - NativeFieldType predicted_type = field->Type().native_type(); |
| + NativeFieldType heuristic_type = |
| + AutofillType(field->heuristic_type()).GetEquivalentNativeType(); |
| + NativeFieldType server_type = |
| + AutofillType(field->server_type()).GetEquivalentNativeType(); |
| + NativeFieldType predicted_type = field->Type().GetEquivalentNativeType(); |
| // Log heuristic, server, and overall type quality metrics, independently of |
| // whether the field was autofilled. |
| @@ -1080,7 +1083,6 @@ bool FormStructure::EncodeFormRequest( |
| } |
| void FormStructure::ParseFieldTypesFromAutocompleteAttributes( |
| - ParseTarget parse_target, |
| bool* found_types, |
| bool* found_sections) { |
| const std::string kDefaultSection = "-default"; |
| @@ -1132,9 +1134,9 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes( |
| DCHECK(!tokens.empty()); |
| std::string field_type_token = tokens.back(); |
| tokens.pop_back(); |
| - NativeFieldType field_type = |
| + HtmlFieldType field_type = |
| FieldTypeFromAutocompleteType(field_type_token, *field); |
| - if (field_type == UNKNOWN_TYPE) |
| + if (field_type == HTML_TYPE_UNKNOWN) |
| continue; |
| // The preceding token, if any, may be a type hint. |
| @@ -1154,21 +1156,15 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes( |
| // section name suffixes. |
| DCHECK_EQ(kDefaultSection, field->section()); |
| std::string section = field->section(); |
| - if (!tokens.empty() && |
| - (tokens.back() == kShippingSection || |
| - tokens.back() == kBillingSection)) { |
| - // Set Autofill field type to billing if section is billing. |
| - if (tokens.back() == kBillingSection) { |
| - field_type = AutofillType::GetEquivalentBillingFieldType(field_type); |
| - |
| - // The Autofill dialog uses the type CREDIT_CARD_NAME to refer to both |
| - // the credit card holder's name and the name on the billing address. |
| - if (parse_target == PARSE_FOR_AUTOFILL_DIALOG && |
| - field_type == NAME_FULL) { |
| - field_type = CREDIT_CARD_NAME; |
| - } |
| - } |
| + HtmlFieldMode mode = HTML_MODE_NONE; |
| + if (!tokens.empty()) { |
| + if (tokens.back() == kShippingMode) |
| + mode = HTML_MODE_SHIPPING; |
| + else if (tokens.back() == kBillingMode) |
| + mode = HTML_MODE_BILLING; |
| + } |
| + if (mode != HTML_MODE_NONE) { |
| section = "-" + tokens.back(); |
| tokens.pop_back(); |
| } |
| @@ -1193,11 +1189,7 @@ void FormStructure::ParseFieldTypesFromAutocompleteAttributes( |
| // No errors encountered while parsing! |
| // Update the |field|'s type based on what was parsed from the attribute. |
| - field->set_heuristic_type(field_type); |
| - if (field_type_token == "tel-local-prefix") |
| - field->set_phone_part(AutofillField::PHONE_PREFIX); |
| - else if (field_type_token == "tel-local-suffix") |
| - field->set_phone_part(AutofillField::PHONE_SUFFIX); |
| + field->SetHtmlType(field_type, mode); |
| } |
| } |
| @@ -1216,7 +1208,7 @@ void FormStructure::IdentifySections(bool has_author_specified_sections) { |
| for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| field != fields_.end(); ++field) { |
| const NativeFieldType current_type = |
| - AutofillType::GetEquivalentFieldType((*field)->Type().native_type()); |
| + (*field)->Type().GetApproximateNativeFieldType(); |
| bool already_saw_current_type = seen_types.count(current_type) > 0; |