| 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 18 matching lines...) Expand all Loading... |
| 29 #include "grit/components_strings.h" | 29 #include "grit/components_strings.h" |
| 30 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 31 #include "third_party/libaddressinput/messages.h" | 31 #include "third_party/libaddressinput/messages.h" |
| 32 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 32 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" |
| 33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" | 33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" |
| 34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | 34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/webui/web_ui_util.h" | 36 #include "ui/base/webui/web_ui_util.h" |
| 37 | 37 |
| 38 using autofill::AutofillCountry; | 38 using autofill::AutofillCountry; |
| 39 using autofill::AutofillType; |
| 39 using autofill::ServerFieldType; | 40 using autofill::ServerFieldType; |
| 40 using autofill::AutofillProfile; | 41 using autofill::AutofillProfile; |
| 41 using autofill::CreditCard; | 42 using autofill::CreditCard; |
| 42 using autofill::PersonalDataManager; | 43 using autofill::PersonalDataManager; |
| 43 using i18n::addressinput::AddressUiComponent; | 44 using i18n::addressinput::AddressUiComponent; |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 const char kSettingsOrigin[] = "Chrome settings"; | 48 const char kSettingsOrigin[] = "Chrome settings"; |
| 48 | 49 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 194 |
| 194 // |GetRawMultiInfo()| always returns at least one, potentially empty, item. | 195 // |GetRawMultiInfo()| always returns at least one, potentially empty, item. |
| 195 if (values.size() == 1 && values.front().empty()) | 196 if (values.size() == 1 && values.front().empty()) |
| 196 return; | 197 return; |
| 197 | 198 |
| 198 for (size_t i = 0; i < values.size(); ++i) { | 199 for (size_t i = 0; i < values.size(); ++i) { |
| 199 (*list)->Set(i, new base::StringValue(values[i])); | 200 (*list)->Set(i, new base::StringValue(values[i])); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 // Set the multi-valued element for |type| from input |list| values. | 204 // Converts a ListValue of StringValues to a vector of string16s. |
| 204 void SetValueList(const base::ListValue* list, | 205 void ListValueToStringVector(const base::ListValue& list, |
| 205 ServerFieldType type, | 206 std::vector<base::string16>* output) { |
| 206 AutofillProfile* profile) { | 207 output->resize(list.GetSize()); |
| 207 std::vector<base::string16> values(list->GetSize()); | 208 for (size_t i = 0; i < list.GetSize(); ++i) { |
| 208 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 209 base::string16 value; | 209 base::string16 value; |
| 210 if (list->GetString(i, &value)) | 210 if (list.GetString(i, &value)) |
| 211 values[i] = value; | 211 (*output)[i].swap(value); |
| 212 } | 212 } |
| 213 profile->SetRawMultiInfo(type, values); | |
| 214 } | 213 } |
| 215 | 214 |
| 216 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from | 215 // Pulls the phone number |index|, |phone_number_list|, and |country_code| from |
| 217 // the |args| input. | 216 // the |args| input. |
| 218 void ExtractPhoneNumberInformation(const base::ListValue* args, | 217 void ExtractPhoneNumberInformation(const base::ListValue* args, |
| 219 size_t* index, | 218 size_t* index, |
| 220 const base::ListValue** phone_number_list, | 219 const base::ListValue** phone_number_list, |
| 221 std::string* country_code) { | 220 std::string* country_code) { |
| 222 // Retrieve index as a |double|, as that is how it comes across from | 221 // Retrieve index as a |double|, as that is how it comes across from |
| 223 // JavaScript. | 222 // JavaScript. |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 std::string guid; | 593 std::string guid; |
| 595 if (!args->GetString(arg_counter++, &guid)) { | 594 if (!args->GetString(arg_counter++, &guid)) { |
| 596 NOTREACHED(); | 595 NOTREACHED(); |
| 597 return; | 596 return; |
| 598 } | 597 } |
| 599 | 598 |
| 600 AutofillProfile profile(guid, kSettingsOrigin); | 599 AutofillProfile profile(guid, kSettingsOrigin); |
| 601 | 600 |
| 602 base::string16 value; | 601 base::string16 value; |
| 603 const base::ListValue* list_value; | 602 const base::ListValue* list_value; |
| 604 if (args->GetList(arg_counter++, &list_value)) | 603 if (args->GetList(arg_counter++, &list_value)) { |
| 605 SetValueList(list_value, autofill::NAME_FULL, &profile); | 604 std::vector<base::string16> values; |
| 605 ListValueToStringVector(*list_value, &values); |
| 606 profile.SetMultiInfo(AutofillType(autofill::NAME_FULL), |
| 607 values, |
| 608 g_browser_process->GetApplicationLocale()); |
| 609 } |
| 606 | 610 |
| 607 if (args->GetString(arg_counter++, &value)) | 611 if (args->GetString(arg_counter++, &value)) |
| 608 profile.SetRawInfo(autofill::COMPANY_NAME, value); | 612 profile.SetRawInfo(autofill::COMPANY_NAME, value); |
| 609 | 613 |
| 610 if (args->GetString(arg_counter++, &value)) | 614 if (args->GetString(arg_counter++, &value)) |
| 611 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value); | 615 profile.SetRawInfo(autofill::ADDRESS_HOME_STREET_ADDRESS, value); |
| 612 | 616 |
| 613 if (args->GetString(arg_counter++, &value)) | 617 if (args->GetString(arg_counter++, &value)) |
| 614 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value); | 618 profile.SetRawInfo(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY, value); |
| 615 | 619 |
| 616 if (args->GetString(arg_counter++, &value)) | 620 if (args->GetString(arg_counter++, &value)) |
| 617 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value); | 621 profile.SetRawInfo(autofill::ADDRESS_HOME_CITY, value); |
| 618 | 622 |
| 619 if (args->GetString(arg_counter++, &value)) | 623 if (args->GetString(arg_counter++, &value)) |
| 620 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value); | 624 profile.SetRawInfo(autofill::ADDRESS_HOME_STATE, value); |
| 621 | 625 |
| 622 if (args->GetString(arg_counter++, &value)) | 626 if (args->GetString(arg_counter++, &value)) |
| 623 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value); | 627 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, value); |
| 624 | 628 |
| 625 if (args->GetString(arg_counter++, &value)) | 629 if (args->GetString(arg_counter++, &value)) |
| 626 profile.SetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE, value); | 630 profile.SetRawInfo(autofill::ADDRESS_HOME_SORTING_CODE, value); |
| 627 | 631 |
| 628 if (args->GetString(arg_counter++, &value)) | 632 if (args->GetString(arg_counter++, &value)) |
| 629 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, value); | 633 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY, value); |
| 630 | 634 |
| 631 if (args->GetList(arg_counter++, &list_value)) | 635 if (args->GetList(arg_counter++, &list_value)) { |
| 632 SetValueList(list_value, autofill::PHONE_HOME_WHOLE_NUMBER, &profile); | 636 std::vector<base::string16> values; |
| 637 ListValueToStringVector(*list_value, &values); |
| 638 profile.SetRawMultiInfo(autofill::PHONE_HOME_WHOLE_NUMBER, values); |
| 639 } |
| 633 | 640 |
| 634 if (args->GetList(arg_counter++, &list_value)) | 641 if (args->GetList(arg_counter++, &list_value)) { |
| 635 SetValueList(list_value, autofill::EMAIL_ADDRESS, &profile); | 642 std::vector<base::string16> values; |
| 643 ListValueToStringVector(*list_value, &values); |
| 644 profile.SetRawMultiInfo(autofill::EMAIL_ADDRESS, values); |
| 645 } |
| 636 | 646 |
| 637 if (args->GetString(arg_counter++, &value)) | 647 if (args->GetString(arg_counter++, &value)) |
| 638 profile.set_language_code(base::UTF16ToUTF8(value)); | 648 profile.set_language_code(base::UTF16ToUTF8(value)); |
| 639 | 649 |
| 640 if (!base::IsValidGUID(profile.guid())) { | 650 if (!base::IsValidGUID(profile.guid())) { |
| 641 profile.set_guid(base::GenerateGUID()); | 651 profile.set_guid(base::GenerateGUID()); |
| 642 personal_data_->AddProfile(profile); | 652 personal_data_->AddProfile(profile); |
| 643 } else { | 653 } else { |
| 644 personal_data_->UpdateProfile(profile); | 654 personal_data_->UpdateProfile(profile); |
| 645 } | 655 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 | 696 |
| 687 web_ui()->CallJavascriptFunction( | 697 web_ui()->CallJavascriptFunction( |
| 688 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 698 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
| 689 } | 699 } |
| 690 | 700 |
| 691 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 701 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
| 692 return personal_data_ && personal_data_->IsDataLoaded(); | 702 return personal_data_ && personal_data_->IsDataLoaded(); |
| 693 } | 703 } |
| 694 | 704 |
| 695 } // namespace options | 705 } // namespace options |
| OLD | NEW |