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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 19 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/sync/profile_sync_service.h" | 22 #include "chrome/browser/sync/profile_sync_service.h" |
22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
23 #include "chrome/browser/ui/autofill/country_combobox_model.h" | 24 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "chrome/grit/chromium_strings.h" | 26 #include "chrome/grit/chromium_strings.h" |
26 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
27 #include "components/autofill/content/browser/wallet/wallet_service_url.h" | 28 #include "components/autofill/content/browser/wallet/wallet_service_url.h" |
28 #include "components/autofill/core/browser/autofill_country.h" | 29 #include "components/autofill/core/browser/autofill_country.h" |
29 #include "components/autofill/core/browser/autofill_profile.h" | 30 #include "components/autofill/core/browser/autofill_profile.h" |
30 #include "components/autofill/core/browser/credit_card.h" | 31 #include "components/autofill/core/browser/credit_card.h" |
31 #include "components/autofill/core/browser/personal_data_manager.h" | 32 #include "components/autofill/core/browser/personal_data_manager.h" |
32 #include "components/autofill/core/browser/phone_number_i18n.h" | 33 #include "components/autofill/core/browser/phone_number_i18n.h" |
33 #include "components/autofill/core/common/autofill_constants.h" | 34 #include "components/autofill/core/common/autofill_constants.h" |
34 #include "components/autofill/core/common/autofill_switches.h" | 35 #include "components/autofill/core/common/autofill_switches.h" |
35 #include "content/public/browser/web_ui.h" | 36 #include "content/public/browser/web_ui.h" |
| 37 #include "grit/components_strings.h" |
36 #include "third_party/libaddressinput/messages.h" | 38 #include "third_party/libaddressinput/messages.h" |
37 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 39 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" |
38 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" | 40 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" |
39 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | 41 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" |
40 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/base/webui/web_ui_util.h" | 43 #include "ui/base/webui/web_ui_util.h" |
42 | 44 |
43 using autofill::AutofillCountry; | 45 using autofill::AutofillCountry; |
44 using autofill::AutofillType; | 46 using autofill::AutofillType; |
45 using autofill::ServerFieldType; | 47 using autofill::ServerFieldType; |
(...skipping 16 matching lines...) Expand all Loading... |
62 static const char kSortingCodeField[] = "sortingCode"; | 64 static const char kSortingCodeField[] = "sortingCode"; |
63 static const char kCountryField[] = "country"; | 65 static const char kCountryField[] = "country"; |
64 | 66 |
65 static const char kComponents[] = "components"; | 67 static const char kComponents[] = "components"; |
66 static const char kLanguageCode[] = "languageCode"; | 68 static const char kLanguageCode[] = "languageCode"; |
67 | 69 |
68 scoped_ptr<base::DictionaryValue> CreditCardToDictionary( | 70 scoped_ptr<base::DictionaryValue> CreditCardToDictionary( |
69 const CreditCard& card) { | 71 const CreditCard& card) { |
70 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 72 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
71 value->SetString("guid", card.guid()); | 73 value->SetString("guid", card.guid()); |
72 value->SetString("label", card.Label()); | 74 std::pair<base::string16, base::string16> label_pieces = card.LabelPieces(); |
| 75 value->SetString("label", label_pieces.first); |
| 76 value->SetString("sublabel", label_pieces.second); |
73 value->SetBoolean("isLocal", card.record_type() == CreditCard::LOCAL_CARD); | 77 value->SetBoolean("isLocal", card.record_type() == CreditCard::LOCAL_CARD); |
74 value->SetBoolean("isCached", | 78 value->SetBoolean("isCached", |
75 card.record_type() == CreditCard::FULL_SERVER_CARD); | 79 card.record_type() == CreditCard::FULL_SERVER_CARD); |
76 return value.Pass(); | 80 return value.Pass(); |
77 } | 81 } |
78 | 82 |
79 // Fills |components| with the address UI components that should be used to | 83 // Fills |components| with the address UI components that should be used to |
80 // input an address for |country_code| when UI BCP 47 language code is | 84 // input an address for |country_code| when UI BCP 47 language code is |
81 // |ui_language_code|. If |components_language_code| is not NULL, then sets it | 85 // |ui_language_code|. If |components_language_code| is not NULL, then sets it |
82 // to the BCP 47 language code that should be used to format the address for | 86 // to the BCP 47 language code that should be used to format the address for |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 void AutofillOptionsHandler::GetLocalizedValues( | 328 void AutofillOptionsHandler::GetLocalizedValues( |
325 base::DictionaryValue* localized_strings) { | 329 base::DictionaryValue* localized_strings) { |
326 DCHECK(localized_strings); | 330 DCHECK(localized_strings); |
327 | 331 |
328 static OptionsStringResource resources[] = { | 332 static OptionsStringResource resources[] = { |
329 { "autofillAddresses", IDS_AUTOFILL_ADDRESSES_GROUP_NAME }, | 333 { "autofillAddresses", IDS_AUTOFILL_ADDRESSES_GROUP_NAME }, |
330 { "autofillCreditCards", IDS_AUTOFILL_CREDITCARDS_GROUP_NAME }, | 334 { "autofillCreditCards", IDS_AUTOFILL_CREDITCARDS_GROUP_NAME }, |
331 { "autofillAddAddress", IDS_AUTOFILL_ADD_ADDRESS_BUTTON }, | 335 { "autofillAddAddress", IDS_AUTOFILL_ADD_ADDRESS_BUTTON }, |
332 { "autofillAddCreditCard", IDS_AUTOFILL_ADD_CREDITCARD_BUTTON }, | 336 { "autofillAddCreditCard", IDS_AUTOFILL_ADD_CREDITCARD_BUTTON }, |
333 { "autofillEditProfileButton", IDS_AUTOFILL_EDIT_PROFILE_BUTTON }, | 337 { "autofillEditProfileButton", IDS_AUTOFILL_EDIT_PROFILE_BUTTON }, |
| 338 { "autofillFromGoogleAccount", IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT }, |
334 { "autofillDescribeLocalCopy", IDS_AUTOFILL_DESCRIBE_LOCAL_COPY }, | 339 { "autofillDescribeLocalCopy", IDS_AUTOFILL_DESCRIBE_LOCAL_COPY }, |
335 { "autofillClearLocalCopyButton", IDS_AUTOFILL_CLEAR_LOCAL_COPY_BUTTON }, | 340 { "autofillClearLocalCopyButton", IDS_AUTOFILL_CLEAR_LOCAL_COPY_BUTTON }, |
336 { "helpButton", IDS_AUTOFILL_HELP_LABEL }, | 341 { "helpButton", IDS_AUTOFILL_HELP_LABEL }, |
337 { "addAddressTitle", IDS_AUTOFILL_ADD_ADDRESS_CAPTION }, | 342 { "addAddressTitle", IDS_AUTOFILL_ADD_ADDRESS_CAPTION }, |
338 { "editAddressTitle", IDS_AUTOFILL_EDIT_ADDRESS_CAPTION }, | 343 { "editAddressTitle", IDS_AUTOFILL_EDIT_ADDRESS_CAPTION }, |
339 { "addCreditCardTitle", IDS_AUTOFILL_ADD_CREDITCARD_CAPTION }, | 344 { "addCreditCardTitle", IDS_AUTOFILL_ADD_CREDITCARD_CAPTION }, |
340 { "editCreditCardTitle", IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION }, | 345 { "editCreditCardTitle", IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION }, |
341 #if defined(OS_MACOSX) | 346 #if defined(OS_MACOSX) |
342 { "auxiliaryProfilesEnabled", IDS_AUTOFILL_USE_MAC_ADDRESS_BOOK }, | 347 { "auxiliaryProfilesEnabled", IDS_AUTOFILL_USE_MAC_ADDRESS_BOOK }, |
343 #endif // defined(OS_MACOSX) | 348 #endif // defined(OS_MACOSX) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 g_browser_process->GetApplicationLocale(), | 472 g_browser_process->GetApplicationLocale(), |
468 &labels); | 473 &labels); |
469 DCHECK_EQ(labels.size(), profiles.size()); | 474 DCHECK_EQ(labels.size(), profiles.size()); |
470 | 475 |
471 base::ListValue addresses; | 476 base::ListValue addresses; |
472 for (size_t i = 0; i < profiles.size(); ++i) { | 477 for (size_t i = 0; i < profiles.size(); ++i) { |
473 // Skip showing auxiliary profiles (e.g. Mac Contacts) for now. | 478 // Skip showing auxiliary profiles (e.g. Mac Contacts) for now. |
474 if (profiles[i]->record_type() == AutofillProfile::AUXILIARY_PROFILE) | 479 if (profiles[i]->record_type() == AutofillProfile::AUXILIARY_PROFILE) |
475 continue; | 480 continue; |
476 | 481 |
| 482 base::string16 separator = |
| 483 l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_SUMMARY_SEPARATOR); |
| 484 std::vector<base::string16> label_parts; |
| 485 base::SplitStringUsingSubstr(labels[i], separator, &label_parts); |
| 486 |
477 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 487 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
478 value->SetString("guid", profiles[i]->guid()); | 488 value->SetString("guid", profiles[i]->guid()); |
479 value->SetString("label", labels[i]); | 489 value->SetString("label", label_parts[0]); |
| 490 value->SetString("sublabel", labels[i].substr(label_parts[0].size())); |
480 value->SetBoolean("isLocal", profiles[i]->record_type() == | 491 value->SetBoolean("isLocal", profiles[i]->record_type() == |
481 AutofillProfile::LOCAL_PROFILE); | 492 AutofillProfile::LOCAL_PROFILE); |
482 addresses.Append(value.release()); | 493 addresses.Append(value.release()); |
483 } | 494 } |
484 | 495 |
485 web_ui()->CallJavascriptFunction("AutofillOptions.setAddressList", addresses); | 496 web_ui()->CallJavascriptFunction("AutofillOptions.setAddressList", addresses); |
486 | 497 |
487 base::ListValue credit_cards; | 498 base::ListValue credit_cards; |
488 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); | 499 const std::vector<CreditCard*>& cards = personal_data_->GetCreditCards(); |
489 for (const CreditCard* card : cards) { | 500 for (const CreditCard* card : cards) { |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 scoped_ptr<base::ListValue> components(new base::ListValue); | 767 scoped_ptr<base::ListValue> components(new base::ListValue); |
757 GetAddressComponents( | 768 GetAddressComponents( |
758 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 769 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
759 profile.language_code(), | 770 profile.language_code(), |
760 components.get(), | 771 components.get(), |
761 NULL); | 772 NULL); |
762 address->Set(kComponents, components.release()); | 773 address->Set(kComponents, components.release()); |
763 } | 774 } |
764 | 775 |
765 } // namespace options | 776 } // namespace options |
OLD | NEW |