OLD | NEW |
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/webui/options/autofill_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 // removed). This will activate the editor for a profile that has been | 481 // removed). This will activate the editor for a profile that has been |
482 // removed. Do nothing in that case. | 482 // removed. Do nothing in that case. |
483 return; | 483 return; |
484 } | 484 } |
485 | 485 |
486 DictionaryValue address; | 486 DictionaryValue address; |
487 address.SetString("guid", profile->guid()); | 487 address.SetString("guid", profile->guid()); |
488 scoped_ptr<ListValue> list; | 488 scoped_ptr<ListValue> list; |
489 GetNameList(*profile, &list); | 489 GetNameList(*profile, &list); |
490 address.Set("fullName", list.release()); | 490 address.Set("fullName", list.release()); |
491 address.SetString("companyName", profile->GetInfo(COMPANY_NAME)); | 491 address.SetString("companyName", profile->GetRawInfo(COMPANY_NAME)); |
492 address.SetString("addrLine1", profile->GetInfo(ADDRESS_HOME_LINE1)); | 492 address.SetString("addrLine1", profile->GetRawInfo(ADDRESS_HOME_LINE1)); |
493 address.SetString("addrLine2", profile->GetInfo(ADDRESS_HOME_LINE2)); | 493 address.SetString("addrLine2", profile->GetRawInfo(ADDRESS_HOME_LINE2)); |
494 address.SetString("city", profile->GetInfo(ADDRESS_HOME_CITY)); | 494 address.SetString("city", profile->GetRawInfo(ADDRESS_HOME_CITY)); |
495 address.SetString("state", profile->GetInfo(ADDRESS_HOME_STATE)); | 495 address.SetString("state", profile->GetRawInfo(ADDRESS_HOME_STATE)); |
496 address.SetString("postalCode", profile->GetInfo(ADDRESS_HOME_ZIP)); | 496 address.SetString("postalCode", profile->GetRawInfo(ADDRESS_HOME_ZIP)); |
497 address.SetString("country", profile->CountryCode()); | 497 address.SetString("country", profile->CountryCode()); |
498 GetValueList(*profile, PHONE_HOME_WHOLE_NUMBER, &list); | 498 GetValueList(*profile, PHONE_HOME_WHOLE_NUMBER, &list); |
499 address.Set("phone", list.release()); | 499 address.Set("phone", list.release()); |
500 GetValueList(*profile, EMAIL_ADDRESS, &list); | 500 GetValueList(*profile, EMAIL_ADDRESS, &list); |
501 address.Set("email", list.release()); | 501 address.Set("email", list.release()); |
502 | 502 |
503 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); | 503 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); |
504 } | 504 } |
505 | 505 |
506 void AutofillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { | 506 void AutofillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { |
(...skipping 11 matching lines...) Expand all Loading... |
518 // quickly click again on the list item before the item is removed (since | 518 // quickly click again on the list item before the item is removed (since |
519 // the list is not updated until the model tells the list an item has been | 519 // the list is not updated until the model tells the list an item has been |
520 // removed). This will activate the editor for a profile that has been | 520 // removed). This will activate the editor for a profile that has been |
521 // removed. Do nothing in that case. | 521 // removed. Do nothing in that case. |
522 return; | 522 return; |
523 } | 523 } |
524 | 524 |
525 DictionaryValue credit_card_data; | 525 DictionaryValue credit_card_data; |
526 credit_card_data.SetString("guid", credit_card->guid()); | 526 credit_card_data.SetString("guid", credit_card->guid()); |
527 credit_card_data.SetString("nameOnCard", | 527 credit_card_data.SetString("nameOnCard", |
528 credit_card->GetInfo(CREDIT_CARD_NAME)); | 528 credit_card->GetRawInfo(CREDIT_CARD_NAME)); |
529 credit_card_data.SetString("creditCardNumber", | 529 credit_card_data.SetString("creditCardNumber", |
530 credit_card->GetInfo(CREDIT_CARD_NUMBER)); | 530 credit_card->GetRawInfo(CREDIT_CARD_NUMBER)); |
531 credit_card_data.SetString("expirationMonth", | 531 credit_card_data.SetString("expirationMonth", |
532 credit_card->GetInfo(CREDIT_CARD_EXP_MONTH)); | 532 credit_card->GetRawInfo(CREDIT_CARD_EXP_MONTH)); |
533 credit_card_data.SetString( | 533 credit_card_data.SetString( |
534 "expirationYear", | 534 "expirationYear", |
535 credit_card->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 535 credit_card->GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
536 | 536 |
537 web_ui()->CallJavascriptFunction("AutofillOptions.editCreditCard", | 537 web_ui()->CallJavascriptFunction("AutofillOptions.editCreditCard", |
538 credit_card_data); | 538 credit_card_data); |
539 } | 539 } |
540 | 540 |
541 void AutofillOptionsHandler::SetAddress(const ListValue* args) { | 541 void AutofillOptionsHandler::SetAddress(const ListValue* args) { |
542 if (!IsPersonalDataLoaded()) | 542 if (!IsPersonalDataLoaded()) |
543 return; | 543 return; |
544 | 544 |
545 std::string guid; | 545 std::string guid; |
546 if (!args->GetString(0, &guid)) { | 546 if (!args->GetString(0, &guid)) { |
547 NOTREACHED(); | 547 NOTREACHED(); |
548 return; | 548 return; |
549 } | 549 } |
550 | 550 |
551 AutofillProfile profile(guid); | 551 AutofillProfile profile(guid); |
552 | 552 |
553 std::string country_code; | 553 std::string country_code; |
554 string16 value; | 554 string16 value; |
555 const ListValue* list_value; | 555 const ListValue* list_value; |
556 if (args->GetList(1, &list_value)) | 556 if (args->GetList(1, &list_value)) |
557 SetNameList(list_value, &profile); | 557 SetNameList(list_value, &profile); |
| 558 |
558 if (args->GetString(2, &value)) | 559 if (args->GetString(2, &value)) |
559 profile.SetInfo(COMPANY_NAME, value); | 560 profile.SetRawInfo(COMPANY_NAME, value); |
| 561 |
560 if (args->GetString(3, &value)) | 562 if (args->GetString(3, &value)) |
561 profile.SetInfo(ADDRESS_HOME_LINE1, value); | 563 profile.SetRawInfo(ADDRESS_HOME_LINE1, value); |
| 564 |
562 if (args->GetString(4, &value)) | 565 if (args->GetString(4, &value)) |
563 profile.SetInfo(ADDRESS_HOME_LINE2, value); | 566 profile.SetRawInfo(ADDRESS_HOME_LINE2, value); |
| 567 |
564 if (args->GetString(5, &value)) | 568 if (args->GetString(5, &value)) |
565 profile.SetInfo(ADDRESS_HOME_CITY, value); | 569 profile.SetRawInfo(ADDRESS_HOME_CITY, value); |
| 570 |
566 if (args->GetString(6, &value)) | 571 if (args->GetString(6, &value)) |
567 profile.SetInfo(ADDRESS_HOME_STATE, value); | 572 profile.SetRawInfo(ADDRESS_HOME_STATE, value); |
| 573 |
568 if (args->GetString(7, &value)) | 574 if (args->GetString(7, &value)) |
569 profile.SetInfo(ADDRESS_HOME_ZIP, value); | 575 profile.SetRawInfo(ADDRESS_HOME_ZIP, value); |
| 576 |
570 if (args->GetString(8, &country_code)) | 577 if (args->GetString(8, &country_code)) |
571 profile.SetCountryCode(country_code); | 578 profile.SetCountryCode(country_code); |
| 579 |
572 if (args->GetList(9, &list_value)) | 580 if (args->GetList(9, &list_value)) |
573 SetValueList(list_value, PHONE_HOME_WHOLE_NUMBER, &profile); | 581 SetValueList(list_value, PHONE_HOME_WHOLE_NUMBER, &profile); |
| 582 |
574 if (args->GetList(10, &list_value)) | 583 if (args->GetList(10, &list_value)) |
575 SetValueList(list_value, EMAIL_ADDRESS, &profile); | 584 SetValueList(list_value, EMAIL_ADDRESS, &profile); |
576 | 585 |
577 if (!base::IsValidGUID(profile.guid())) { | 586 if (!base::IsValidGUID(profile.guid())) { |
578 profile.set_guid(base::GenerateGUID()); | 587 profile.set_guid(base::GenerateGUID()); |
579 personal_data_->AddProfile(profile); | 588 personal_data_->AddProfile(profile); |
580 } else { | 589 } else { |
581 personal_data_->UpdateProfile(profile); | 590 personal_data_->UpdateProfile(profile); |
582 } | 591 } |
583 } | 592 } |
584 | 593 |
585 void AutofillOptionsHandler::SetCreditCard(const ListValue* args) { | 594 void AutofillOptionsHandler::SetCreditCard(const ListValue* args) { |
586 if (!IsPersonalDataLoaded()) | 595 if (!IsPersonalDataLoaded()) |
587 return; | 596 return; |
588 | 597 |
589 std::string guid; | 598 std::string guid; |
590 if (!args->GetString(0, &guid)) { | 599 if (!args->GetString(0, &guid)) { |
591 NOTREACHED(); | 600 NOTREACHED(); |
592 return; | 601 return; |
593 } | 602 } |
594 | 603 |
595 CreditCard credit_card(guid); | 604 CreditCard credit_card(guid); |
596 | 605 |
597 string16 value; | 606 string16 value; |
598 if (args->GetString(1, &value)) | 607 if (args->GetString(1, &value)) |
599 credit_card.SetInfo(CREDIT_CARD_NAME, value); | 608 credit_card.SetRawInfo(CREDIT_CARD_NAME, value); |
| 609 |
600 if (args->GetString(2, &value)) | 610 if (args->GetString(2, &value)) |
601 credit_card.SetInfo(CREDIT_CARD_NUMBER, value); | 611 credit_card.SetRawInfo(CREDIT_CARD_NUMBER, value); |
| 612 |
602 if (args->GetString(3, &value)) | 613 if (args->GetString(3, &value)) |
603 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, value); | 614 credit_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, value); |
| 615 |
604 if (args->GetString(4, &value)) | 616 if (args->GetString(4, &value)) |
605 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value); | 617 credit_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value); |
606 | 618 |
607 if (!base::IsValidGUID(credit_card.guid())) { | 619 if (!base::IsValidGUID(credit_card.guid())) { |
608 credit_card.set_guid(base::GenerateGUID()); | 620 credit_card.set_guid(base::GenerateGUID()); |
609 personal_data_->AddCreditCard(credit_card); | 621 personal_data_->AddCreditCard(credit_card); |
610 } else { | 622 } else { |
611 personal_data_->UpdateCreditCard(credit_card); | 623 personal_data_->UpdateCreditCard(credit_card); |
612 } | 624 } |
613 } | 625 } |
614 | 626 |
615 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { | 627 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { |
616 if (!IsPersonalDataLoaded()) | 628 if (!IsPersonalDataLoaded()) |
617 return; | 629 return; |
618 | 630 |
619 scoped_ptr<ListValue> list_value = ValidatePhoneArguments(args); | 631 scoped_ptr<ListValue> list_value = ValidatePhoneArguments(args); |
620 | 632 |
621 web_ui()->CallJavascriptFunction( | 633 web_ui()->CallJavascriptFunction( |
622 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 634 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
623 } | 635 } |
624 | 636 |
625 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 637 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
626 return personal_data_ && personal_data_->IsDataLoaded(); | 638 return personal_data_ && personal_data_->IsDataLoaded(); |
627 } | 639 } |
628 | 640 |
629 } // namespace options | 641 } // namespace options |
OLD | NEW |