Chromium Code Reviews| 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 const base::string16& phone_number = values[GetVariantForType(type)]; | |
| 144 | |
| 145 // If there is no user-defined formatting at all, add some standard | |
| 146 // formatting. | |
| 147 if (ContainsOnlyChars(phone_number, ASCIIToUTF16("0123456789"))) { | |
| 148 std::string region = UTF16ToASCII( | |
| 149 GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); | |
| 150 i18n::PhoneObject phone(phone_number, region); | |
| 151 return phone.GetFormattedNumber(); | |
| 152 } | |
| 153 | |
| 154 return phone_number; | |
| 155 } | |
| 156 | |
| 157 return DataModelWrapper::GetInfoForDisplay(type); | |
| 158 } | |
| 159 | |
| 131 void AutofillProfileWrapper::FillFormField(AutofillField* field) const { | 160 void AutofillProfileWrapper::FillFormField(AutofillField* field) const { |
| 132 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) { | 161 if (field->Type().GetStorableType() == CREDIT_CARD_NAME) { |
| 133 // Cache the field's true type. | 162 // Cache the field's true type. |
| 134 HtmlFieldType original_type = field->html_type(); | 163 HtmlFieldType original_type = field->html_type(); |
| 135 | 164 |
| 136 // Requests for the user's credit card are filled from the billing address, | 165 // 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 | 166 // but the AutofillProfile class doesn't know how to fill credit card |
| 138 // fields. So, temporarily set the type to the corresponding profile type. | 167 // fields. So, temporarily set the type to the corresponding profile type. |
| 139 field->SetHtmlType(HTML_TYPE_NAME, field->html_mode()); | 168 field->SetHtmlType(HTML_TYPE_NAME, field->html_mode()); |
| 140 | 169 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 WalletAddressWrapper::~WalletAddressWrapper() {} | 251 WalletAddressWrapper::~WalletAddressWrapper() {} |
| 223 | 252 |
| 224 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { | 253 base::string16 WalletAddressWrapper::GetInfo(const AutofillType& type) const { |
| 225 // Reachable from DataModelWrapper::GetDisplayText(). | 254 // Reachable from DataModelWrapper::GetDisplayText(). |
| 226 if (type.GetStorableType() == EMAIL_ADDRESS) | 255 if (type.GetStorableType() == EMAIL_ADDRESS) |
| 227 return base::string16(); | 256 return base::string16(); |
| 228 | 257 |
| 229 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 258 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
| 230 } | 259 } |
| 231 | 260 |
| 261 base::string16 WalletAddressWrapper::GetInfoForDisplay(const AutofillType& type) | |
| 262 const { | |
| 263 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) | |
| 264 return address_->DisplayPhoneNumber(); | |
| 265 | |
| 266 return DataModelWrapper::GetInfoForDisplay(type); | |
| 267 return GetInfo(type); | |
|
aruslan
2013/10/01 01:51:17
unreachable GetInfo.
Evan Stade
2013/10/01 02:00:36
Done.
| |
| 268 } | |
| 269 | |
| 232 bool WalletAddressWrapper::GetDisplayText( | 270 bool WalletAddressWrapper::GetDisplayText( |
| 233 base::string16* vertically_compact, | 271 base::string16* vertically_compact, |
| 234 base::string16* horizontally_compact) { | 272 base::string16* horizontally_compact) { |
| 235 if (!address_->is_complete_address() || | 273 if (!address_->is_complete_address() || |
| 236 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { | 274 GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER)).empty()) { |
| 237 return false; | 275 return false; |
| 238 } | 276 } |
| 239 | 277 |
| 240 return DataModelWrapper::GetDisplayText(vertically_compact, | 278 return DataModelWrapper::GetDisplayText(vertically_compact, |
| 241 horizontally_compact); | 279 horizontally_compact); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 254 // Reachable from DataModelWrapper::GetDisplayText(). | 292 // Reachable from DataModelWrapper::GetDisplayText(). |
| 255 if (type.GetStorableType() == EMAIL_ADDRESS) | 293 if (type.GetStorableType() == EMAIL_ADDRESS) |
| 256 return base::string16(); | 294 return base::string16(); |
| 257 | 295 |
| 258 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) | 296 if (type.GetStorableType() == CREDIT_CARD_EXP_MONTH) |
| 259 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); | 297 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); |
| 260 | 298 |
| 261 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 299 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
| 262 } | 300 } |
| 263 | 301 |
| 302 base::string16 WalletInstrumentWrapper::GetInfoForDisplay( | |
| 303 const AutofillType& type) const { | |
| 304 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) | |
| 305 return instrument_->address().DisplayPhoneNumber(); | |
| 306 | |
| 307 return DataModelWrapper::GetInfoForDisplay(type); | |
| 308 } | |
| 309 | |
| 264 gfx::Image WalletInstrumentWrapper::GetIcon() { | 310 gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 265 return instrument_->CardIcon(); | 311 return instrument_->CardIcon(); |
| 266 } | 312 } |
| 267 | 313 |
| 268 bool WalletInstrumentWrapper::GetDisplayText( | 314 bool WalletInstrumentWrapper::GetDisplayText( |
| 269 base::string16* vertically_compact, | 315 base::string16* vertically_compact, |
| 270 base::string16* horizontally_compact) { | 316 base::string16* horizontally_compact) { |
| 271 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 | 317 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 |
| 272 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || | 318 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED || |
| 273 !instrument_->address().is_complete_address() || | 319 !instrument_->address().is_complete_address() || |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 ServerFieldType storable_type = type.GetStorableType(); | 388 ServerFieldType storable_type = type.GetStorableType(); |
| 343 for (DetailOutputMap::const_iterator it = outputs_.begin(); | 389 for (DetailOutputMap::const_iterator it = outputs_.begin(); |
| 344 it != outputs_.end(); ++it) { | 390 it != outputs_.end(); ++it) { |
| 345 if (storable_type == AutofillType(it->first->type).GetStorableType()) | 391 if (storable_type == AutofillType(it->first->type).GetStorableType()) |
| 346 return it->second; | 392 return it->second; |
| 347 } | 393 } |
| 348 return base::string16(); | 394 return base::string16(); |
| 349 } | 395 } |
| 350 | 396 |
| 351 } // namespace autofill | 397 } // namespace autofill |
| OLD | NEW |