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_private_api.h" | 5 #include "chrome/browser/extensions/api/autofill_private/autofill_private_api.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 | 22 |
23 namespace autofill_private = extensions::api::autofill_private; | 23 namespace autofill_private = extensions::api::autofill_private; |
24 namespace addressinput = i18n::addressinput; | 24 namespace addressinput = i18n::addressinput; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 static const char kSettingsOrigin[] = "Chrome settings"; | 28 static const char kSettingsOrigin[] = "Chrome settings"; |
29 static const char kErrorDataUnavailable[] = "Autofill data unavailable."; | 29 static const char kErrorDataUnavailable[] = "Autofill data unavailable."; |
30 | 30 |
31 // Converts the UTF-8 strings in |input| to UTF-16 strings and adds them to | |
32 // |output|. | |
33 void UTF8VectorToUTF16Vector( | |
34 const std::vector<std::string>& input, | |
35 std::vector<base::string16>* output) { | |
36 // Ensure output is clear. | |
37 output->clear(); | |
38 | |
39 for (const std::string& s : input) | |
40 output->push_back(base::UTF8ToUTF16(s)); | |
41 } | |
42 | |
43 // Fills |components| with the address UI components that should be used to | 31 // Fills |components| with the address UI components that should be used to |
44 // input an address for |country_code| when UI BCP 47 language code is | 32 // input an address for |country_code| when UI BCP 47 language code is |
45 // |ui_language_code|. | 33 // |ui_language_code|. |
46 void PopulateAddressComponents( | 34 void PopulateAddressComponents( |
47 const std::string& country_code, | 35 const std::string& country_code, |
48 const std::string& ui_language_code, | 36 const std::string& ui_language_code, |
49 autofill_private::AddressComponents* address_components) { | 37 autofill_private::AddressComponents* address_components) { |
50 DCHECK(address_components); | 38 DCHECK(address_components); |
51 | 39 |
52 i18n::addressinput::Localization localization; | 40 i18n::addressinput::Localization localization; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 base::UTF8ToUTF16(*address->sorting_code)); | 242 base::UTF8ToUTF16(*address->sorting_code)); |
255 } | 243 } |
256 | 244 |
257 if (address->country_code) { | 245 if (address->country_code) { |
258 profile.SetRawInfo( | 246 profile.SetRawInfo( |
259 autofill::ADDRESS_HOME_COUNTRY, | 247 autofill::ADDRESS_HOME_COUNTRY, |
260 base::UTF8ToUTF16(*address->country_code)); | 248 base::UTF8ToUTF16(*address->country_code)); |
261 } | 249 } |
262 | 250 |
263 if (address->phone_numbers) { | 251 if (address->phone_numbers) { |
264 UTF8VectorToUTF16Vector(*address->phone_numbers, &string16Container); | 252 std::string phone; |
265 profile.SetRawMultiInfo( | 253 if (!address->phone_numbers->empty()) |
266 autofill::PHONE_HOME_WHOLE_NUMBER, string16Container); | 254 phone = address->phone_numbers->at(0); |
| 255 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, |
| 256 base::UTF8ToUTF16(phone)); |
267 } | 257 } |
268 | 258 |
269 if (address->email_addresses) { | 259 if (address->email_addresses) { |
270 UTF8VectorToUTF16Vector(*address->email_addresses, &string16Container); | 260 std::string email; |
271 profile.SetRawMultiInfo(autofill::EMAIL_ADDRESS, string16Container); | 261 if (!address->email_addresses->empty()) |
| 262 email = address->email_addresses->at(0); |
| 263 profile.SetRawInfo(autofill::EMAIL_ADDRESS, base::UTF8ToUTF16(email)); |
272 } | 264 } |
273 | 265 |
274 if (address->language_code) | 266 if (address->language_code) |
275 profile.set_language_code(*address->language_code); | 267 profile.set_language_code(*address->language_code); |
276 | 268 |
277 if (!base::IsValidGUID(profile.guid())) { | 269 if (!base::IsValidGUID(profile.guid())) { |
278 profile.set_guid(base::GenerateGUID()); | 270 profile.set_guid(base::GenerateGUID()); |
279 personal_data->AddProfile(profile); | 271 personal_data->AddProfile(profile); |
280 } else { | 272 } else { |
281 personal_data->UpdateProfile(profile); | 273 personal_data->UpdateProfile(profile); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 error_ = kErrorDataUnavailable; | 429 error_ = kErrorDataUnavailable; |
438 return RespondNow(NoArguments()); | 430 return RespondNow(NoArguments()); |
439 } | 431 } |
440 | 432 |
441 personal_data->ResetFullServerCard(parameters->guid); | 433 personal_data->ResetFullServerCard(parameters->guid); |
442 | 434 |
443 return RespondNow(NoArguments()); | 435 return RespondNow(NoArguments()); |
444 } | 436 } |
445 | 437 |
446 } // namespace extensions | 438 } // namespace extensions |
OLD | NEW |