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/autofill/data_model_wrapper.h" | 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 12 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
13 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 13 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
14 #include "components/autofill/content/browser/wallet/full_wallet.h" | 14 #include "components/autofill/content/browser/wallet/full_wallet.h" |
15 #include "components/autofill/content/browser/wallet/wallet_address.h" | 15 #include "components/autofill/content/browser/wallet/wallet_address.h" |
16 #include "components/autofill/content/browser/wallet/wallet_items.h" | 16 #include "components/autofill/content/browser/wallet/wallet_items.h" |
17 #include "components/autofill/core/browser/autofill_data_model.h" | 17 #include "components/autofill/core/browser/autofill_data_model.h" |
18 #include "components/autofill/core/browser/autofill_field.h" | 18 #include "components/autofill/core/browser/autofill_field.h" |
19 #include "components/autofill/core/browser/autofill_profile.h" | 19 #include "components/autofill/core/browser/autofill_profile.h" |
20 #include "components/autofill/core/browser/autofill_type.h" | 20 #include "components/autofill/core/browser/autofill_type.h" |
21 #include "components/autofill/core/browser/credit_card.h" | 21 #include "components/autofill/core/browser/credit_card.h" |
22 #include "components/autofill/core/browser/form_structure.h" | 22 #include "components/autofill/core/browser/form_structure.h" |
23 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" | 23 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" |
24 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" | 24 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
27 | 27 |
28 namespace autofill { | 28 namespace autofill { |
29 | 29 |
30 using base::ASCIIToUTF16; | |
31 using base::UTF16ToUTF8; | |
32 | |
33 DataModelWrapper::~DataModelWrapper() {} | 30 DataModelWrapper::~DataModelWrapper() {} |
34 | 31 |
35 void DataModelWrapper::FillInputs(DetailInputs* inputs) { | 32 void DataModelWrapper::FillInputs(DetailInputs* inputs) { |
36 for (size_t i = 0; i < inputs->size(); ++i) { | 33 for (size_t i = 0; i < inputs->size(); ++i) { |
37 (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type)); | 34 (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type)); |
38 } | 35 } |
39 } | 36 } |
40 | 37 |
41 base::string16 DataModelWrapper::GetInfoForDisplay(const AutofillType& type) | 38 base::string16 DataModelWrapper::GetInfoForDisplay(const AutofillType& type) |
42 const { | 39 const { |
(...skipping 17 matching lines...) Expand all Loading... |
60 i18ninput::CreateAddressData( | 57 i18ninput::CreateAddressData( |
61 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), | 58 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), |
62 &address_data); | 59 &address_data); |
63 std::vector<std::string> lines; | 60 std::vector<std::string> lines; |
64 address_data.FormatForDisplay(&lines); | 61 address_data.FormatForDisplay(&lines); |
65 | 62 |
66 // Email and phone number aren't part of address formatting. | 63 // Email and phone number aren't part of address formatting. |
67 base::string16 non_address_info; | 64 base::string16 non_address_info; |
68 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); | 65 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); |
69 if (!email.empty()) | 66 if (!email.empty()) |
70 non_address_info += ASCIIToUTF16("\n") + email; | 67 non_address_info += base::ASCIIToUTF16("\n") + email; |
71 | 68 |
72 non_address_info += ASCIIToUTF16("\n") + phone; | 69 non_address_info += base::ASCIIToUTF16("\n") + phone; |
73 | 70 |
74 // The separator is locale-specific. | 71 // The separator is locale-specific. |
75 std::string compact_separator = | 72 std::string compact_separator = |
76 ::i18n::addressinput::GetCompactAddressLinesSeparator( | 73 ::i18n::addressinput::GetCompactAddressLinesSeparator( |
77 g_browser_process->GetApplicationLocale()); | 74 g_browser_process->GetApplicationLocale()); |
78 *vertically_compact = | 75 *vertically_compact = |
79 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + | 76 base::UTF8ToUTF16(JoinString(lines, compact_separator)) + |
80 non_address_info; | 77 non_address_info; |
81 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + | 78 *horizontally_compact = base::UTF8ToUTF16(JoinString(lines, "\n")) + |
82 non_address_info; | 79 non_address_info; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 base::string16 AutofillProfileWrapper::GetInfoForDisplay( | 127 base::string16 AutofillProfileWrapper::GetInfoForDisplay( |
131 const AutofillType& type) const { | 128 const AutofillType& type) const { |
132 // We display the "raw" phone number which contains user-defined formatting. | 129 // We display the "raw" phone number which contains user-defined formatting. |
133 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) { | 130 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) { |
134 std::vector<base::string16> values; | 131 std::vector<base::string16> values; |
135 profile_->GetRawMultiInfo(type.GetStorableType(), &values); | 132 profile_->GetRawMultiInfo(type.GetStorableType(), &values); |
136 const base::string16& phone_number = values[GetVariantForType(type)]; | 133 const base::string16& phone_number = values[GetVariantForType(type)]; |
137 | 134 |
138 // If there is no user-defined formatting at all, add some standard | 135 // If there is no user-defined formatting at all, add some standard |
139 // formatting. | 136 // formatting. |
140 if (base::ContainsOnlyChars(phone_number, ASCIIToUTF16("0123456789"))) { | 137 if (base::ContainsOnlyChars(phone_number, |
141 std::string region = UTF16ToASCII( | 138 base::ASCIIToUTF16("0123456789"))) { |
| 139 std::string region = base::UTF16ToASCII( |
142 GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); | 140 GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); |
143 i18n::PhoneObject phone(phone_number, region); | 141 i18n::PhoneObject phone(phone_number, region); |
144 return phone.GetFormattedNumber(); | 142 return phone.GetFormattedNumber(); |
145 } | 143 } |
146 | 144 |
147 return phone_number; | 145 return phone_number; |
148 } | 146 } |
149 | 147 |
150 return DataModelWrapper::GetInfoForDisplay(type); | 148 return DataModelWrapper::GetInfoForDisplay(type); |
151 } | 149 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return false; | 280 return false; |
283 } | 281 } |
284 | 282 |
285 if (!DataModelWrapper::GetDisplayText(vertically_compact, | 283 if (!DataModelWrapper::GetDisplayText(vertically_compact, |
286 horizontally_compact)) { | 284 horizontally_compact)) { |
287 return false; | 285 return false; |
288 } | 286 } |
289 | 287 |
290 // TODO(estade): descriptive_name() is user-provided. Should we use it or | 288 // TODO(estade): descriptive_name() is user-provided. Should we use it or |
291 // just type + last 4 digits? | 289 // just type + last 4 digits? |
292 base::string16 line1 = instrument_->descriptive_name() + ASCIIToUTF16("\n"); | 290 base::string16 line1 = |
| 291 instrument_->descriptive_name() + base::ASCIIToUTF16("\n"); |
293 *vertically_compact = line1 + *vertically_compact; | 292 *vertically_compact = line1 + *vertically_compact; |
294 *horizontally_compact = line1 + *horizontally_compact; | 293 *horizontally_compact = line1 + *horizontally_compact; |
295 return true; | 294 return true; |
296 } | 295 } |
297 | 296 |
298 // FullWalletBillingWrapper | 297 // FullWalletBillingWrapper |
299 | 298 |
300 FullWalletBillingWrapper::FullWalletBillingWrapper( | 299 FullWalletBillingWrapper::FullWalletBillingWrapper( |
301 wallet::FullWallet* full_wallet) | 300 wallet::FullWallet* full_wallet) |
302 : full_wallet_(full_wallet) { | 301 : full_wallet_(full_wallet) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 | 333 |
335 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} | 334 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} |
336 | 335 |
337 base::string16 FullWalletShippingWrapper::GetInfo( | 336 base::string16 FullWalletShippingWrapper::GetInfo( |
338 const AutofillType& type) const { | 337 const AutofillType& type) const { |
339 return full_wallet_->shipping_address()->GetInfo( | 338 return full_wallet_->shipping_address()->GetInfo( |
340 type, g_browser_process->GetApplicationLocale()); | 339 type, g_browser_process->GetApplicationLocale()); |
341 } | 340 } |
342 | 341 |
343 } // namespace autofill | 342 } // namespace autofill |
OLD | NEW |