| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/browser/autofill_type.h" | |
| 6 | |
| 7 #include <ostream> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace autofill { | |
| 12 | |
| 13 AutofillType::AutofillType(AutofillFieldType field_type) { | |
| 14 if ((field_type < NO_SERVER_DATA || field_type >= MAX_VALID_FIELD_TYPE) || | |
| 15 (field_type >= 15 && field_type <= 19) || | |
| 16 (field_type >= 25 && field_type <= 29) || | |
| 17 (field_type >= 44 && field_type <= 50)) | |
| 18 field_type_ = UNKNOWN_TYPE; | |
| 19 else | |
| 20 field_type_ = field_type; | |
| 21 } | |
| 22 | |
| 23 AutofillType::AutofillType(const AutofillType& autofill_type) { | |
| 24 *this = autofill_type; | |
| 25 } | |
| 26 | |
| 27 AutofillType& AutofillType::operator=(const AutofillType& autofill_type) { | |
| 28 if (this != &autofill_type) | |
| 29 this->field_type_ = autofill_type.field_type_; | |
| 30 return *this; | |
| 31 } | |
| 32 | |
| 33 AutofillFieldType AutofillType::field_type() const { | |
| 34 return field_type_; | |
| 35 } | |
| 36 | |
| 37 FieldTypeGroup AutofillType::group() const { | |
| 38 switch (field_type_) { | |
| 39 case NAME_FIRST: | |
| 40 case NAME_MIDDLE: | |
| 41 case NAME_LAST: | |
| 42 case NAME_MIDDLE_INITIAL: | |
| 43 case NAME_FULL: | |
| 44 case NAME_SUFFIX: | |
| 45 return NAME; | |
| 46 | |
| 47 case EMAIL_ADDRESS: | |
| 48 return EMAIL; | |
| 49 | |
| 50 case PHONE_HOME_NUMBER: | |
| 51 case PHONE_HOME_CITY_CODE: | |
| 52 case PHONE_HOME_COUNTRY_CODE: | |
| 53 case PHONE_HOME_CITY_AND_NUMBER: | |
| 54 case PHONE_HOME_WHOLE_NUMBER: | |
| 55 return PHONE_HOME; | |
| 56 | |
| 57 case PHONE_BILLING_NUMBER: | |
| 58 case PHONE_BILLING_CITY_CODE: | |
| 59 case PHONE_BILLING_COUNTRY_CODE: | |
| 60 case PHONE_BILLING_CITY_AND_NUMBER: | |
| 61 case PHONE_BILLING_WHOLE_NUMBER: | |
| 62 return PHONE_BILLING; | |
| 63 | |
| 64 case ADDRESS_HOME_LINE1: | |
| 65 case ADDRESS_HOME_LINE2: | |
| 66 case ADDRESS_HOME_APT_NUM: | |
| 67 case ADDRESS_HOME_CITY: | |
| 68 case ADDRESS_HOME_STATE: | |
| 69 case ADDRESS_HOME_ZIP: | |
| 70 case ADDRESS_HOME_COUNTRY: | |
| 71 return ADDRESS_HOME; | |
| 72 | |
| 73 case ADDRESS_BILLING_LINE1: | |
| 74 case ADDRESS_BILLING_LINE2: | |
| 75 case ADDRESS_BILLING_APT_NUM: | |
| 76 case ADDRESS_BILLING_CITY: | |
| 77 case ADDRESS_BILLING_STATE: | |
| 78 case ADDRESS_BILLING_ZIP: | |
| 79 case ADDRESS_BILLING_COUNTRY: | |
| 80 return ADDRESS_BILLING; | |
| 81 | |
| 82 case CREDIT_CARD_NAME: | |
| 83 case CREDIT_CARD_NUMBER: | |
| 84 case CREDIT_CARD_EXP_MONTH: | |
| 85 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | |
| 86 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | |
| 87 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: | |
| 88 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: | |
| 89 case CREDIT_CARD_TYPE: | |
| 90 case CREDIT_CARD_VERIFICATION_CODE: | |
| 91 return CREDIT_CARD; | |
| 92 | |
| 93 case COMPANY_NAME: | |
| 94 return COMPANY; | |
| 95 | |
| 96 default: | |
| 97 return NO_GROUP; | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 // static | |
| 102 AutofillFieldType AutofillType::GetEquivalentFieldType( | |
| 103 AutofillFieldType field_type) { | |
| 104 // When billing information is requested from the profile we map to the | |
| 105 // home address equivalents. | |
| 106 switch (field_type) { | |
| 107 case ADDRESS_BILLING_LINE1: | |
| 108 return ADDRESS_HOME_LINE1; | |
| 109 | |
| 110 case ADDRESS_BILLING_LINE2: | |
| 111 return ADDRESS_HOME_LINE2; | |
| 112 | |
| 113 case ADDRESS_BILLING_APT_NUM: | |
| 114 return ADDRESS_HOME_APT_NUM; | |
| 115 | |
| 116 case ADDRESS_BILLING_CITY: | |
| 117 return ADDRESS_HOME_CITY; | |
| 118 | |
| 119 case ADDRESS_BILLING_STATE: | |
| 120 return ADDRESS_HOME_STATE; | |
| 121 | |
| 122 case ADDRESS_BILLING_ZIP: | |
| 123 return ADDRESS_HOME_ZIP; | |
| 124 | |
| 125 case ADDRESS_BILLING_COUNTRY: | |
| 126 return ADDRESS_HOME_COUNTRY; | |
| 127 | |
| 128 case PHONE_BILLING_WHOLE_NUMBER: | |
| 129 return PHONE_HOME_WHOLE_NUMBER; | |
| 130 | |
| 131 case PHONE_BILLING_NUMBER: | |
| 132 return PHONE_HOME_NUMBER; | |
| 133 | |
| 134 case PHONE_BILLING_CITY_CODE: | |
| 135 return PHONE_HOME_CITY_CODE; | |
| 136 | |
| 137 case PHONE_BILLING_COUNTRY_CODE: | |
| 138 return PHONE_HOME_COUNTRY_CODE; | |
| 139 | |
| 140 case PHONE_BILLING_CITY_AND_NUMBER: | |
| 141 return PHONE_HOME_CITY_AND_NUMBER; | |
| 142 | |
| 143 default: | |
| 144 return field_type; | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 // static | |
| 149 AutofillFieldType AutofillType::GetEquivalentBillingFieldType( | |
| 150 AutofillFieldType field_type) { | |
| 151 switch (field_type) { | |
| 152 case ADDRESS_HOME_LINE1: | |
| 153 return ADDRESS_BILLING_LINE1; | |
| 154 | |
| 155 case ADDRESS_HOME_LINE2: | |
| 156 return ADDRESS_BILLING_LINE2; | |
| 157 | |
| 158 case ADDRESS_HOME_APT_NUM: | |
| 159 return ADDRESS_BILLING_APT_NUM; | |
| 160 | |
| 161 case ADDRESS_HOME_CITY: | |
| 162 return ADDRESS_BILLING_CITY; | |
| 163 | |
| 164 case ADDRESS_HOME_STATE: | |
| 165 return ADDRESS_BILLING_STATE; | |
| 166 | |
| 167 case ADDRESS_HOME_ZIP: | |
| 168 return ADDRESS_BILLING_ZIP; | |
| 169 | |
| 170 case ADDRESS_HOME_COUNTRY: | |
| 171 return ADDRESS_BILLING_COUNTRY; | |
| 172 | |
| 173 case PHONE_HOME_WHOLE_NUMBER: | |
| 174 return PHONE_BILLING_WHOLE_NUMBER; | |
| 175 | |
| 176 case PHONE_HOME_NUMBER: | |
| 177 return PHONE_BILLING_NUMBER; | |
| 178 | |
| 179 case PHONE_HOME_CITY_CODE: | |
| 180 return PHONE_BILLING_CITY_CODE; | |
| 181 | |
| 182 case PHONE_HOME_COUNTRY_CODE: | |
| 183 return PHONE_BILLING_COUNTRY_CODE; | |
| 184 | |
| 185 case PHONE_HOME_CITY_AND_NUMBER: | |
| 186 return PHONE_BILLING_CITY_AND_NUMBER; | |
| 187 | |
| 188 default: | |
| 189 return field_type; | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 // static | |
| 194 std::string AutofillType::FieldTypeToString(AutofillFieldType type) { | |
| 195 switch (type) { | |
| 196 case NO_SERVER_DATA: | |
| 197 return "NO_SERVER_DATA"; | |
| 198 case UNKNOWN_TYPE: | |
| 199 return "UNKNOWN_TYPE"; | |
| 200 case EMPTY_TYPE: | |
| 201 return "EMPTY_TYPE"; | |
| 202 case NAME_FIRST: | |
| 203 return "NAME_FIRST"; | |
| 204 case NAME_MIDDLE: | |
| 205 return "NAME_MIDDLE"; | |
| 206 case NAME_LAST: | |
| 207 return "NAME_LAST"; | |
| 208 case NAME_MIDDLE_INITIAL: | |
| 209 return "NAME_MIDDLE_INITIAL"; | |
| 210 case NAME_FULL: | |
| 211 return "NAME_FULL"; | |
| 212 case NAME_SUFFIX: | |
| 213 return "NAME_SUFFIX"; | |
| 214 case EMAIL_ADDRESS: | |
| 215 return "EMAIL_ADDRESS"; | |
| 216 case PHONE_HOME_NUMBER: | |
| 217 return "PHONE_HOME_NUMBER"; | |
| 218 case PHONE_HOME_CITY_CODE: | |
| 219 return "PHONE_HOME_CITY_CODE"; | |
| 220 case PHONE_HOME_COUNTRY_CODE: | |
| 221 return "PHONE_HOME_COUNTRY_CODE"; | |
| 222 case PHONE_HOME_CITY_AND_NUMBER: | |
| 223 return "PHONE_HOME_CITY_AND_NUMBER"; | |
| 224 case PHONE_HOME_WHOLE_NUMBER: | |
| 225 return "PHONE_HOME_WHOLE_NUMBER"; | |
| 226 case ADDRESS_HOME_LINE1: | |
| 227 return "ADDRESS_HOME_LINE1"; | |
| 228 case ADDRESS_HOME_LINE2: | |
| 229 return "ADDRESS_HOME_LINE2"; | |
| 230 case ADDRESS_HOME_APT_NUM: | |
| 231 return "ADDRESS_HOME_APT_NUM"; | |
| 232 case ADDRESS_HOME_CITY: | |
| 233 return "ADDRESS_HOME_CITY"; | |
| 234 case ADDRESS_HOME_STATE: | |
| 235 return "ADDRESS_HOME_STATE"; | |
| 236 case ADDRESS_HOME_ZIP: | |
| 237 return "ADDRESS_HOME_ZIP"; | |
| 238 case ADDRESS_HOME_COUNTRY: | |
| 239 return "ADDRESS_HOME_COUNTRY"; | |
| 240 case ADDRESS_BILLING_LINE1: | |
| 241 return "ADDRESS_BILLING_LINE1"; | |
| 242 case ADDRESS_BILLING_LINE2: | |
| 243 return "ADDRESS_BILLING_LINE2"; | |
| 244 case ADDRESS_BILLING_APT_NUM: | |
| 245 return "ADDRESS_BILLING_APT_NUM"; | |
| 246 case ADDRESS_BILLING_CITY: | |
| 247 return "ADDRESS_BILLING_CITY"; | |
| 248 case ADDRESS_BILLING_STATE: | |
| 249 return "ADDRESS_BILLING_STATE"; | |
| 250 case ADDRESS_BILLING_ZIP: | |
| 251 return "ADDRESS_BILLING_ZIP"; | |
| 252 case ADDRESS_BILLING_COUNTRY: | |
| 253 return "ADDRESS_BILLING_COUNTRY"; | |
| 254 case CREDIT_CARD_NAME: | |
| 255 return "CREDIT_CARD_NAME"; | |
| 256 case CREDIT_CARD_NUMBER: | |
| 257 return "CREDIT_CARD_NUMBER"; | |
| 258 case CREDIT_CARD_EXP_MONTH: | |
| 259 return "CREDIT_CARD_EXP_MONTH"; | |
| 260 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | |
| 261 return "CREDIT_CARD_EXP_2_DIGIT_YEAR"; | |
| 262 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | |
| 263 return "CREDIT_CARD_EXP_4_DIGIT_YEAR"; | |
| 264 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: | |
| 265 return "CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR"; | |
| 266 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: | |
| 267 return "CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR"; | |
| 268 case CREDIT_CARD_TYPE: | |
| 269 return "CREDIT_CARD_TYPE"; | |
| 270 case CREDIT_CARD_VERIFICATION_CODE: | |
| 271 return "CREDIT_CARD_VERIFICATION_CODE"; | |
| 272 case COMPANY_NAME: | |
| 273 return "COMPANY_NAME"; | |
| 274 default: | |
| 275 NOTREACHED() << "Invalid AutofillFieldType value."; | |
| 276 } | |
| 277 return std::string(); | |
| 278 } | |
| 279 | |
| 280 // static | |
| 281 AutofillFieldType AutofillType::StringToFieldType(const std::string& str) { | |
| 282 if (str == "NO_SERVER_DATA") | |
| 283 return NO_SERVER_DATA; | |
| 284 if (str == "UNKNOWN_TYPE") | |
| 285 return UNKNOWN_TYPE; | |
| 286 if (str == "EMPTY_TYPE") | |
| 287 return EMPTY_TYPE; | |
| 288 if (str == "NAME_FIRST") | |
| 289 return NAME_FIRST; | |
| 290 if (str == "NAME_MIDDLE") | |
| 291 return NAME_MIDDLE; | |
| 292 if (str == "NAME_LAST") | |
| 293 return NAME_LAST; | |
| 294 if (str == "NAME_MIDDLE_INITIAL") | |
| 295 return NAME_MIDDLE_INITIAL; | |
| 296 if (str == "NAME_FULL") | |
| 297 return NAME_FULL; | |
| 298 if (str == "NAME_SUFFIX") | |
| 299 return NAME_SUFFIX; | |
| 300 if (str == "EMAIL_ADDRESS") | |
| 301 return EMAIL_ADDRESS; | |
| 302 if (str == "PHONE_HOME_NUMBER") | |
| 303 return PHONE_HOME_NUMBER; | |
| 304 if (str == "PHONE_HOME_CITY_CODE") | |
| 305 return PHONE_HOME_CITY_CODE; | |
| 306 if (str == "PHONE_HOME_COUNTRY_CODE") | |
| 307 return PHONE_HOME_COUNTRY_CODE; | |
| 308 if (str == "PHONE_HOME_CITY_AND_NUMBER") | |
| 309 return PHONE_HOME_CITY_AND_NUMBER; | |
| 310 if (str == "PHONE_HOME_WHOLE_NUMBER") | |
| 311 return PHONE_HOME_WHOLE_NUMBER; | |
| 312 if (str == "ADDRESS_HOME_LINE1") | |
| 313 return ADDRESS_HOME_LINE1; | |
| 314 if (str == "ADDRESS_HOME_LINE2") | |
| 315 return ADDRESS_HOME_LINE2; | |
| 316 if (str == "ADDRESS_HOME_APT_NUM") | |
| 317 return ADDRESS_HOME_APT_NUM; | |
| 318 if (str == "ADDRESS_HOME_CITY") | |
| 319 return ADDRESS_HOME_CITY; | |
| 320 if (str == "ADDRESS_HOME_STATE") | |
| 321 return ADDRESS_HOME_STATE; | |
| 322 if (str == "ADDRESS_HOME_ZIP") | |
| 323 return ADDRESS_HOME_ZIP; | |
| 324 if (str == "ADDRESS_HOME_COUNTRY") | |
| 325 return ADDRESS_HOME_COUNTRY; | |
| 326 if (str == "ADDRESS_BILLING_LINE1") | |
| 327 return ADDRESS_BILLING_LINE1; | |
| 328 if (str == "ADDRESS_BILLING_LINE2") | |
| 329 return ADDRESS_BILLING_LINE2; | |
| 330 if (str == "ADDRESS_BILLING_APT_NUM") | |
| 331 return ADDRESS_BILLING_APT_NUM; | |
| 332 if (str == "ADDRESS_BILLING_CITY") | |
| 333 return ADDRESS_BILLING_CITY; | |
| 334 if (str == "ADDRESS_BILLING_STATE") | |
| 335 return ADDRESS_BILLING_STATE; | |
| 336 if (str == "ADDRESS_BILLING_ZIP") | |
| 337 return ADDRESS_BILLING_ZIP; | |
| 338 if (str == "ADDRESS_BILLING_COUNTRY") | |
| 339 return ADDRESS_BILLING_COUNTRY; | |
| 340 if (str == "CREDIT_CARD_NAME") | |
| 341 return CREDIT_CARD_NAME; | |
| 342 if (str == "CREDIT_CARD_NUMBER") | |
| 343 return CREDIT_CARD_NUMBER; | |
| 344 if (str == "CREDIT_CARD_EXP_MONTH") | |
| 345 return CREDIT_CARD_EXP_MONTH; | |
| 346 if (str == "CREDIT_CARD_EXP_2_DIGIT_YEAR") | |
| 347 return CREDIT_CARD_EXP_2_DIGIT_YEAR; | |
| 348 if (str == "CREDIT_CARD_EXP_4_DIGIT_YEAR") | |
| 349 return CREDIT_CARD_EXP_4_DIGIT_YEAR; | |
| 350 if (str == "CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR") | |
| 351 return CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR; | |
| 352 if (str == "CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR") | |
| 353 return CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR; | |
| 354 if (str == "CREDIT_CARD_TYPE") | |
| 355 return CREDIT_CARD_TYPE; | |
| 356 if (str == "CREDIT_CARD_VERIFICATION_CODE") | |
| 357 return CREDIT_CARD_VERIFICATION_CODE; | |
| 358 if (str == "COMPANY_NAME") | |
| 359 return COMPANY_NAME; | |
| 360 | |
| 361 NOTREACHED() << "Unknown AutofillFieldType " << str; | |
| 362 return UNKNOWN_TYPE; | |
| 363 } | |
| 364 | |
| 365 } // namespace autofill | |
| OLD | NEW |