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_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || | 292 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
293 field_data->max_length == PhoneNumber::kSuffixLength) { | 293 field_data->max_length == PhoneNumber::kSuffixLength) { |
294 value = number.substr(PhoneNumber::kSuffixOffset, | 294 value = number.substr(PhoneNumber::kSuffixOffset, |
295 PhoneNumber::kSuffixLength); | 295 PhoneNumber::kSuffixLength); |
296 } | 296 } |
297 } | 297 } |
298 | 298 |
299 field_data->value = value; | 299 field_data->value = value; |
300 } | 300 } |
301 | 301 |
| 302 // Set |field_data|'s value to |number|, or possibly an appropriate substring |
| 303 // of |number| for cases where credit card number splits across multiple HTML |
| 304 // form input fields. |
| 305 // The |field| specifies the |credit_card_number_offset_| to the substring |
| 306 // within credit card number. |
| 307 void FillCreditCardNumberField(const AutofillField& field, |
| 308 const base::string16& number, |
| 309 FormFieldData* field_data) { |
| 310 base::string16 value = number; |
| 311 |
| 312 // |field|'s max_length truncates credit card number to fit within. |
| 313 if (field.credit_card_number_offset() < value.length()) |
| 314 value = value.substr(field.credit_card_number_offset()); |
| 315 |
| 316 field_data->value = value; |
| 317 } |
| 318 |
302 // Fills in the select control |field| with |value|. If an exact match is not | 319 // Fills in the select control |field| with |value|. If an exact match is not |
303 // found, falls back to alternate filling strategies based on the |type|. | 320 // found, falls back to alternate filling strategies based on the |type|. |
304 bool FillSelectControl(const AutofillType& type, | 321 bool FillSelectControl(const AutofillType& type, |
305 const base::string16& value, | 322 const base::string16& value, |
306 const std::string& app_locale, | 323 const std::string& app_locale, |
307 FormFieldData* field) { | 324 FormFieldData* field) { |
308 DCHECK_EQ("select-one", field->form_control_type); | 325 DCHECK_EQ("select-one", field->form_control_type); |
309 | 326 |
310 // Guard against corrupted values passed over IPC. | 327 // Guard against corrupted values passed over IPC. |
311 if (field->option_values.size() != field->option_contents.size()) | 328 if (field->option_values.size() != field->option_contents.size()) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 return base::UintToString(hash32); | 407 return base::UintToString(hash32); |
391 } | 408 } |
392 | 409 |
393 } // namespace | 410 } // namespace |
394 | 411 |
395 AutofillField::AutofillField() | 412 AutofillField::AutofillField() |
396 : server_type_(NO_SERVER_DATA), | 413 : server_type_(NO_SERVER_DATA), |
397 heuristic_type_(UNKNOWN_TYPE), | 414 heuristic_type_(UNKNOWN_TYPE), |
398 html_type_(HTML_TYPE_UNKNOWN), | 415 html_type_(HTML_TYPE_UNKNOWN), |
399 html_mode_(HTML_MODE_NONE), | 416 html_mode_(HTML_MODE_NONE), |
400 phone_part_(IGNORED) { | 417 phone_part_(IGNORED), |
| 418 credit_card_number_offset_(0) { |
401 } | 419 } |
402 | 420 |
403 AutofillField::AutofillField(const FormFieldData& field, | 421 AutofillField::AutofillField(const FormFieldData& field, |
404 const base::string16& unique_name) | 422 const base::string16& unique_name) |
405 : FormFieldData(field), | 423 : FormFieldData(field), |
406 unique_name_(unique_name), | 424 unique_name_(unique_name), |
407 server_type_(NO_SERVER_DATA), | 425 server_type_(NO_SERVER_DATA), |
408 heuristic_type_(UNKNOWN_TYPE), | 426 heuristic_type_(UNKNOWN_TYPE), |
409 html_type_(HTML_TYPE_UNKNOWN), | 427 html_type_(HTML_TYPE_UNKNOWN), |
410 html_mode_(HTML_MODE_NONE), | 428 html_mode_(HTML_MODE_NONE), |
411 phone_part_(IGNORED) { | 429 phone_part_(IGNORED), |
| 430 credit_card_number_offset_(0) { |
412 } | 431 } |
413 | 432 |
414 AutofillField::~AutofillField() {} | 433 AutofillField::~AutofillField() {} |
415 | 434 |
416 void AutofillField::set_heuristic_type(ServerFieldType type) { | 435 void AutofillField::set_heuristic_type(ServerFieldType type) { |
417 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && | 436 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && |
418 type != FIELD_WITH_DEFAULT_VALUE) { | 437 type != FIELD_WITH_DEFAULT_VALUE) { |
419 heuristic_type_ = type; | 438 heuristic_type_ = type; |
420 } else { | 439 } else { |
421 NOTREACHED(); | 440 NOTREACHED(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 if (type.GetStorableType() == PHONE_HOME_NUMBER) { | 499 if (type.GetStorableType() == PHONE_HOME_NUMBER) { |
481 FillPhoneNumberField(field, value, field_data); | 500 FillPhoneNumberField(field, value, field_data); |
482 return true; | 501 return true; |
483 } else if (field_data->form_control_type == "select-one") { | 502 } else if (field_data->form_control_type == "select-one") { |
484 return FillSelectControl(type, value, app_locale, field_data); | 503 return FillSelectControl(type, value, app_locale, field_data); |
485 } else if (field_data->form_control_type == "month") { | 504 } else if (field_data->form_control_type == "month") { |
486 return FillMonthControl(value, field_data); | 505 return FillMonthControl(value, field_data); |
487 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 506 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
488 FillStreetAddress(value, address_language_code, field_data); | 507 FillStreetAddress(value, address_language_code, field_data); |
489 return true; | 508 return true; |
| 509 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| 510 FillCreditCardNumberField(field, value, field_data); |
| 511 return true; |
490 } | 512 } |
491 | 513 |
492 field_data->value = value; | 514 field_data->value = value; |
493 return true; | 515 return true; |
494 } | 516 } |
495 | 517 |
496 } // namespace autofill | 518 } // namespace autofill |
OLD | NEW |