Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(865)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller.cc

Issue 11299323: [imperative autofill] handle filling in <select> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: typo fix Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/autofill/autofill_dialog_controller.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autofill/autofill_manager.h" 9 #include "chrome/browser/autofill/autofill_manager.h"
10 #include "chrome/browser/autofill/personal_data_manager.h" 10 #include "chrome/browser/autofill/personal_data_manager.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 FillOutputForSection(SECTION_EMAIL); 313 FillOutputForSection(SECTION_EMAIL);
314 FillOutputForSection(SECTION_CC); 314 FillOutputForSection(SECTION_CC);
315 FillOutputForSection(SECTION_BILLING); 315 FillOutputForSection(SECTION_BILLING);
316 if (view_->UseBillingForShipping()) { 316 if (view_->UseBillingForShipping()) {
317 FillOutputForSectionWithComparator( 317 FillOutputForSectionWithComparator(
318 SECTION_BILLING, 318 SECTION_BILLING,
319 base::Bind(DetailInputMatchesFieldWithSection, "shipping")); 319 base::Bind(DetailInputMatchesFieldWithSection, "shipping"));
320 } else { 320 } else {
321 FillOutputForSection(SECTION_SHIPPING); 321 FillOutputForSection(SECTION_SHIPPING);
322 } 322 }
323 callback_.Run(&form_structure_);
324 } else {
325 callback_.Run(NULL);
Dan Beam 2012/12/04 03:31:51 this part lgtm :)
323 } 326 }
324 327
325 callback_.Run(&form_structure_);
326 delete this; 328 delete this;
327 } 329 }
328 330
329 void AutofillDialogController::GenerateComboboxModels() { 331 void AutofillDialogController::GenerateComboboxModels() {
330 PersonalDataManager* manager = 332 PersonalDataManager* manager =
331 PersonalDataManagerFactory::GetForProfile(profile_); 333 PersonalDataManagerFactory::GetForProfile(profile_);
332 const std::vector<CreditCard*>& cards = manager->credit_cards(); 334 const std::vector<CreditCard*>& cards = manager->credit_cards();
333 for (size_t i = 0; i < cards.size(); ++i) { 335 for (size_t i = 0; i < cards.size(); ++i) {
334 suggested_cc_.AddItem(cards[i]->guid(), cards[i]->Label()); 336 suggested_cc_.AddItem(cards[i]->guid(), cards[i]->Label());
335 } 337 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 std::string guid = model->GetItemKeyAt(suggestion_selection); 384 std::string guid = model->GetItemKeyAt(suggestion_selection);
383 PersonalDataManager* manager = 385 PersonalDataManager* manager =
384 PersonalDataManagerFactory::GetForProfile(profile_); 386 PersonalDataManagerFactory::GetForProfile(profile_);
385 FormGroup* form_group = section == SECTION_CC ? 387 FormGroup* form_group = section == SECTION_CC ?
386 static_cast<FormGroup*>(manager->GetCreditCardByGUID(guid)) : 388 static_cast<FormGroup*>(manager->GetCreditCardByGUID(guid)) :
387 static_cast<FormGroup*>(manager->GetProfileByGUID(guid)); 389 static_cast<FormGroup*>(manager->GetProfileByGUID(guid));
388 // TODO(estade): we shouldn't let this happen. 390 // TODO(estade): we shouldn't let this happen.
389 if (!form_group) 391 if (!form_group)
390 return; 392 return;
391 393
392 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 394 FillFormStructureForSection(*form_group, section, compare);
393 AutofillField* field = form_structure_.field(i);
394 // Only fill in data that is associated with this section.
395 const DetailInputs& inputs = RequestedFieldsForSection(section);
396 for (size_t j = 0; j < inputs.size(); ++j) {
397 if (compare.Run(inputs[j], *field)) {
398 form_group->FillFormField(*field, 0, field);
399 break;
400 }
401 }
402 }
403 } else { 395 } else {
404 // The user manually input data. 396 // The user manually input data.
405 DetailOutputMap output; 397 DetailOutputMap output;
406 view_->GetUserInput(section, &output); 398 view_->GetUserInput(section, &output);
407 399
408 // First fill in |form_structure_| to return to the page. 400 // Save the info as new or edited data, then fill it into |form_structure_|.
409 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
410 AutofillField* field = form_structure_.field(i);
411 for (DetailOutputMap::iterator iter = output.begin();
412 iter != output.end(); ++iter) {
413 if (!iter->second.empty() && compare.Run(*iter->first, *field)) {
414 // TODO(estade): handle select controls and such. Also, canonicalize
415 // the entered data.
416 field->value = iter->second;
417 break;
418 }
419 }
420 }
421
422 // Next, save the info as new or edited data.
423 PersonalDataManager* manager = 401 PersonalDataManager* manager =
424 PersonalDataManagerFactory::GetForProfile(profile_); 402 PersonalDataManagerFactory::GetForProfile(profile_);
425 if (section == SECTION_CC) { 403 if (section == SECTION_CC) {
426 CreditCard card; 404 CreditCard card;
427 FillFormGroupFromOutputs(output, &card); 405 FillFormGroupFromOutputs(output, &card);
428 manager->SaveImportedCreditCard(card); 406 manager->SaveImportedCreditCard(card);
407 FillFormStructureForSection(card, section, compare);
408
409 // CVC needs special-casing because the CreditCard class doesn't store
410 // or handle them. Fill it in directly from |output|.
411 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
412 AutofillField* field = form_structure_.field(i);
413 if (field->type() != CREDIT_CARD_VERIFICATION_CODE)
414 continue;
415
416 for (DetailOutputMap::iterator iter = output.begin();
417 iter != output.end(); ++iter) {
418 if (!iter->second.empty() && compare.Run(*iter->first, *field)) {
419 field->value = iter->second;
420 break;
421 }
422 }
423 }
429 } else { 424 } else {
430 AutofillProfile profile; 425 AutofillProfile profile;
431 FillFormGroupFromOutputs(output, &profile); 426 FillFormGroupFromOutputs(output, &profile);
432 manager->SaveImportedProfile(profile); 427 manager->SaveImportedProfile(profile);
428 FillFormStructureForSection(profile, section, compare);
433 } 429 }
434 } 430 }
435 } 431 }
436 432
437 void AutofillDialogController::FillOutputForSection(DialogSection section) { 433 void AutofillDialogController::FillOutputForSection(DialogSection section) {
438 FillOutputForSectionWithComparator(section, 434 FillOutputForSectionWithComparator(section,
439 base::Bind(DetailInputMatchesField)); 435 base::Bind(DetailInputMatchesField));
440 } 436 }
441 437
438 void AutofillDialogController::FillFormStructureForSection(
439 const FormGroup& form_group,
440 DialogSection section,
441 const InputFieldComparator& compare) {
442 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
443 AutofillField* field = form_structure_.field(i);
444 // Only fill in data that is associated with this section.
445 const DetailInputs& inputs = RequestedFieldsForSection(section);
446 for (size_t j = 0; j < inputs.size(); ++j) {
447 if (compare.Run(inputs[j], *field)) {
448 form_group.FillFormField(*field, 0, field);
449 break;
450 }
451 }
452 }
453 }
454
442 SuggestionsComboboxModel* AutofillDialogController::SuggestionsModelForSection( 455 SuggestionsComboboxModel* AutofillDialogController::SuggestionsModelForSection(
443 DialogSection section) { 456 DialogSection section) {
444 switch (section) { 457 switch (section) {
445 case SECTION_EMAIL: 458 case SECTION_EMAIL:
446 return &suggested_email_; 459 return &suggested_email_;
447 case SECTION_CC: 460 case SECTION_CC:
448 return &suggested_cc_; 461 return &suggested_cc_;
449 case SECTION_BILLING: 462 case SECTION_BILLING:
450 return &suggested_billing_; 463 return &suggested_billing_;
451 case SECTION_SHIPPING: 464 case SECTION_SHIPPING:
452 return &suggested_shipping_; 465 return &suggested_shipping_;
453 } 466 }
454 467
455 NOTREACHED(); 468 NOTREACHED();
456 return NULL; 469 return NULL;
457 } 470 }
458 471
459 } // namespace autofill 472 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller.h ('k') | chrome/renderer/autofill/autofill_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698