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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 DCHECK_EQ(20U, hash_bin.length()); | 382 DCHECK_EQ(20U, hash_bin.length()); |
383 | 383 |
384 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | | 384 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | |
385 ((hash_bin[1] & 0xFF) << 16) | | 385 ((hash_bin[1] & 0xFF) << 16) | |
386 ((hash_bin[2] & 0xFF) << 8) | | 386 ((hash_bin[2] & 0xFF) << 8) | |
387 (hash_bin[3] & 0xFF); | 387 (hash_bin[3] & 0xFF); |
388 | 388 |
389 return base::UintToString(hash32); | 389 return base::UintToString(hash32); |
390 } | 390 } |
391 | 391 |
392 void FillCreditCardNumberField(const AutofillField& field, | |
393 const base::string16& cc_number, | |
394 FormFieldData* field_data) { | |
Ilya Sherman
2014/08/07 20:57:25
nit: Please add documentation for this function.
Pritam Nikam
2014/08/08 14:14:33
Done.
| |
395 base::string16 value = cc_number; | |
396 size_t length = value.length(); | |
397 AutofillField::CreditCardNumberInfo* number_info = | |
398 const_cast<AutofillField::CreditCardNumberInfo*>( | |
399 field.credit_card_number_info()); | |
400 if (field_data->max_length && field_data->max_length < length && | |
Ilya Sherman
2014/08/07 20:57:25
max_length is always set, isn't it?
Pritam Nikam
2014/08/08 14:14:33
Done.
For HTML forms i didn't notice this being c
| |
401 number_info) { | |
Ilya Sherman
2014/08/07 20:57:25
Is it possible to have the number_info set on a fi
Pritam Nikam
2014/08/08 14:14:33
Done.
| |
402 base::RemoveChars(cc_number, base::ASCIIToUTF16("- "), &value); | |
Ilya Sherman
2014/08/07 20:57:25
Why is this needed? I would have expected that th
Pritam Nikam
2014/08/08 14:14:33
Done.
| |
403 length = value.length(); | |
Ilya Sherman
2014/08/07 20:57:25
Why do you set this again?
Pritam Nikam
2014/08/08 14:14:33
Done.
| |
404 length = | |
405 std::min(field_data->max_length, length - number_info->start_index_); | |
406 value = value.substr(number_info->start_index_, length); | |
Ilya Sherman
2014/08/07 20:57:25
I don't think you need to set the end index manual
Pritam Nikam
2014/08/08 14:14:33
Done.
| |
407 } | |
408 | |
409 field_data->value = value; | |
410 } | |
Ilya Sherman
2014/08/07 20:57:25
Please move this to be adjacent to the FillPhoneNu
Pritam Nikam
2014/08/08 14:14:34
Done.
| |
411 | |
392 } // namespace | 412 } // namespace |
393 | 413 |
394 AutofillField::AutofillField() | 414 AutofillField::AutofillField() |
395 : server_type_(NO_SERVER_DATA), | 415 : server_type_(NO_SERVER_DATA), |
396 heuristic_type_(UNKNOWN_TYPE), | 416 heuristic_type_(UNKNOWN_TYPE), |
397 html_type_(HTML_TYPE_UNKNOWN), | 417 html_type_(HTML_TYPE_UNKNOWN), |
398 html_mode_(HTML_MODE_NONE), | 418 html_mode_(HTML_MODE_NONE), |
399 phone_part_(IGNORED) { | 419 phone_part_(IGNORED), |
420 credit_card_number_info_(NULL) { | |
400 } | 421 } |
401 | 422 |
402 AutofillField::AutofillField(const FormFieldData& field, | 423 AutofillField::AutofillField(const FormFieldData& field, |
403 const base::string16& unique_name) | 424 const base::string16& unique_name) |
404 : FormFieldData(field), | 425 : FormFieldData(field), |
405 unique_name_(unique_name), | 426 unique_name_(unique_name), |
406 server_type_(NO_SERVER_DATA), | 427 server_type_(NO_SERVER_DATA), |
407 heuristic_type_(UNKNOWN_TYPE), | 428 heuristic_type_(UNKNOWN_TYPE), |
408 html_type_(HTML_TYPE_UNKNOWN), | 429 html_type_(HTML_TYPE_UNKNOWN), |
409 html_mode_(HTML_MODE_NONE), | 430 html_mode_(HTML_MODE_NONE), |
410 phone_part_(IGNORED) { | 431 phone_part_(IGNORED), |
432 credit_card_number_info_(NULL) { | |
411 } | 433 } |
412 | 434 |
413 AutofillField::~AutofillField() {} | 435 AutofillField::~AutofillField() { |
436 if (credit_card_number_info_) { | |
437 delete credit_card_number_info_; | |
Ilya Sherman
2014/08/07 20:57:25
You should pretty much always prefer a scoped_ptr
Pritam Nikam
2014/08/08 14:14:34
Done.
| |
438 credit_card_number_info_ = NULL; | |
439 } | |
440 } | |
414 | 441 |
415 void AutofillField::set_heuristic_type(ServerFieldType type) { | 442 void AutofillField::set_heuristic_type(ServerFieldType type) { |
416 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && | 443 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && |
417 type != FIELD_WITH_DEFAULT_VALUE) { | 444 type != FIELD_WITH_DEFAULT_VALUE) { |
418 heuristic_type_ = type; | 445 heuristic_type_ = type; |
419 } else { | 446 } else { |
420 NOTREACHED(); | 447 NOTREACHED(); |
421 // This case should not be reachable; but since this has potential | 448 // This case should not be reachable; but since this has potential |
422 // implications on data uploaded to the server, better safe than sorry. | 449 // implications on data uploaded to the server, better safe than sorry. |
423 heuristic_type_ = UNKNOWN_TYPE; | 450 heuristic_type_ = UNKNOWN_TYPE; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 if (type.GetStorableType() == PHONE_HOME_NUMBER) { | 506 if (type.GetStorableType() == PHONE_HOME_NUMBER) { |
480 FillPhoneNumberField(field, value, field_data); | 507 FillPhoneNumberField(field, value, field_data); |
481 return true; | 508 return true; |
482 } else if (field_data->form_control_type == "select-one") { | 509 } else if (field_data->form_control_type == "select-one") { |
483 return FillSelectControl(type, value, app_locale, field_data); | 510 return FillSelectControl(type, value, app_locale, field_data); |
484 } else if (field_data->form_control_type == "month") { | 511 } else if (field_data->form_control_type == "month") { |
485 return FillMonthControl(value, field_data); | 512 return FillMonthControl(value, field_data); |
486 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 513 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
487 FillStreetAddress(value, address_language_code, field_data); | 514 FillStreetAddress(value, address_language_code, field_data); |
488 return true; | 515 return true; |
516 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | |
517 FillCreditCardNumberField(field, value, field_data); | |
518 return true; | |
489 } | 519 } |
490 | 520 |
491 field_data->value = value; | 521 field_data->value = value; |
492 return true; | 522 return true; |
493 } | 523 } |
494 | 524 |
495 } // namespace autofill | 525 } // namespace autofill |
OLD | NEW |