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_start_index_| 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_start_index() < value.length()) | |
314 value = value.substr(field.credit_card_number_start_index()); | |
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_start_index_(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_start_index_(0) { | |
412 } | 431 } |
413 | 432 |
414 AutofillField::~AutofillField() {} | 433 AutofillField::~AutofillField() { |
Evan Stade
2014/08/28 18:18:42
did git cl format change this? dang that thing
Pritam Nikam
2014/09/01 09:03:35
Yes! It's after git cl format.
| |
434 } | |
415 | 435 |
416 void AutofillField::set_heuristic_type(ServerFieldType type) { | 436 void AutofillField::set_heuristic_type(ServerFieldType type) { |
417 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && | 437 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && |
418 type != FIELD_WITH_DEFAULT_VALUE) { | 438 type != FIELD_WITH_DEFAULT_VALUE) { |
419 heuristic_type_ = type; | 439 heuristic_type_ = type; |
420 } else { | 440 } else { |
421 NOTREACHED(); | 441 NOTREACHED(); |
422 // This case should not be reachable; but since this has potential | 442 // This case should not be reachable; but since this has potential |
423 // implications on data uploaded to the server, better safe than sorry. | 443 // implications on data uploaded to the server, better safe than sorry. |
424 heuristic_type_ = UNKNOWN_TYPE; | 444 heuristic_type_ = UNKNOWN_TYPE; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 if (type.GetStorableType() == PHONE_HOME_NUMBER) { | 500 if (type.GetStorableType() == PHONE_HOME_NUMBER) { |
481 FillPhoneNumberField(field, value, field_data); | 501 FillPhoneNumberField(field, value, field_data); |
482 return true; | 502 return true; |
483 } else if (field_data->form_control_type == "select-one") { | 503 } else if (field_data->form_control_type == "select-one") { |
484 return FillSelectControl(type, value, app_locale, field_data); | 504 return FillSelectControl(type, value, app_locale, field_data); |
485 } else if (field_data->form_control_type == "month") { | 505 } else if (field_data->form_control_type == "month") { |
486 return FillMonthControl(value, field_data); | 506 return FillMonthControl(value, field_data); |
487 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 507 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
488 FillStreetAddress(value, address_language_code, field_data); | 508 FillStreetAddress(value, address_language_code, field_data); |
489 return true; | 509 return true; |
510 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | |
511 FillCreditCardNumberField(field, value, field_data); | |
512 return true; | |
490 } | 513 } |
491 | 514 |
492 field_data->value = value; | 515 field_data->value = value; |
493 return true; | 516 return true; |
494 } | 517 } |
495 | 518 |
496 } // namespace autofill | 519 } // namespace autofill |
OLD | NEW |