| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/extensions/api/autofill_private/autofill_util.h" | 5 #include "chrome/browser/extensions/api/autofill_private/autofill_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" | 15 #include "chrome/browser/extensions/api/settings_private/prefs_util.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
| 17 #include "chrome/common/extensions/api/autofill_private.h" | 18 #include "chrome/common/extensions/api/autofill_private.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "components/autofill/core/browser/autofill_country.h" |
| 19 #include "components/autofill/core/browser/autofill_profile.h" | 21 #include "components/autofill/core/browser/autofill_profile.h" |
| 20 #include "components/autofill/core/browser/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
| 21 #include "components/autofill/core/browser/credit_card.h" | 23 #include "components/autofill/core/browser/credit_card.h" |
| 22 #include "components/autofill/core/browser/field_types.h" | 24 #include "components/autofill/core/browser/field_types.h" |
| 23 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 24 #include "grit/components_strings.h" | 26 #include "grit/components_strings.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 26 | 28 |
| 27 namespace autofill_private = extensions::api::autofill_private; | 29 namespace autofill_private = extensions::api::autofill_private; |
| 28 | 30 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]); | 110 metadata->summary_label = base::UTF16ToUTF8(label_pieces[0]); |
| 109 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( | 111 metadata->summary_sublabel.reset(new std::string(base::UTF16ToUTF8( |
| 110 label.substr(label_pieces[0].size())))); | 112 label.substr(label_pieces[0].size())))); |
| 111 metadata->is_local.reset(new bool( | 113 metadata->is_local.reset(new bool( |
| 112 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE)); | 114 profile.record_type() == autofill::AutofillProfile::LOCAL_PROFILE)); |
| 113 address.metadata = std::move(metadata); | 115 address.metadata = std::move(metadata); |
| 114 | 116 |
| 115 return address; | 117 return address; |
| 116 } | 118 } |
| 117 | 119 |
| 120 autofill_private::CountryEntry CountryToCountryEntry( |
| 121 autofill::AutofillCountry* country) { |
| 122 autofill_private::CountryEntry entry; |
| 123 |
| 124 // A null |country| means "insert a space here", so we add a country w/o a |
| 125 // |name| or |country_code| to the list and let the UI handle it. |
| 126 if (country) { |
| 127 entry.name.reset(new std::string(base::UTF16ToUTF8(country->name()))); |
| 128 entry.country_code.reset(new std::string(country->country_code())); |
| 129 } |
| 130 |
| 131 return entry; |
| 132 } |
| 133 |
| 118 autofill_private::CreditCardEntry CreditCardToCreditCardEntry( | 134 autofill_private::CreditCardEntry CreditCardToCreditCardEntry( |
| 119 const autofill::CreditCard& credit_card) { | 135 const autofill::CreditCard& credit_card) { |
| 120 autofill_private::CreditCardEntry card; | 136 autofill_private::CreditCardEntry card; |
| 121 | 137 |
| 122 // Add all credit card fields to the entry. | 138 // Add all credit card fields to the entry. |
| 123 card.guid.reset(new std::string(credit_card.guid())); | 139 card.guid.reset(new std::string(credit_card.guid())); |
| 124 card.name.reset(new std::string(base::UTF16ToUTF8( | 140 card.name.reset(new std::string(base::UTF16ToUTF8( |
| 125 credit_card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)))); | 141 credit_card.GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)))); |
| 126 card.card_number.reset(new std::string( | 142 card.card_number.reset(new std::string( |
| 127 base::UTF16ToUTF8(credit_card.GetRawInfo(autofill::CREDIT_CARD_NUMBER)))); | 143 base::UTF16ToUTF8(credit_card.GetRawInfo(autofill::CREDIT_CARD_NUMBER)))); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 &labels); | 180 &labels); |
| 165 DCHECK_EQ(labels.size(), profiles.size()); | 181 DCHECK_EQ(labels.size(), profiles.size()); |
| 166 | 182 |
| 167 AddressEntryList list; | 183 AddressEntryList list; |
| 168 for (size_t i = 0; i < profiles.size(); ++i) | 184 for (size_t i = 0; i < profiles.size(); ++i) |
| 169 list.push_back(ProfileToAddressEntry(*profiles[i], labels[i])); | 185 list.push_back(ProfileToAddressEntry(*profiles[i], labels[i])); |
| 170 | 186 |
| 171 return list; | 187 return list; |
| 172 } | 188 } |
| 173 | 189 |
| 190 CountryEntryList GenerateCountryList( |
| 191 const autofill::PersonalDataManager& personal_data) { |
| 192 autofill::CountryComboboxModel model; |
| 193 model.SetCountries(personal_data, base::Callback<bool(const std::string&)>()); |
| 194 const std::vector<autofill::AutofillCountry*>& countries = model.countries(); |
| 195 |
| 196 CountryEntryList list; |
| 197 |
| 198 for (size_t i = 0; i < countries.size(); ++i) |
| 199 list.push_back(CountryToCountryEntry(countries[i])); |
| 200 |
| 201 return list; |
| 202 } |
| 203 |
| 174 CreditCardEntryList GenerateCreditCardList( | 204 CreditCardEntryList GenerateCreditCardList( |
| 175 const autofill::PersonalDataManager& personal_data) { | 205 const autofill::PersonalDataManager& personal_data) { |
| 176 const std::vector<autofill::CreditCard*>& cards = | 206 const std::vector<autofill::CreditCard*>& cards = |
| 177 personal_data.GetCreditCards(); | 207 personal_data.GetCreditCards(); |
| 178 | 208 |
| 179 CreditCardEntryList list; | 209 CreditCardEntryList list; |
| 180 for (const autofill::CreditCard* card : cards) | 210 for (const autofill::CreditCard* card : cards) |
| 181 list.push_back(CreditCardToCreditCardEntry(*card)); | 211 list.push_back(CreditCardToCreditCardEntry(*card)); |
| 182 | 212 |
| 183 return list; | 213 return list; |
| 184 } | 214 } |
| 185 | 215 |
| 186 } // namespace autofill_util | 216 } // namespace autofill_util |
| 187 | 217 |
| 188 } // namespace extensions | 218 } // namespace extensions |
| OLD | NEW |