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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 DCHECK(tab_contents); | 444 DCHECK(tab_contents); |
445 } | 445 } |
446 | 446 |
447 void AutoFillManager::GetProfileSuggestions(FormStructure* form, | 447 void AutoFillManager::GetProfileSuggestions(FormStructure* form, |
448 const FormField& field, | 448 const FormField& field, |
449 AutoFillType type, | 449 AutoFillType type, |
450 std::vector<string16>* values, | 450 std::vector<string16>* values, |
451 std::vector<string16>* labels, | 451 std::vector<string16>* labels, |
452 std::vector<int>* unique_ids) { | 452 std::vector<int>* unique_ids) { |
453 const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); | 453 const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); |
| 454 std::vector<AutoFillProfile*> matched_profiles; |
454 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); | 455 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); |
455 iter != profiles.end(); ++iter) { | 456 iter != profiles.end(); ++iter) { |
456 AutoFillProfile* profile = *iter; | 457 AutoFillProfile* profile = *iter; |
457 | 458 |
458 // The value of the stored data for this field type in the |profile|. | 459 // The value of the stored data for this field type in the |profile|. |
459 string16 profile_field_value = profile->GetFieldText(type); | 460 string16 profile_field_value = profile->GetFieldText(type); |
460 | 461 |
461 if (!profile_field_value.empty() && | 462 if (!profile_field_value.empty() && |
462 StartsWith(profile_field_value, field.value(), false)) { | 463 StartsWith(profile_field_value, field.value(), false)) { |
463 if (!form->HasBillingFields()) { | 464 matched_profiles.push_back(profile); |
464 values->push_back(profile_field_value); | 465 values->push_back(profile_field_value); |
465 labels->push_back(profile->Label()); | 466 unique_ids->push_back(profile->unique_id()); |
| 467 } |
| 468 } |
| 469 AutoFillProfile::CreateInferredLabels(&matched_profiles, labels, 0, |
| 470 type.field_type()); |
| 471 if (form->HasBillingFields()) { |
| 472 size_t i = 0; |
| 473 std::vector<string16> expanded_values; |
| 474 std::vector<string16> expanded_labels; |
| 475 for (std::vector<AutoFillProfile*>::const_iterator iter = |
| 476 matched_profiles.begin(); iter != matched_profiles.end(); |
| 477 ++iter, ++i) { |
| 478 AutoFillProfile* profile = *iter; |
| 479 for (std::vector<CreditCard*>::const_iterator cc = |
| 480 personal_data_->credit_cards().begin(); |
| 481 cc != personal_data_->credit_cards().end(); ++cc) { |
| 482 expanded_values.push_back((*values)[i]); |
| 483 string16 label = (*labels)[i] + kLabelSeparator + |
| 484 (*cc)->LastFourDigits(); |
| 485 expanded_labels.push_back(label); |
466 unique_ids->push_back(profile->unique_id()); | 486 unique_ids->push_back(profile->unique_id()); |
467 } else { | |
468 for (std::vector<CreditCard*>::const_iterator cc = | |
469 personal_data_->credit_cards().begin(); | |
470 cc != personal_data_->credit_cards().end(); ++cc) { | |
471 values->push_back(profile_field_value); | |
472 | |
473 string16 label = profile->Label() + kLabelSeparator + | |
474 (*cc)->LastFourDigits(); | |
475 labels->push_back(label); | |
476 unique_ids->push_back(profile->unique_id()); | |
477 } | |
478 } | 487 } |
479 } | 488 } |
| 489 expanded_labels.swap(*labels); |
| 490 expanded_values.swap(*values); |
480 } | 491 } |
481 } | 492 } |
482 | 493 |
483 void AutoFillManager::GetBillingProfileSuggestions( | 494 void AutoFillManager::GetBillingProfileSuggestions( |
484 const FormField& field, | 495 const FormField& field, |
485 AutoFillType type, | 496 AutoFillType type, |
486 std::vector<string16>* values, | 497 std::vector<string16>* values, |
487 std::vector<string16>* labels, | 498 std::vector<string16>* labels, |
488 std::vector<int>* unique_ids) { | 499 std::vector<int>* unique_ids) { |
489 std::vector<CreditCard*> matching_creditcards; | 500 std::vector<CreditCard*> matching_creditcards; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 continue; | 656 continue; |
646 | 657 |
647 DeterminePossibleFieldTypes(form_structure); | 658 DeterminePossibleFieldTypes(form_structure); |
648 form_structures_.push_back(form_structure); | 659 form_structures_.push_back(form_structure); |
649 } | 660 } |
650 | 661 |
651 // If none of the forms were parsed, no use querying the server. | 662 // If none of the forms were parsed, no use querying the server. |
652 if (!form_structures_.empty()) | 663 if (!form_structures_.empty()) |
653 download_manager_.StartQueryRequest(form_structures_); | 664 download_manager_.StartQueryRequest(form_structures_); |
654 } | 665 } |
OLD | NEW |