OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 FormData result = form; | 445 FormData result = form; |
446 | 446 |
447 // If the relevant section is auto-filled, we should fill |field| but not the | 447 // If the relevant section is auto-filled, we should fill |field| but not the |
448 // rest of the form. | 448 // rest of the form. |
449 if (SectionIsAutoFilled(form_structure, form, section_start, section_end)) { | 449 if (SectionIsAutoFilled(form_structure, form, section_start, section_end)) { |
450 for (std::vector<FormField>::iterator iter = result.fields.begin(); | 450 for (std::vector<FormField>::iterator iter = result.fields.begin(); |
451 iter != result.fields.end(); ++iter) { | 451 iter != result.fields.end(); ++iter) { |
452 if ((*iter) == field) { | 452 if ((*iter) == field) { |
453 AutoFillType autofill_type(autofill_field->type()); | 453 AutoFillType autofill_type(autofill_field->type()); |
454 if (profile) { | 454 if (profile) { |
455 DCHECK(autofill_type.group() != AutoFillType::CREDIT_CARD); | 455 DCHECK_NE(autofill_type.group(), AutoFillType::CREDIT_CARD); |
456 FillFormField(profile, autofill_type, &(*iter)); | 456 FillFormField(profile, autofill_type, &(*iter)); |
457 } else { | 457 } else { |
458 DCHECK(autofill_type.group() == AutoFillType::CREDIT_CARD); | 458 DCHECK_EQ(autofill_type.group(), AutoFillType::CREDIT_CARD); |
459 FillCreditCardFormField(credit_card, autofill_type, &(*iter)); | 459 FillCreditCardFormField(credit_card, autofill_type, &(*iter)); |
460 } | 460 } |
461 break; | 461 break; |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 host->Send(new AutoFillMsg_FormDataFilled(host->routing_id(), query_id, | 465 host->Send(new AutoFillMsg_FormDataFilled(host->routing_id(), query_id, |
466 result)); | 466 result)); |
467 return; | 467 return; |
468 } | 468 } |
(...skipping 15 matching lines...) Expand all Loading... |
484 } | 484 } |
485 | 485 |
486 // If we've found a match then fill the |result| field with the found | 486 // If we've found a match then fill the |result| field with the found |
487 // field in the |form_structure|. | 487 // field in the |form_structure|. |
488 if (k >= section_end) | 488 if (k >= section_end) |
489 continue; | 489 continue; |
490 | 490 |
491 AutoFillType autofill_type(form_structure->field(k)->type()); | 491 AutoFillType autofill_type(form_structure->field(k)->type()); |
492 if (autofill_type.group() != AutoFillType::NO_GROUP) { | 492 if (autofill_type.group() != AutoFillType::NO_GROUP) { |
493 if (profile) { | 493 if (profile) { |
494 DCHECK(autofill_type.group() != AutoFillType::CREDIT_CARD); | 494 DCHECK_NE(autofill_type.group(), AutoFillType::CREDIT_CARD); |
495 FillFormField(profile, autofill_type, &result.fields[j]); | 495 FillFormField(profile, autofill_type, &result.fields[j]); |
496 } else { | 496 } else { |
497 DCHECK(autofill_type.group() == AutoFillType::CREDIT_CARD); | 497 DCHECK_EQ(autofill_type.group(), AutoFillType::CREDIT_CARD); |
498 FillCreditCardFormField(credit_card, autofill_type, &result.fields[j]); | 498 FillCreditCardFormField(credit_card, autofill_type, &result.fields[j]); |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 // We found a matching field in the |form_structure| so we | 502 // We found a matching field in the |form_structure| so we |
503 // proceed to the next |result| field, and the next |form_structure|. | 503 // proceed to the next |result| field, and the next |form_structure|. |
504 ++i; | 504 ++i; |
505 } | 505 } |
506 autofilled_forms_signatures_.push_front(form_structure->FormSignature()); | 506 autofilled_forms_signatures_.push_front(form_structure->FormSignature()); |
507 | 507 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 icons->push_back(credit_card->type()); | 866 icons->push_back(credit_card->type()); |
867 unique_ids->push_back(PackGUIDs(credit_card->guid(), std::string())); | 867 unique_ids->push_back(PackGUIDs(credit_card->guid(), std::string())); |
868 } | 868 } |
869 } | 869 } |
870 } | 870 } |
871 | 871 |
872 void AutoFillManager::FillCreditCardFormField(const CreditCard* credit_card, | 872 void AutoFillManager::FillCreditCardFormField(const CreditCard* credit_card, |
873 AutoFillType type, | 873 AutoFillType type, |
874 webkit_glue::FormField* field) { | 874 webkit_glue::FormField* field) { |
875 DCHECK(credit_card); | 875 DCHECK(credit_card); |
876 DCHECK(type.group() == AutoFillType::CREDIT_CARD); | 876 DCHECK_EQ(type.group(), AutoFillType::CREDIT_CARD); |
877 DCHECK(field); | 877 DCHECK(field); |
878 | 878 |
879 if (field->form_control_type() == ASCIIToUTF16("select-one")) { | 879 if (field->form_control_type() == ASCIIToUTF16("select-one")) { |
880 autofill::FillSelectControl(*credit_card, type, field); | 880 autofill::FillSelectControl(*credit_card, type, field); |
881 } else if (field->form_control_type() == ASCIIToUTF16("month")) { | 881 } else if (field->form_control_type() == ASCIIToUTF16("month")) { |
882 // HTML5 input="month" consists of year-month. | 882 // HTML5 input="month" consists of year-month. |
883 string16 year = credit_card->GetFieldText( | 883 string16 year = credit_card->GetFieldText( |
884 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 884 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
885 string16 month = credit_card->GetFieldText( | 885 string16 month = credit_card->GetFieldText( |
886 AutoFillType(CREDIT_CARD_EXP_MONTH)); | 886 AutoFillType(CREDIT_CARD_EXP_MONTH)); |
887 if (!year.empty() && !month.empty()) { | 887 if (!year.empty() && !month.empty()) { |
888 // Fill the value only if |credit_card| includes both year and month | 888 // Fill the value only if |credit_card| includes both year and month |
889 // information. | 889 // information. |
890 field->set_value(year + ASCIIToUTF16("-") + month); | 890 field->set_value(year + ASCIIToUTF16("-") + month); |
891 } | 891 } |
892 } else { | 892 } else { |
893 field->set_value(credit_card->GetFieldText(type)); | 893 field->set_value(credit_card->GetFieldText(type)); |
894 } | 894 } |
895 } | 895 } |
896 | 896 |
897 void AutoFillManager::FillFormField(const AutoFillProfile* profile, | 897 void AutoFillManager::FillFormField(const AutoFillProfile* profile, |
898 AutoFillType type, | 898 AutoFillType type, |
899 webkit_glue::FormField* field) { | 899 webkit_glue::FormField* field) { |
900 DCHECK(profile); | 900 DCHECK(profile); |
901 DCHECK(type.group() != AutoFillType::CREDIT_CARD); | 901 DCHECK_NE(type.group(), AutoFillType::CREDIT_CARD); |
902 DCHECK(field); | 902 DCHECK(field); |
903 | 903 |
904 if (type.subgroup() == AutoFillType::PHONE_NUMBER) { | 904 if (type.subgroup() == AutoFillType::PHONE_NUMBER) { |
905 FillPhoneNumberField(profile, type, field); | 905 FillPhoneNumberField(profile, type, field); |
906 } else { | 906 } else { |
907 if (field->form_control_type() == ASCIIToUTF16("select-one")) | 907 if (field->form_control_type() == ASCIIToUTF16("select-one")) |
908 autofill::FillSelectControl(*profile, type, field); | 908 autofill::FillSelectControl(*profile, type, field); |
909 else | 909 else |
910 field->set_value(profile->GetFieldText(type)); | 910 field->set_value(profile->GetFieldText(type)); |
911 } | 911 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 return std::string(); | 1011 return std::string(); |
1012 | 1012 |
1013 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); | 1013 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); |
1014 if (iter == id_guid_map_.end()) { | 1014 if (iter == id_guid_map_.end()) { |
1015 NOTREACHED(); | 1015 NOTREACHED(); |
1016 return std::string(); | 1016 return std::string(); |
1017 } | 1017 } |
1018 | 1018 |
1019 return iter->second; | 1019 return iter->second; |
1020 } | 1020 } |
OLD | NEW |