Chromium Code Reviews| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 // Set |field_data|'s value to |number|, or possibly an appropriate substring of | 277 // Set |field_data|'s value to |number|, or possibly an appropriate substring of |
| 278 // |number|. The |field| specifies the type of the phone and whether this is a | 278 // |number|. The |field| specifies the type of the phone and whether this is a |
| 279 // phone prefix or suffix. | 279 // phone prefix or suffix. |
| 280 void FillPhoneNumberField(const AutofillField& field, | 280 void FillPhoneNumberField(const AutofillField& field, |
| 281 const base::string16& number, | 281 const base::string16& number, |
| 282 FormFieldData* field_data) { | 282 FormFieldData* field_data) { |
| 283 field_data->value = | 283 field_data->value = |
| 284 AutofillField::GetPhoneNumberValue(field, number, *field_data); | 284 AutofillField::GetPhoneNumberValue(field, number, *field_data); |
| 285 } | 285 } |
| 286 | 286 |
| 287 // Set |field_data|'s value to |number|, or possibly an appropriate substring | |
| 288 // of |number| for cases where credit card number splits across multiple HTML | |
| 289 // form input fields. | |
| 290 // The |field| specifies the |credit_card_number_offset_| to the substring | |
| 291 // within credit card number. | |
| 292 void FillCreditCardNumberField(const AutofillField& field, | |
| 293 const base::string16& number, | |
| 294 FormFieldData* field_data) { | |
| 295 base::string16 value = number; | |
| 296 | |
| 297 // |field|'s max_length truncates credit card number to fit within. | |
| 298 if (field.credit_card_number_offset() < value.length()) | |
| 299 value = value.substr(field.credit_card_number_offset()); | |
| 300 | |
| 301 field_data->value = value; | |
| 302 } | |
| 303 | |
| 304 // Fills in the select control |field| with |value|. If an exact match is not | 287 // Fills in the select control |field| with |value|. If an exact match is not |
| 305 // found, falls back to alternate filling strategies based on the |type|. | 288 // found, falls back to alternate filling strategies based on the |type|. |
| 306 bool FillSelectControl(const AutofillType& type, | 289 bool FillSelectControl(const AutofillType& type, |
| 307 const base::string16& value, | 290 const base::string16& value, |
| 308 const std::string& app_locale, | 291 const std::string& app_locale, |
| 309 FormFieldData* field) { | 292 FormFieldData* field) { |
| 310 DCHECK_EQ("select-one", field->form_control_type); | 293 DCHECK_EQ("select-one", field->form_control_type); |
| 311 | 294 |
| 312 // Guard against corrupted values passed over IPC. | 295 // Guard against corrupted values passed over IPC. |
| 313 if (field->option_values.size() != field->option_contents.size()) | 296 if (field->option_values.size() != field->option_contents.size()) |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 FillPhoneNumberField(field, value, field_data); | 468 FillPhoneNumberField(field, value, field_data); |
| 486 return true; | 469 return true; |
| 487 } else if (field_data->form_control_type == "select-one") { | 470 } else if (field_data->form_control_type == "select-one") { |
| 488 return FillSelectControl(type, value, app_locale, field_data); | 471 return FillSelectControl(type, value, app_locale, field_data); |
| 489 } else if (field_data->form_control_type == "month") { | 472 } else if (field_data->form_control_type == "month") { |
| 490 return FillMonthControl(value, field_data); | 473 return FillMonthControl(value, field_data); |
| 491 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 474 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
| 492 FillStreetAddress(value, address_language_code, field_data); | 475 FillStreetAddress(value, address_language_code, field_data); |
| 493 return true; | 476 return true; |
| 494 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 477 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| 495 FillCreditCardNumberField(field, value, field_data); | 478 field_data->value = AutofillField::GetCreditCardNumberValue(field, value); |
|
ziran.sun
2014/10/08 16:25:55
For consistency it might be worth keeping FillCred
Ilya Sherman
2014/10/08 21:04:38
Alternately, you could inline the FillPhoneNumberF
Pritam Nikam
2014/10/09 06:11:11
Done.
| |
| 496 return true; | 479 return true; |
| 497 } | 480 } |
| 498 | 481 |
| 499 field_data->value = value; | 482 field_data->value = value; |
| 500 return true; | 483 return true; |
| 501 } | 484 } |
| 502 | 485 |
| 503 base::string16 AutofillField::GetPhoneNumberValue( | 486 base::string16 AutofillField::GetPhoneNumberValue( |
| 504 const AutofillField& field, | 487 const AutofillField& field, |
| 505 const base::string16& number, | 488 const base::string16& number, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 519 | 502 |
| 520 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | 503 if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
| 521 field_data.max_length == PhoneNumber::kSuffixLength) { | 504 field_data.max_length == PhoneNumber::kSuffixLength) { |
| 522 return | 505 return |
| 523 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | 506 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); |
| 524 } | 507 } |
| 525 | 508 |
| 526 return number; | 509 return number; |
| 527 } | 510 } |
| 528 | 511 |
| 512 // The |field| specifies the |credit_card_number_offset_| to the substring | |
|
Ilya Sherman
2014/10/07 21:49:10
nit: "credit_card_number_offset_" -> "credit_card_
Pritam Nikam
2014/10/08 05:17:17
Done.
| |
| 513 // within credit card number. | |
| 514 base::string16 AutofillField::GetCreditCardNumberValue( | |
| 515 const AutofillField& field, | |
| 516 const base::string16& number) { | |
| 517 base::string16 value = number; | |
| 518 | |
| 519 // |field|'s max_length truncates credit card number to fit within. | |
| 520 if (field.credit_card_number_offset() < value.length()) | |
| 521 value = value.substr(field.credit_card_number_offset()); | |
| 522 | |
| 523 return value; | |
| 524 } | |
| 525 | |
| 529 } // namespace autofill | 526 } // namespace autofill |
| OLD | NEW |