OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_type.h" | 5 #include "chrome/browser/autofill/autofill_type.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 // TODO(jhawkins) all of the Human Readable names will need to be added to a | 10 namespace { |
11 // resource file and localized because they are used in the confirmation | |
12 // dialog. | |
13 AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = { | |
14 { NO_SERVER_DATA, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "No Serve
r Data" }, | |
15 { UNKNOWN_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Unknown Ty
pe" }, | |
16 { EMPTY_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, "Empty Type"
}, | |
17 | 11 |
18 { NAME_FIRST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "First Na
me" }, | 12 const AutoFillType::AutoFillTypeDefinition kUnknownAutoFillTypeDefinition = { |
19 { NAME_MIDDLE, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Middle
Name" }, | 13 /* UNKNOWN_TYPE */ AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP |
20 { NAME_LAST, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Last Name
" }, | |
21 { NAME_MIDDLE_INITIAL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP,
"Middle Initial" }, | |
22 { NAME_FULL, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Full Name
" }, | |
23 { NAME_SUFFIX, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Name Su
ffix" }, | |
24 | |
25 { EMAIL_ADDRESS, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Email
Address" }, | |
26 { COMPANY_NAME, AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP, "Compan
y Name" }, | |
27 | |
28 { PHONE_HOME_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER, "Ho
me Phone Number" }, | |
29 { PHONE_HOME_CITY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_COD
E, "Home Area Code" }, | |
30 { PHONE_HOME_COUNTRY_CODE, AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNT
RY_CODE, "Home Country Code" }, | |
31 { PHONE_HOME_CITY_AND_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_CI
TY_AND_NUMBER, "Home Phone Number" }, | |
32 { PHONE_HOME_WHOLE_NUMBER, AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE
_NUMBER, "Home Phone Number" }, | |
33 | |
34 { PHONE_FAX_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER, "Fax
Number" }, | |
35 { PHONE_FAX_CITY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE,
"Fax Area Code" }, | |
36 { PHONE_FAX_COUNTRY_CODE, AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY
_CODE, "Fax Country Code" }, | |
37 { PHONE_FAX_CITY_AND_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY
_AND_NUMBER, "Fax Number" }, | |
38 { PHONE_FAX_WHOLE_NUMBER, AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_N
UMBER, "Fax Number" }, | |
39 | |
40 { ADDRESS_HOME_LINE1, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1,
"Home Address Line 1" }, | |
41 { ADDRESS_HOME_LINE2, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2,
"Home Address Line 2" }, | |
42 { ADDRESS_HOME_APT_NUM, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_
NUM, "Home Address Apartment Number" }, | |
43 { ADDRESS_HOME_CITY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY,
"Home Address City" }, | |
44 { ADDRESS_HOME_STATE, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE,
"Home Address State" }, | |
45 { ADDRESS_HOME_ZIP, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP, "Ho
me Address Zip Code" }, | |
46 { ADDRESS_HOME_COUNTRY, AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUN
TRY, "Home Address Country" }, | |
47 | |
48 { ADDRESS_BILLING_LINE1, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_
LINE1, "Billing Address Line 1" }, | |
49 { ADDRESS_BILLING_LINE2, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_
LINE2, "Billing Address Line 2" }, | |
50 { ADDRESS_BILLING_APT_NUM, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRES
S_APT_NUM, "Billing Address Apartment Number" }, | |
51 { ADDRESS_BILLING_CITY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_C
ITY, "Billing Address City" }, | |
52 { ADDRESS_BILLING_STATE, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_
STATE, "Billing Address State" }, | |
53 { ADDRESS_BILLING_ZIP, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZI
P, "Billing Address Zip Code" }, | |
54 { ADDRESS_BILLING_COUNTRY, AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRES
S_COUNTRY, "Billing Address Country" }, | |
55 | |
56 { CREDIT_CARD_NAME, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Nam
e on Credit Card" }, | |
57 { CREDIT_CARD_NUMBER, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "C
redit Card Number" }, | |
58 { CREDIT_CARD_EXP_MONTH, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP,
"Credit Card Expiration Month" }, | |
59 { CREDIT_CARD_EXP_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SU
BGROUP, "Credit Card Expiration Year" }, | |
60 { CREDIT_CARD_EXP_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::NO_SU
BGROUP, "Credit Card Expiration Year" }, | |
61 { CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::
NO_SUBGROUP, "Credit Card Expiration Date" }, | |
62 { CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR, AutoFillType::CREDIT_CARD, AutoFillType::
NO_SUBGROUP, "Credit Card Expiration Date" }, | |
63 { CREDIT_CARD_TYPE, AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP, "Cre
dit Card Type" }, | |
64 { CREDIT_CARD_VERIFICATION_CODE, AutoFillType::CREDIT_CARD, AutoFillType::NO_S
UBGROUP, "Credit Card Verification Number" }, | |
65 | |
66 { MAX_VALID_FIELD_TYPE, AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP, ""
}, | |
67 }; | 14 }; |
68 | 15 |
69 bool AutoFillType::initialized_ = false; | 16 AutoFillType::AutoFillTypeDefinition kAutoFillTypeDefinitions[] = { |
70 AutoFillType AutoFillType::types_[MAX_VALID_FIELD_TYPE + 1]; | 17 // NO_SERVER_DATA |
| 18 { AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }, |
| 19 // UNKNOWN_TYPE |
| 20 kUnknownAutoFillTypeDefinition, |
| 21 // EMPTY_TYPE |
| 22 { AutoFillType::NO_GROUP, AutoFillType::NO_SUBGROUP }, |
71 | 23 |
72 AutoFillType::AutoFillType(AutoFillTypeDefinition* definition) | 24 // NAME_FIRST |
73 : autofill_type_definition_(definition) { | 25 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
74 DCHECK(definition != NULL); | 26 // NAME_MIDDLE |
| 27 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 28 // NAME_LAST |
| 29 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 30 // NAME_MIDDLE_INITIAL |
| 31 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 32 // NAME_FULL |
| 33 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 34 // NAME_SUFFIX |
| 35 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 36 |
| 37 // EMAIL_ADDRESS |
| 38 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 39 |
| 40 // PHONE_HOME_NUMBER |
| 41 { AutoFillType::PHONE_HOME, AutoFillType::PHONE_NUMBER }, |
| 42 // PHONE_HOME_CITY_CODE |
| 43 { AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_CODE }, |
| 44 // PHONE_HOME_COUNTRY_CODE |
| 45 { AutoFillType::PHONE_HOME, AutoFillType::PHONE_COUNTRY_CODE }, |
| 46 // PHONE_HOME_CITY_AND_NUMBER |
| 47 { AutoFillType::PHONE_HOME, AutoFillType::PHONE_CITY_AND_NUMBER }, |
| 48 // PHONE_HOME_WHOLE_NUMBER |
| 49 { AutoFillType::PHONE_HOME, AutoFillType::PHONE_WHOLE_NUMBER }, |
| 50 |
| 51 // Work phone numbers (values [15,19]) are deprecated. |
| 52 kUnknownAutoFillTypeDefinition, |
| 53 kUnknownAutoFillTypeDefinition, |
| 54 kUnknownAutoFillTypeDefinition, |
| 55 kUnknownAutoFillTypeDefinition, |
| 56 kUnknownAutoFillTypeDefinition, |
| 57 |
| 58 // PHONE_FAX_NUMBER |
| 59 { AutoFillType::PHONE_FAX, AutoFillType::PHONE_NUMBER }, |
| 60 // PHONE_FAX_CITY_CODE |
| 61 { AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_CODE }, |
| 62 // PHONE_FAX_COUNTRY_CODE |
| 63 { AutoFillType::PHONE_FAX, AutoFillType::PHONE_COUNTRY_CODE }, |
| 64 // PHONE_FAX_CITY_AND_NUMBER |
| 65 { AutoFillType::PHONE_FAX, AutoFillType::PHONE_CITY_AND_NUMBER }, |
| 66 // PHONE_FAX_WHOLE_NUMBER |
| 67 { AutoFillType::PHONE_FAX, AutoFillType::PHONE_WHOLE_NUMBER }, |
| 68 |
| 69 // Cell phone numbers (values [25, 29]) are deprecated. |
| 70 kUnknownAutoFillTypeDefinition, |
| 71 kUnknownAutoFillTypeDefinition, |
| 72 kUnknownAutoFillTypeDefinition, |
| 73 kUnknownAutoFillTypeDefinition, |
| 74 kUnknownAutoFillTypeDefinition, |
| 75 |
| 76 // ADDRESS_HOME_LINE1 |
| 77 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE1 }, |
| 78 // ADDRESS_HOME_LINE2 |
| 79 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_LINE2 }, |
| 80 // ADDRESS_HOME_APT_NUM |
| 81 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_APT_NUM }, |
| 82 // ADDRESS_HOME_CITY |
| 83 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_CITY }, |
| 84 // ADDRESS_HOME_STATE |
| 85 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_STATE }, |
| 86 // ADDRESS_HOME_ZIP |
| 87 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_ZIP }, |
| 88 // ADDRESS_HOME_COUNTRY |
| 89 { AutoFillType::ADDRESS_HOME, AutoFillType::ADDRESS_COUNTRY }, |
| 90 |
| 91 // ADDRESS_BILLING_LINE1 |
| 92 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE1 }, |
| 93 // ADDRESS_BILLING_LINE2 |
| 94 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_LINE2 }, |
| 95 // ADDRESS_BILLING_APT_NUM |
| 96 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_APT_NUM }, |
| 97 // ADDRESS_BILLING_CITY |
| 98 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_CITY }, |
| 99 // ADDRESS_BILLING_STATE |
| 100 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_STATE }, |
| 101 // ADDRESS_BILLING_ZIP |
| 102 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_ZIP }, |
| 103 // ADDRESS_BILLING_COUNTRY |
| 104 { AutoFillType::ADDRESS_BILLING, AutoFillType::ADDRESS_COUNTRY }, |
| 105 |
| 106 // ADDRESS_SHIPPING values [44,50] are deprecated. |
| 107 kUnknownAutoFillTypeDefinition, |
| 108 kUnknownAutoFillTypeDefinition, |
| 109 kUnknownAutoFillTypeDefinition, |
| 110 kUnknownAutoFillTypeDefinition, |
| 111 kUnknownAutoFillTypeDefinition, |
| 112 kUnknownAutoFillTypeDefinition, |
| 113 kUnknownAutoFillTypeDefinition, |
| 114 |
| 115 // CREDIT_CARD_NAME |
| 116 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 117 // CREDIT_CARD_NUMBER |
| 118 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 119 // CREDIT_CARD_EXP_MONTH |
| 120 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 121 // CREDIT_CARD_EXP_2_DIGIT_YEAR |
| 122 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 123 // CREDIT_CARD_EXP_4_DIGIT_YEAR |
| 124 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 125 // CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR |
| 126 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 127 // CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR |
| 128 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 129 // CREDIT_CARD_TYPE |
| 130 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 131 // CREDIT_CARD_VERIFICATION_CODE |
| 132 { AutoFillType::CREDIT_CARD, AutoFillType::NO_SUBGROUP }, |
| 133 |
| 134 // COMPANY_NAME |
| 135 { AutoFillType::CONTACT_INFO, AutoFillType::NO_SUBGROUP }, |
| 136 }; |
| 137 |
| 138 } // namespace |
| 139 |
| 140 AutoFillType::AutoFillType(AutoFillFieldType field_type) { |
| 141 if ((field_type < NO_SERVER_DATA || field_type >= MAX_VALID_FIELD_TYPE) || |
| 142 (field_type >= 15 && field_type <= 19) || |
| 143 (field_type >= 25 && field_type <= 29) || |
| 144 (field_type >= 44 && field_type <= 50)) |
| 145 field_type_ = UNKNOWN_TYPE; |
| 146 else |
| 147 field_type_ = field_type; |
75 } | 148 } |
76 | 149 |
77 AutoFillType::AutoFillType(AutoFillFieldType field_type) { | 150 AutoFillType::AutoFillType(const AutoFillType& autofill_type) { |
78 StaticInitialize(); | 151 *this = autofill_type; |
79 DCHECK(initialized_); | |
80 | |
81 if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE || | |
82 types_[field_type].autofill_type_definition_ == NULL) { | |
83 field_type = UNKNOWN_TYPE; | |
84 } | |
85 | |
86 autofill_type_definition_ = types_[field_type].autofill_type_definition_; | |
87 } | 152 } |
88 | 153 |
89 // TODO(jhawkins): refactor this class to not require static initialization. | 154 AutoFillType& AutoFillType::operator=(const AutoFillType& autofill_type) { |
90 void AutoFillType::StaticInitialize() { | 155 if (this != &autofill_type) |
91 // Can be called more than once (in unit tests for example). | 156 this->field_type_ = autofill_type.field_type_; |
92 if (initialized_) | 157 return *this; |
93 return; | |
94 | |
95 initialized_ = true; | |
96 | |
97 InitializeFieldTypeMap(); | |
98 } | 158 } |
99 | 159 |
100 void AutoFillType::InitializeFieldTypeMap() { | 160 AutoFillFieldType AutoFillType::field_type() const { |
101 for (size_t i = 0; i < arraysize(kAutoFillTypeDefinitions); ++i) { | 161 return field_type_; |
102 AutoFillType type(&kAutoFillTypeDefinitions[i]); | |
103 types_[type.field_type()] = type; | |
104 } | |
105 } | 162 } |
| 163 |
| 164 FieldTypeGroup AutoFillType::group() const { |
| 165 return kAutoFillTypeDefinitions[field_type_].group; |
| 166 } |
| 167 |
| 168 FieldTypeSubGroup AutoFillType::subgroup() const { |
| 169 return kAutoFillTypeDefinitions[field_type_].subgroup; |
| 170 } |
OLD | NEW |