Index: chrome/browser/autofill/autofill_type.cc |
diff --git a/chrome/browser/autofill/autofill_type.cc b/chrome/browser/autofill/autofill_type.cc |
index 46c2aef18c5aa43833ce6af02728821daefb2f76..030b12cbc816c3acad8d039f01f620f1846090af 100644 |
--- a/chrome/browser/autofill/autofill_type.cc |
+++ b/chrome/browser/autofill/autofill_type.cc |
@@ -7,99 +7,164 @@ |
#include "base/basictypes.h" |
#include "base/logging.h" |
-// TODO(jhawkins) all of the Human Readable names will need to be added to a |
-// resource file and localized because they are used in the confirmation |
-// dialog. |
-AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = { |
- { NO_SERVER_DATA, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "No Server Data" }, |
- { UNKNOWN_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Unknown Type" }, |
- { EMPTY_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Empty Type" }, |
- |
- { NAME_FIRST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "First Name" }, |
- { NAME_MIDDLE, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle Name" }, |
- { NAME_LAST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Last Name" }, |
- { NAME_MIDDLE_INITIAL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle Initial" }, |
- { NAME_FULL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Full Name" }, |
- { NAME_SUFFIX, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Name Suffix" }, |
- |
- { EMAIL_ADDRESS, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Email Address" }, |
- { COMPANY_NAME, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Company Name" }, |
- |
- { PHONE_HOME_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER, "Home Phone Number" }, |
- { PHONE_HOME_CITY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_CODE, "Home Area Code" }, |
- { PHONE_HOME_COUNTRY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNTRY_CODE, "Home Country Code" }, |
- { PHONE_HOME_CITY_AND_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_AND_NUMBER, "Home Phone Number" }, |
- { PHONE_HOME_WHOLE_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE_NUMBER, "Home Phone Number" }, |
- |
- { PHONE_FAX_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER, "Fax Number" }, |
- { PHONE_FAX_CITY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE, "Fax Area Code" }, |
- { PHONE_FAX_COUNTRY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY_CODE, "Fax Country Code" }, |
- { PHONE_FAX_CITY_AND_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_AND_NUMBER, "Fax Number" }, |
- { PHONE_FAX_WHOLE_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_NUMBER, "Fax Number" }, |
- |
- { ADDRESS_HOME_LINE1, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1, "Home Address Line 1" }, |
- { ADDRESS_HOME_LINE2, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2, "Home Address Line 2" }, |
- { ADDRESS_HOME_APT_NUM, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_NUM, "Home Address Apartment Number" }, |
- { ADDRESS_HOME_CITY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY, "Home Address City" }, |
- { ADDRESS_HOME_STATE, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE, "Home Address State" }, |
- { ADDRESS_HOME_ZIP, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP, "Home Address Zip Code" }, |
- { ADDRESS_HOME_COUNTRY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUNTRY, "Home Address Country" }, |
- |
- { ADDRESS_BILLING_LINE1, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1, "Billing Address Line 1" }, |
- { ADDRESS_BILLING_LINE2, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2, "Billing Address Line 2" }, |
- { ADDRESS_BILLING_APT_NUM, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APT_NUM, "Billing Address Apartment Number" }, |
- { ADDRESS_BILLING_CITY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY, "Billing Address City" }, |
- { ADDRESS_BILLING_STATE, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE, "Billing Address State" }, |
- { ADDRESS_BILLING_ZIP, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP, "Billing Address Zip Code" }, |
- { ADDRESS_BILLING_COUNTRY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_COUNTRY, "Billing Address Country" }, |
- |
- { CREDIT_CARD_NAME, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Name on Credit Card" }, |
- { CREDIT_CARD_NUMBER, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Number" }, |
- { CREDIT_CARD_EXP_MONTH, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Month" }, |
- { CREDIT_CARD_EXP_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Year" }, |
- { CREDIT_CARD_EXP_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Year" }, |
- { CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Date" }, |
- { CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Expiration Date" }, |
- { CREDIT_CARD_TYPE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Type" }, |
- { CREDIT_CARD_VERIFICATION_CODE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Credit Card Verification Number" }, |
- |
- { MAX_VALID_FIELD_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "" }, |
+namespace { |
+ |
+const AutoFillType::AutoFillTypeDefinition kUnknownAutoFillTypeDefinition = { |
+ /* UNKNOWN_TYPE */ AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP |
}; |
-bool AutoFillType::initialized_ = false; |
-AutoFillType AutoFillType::types_[MAX_VALID_FIELD_TYPE + 1]; |
+AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = { |
+ // NO_SERVER_DATA |
+ { AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }, |
+ // UNKNOWN_TYPE |
+ kUnknownAutoFillTypeDefinition, |
+ // EMPTY_TYPE |
+ { AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }, |
+ |
+ // NAME_FIRST |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ // NAME_MIDDLE |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ // NAME_LAST |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ // NAME_MIDDLE_INITIAL |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ // NAME_FULL |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ // NAME_SUFFIX |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ |
+ // EMAIL_ADDRESS |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+ |
+ // PHONE_HOME_NUMBER |
+ { AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER }, |
+ // PHONE_HOME_CITY_CODE |
+ { AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_CODE }, |
+ // PHONE_HOME_COUNTRY_CODE |
+ { AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNTRY_CODE }, |
+ // PHONE_HOME_CITY_AND_NUMBER |
+ { AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_AND_NUMBER }, |
+ // PHONE_HOME_WHOLE_NUMBER |
+ { AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE_NUMBER }, |
+ |
+ // Work phone numbers (values [15,19]) are deprecated. |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ |
+ // PHONE_FAX_NUMBER |
+ { AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER }, |
+ // PHONE_FAX_CITY_CODE |
+ { AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE }, |
+ // PHONE_FAX_COUNTRY_CODE |
+ { AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY_CODE }, |
+ // PHONE_FAX_CITY_AND_NUMBER |
+ { AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_AND_NUMBER }, |
+ // PHONE_FAX_WHOLE_NUMBER |
+ { AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_NUMBER }, |
+ |
+ // Cell phone numbers (values [25, 29]) are deprecated. |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ |
+ // ADDRESS_HOME_LINE1 |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1 }, |
+ // ADDRESS_HOME_LINE2 |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2 }, |
+ // ADDRESS_HOME_APT_NUM |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_NUM }, |
+ // ADDRESS_HOME_CITY |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY }, |
+ // ADDRESS_HOME_STATE |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE }, |
+ // ADDRESS_HOME_ZIP |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP }, |
+ // ADDRESS_HOME_COUNTRY |
+ { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUNTRY }, |
+ |
+ // ADDRESS_BILLING_LINE1 |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1 }, |
+ // ADDRESS_BILLING_LINE2 |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2 }, |
+ // ADDRESS_BILLING_APT_NUM |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APT_NUM }, |
+ // ADDRESS_BILLING_CITY |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY }, |
+ // ADDRESS_BILLING_STATE |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE }, |
+ // ADDRESS_BILLING_ZIP |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP }, |
+ // ADDRESS_BILLING_COUNTRY |
+ { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_COUNTRY }, |
+ |
+ // ADDRESS_SHIPPING values [44,50] are deprecated. |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ kUnknownAutoFillTypeDefinition, |
+ |
+ // CREDIT_CARD_NAME |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_NUMBER |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_EXP_MONTH |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_EXP_2_DIGIT_YEAR |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_EXP_4_DIGIT_YEAR |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_TYPE |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ // CREDIT_CARD_VERIFICATION_CODE |
+ { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
+ |
+ // COMPANY_NAME |
+ { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
+}; |
-AutoFillType::AutoFillType(AutoFillTypeDefinition* definition) |
- : autofill_type_definition_(definition) { |
- DCHECK(definition != NULL); |
-} |
+} // namespace |
AutoFillType::AutoFillType(AutoFillFieldType field_type) { |
- StaticInitialize(); |
- DCHECK(initialized_); |
- |
- if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE || |
- types_[field_type].autofill_type_definition_ == NULL) { |
- field_type = UNKNOWN_TYPE; |
- } |
+ if ((field_type < NO_SERVER_DATA || field_type >= MAX_VALID_FIELD_TYPE) || |
+ (field_type >= 15 && field_type <= 19) || |
+ (field_type >= 25 && field_type <= 29) || |
+ (field_type >= 44 && field_type <= 50)) |
+ field_type_ = UNKNOWN_TYPE; |
+ else |
+ field_type_ = field_type; |
+} |
- autofill_type_definition_ = types_[field_type].autofill_type_definition_; |
+AutoFillType::AutoFillType(const AutoFillType& autofill_type) { |
+ *this = autofill_type; |
} |
-// TODO(jhawkins): refactor this class to not require static initialization. |
-void AutoFillType::StaticInitialize() { |
- // Can be called more than once (in unit tests for example). |
- if (initialized_) |
- return; |
+AutoFillType& AutoFillType::operator=(const AutoFillType& autofill_type) { |
+ if (this != &autofill_type) |
+ this->field_type_ = autofill_type.field_type_; |
+ return *this; |
+} |
- initialized_ = true; |
+AutoFillFieldType AutoFillType::field_type() const { |
+ return field_type_; |
+} |
- InitializeFieldTypeMap(); |
+FieldTypeGroup AutoFillType::group() const { |
+ return kAutoFillTypeDefinitions[field_type_].group; |
} |
-void AutoFillType::InitializeFieldTypeMap() { |
- for (size_t i = 0; i < arraysize(kAutoFillTypeDefinitions); ++i) { |
- AutoFillType type(&kAutoFillTypeDefinitions[i]); |
- types_[type.field_type()] = type; |
- } |
+FieldTypeSubGroup AutoFillType::subgroup() const { |
+ return kAutoFillTypeDefinitions[field_type_].subgroup; |
} |