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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/autofill/autofill_dialog.h" | 10 #include "chrome/browser/autofill/autofill_dialog.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 DCHECK_EQ(form_structure->field_count(), result.fields.size()); | 237 DCHECK_EQ(form_structure->field_count(), result.fields.size()); |
238 | 238 |
239 for (size_t i = 0; i < form_structure->field_count(); ++i) { | 239 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
240 const AutoFillField* field = form_structure->field(i); | 240 const AutoFillField* field = form_structure->field(i); |
241 | 241 |
242 AutoFillType autofill_type(field->type()); | 242 AutoFillType autofill_type(field->type()); |
243 if (credit_card && | 243 if (credit_card && |
244 autofill_type.group() == AutoFillType::CREDIT_CARD) { | 244 autofill_type.group() == AutoFillType::CREDIT_CARD) { |
245 result.fields[i].set_value( | 245 result.fields[i].set_value( |
246 credit_card->GetFieldText(autofill_type)); | 246 credit_card->GetFieldText(autofill_type)); |
| 247 } else if (credit_card && |
| 248 autofill_type.group() == AutoFillType::ADDRESS_BILLING) { |
| 249 FillBillingFormField(credit_card, autofill_type, &result.fields[i]); |
247 } else if (profile) { | 250 } else if (profile) { |
248 FillFormField(profile, autofill_type, &result.fields[i]); | 251 FillFormField(profile, autofill_type, &result.fields[i]); |
249 } | 252 } |
250 } | 253 } |
251 } | 254 } |
252 | 255 |
253 host->AutoFillFormDataFilled(query_id, result); | 256 host->AutoFillFormDataFilled(query_id, result); |
254 return true; | 257 return true; |
255 } | 258 } |
256 | 259 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 string16 creditcard_field_value = | 462 string16 creditcard_field_value = |
460 credit_card->GetFieldText(AutoFillType(type)); | 463 credit_card->GetFieldText(AutoFillType(type)); |
461 if (!creditcard_field_value.empty() && | 464 if (!creditcard_field_value.empty() && |
462 StartsWith(creditcard_field_value, field.value(), false)) { | 465 StartsWith(creditcard_field_value, field.value(), false)) { |
463 values->push_back(credit_card->ObfuscatedNumber()); | 466 values->push_back(credit_card->ObfuscatedNumber()); |
464 labels->push_back(credit_card->Label()); | 467 labels->push_back(credit_card->Label()); |
465 } | 468 } |
466 } | 469 } |
467 } | 470 } |
468 | 471 |
| 472 void AutoFillManager::FillBillingFormField(const CreditCard* credit_card, |
| 473 AutoFillType type, |
| 474 webkit_glue::FormField* field) { |
| 475 DCHECK(credit_card); |
| 476 DCHECK(type.group() == AutoFillType::ADDRESS_BILLING); |
| 477 DCHECK(field); |
| 478 |
| 479 string16 billing_address = credit_card->billing_address(); |
| 480 if (!billing_address.empty()) { |
| 481 AutoFillProfile* profile = NULL; |
| 482 const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); |
| 483 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); |
| 484 iter != profiles.end(); ++iter) { |
| 485 if ((*iter)->Label() == billing_address) { |
| 486 profile = *iter; |
| 487 break; |
| 488 } |
| 489 } |
| 490 |
| 491 if (profile) { |
| 492 FillFormField(profile, type, field); |
| 493 } |
| 494 } |
| 495 } |
| 496 |
469 void AutoFillManager::FillFormField(const AutoFillProfile* profile, | 497 void AutoFillManager::FillFormField(const AutoFillProfile* profile, |
470 AutoFillType type, | 498 AutoFillType type, |
471 webkit_glue::FormField* field) { | 499 webkit_glue::FormField* field) { |
472 DCHECK(profile); | 500 DCHECK(profile); |
473 DCHECK(field); | 501 DCHECK(field); |
474 | 502 |
475 if (type.subgroup() == AutoFillType::PHONE_NUMBER) { | 503 if (type.subgroup() == AutoFillType::PHONE_NUMBER) { |
476 FillPhoneNumberField(profile, field); | 504 FillPhoneNumberField(profile, field); |
477 } else { | 505 } else { |
478 field->set_value(profile->GetFieldText(type)); | 506 field->set_value(profile->GetFieldText(type)); |
(...skipping 10 matching lines...) Expand all Loading... |
489 kAutoFillPhoneNumberPrefixCount); | 517 kAutoFillPhoneNumberPrefixCount); |
490 field->set_value(number); | 518 field->set_value(number); |
491 } else if (field->size() == kAutoFillPhoneNumberSuffixCount) { | 519 } else if (field->size() == kAutoFillPhoneNumberSuffixCount) { |
492 number = number.substr(kAutoFillPhoneNumberSuffixOffset, | 520 number = number.substr(kAutoFillPhoneNumberSuffixOffset, |
493 kAutoFillPhoneNumberSuffixCount); | 521 kAutoFillPhoneNumberSuffixCount); |
494 field->set_value(number); | 522 field->set_value(number); |
495 } else { | 523 } else { |
496 field->set_value(number); | 524 field->set_value(number); |
497 } | 525 } |
498 } | 526 } |
OLD | NEW |