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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/strings/string_util.h" | |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 11 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
11 #include "components/autofill/content/browser/wallet/full_wallet.h" | 12 #include "components/autofill/content/browser/wallet/full_wallet.h" |
12 #include "components/autofill/content/browser/wallet/wallet_address.h" | 13 #include "components/autofill/content/browser/wallet/wallet_address.h" |
13 #include "components/autofill/content/browser/wallet/wallet_items.h" | 14 #include "components/autofill/content/browser/wallet/wallet_items.h" |
14 #include "components/autofill/core/browser/autofill_data_model.h" | 15 #include "components/autofill/core/browser/autofill_data_model.h" |
15 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
16 #include "components/autofill/core/browser/autofill_type.h" | 17 #include "components/autofill/core/browser/autofill_type.h" |
17 #include "components/autofill/core/browser/credit_card.h" | 18 #include "components/autofill/core/browser/credit_card.h" |
18 #include "components/autofill/core/browser/form_structure.h" | 19 #include "components/autofill/core/browser/form_structure.h" |
19 #include "components/autofill/core/browser/validation.h" | 20 #include "components/autofill/core/browser/validation.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
22 | 23 |
23 namespace autofill { | 24 namespace autofill { |
24 | 25 |
25 DataModelWrapper::~DataModelWrapper() {} | 26 DataModelWrapper::~DataModelWrapper() {} |
26 | 27 |
27 void DataModelWrapper::FillInputs(DetailInputs* inputs) { | 28 void DataModelWrapper::FillInputs(DetailInputs* inputs) { |
28 for (size_t i = 0; i < inputs->size(); ++i) { | 29 for (size_t i = 0; i < inputs->size(); ++i) { |
29 (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type)); | 30 (*inputs)[i].initial_value = GetInfo(AutofillType((*inputs)[i].type)); |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
34 base::string16 DataModelWrapper::GetInfoForDisplay(const AutofillType& type) | |
35 const { | |
36 return GetInfo(type); | |
37 } | |
38 | |
33 gfx::Image DataModelWrapper::GetIcon() { | 39 gfx::Image DataModelWrapper::GetIcon() { |
34 return gfx::Image(); | 40 return gfx::Image(); |
35 } | 41 } |
36 | 42 |
37 bool DataModelWrapper::GetDisplayText( | 43 bool DataModelWrapper::GetDisplayText( |
38 base::string16* vertically_compact, | 44 base::string16* vertically_compact, |
39 base::string16* horizontally_compact) { | 45 base::string16* horizontally_compact) { |
40 base::string16 comma = ASCIIToUTF16(", "); | 46 base::string16 comma = ASCIIToUTF16(", "); |
41 base::string16 newline = ASCIIToUTF16("\n"); | 47 base::string16 newline = ASCIIToUTF16("\n"); |
42 | 48 |
(...skipping 21 matching lines...) Expand all Loading... | |
64 } | 70 } |
65 | 71 |
66 DataModelWrapper::DataModelWrapper() {} | 72 DataModelWrapper::DataModelWrapper() {} |
67 | 73 |
68 void DataModelWrapper::FillFormField(AutofillField* field) const { | 74 void DataModelWrapper::FillFormField(AutofillField* field) const { |
69 field->value = GetInfo(field->Type()); | 75 field->value = GetInfo(field->Type()); |
70 } | 76 } |
71 | 77 |
72 base::string16 DataModelWrapper::GetAddressDisplayText( | 78 base::string16 DataModelWrapper::GetAddressDisplayText( |
73 const base::string16& separator) { | 79 const base::string16& separator) { |
74 base::string16 address = GetInfo(AutofillType(NAME_FULL)) + separator + | 80 base::string16 address = GetInfoForDisplay(AutofillType(NAME_FULL)) + |
75 GetInfo(AutofillType(ADDRESS_HOME_LINE1)); | 81 separator + GetInfoForDisplay(AutofillType(ADDRESS_HOME_LINE1)); |
76 base::string16 address2 = GetInfo(AutofillType(ADDRESS_HOME_LINE2)); | 82 base::string16 address2 = GetInfoForDisplay(AutofillType(ADDRESS_HOME_LINE2)); |
77 if (!address2.empty()) | 83 if (!address2.empty()) |
78 address += separator + address2; | 84 address += separator + address2; |
79 | 85 |
80 base::string16 comma = ASCIIToUTF16(", "); | 86 base::string16 comma = ASCIIToUTF16(", "); |
81 base::string16 newline = ASCIIToUTF16("\n"); | 87 base::string16 newline = ASCIIToUTF16("\n"); |
82 address += separator + | 88 address += separator + |
83 GetInfo(AutofillType(ADDRESS_HOME_CITY)) + comma + | 89 GetInfoForDisplay(AutofillType(ADDRESS_HOME_CITY)) + comma + |
84 GetInfo(AutofillType(ADDRESS_HOME_STATE)) + ASCIIToUTF16(" ") + | 90 GetInfoForDisplay(AutofillType(ADDRESS_HOME_STATE)) + ASCIIToUTF16(" ") + |
85 GetInfo(AutofillType(ADDRESS_HOME_ZIP)); | 91 GetInfoForDisplay(AutofillType(ADDRESS_HOME_ZIP)); |
86 | 92 |
87 base::string16 email = GetInfo(AutofillType(EMAIL_ADDRESS)); | 93 base::string16 email = GetInfoForDisplay(AutofillType(EMAIL_ADDRESS)); |
88 if (!email.empty()) | 94 if (!email.empty()) |
89 address += newline + email; | 95 address += newline + email; |
90 address += newline + GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)); | 96 address += newline + GetInfoForDisplay(AutofillType(PHONE_HOME_WHOLE_NUMBER)); |
91 | 97 |
92 return address; | 98 return address; |
93 } | 99 } |
94 | 100 |
95 // EmptyDataModelWrapper | 101 // EmptyDataModelWrapper |
96 | 102 |
97 EmptyDataModelWrapper::EmptyDataModelWrapper() {} | 103 EmptyDataModelWrapper::EmptyDataModelWrapper() {} |
98 EmptyDataModelWrapper::~EmptyDataModelWrapper() {} | 104 EmptyDataModelWrapper::~EmptyDataModelWrapper() {} |
99 | 105 |
100 base::string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const { | 106 base::string16 EmptyDataModelWrapper::GetInfo(const AutofillType& type) const { |
(...skipping 20 matching lines...) Expand all Loading... | |
121 AutofillProfileWrapper::~AutofillProfileWrapper() {} | 127 AutofillProfileWrapper::~AutofillProfileWrapper() {} |
122 | 128 |
123 base::string16 AutofillProfileWrapper::GetInfo(const AutofillType& type) | 129 base::string16 AutofillProfileWrapper::GetInfo(const AutofillType& type) |
124 const { | 130 const { |
125 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 131 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
126 std::vector<base::string16> values; | 132 std::vector<base::string16> values; |
127 profile_->GetMultiInfo(type, app_locale, &values); | 133 profile_->GetMultiInfo(type, app_locale, &values); |
128 return values[GetVariantForType(type)]; | 134 return values[GetVariantForType(type)]; |
129 } | 135 } |
130 | 136 |
137 base::string16 AutofillProfileWrapper::GetInfoForDisplay( | |
138 const AutofillType& type) const { | |
139 // We display the "raw" phone number which contains user-defined formatting. | |
140 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) { | |
141 std::vector<base::string16> values; | |
142 profile_->GetRawMultiInfo(type.GetStorableType(), &values); | |
143 base::string16 phone_number = values[GetVariantForType(type)]; | |
Ilya Sherman
2013/09/26 22:01:06
Optional nit: const-ref?
Evan Stade
2013/09/27 00:29:17
Done.
| |
144 | |
145 if (ContainsOnlyChars(phone_number, ASCIIToUTF16("0123456789"))) { | |
Ilya Sherman
2013/09/26 22:01:06
nit: Please add a comment describing what this blo
Evan Stade
2013/09/27 00:29:17
Done.
| |
146 std::string region = UTF16ToASCII( | |
147 GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); | |
148 i18n::PhoneObject phone(phone_number, region); | |
149 phone_number = phone.GetFormattedNumber(); | |
150 } | |
151 | |
152 return phone_number; | |
153 } | |
154 | |
155 return GetInfo(type); | |
Ilya Sherman
2013/09/26 22:01:06
Optional nit: Perhaps this should call DataModelWr
Evan Stade
2013/09/27 00:29:17
Done.
| |
156 } | |
157 | |
131 void AutofillProfileWrapper::FillFormField(AutofillField* field) const { | 158 void AutofillProfileWrapper::FillFormField(AutofillField* field) const { |
132 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) { | 159 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) { |
133 // Cache the field's true type. | 160 // Cache the field's true type. |
134 HtmlFieldType original_type = field->html_type(); | 161 HtmlFieldType original_type = field->html_type(); |
135 | 162 |
136 // Requests for the user's credit card are filled from the billing address, | 163 // Requests for the user's credit card are filled from the billing address, |
137 // but the AutofillProfile class doesn't know how to fill credit card | 164 // but the AutofillProfile class doesn't know how to fill credit card |
138 // fields. So, temporarily set the type to the corresponding profile type. | 165 // fields. So, temporarily set the type to the corresponding profile type. |
139 field->SetHtmlType(HTML_TYPE_NAME, field->html_mode()); | 166 field->SetHtmlType(HTML_TYPE_NAME, field->html_mode()); |
140 | 167 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 WalletAddressWrapper::~WalletAddressWrapper() {} | 249 WalletAddressWrapper::~WalletAddressWrapper() {} |
223 | 250 |
224 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { | 251 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { |
225 // Reachable from DataModelWrapper::GetDisplayText(). | 252 // Reachable from DataModelWrapper::GetDisplayText(). |
226 if (type.GetStorableType() == EMAIL_ADDRESS) | 253 if (type.GetStorableType() == EMAIL_ADDRESS) |
227 return base::string16(); | 254 return base::string16(); |
228 | 255 |
229 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 256 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
230 } | 257 } |
231 | 258 |
259 base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type) | |
260 const { | |
261 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) | |
262 return address_->DisplayPhoneNumber(); | |
263 | |
264 return GetInfo(type); | |
265 } | |
266 | |
232 bool WalletAddressWrapper::GetDisplayText( | 267 bool WalletAddressWrapper::GetDisplayText( |
233 base::string16* vertically_compact, | 268 base::string16* vertically_compact, |
234 base::string16* horizontally_compact) { | 269 base::string16* horizontally_compact) { |
235 if (!address_->is_complete_address() || | 270 if (!address_->is_complete_address() || |
236 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { | 271 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { |
237 return false; | 272 return false; |
238 } | 273 } |
239 | 274 |
240 return DataModelWrapper::GetDisplayText(vertically_compact, | 275 return DataModelWrapper::GetDisplayText(vertically_compact, |
241 horizontally_compact); | 276 horizontally_compact); |
(...skipping 12 matching lines...) Expand all Loading... | |
254 // Reachable from DataModelWrapper::GetDisplayText(). | 289 // Reachable from DataModelWrapper::GetDisplayText(). |
255 if (type.GetStorableType() == EMAIL_ADDRESS) | 290 if (type.GetStorableType() == EMAIL_ADDRESS) |
256 return base::string16(); | 291 return base::string16(); |
257 | 292 |
258 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) | 293 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) |
259 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); | 294 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); |
260 | 295 |
261 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 296 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
262 } | 297 } |
263 | 298 |
299 base::string16 WalletInstrumentWrapper::GetInfoForDisplay( | |
300 const AutofillType& type) const { | |
301 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) | |
302 return instrument_->address().DisplayPhoneNumber(); | |
303 | |
304 return GetInfo(type); | |
305 } | |
306 | |
264 gfx::Image WalletInstrumentWrapper::GetIcon() { | 307 gfx::Image WalletInstrumentWrapper::GetIcon() { |
265 return instrument_->CardIcon(); | 308 return instrument_->CardIcon(); |
266 } | 309 } |
267 | 310 |
268 bool WalletInstrumentWrapper::GetDisplayText( | 311 bool WalletInstrumentWrapper::GetDisplayText( |
269 base::string16* vertically_compact, | 312 base::string16* vertically_compact, |
270 base::string16* horizontally_compact) { | 313 base::string16* horizontally_compact) { |
271 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 | 314 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 |
272 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || | 315 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || |
273 !instrument_->address().is_complete_address() || | 316 !instrument_->address().is_complete_address() || |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 ServerFieldType storable_type = type.GetStorableType(); | 385 ServerFieldType storable_type = type.GetStorableType(); |
343 for (DetailOutputMap::const_iterator it = outputs_.begin(); | 386 for (DetailOutputMap::const_iterator it = outputs_.begin(); |
344 it != outputs_.end(); ++it) { | 387 it != outputs_.end(); ++it) { |
345 if (storable_type == AutofillType(it->first->type).GetStorableType()) | 388 if (storable_type == AutofillType(it->first->type).GetStorableType()) |
346 return it->second; | 389 return it->second; |
347 } | 390 } |
348 return base::string16(); | 391 return base::string16(); |
349 } | 392 } |
350 | 393 |
351 } // namespace autofill | 394 } // namespace autofill |
OLD | NEW |