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" |
| 11 #include "base/guid.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/string16.h" | 13 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/browser/autofill/autofill_country.h" | 17 #include "chrome/browser/autofill/autofill_country.h" |
17 #include "chrome/browser/autofill/autofill_profile.h" | 18 #include "chrome/browser/autofill/autofill_profile.h" |
18 #include "chrome/browser/autofill/credit_card.h" | 19 #include "chrome/browser/autofill/credit_card.h" |
19 #include "chrome/browser/autofill/personal_data_manager.h" | 20 #include "chrome/browser/autofill/personal_data_manager.h" |
20 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 21 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
21 #include "chrome/browser/autofill/phone_number_i18n.h" | 22 #include "chrome/browser/autofill/phone_number_i18n.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/webui/web_ui_util.h" | 24 #include "chrome/browser/ui/webui/web_ui_util.h" |
24 #include "chrome/common/guid.h" | |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "grit/webkit_resources.h" | 28 #include "grit/webkit_resources.h" |
29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Converts a credit card type to the appropriate resource ID of the CC icon. | 33 // Converts a credit card type to the appropriate resource ID of the CC icon. |
34 int CreditCardTypeToResourceID(const std::string& type) { | 34 int CreditCardTypeToResourceID(const std::string& type) { |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 profile.SetInfo(ADDRESS_HOME_STATE, value); | 565 profile.SetInfo(ADDRESS_HOME_STATE, value); |
566 if (args->GetString(7, &value)) | 566 if (args->GetString(7, &value)) |
567 profile.SetInfo(ADDRESS_HOME_ZIP, value); | 567 profile.SetInfo(ADDRESS_HOME_ZIP, value); |
568 if (args->GetString(8, &country_code)) | 568 if (args->GetString(8, &country_code)) |
569 profile.SetCountryCode(country_code); | 569 profile.SetCountryCode(country_code); |
570 if (args->GetList(9, &list_value)) | 570 if (args->GetList(9, &list_value)) |
571 SetValueList(list_value, PHONE_HOME_WHOLE_NUMBER, &profile); | 571 SetValueList(list_value, PHONE_HOME_WHOLE_NUMBER, &profile); |
572 if (args->GetList(10, &list_value)) | 572 if (args->GetList(10, &list_value)) |
573 SetValueList(list_value, EMAIL_ADDRESS, &profile); | 573 SetValueList(list_value, EMAIL_ADDRESS, &profile); |
574 | 574 |
575 if (!guid::IsValidGUID(profile.guid())) { | 575 if (!base::IsValidGUID(profile.guid())) { |
576 profile.set_guid(guid::GenerateGUID()); | 576 profile.set_guid(base::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 (!IsPersonalDataLoaded()) | 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 (!base::IsValidGUID(credit_card.guid())) { |
606 credit_card.set_guid(guid::GenerateGUID()); | 606 credit_card.set_guid(base::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 (!IsPersonalDataLoaded()) | 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 { | 624 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
625 return personal_data_ && personal_data_->IsDataLoaded(); | 625 return personal_data_ && personal_data_->IsDataLoaded(); |
626 } | 626 } |
627 | 627 |
628 } // namespace options2 | 628 } // namespace options2 |
OLD | NEW |