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/options2/autofill_options_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/autofill_options_handler2.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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 398 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
399 localized_strings->SetString("nameOnCardLabel", | 399 localized_strings->SetString("nameOnCardLabel", |
400 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); | 400 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_NAME_ON_CARD)); |
401 localized_strings->SetString("creditCardNumberLabel", | 401 localized_strings->SetString("creditCardNumberLabel", |
402 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); | 402 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_CREDIT_CARD_NUMBER)); |
403 localized_strings->SetString("creditCardExpirationDateLabel", | 403 localized_strings->SetString("creditCardExpirationDateLabel", |
404 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE)); | 404 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EXPIRATION_DATE)); |
405 } | 405 } |
406 | 406 |
407 void AutofillOptionsHandler::LoadAutofillData() { | 407 void AutofillOptionsHandler::LoadAutofillData() { |
408 if (!personal_data_->IsDataLoaded()) | 408 if (!IsPersonalDataLoaded()) |
409 return; | 409 return; |
410 | 410 |
411 ListValue addresses; | 411 ListValue addresses; |
412 for (std::vector<AutofillProfile*>::const_iterator i = | 412 for (std::vector<AutofillProfile*>::const_iterator i = |
413 personal_data_->web_profiles().begin(); | 413 personal_data_->web_profiles().begin(); |
414 i != personal_data_->web_profiles().end(); ++i) { | 414 i != personal_data_->web_profiles().end(); ++i) { |
415 ListValue* entry = new ListValue(); | 415 ListValue* entry = new ListValue(); |
416 entry->Append(new StringValue((*i)->guid())); | 416 entry->Append(new StringValue((*i)->guid())); |
417 entry->Append(new StringValue((*i)->Label())); | 417 entry->Append(new StringValue((*i)->Label())); |
418 addresses.Append(entry); | 418 addresses.Append(entry); |
(...skipping 13 matching lines...) Expand all Loading... |
432 new StringValue(web_ui_util::GetImageDataUrlFromResource(res))); | 432 new StringValue(web_ui_util::GetImageDataUrlFromResource(res))); |
433 entry->Append(new StringValue(LocalizedCreditCardType((*i)->type()))); | 433 entry->Append(new StringValue(LocalizedCreditCardType((*i)->type()))); |
434 credit_cards.Append(entry); | 434 credit_cards.Append(entry); |
435 } | 435 } |
436 | 436 |
437 web_ui()->CallJavascriptFunction("AutofillOptions.setCreditCardList", | 437 web_ui()->CallJavascriptFunction("AutofillOptions.setCreditCardList", |
438 credit_cards); | 438 credit_cards); |
439 } | 439 } |
440 | 440 |
441 void AutofillOptionsHandler::RemoveAddress(const ListValue* args) { | 441 void AutofillOptionsHandler::RemoveAddress(const ListValue* args) { |
442 DCHECK(personal_data_->IsDataLoaded()); | 442 DCHECK(IsPersonalDataLoaded()); |
443 | 443 |
444 std::string guid; | 444 std::string guid; |
445 if (!args->GetString(0, &guid)) { | 445 if (!args->GetString(0, &guid)) { |
446 NOTREACHED(); | 446 NOTREACHED(); |
447 return; | 447 return; |
448 } | 448 } |
449 | 449 |
450 personal_data_->RemoveProfile(guid); | 450 personal_data_->RemoveProfile(guid); |
451 } | 451 } |
452 | 452 |
453 void AutofillOptionsHandler::RemoveCreditCard(const ListValue* args) { | 453 void AutofillOptionsHandler::RemoveCreditCard(const ListValue* args) { |
454 DCHECK(personal_data_->IsDataLoaded()); | 454 DCHECK(IsPersonalDataLoaded()); |
455 | 455 |
456 std::string guid; | 456 std::string guid; |
457 if (!args->GetString(0, &guid)) { | 457 if (!args->GetString(0, &guid)) { |
458 NOTREACHED(); | 458 NOTREACHED(); |
459 return; | 459 return; |
460 } | 460 } |
461 | 461 |
462 personal_data_->RemoveCreditCard(guid); | 462 personal_data_->RemoveCreditCard(guid); |
463 } | 463 } |
464 | 464 |
465 void AutofillOptionsHandler::LoadAddressEditor(const ListValue* args) { | 465 void AutofillOptionsHandler::LoadAddressEditor(const ListValue* args) { |
466 DCHECK(personal_data_->IsDataLoaded()); | 466 DCHECK(IsPersonalDataLoaded()); |
467 | 467 |
468 std::string guid; | 468 std::string guid; |
469 if (!args->GetString(0, &guid)) { | 469 if (!args->GetString(0, &guid)) { |
470 NOTREACHED(); | 470 NOTREACHED(); |
471 return; | 471 return; |
472 } | 472 } |
473 | 473 |
474 AutofillProfile* profile = personal_data_->GetProfileByGUID(guid); | 474 AutofillProfile* profile = personal_data_->GetProfileByGUID(guid); |
475 if (!profile) { | 475 if (!profile) { |
476 // There is a race where a user can click once on the close button and | 476 // There is a race where a user can click once on the close button and |
(...skipping 18 matching lines...) Expand all Loading... |
495 address.SetString("country", profile->CountryCode()); | 495 address.SetString("country", profile->CountryCode()); |
496 GetValueList(*profile, PHONE_HOME_WHOLE_NUMBER, &list); | 496 GetValueList(*profile, PHONE_HOME_WHOLE_NUMBER, &list); |
497 address.Set("phone", list.release()); | 497 address.Set("phone", list.release()); |
498 GetValueList(*profile, EMAIL_ADDRESS, &list); | 498 GetValueList(*profile, EMAIL_ADDRESS, &list); |
499 address.Set("email", list.release()); | 499 address.Set("email", list.release()); |
500 | 500 |
501 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); | 501 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); |
502 } | 502 } |
503 | 503 |
504 void AutofillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { | 504 void AutofillOptionsHandler::LoadCreditCardEditor(const ListValue* args) { |
505 DCHECK(personal_data_->IsDataLoaded()); | 505 DCHECK(IsPersonalDataLoaded()); |
506 | 506 |
507 std::string guid; | 507 std::string guid; |
508 if (!args->GetString(0, &guid)) { | 508 if (!args->GetString(0, &guid)) { |
509 NOTREACHED(); | 509 NOTREACHED(); |
510 return; | 510 return; |
511 } | 511 } |
512 | 512 |
513 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); | 513 CreditCard* credit_card = personal_data_->GetCreditCardByGUID(guid); |
514 if (!credit_card) { | 514 if (!credit_card) { |
515 // There is a race where a user can click once on the close button and | 515 // There is a race where a user can click once on the close button and |
(...skipping 14 matching lines...) Expand all Loading... |
530 credit_card->GetInfo(CREDIT_CARD_EXP_MONTH)); | 530 credit_card->GetInfo(CREDIT_CARD_EXP_MONTH)); |
531 credit_card_data.SetString( | 531 credit_card_data.SetString( |
532 "expirationYear", | 532 "expirationYear", |
533 credit_card->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 533 credit_card->GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
534 | 534 |
535 web_ui()->CallJavascriptFunction("AutofillOptions.editCreditCard", | 535 web_ui()->CallJavascriptFunction("AutofillOptions.editCreditCard", |
536 credit_card_data); | 536 credit_card_data); |
537 } | 537 } |
538 | 538 |
539 void AutofillOptionsHandler::SetAddress(const ListValue* args) { | 539 void AutofillOptionsHandler::SetAddress(const ListValue* args) { |
540 if (!personal_data_->IsDataLoaded()) | 540 if (!IsPersonalDataLoaded()) |
541 return; | 541 return; |
542 | 542 |
543 std::string guid; | 543 std::string guid; |
544 if (!args->GetString(0, &guid)) { | 544 if (!args->GetString(0, &guid)) { |
545 NOTREACHED(); | 545 NOTREACHED(); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 AutofillProfile profile(guid); | 549 AutofillProfile profile(guid); |
550 | 550 |
(...skipping 23 matching lines...) Expand all Loading... |
574 | 574 |
575 if (!guid::IsValidGUID(profile.guid())) { | 575 if (!guid::IsValidGUID(profile.guid())) { |
576 profile.set_guid(guid::GenerateGUID()); | 576 profile.set_guid(guid::GenerateGUID()); |
577 personal_data_->AddProfile(profile); | 577 personal_data_->AddProfile(profile); |
578 } else { | 578 } else { |
579 personal_data_->UpdateProfile(profile); | 579 personal_data_->UpdateProfile(profile); |
580 } | 580 } |
581 } | 581 } |
582 | 582 |
583 void AutofillOptionsHandler::SetCreditCard(const ListValue* args) { | 583 void AutofillOptionsHandler::SetCreditCard(const ListValue* args) { |
584 if (!personal_data_->IsDataLoaded()) | 584 if (!IsPersonalDataLoaded()) |
585 return; | 585 return; |
586 | 586 |
587 std::string guid; | 587 std::string guid; |
588 if (!args->GetString(0, &guid)) { | 588 if (!args->GetString(0, &guid)) { |
589 NOTREACHED(); | 589 NOTREACHED(); |
590 return; | 590 return; |
591 } | 591 } |
592 | 592 |
593 CreditCard credit_card(guid); | 593 CreditCard credit_card(guid); |
594 | 594 |
595 string16 value; | 595 string16 value; |
596 if (args->GetString(1, &value)) | 596 if (args->GetString(1, &value)) |
597 credit_card.SetInfo(CREDIT_CARD_NAME, value); | 597 credit_card.SetInfo(CREDIT_CARD_NAME, value); |
598 if (args->GetString(2, &value)) | 598 if (args->GetString(2, &value)) |
599 credit_card.SetInfo(CREDIT_CARD_NUMBER, value); | 599 credit_card.SetInfo(CREDIT_CARD_NUMBER, value); |
600 if (args->GetString(3, &value)) | 600 if (args->GetString(3, &value)) |
601 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, value); | 601 credit_card.SetInfo(CREDIT_CARD_EXP_MONTH, value); |
602 if (args->GetString(4, &value)) | 602 if (args->GetString(4, &value)) |
603 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value); | 603 credit_card.SetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, value); |
604 | 604 |
605 if (!guid::IsValidGUID(credit_card.guid())) { | 605 if (!guid::IsValidGUID(credit_card.guid())) { |
606 credit_card.set_guid(guid::GenerateGUID()); | 606 credit_card.set_guid(guid::GenerateGUID()); |
607 personal_data_->AddCreditCard(credit_card); | 607 personal_data_->AddCreditCard(credit_card); |
608 } else { | 608 } else { |
609 personal_data_->UpdateCreditCard(credit_card); | 609 personal_data_->UpdateCreditCard(credit_card); |
610 } | 610 } |
611 } | 611 } |
612 | 612 |
613 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { | 613 void AutofillOptionsHandler::ValidatePhoneNumbers(const ListValue* args) { |
614 if (!personal_data_->IsDataLoaded()) | 614 if (!IsPersonalDataLoaded()) |
615 return; | 615 return; |
616 | 616 |
617 ListValue* list_value = NULL; | 617 ListValue* list_value = NULL; |
618 ValidatePhoneArguments(args, &list_value); | 618 ValidatePhoneArguments(args, &list_value); |
619 | 619 |
620 web_ui()->CallJavascriptFunction( | 620 web_ui()->CallJavascriptFunction( |
621 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 621 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
622 } | 622 } |
623 | 623 |
| 624 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
| 625 return personal_data_ && personal_data_->IsDataLoaded(); |
| 626 } |
| 627 |
624 } // namespace options2 | 628 } // namespace options2 |
OLD | NEW |