| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | 613 |
| 614 void AutoFillManager::FillFormField(const AutoFillProfile* profile, | 614 void AutoFillManager::FillFormField(const AutoFillProfile* profile, |
| 615 AutoFillType type, | 615 AutoFillType type, |
| 616 webkit_glue::FormField* field) { | 616 webkit_glue::FormField* field) { |
| 617 DCHECK(profile); | 617 DCHECK(profile); |
| 618 DCHECK(field); | 618 DCHECK(field); |
| 619 | 619 |
| 620 if (type.subgroup() == AutoFillType::PHONE_NUMBER) { | 620 if (type.subgroup() == AutoFillType::PHONE_NUMBER) { |
| 621 FillPhoneNumberField(profile, field); | 621 FillPhoneNumberField(profile, field); |
| 622 } else { | 622 } else { |
| 623 field->set_value(profile->GetFieldText(type)); | 623 if (field->form_control_type() == ASCIIToUTF16("select-one")) |
| 624 FillSelectOneField(profile, type, field); |
| 625 else |
| 626 field->set_value(profile->GetFieldText(type)); |
| 624 } | 627 } |
| 625 } | 628 } |
| 626 | 629 |
| 630 void AutoFillManager::FillSelectOneField(const AutoFillProfile* profile, |
| 631 AutoFillType type, |
| 632 webkit_glue::FormField* field) { |
| 633 DCHECK(profile); |
| 634 DCHECK(field); |
| 635 DCHECK(field->form_control_type() == ASCIIToUTF16("select-one")); |
| 636 string16 selected_string = profile->GetFieldText(type); |
| 637 std::string ascii_value = UTF16ToASCII(selected_string); |
| 638 for (size_t i = 0; i < field->option_strings().size(); ++i) { |
| 639 if (profile->GetFieldText(type) == field->option_strings()[i]) { |
| 640 // An exact match - use it. |
| 641 selected_string = profile->GetFieldText(type); |
| 642 break; |
| 643 } |
| 644 if (!base::strcasecmp(UTF16ToASCII(field->option_strings()[i]).c_str(), |
| 645 ascii_value.c_str())) { |
| 646 // A match, but not in the same case - save it for the case we won't |
| 647 // find an exact match. |
| 648 selected_string = field->option_strings()[i]; |
| 649 } |
| 650 } |
| 651 field->set_value(selected_string); |
| 652 } |
| 653 |
| 654 |
| 627 void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile, | 655 void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile, |
| 628 webkit_glue::FormField* field) { | 656 webkit_glue::FormField* field) { |
| 629 // If we are filling a phone number, check to see if the size field | 657 // If we are filling a phone number, check to see if the size field |
| 630 // matches the "prefix" or "suffix" sizes and fill accordingly. | 658 // matches the "prefix" or "suffix" sizes and fill accordingly. |
| 631 string16 number = profile->GetFieldText(AutoFillType(PHONE_HOME_NUMBER)); | 659 string16 number = profile->GetFieldText(AutoFillType(PHONE_HOME_NUMBER)); |
| 632 bool has_valid_suffix_and_prefix = (number.length() == | 660 bool has_valid_suffix_and_prefix = (number.length() == |
| 633 (kAutoFillPhoneNumberPrefixCount + kAutoFillPhoneNumberSuffixCount)); | 661 (kAutoFillPhoneNumberPrefixCount + kAutoFillPhoneNumberSuffixCount)); |
| 634 if (has_valid_suffix_and_prefix && | 662 if (has_valid_suffix_and_prefix && |
| 635 field->size() == kAutoFillPhoneNumberPrefixCount) { | 663 field->size() == kAutoFillPhoneNumberPrefixCount) { |
| 636 number = number.substr(kAutoFillPhoneNumberPrefixOffset, | 664 number = number.substr(kAutoFillPhoneNumberPrefixOffset, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 656 continue; | 684 continue; |
| 657 | 685 |
| 658 DeterminePossibleFieldTypes(form_structure); | 686 DeterminePossibleFieldTypes(form_structure); |
| 659 form_structures_.push_back(form_structure); | 687 form_structures_.push_back(form_structure); |
| 660 } | 688 } |
| 661 | 689 |
| 662 // If none of the forms were parsed, no use querying the server. | 690 // If none of the forms were parsed, no use querying the server. |
| 663 if (!form_structures_.empty()) | 691 if (!form_structures_.empty()) |
| 664 download_manager_.StartQueryRequest(form_structures_); | 692 download_manager_.StartQueryRequest(form_structures_); |
| 665 } | 693 } |
| OLD | NEW |