| 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" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), | 95 base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), |
| 96 GetLanguageCode(), | 96 GetLanguageCode(), |
| 97 g_browser_process->GetApplicationLocale()); | 97 g_browser_process->GetApplicationLocale()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 DataModelWrapper::DataModelWrapper() {} | 100 DataModelWrapper::DataModelWrapper() {} |
| 101 | 101 |
| 102 // AutofillProfileWrapper | 102 // AutofillProfileWrapper |
| 103 | 103 |
| 104 AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile) | 104 AutofillProfileWrapper::AutofillProfileWrapper(const AutofillProfile* profile) |
| 105 : profile_(profile), | 105 : profile_(profile) {} |
| 106 variant_group_(NO_GROUP), | |
| 107 variant_(0) {} | |
| 108 | |
| 109 AutofillProfileWrapper::AutofillProfileWrapper( | |
| 110 const AutofillProfile* profile, | |
| 111 const AutofillType& type, | |
| 112 size_t variant) | |
| 113 : profile_(profile), | |
| 114 variant_group_(type.group()), | |
| 115 variant_(variant) {} | |
| 116 | 106 |
| 117 AutofillProfileWrapper::~AutofillProfileWrapper() {} | 107 AutofillProfileWrapper::~AutofillProfileWrapper() {} |
| 118 | 108 |
| 119 base::string16 AutofillProfileWrapper::GetInfo(const AutofillType& type) const { | 109 base::string16 AutofillProfileWrapper::GetInfo(const AutofillType& type) const { |
| 120 // Requests for the user's credit card are filled from the billing address, | 110 // Requests for the user's credit card are filled from the billing address, |
| 121 // but the AutofillProfile class doesn't know how to fill credit card | 111 // but the AutofillProfile class doesn't know how to fill credit card |
| 122 // fields. So, request for the corresponding profile type instead. | 112 // fields. So, request for the corresponding profile type instead. |
| 123 AutofillType effective_type = type; | 113 AutofillType effective_type = type; |
| 124 if (type.GetStorableType() == CREDIT_CARD_NAME) | 114 if (type.GetStorableType() == CREDIT_CARD_NAME) |
| 125 effective_type = AutofillType(NAME_BILLING_FULL); | 115 effective_type = AutofillType(NAME_BILLING_FULL); |
| 126 | 116 |
| 127 size_t variant = GetVariantForType(effective_type); | |
| 128 const std::string& app_locale = g_browser_process->GetApplicationLocale(); | 117 const std::string& app_locale = g_browser_process->GetApplicationLocale(); |
| 129 return profile_->GetInfoForVariant(effective_type, variant, app_locale); | 118 return profile_->GetInfo(effective_type, app_locale); |
| 130 } | 119 } |
| 131 | 120 |
| 132 base::string16 AutofillProfileWrapper::GetInfoForDisplay( | 121 base::string16 AutofillProfileWrapper::GetInfoForDisplay( |
| 133 const AutofillType& type) const { | 122 const AutofillType& type) const { |
| 134 // We display the "raw" phone number which contains user-defined formatting. | 123 // We display the "raw" phone number which contains user-defined formatting. |
| 135 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) { | 124 if (type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) { |
| 136 std::vector<base::string16> values; | 125 base::string16 phone_number = profile_->GetRawInfo(type.GetStorableType()); |
| 137 profile_->GetRawMultiInfo(type.GetStorableType(), &values); | |
| 138 const base::string16& phone_number = values[GetVariantForType(type)]; | |
| 139 | 126 |
| 140 // If there is no user-defined formatting at all, add some standard | 127 // If there is no user-defined formatting at all, add some standard |
| 141 // formatting. | 128 // formatting. |
| 142 if (base::ContainsOnlyChars(phone_number, | 129 if (base::ContainsOnlyChars(phone_number, |
| 143 base::ASCIIToUTF16("+0123456789"))) { | 130 base::ASCIIToUTF16("+0123456789"))) { |
| 144 std::string region = base::UTF16ToASCII( | 131 std::string region = base::UTF16ToASCII( |
| 145 GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); | 132 GetInfo(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); |
| 146 i18n::PhoneObject phone(phone_number, region); | 133 i18n::PhoneObject phone(phone_number, region); |
| 147 base::string16 formatted_number = phone.GetFormattedNumber(); | 134 base::string16 formatted_number = phone.GetFormattedNumber(); |
| 148 // Formatting may fail. | 135 // Formatting may fail. |
| 149 if (!formatted_number.empty()) | 136 if (!formatted_number.empty()) |
| 150 return formatted_number; | 137 return formatted_number; |
| 151 } | 138 } |
| 152 | 139 |
| 153 return phone_number; | 140 return phone_number; |
| 154 } | 141 } |
| 155 | 142 |
| 156 return DataModelWrapper::GetInfoForDisplay(type); | 143 return DataModelWrapper::GetInfoForDisplay(type); |
| 157 } | 144 } |
| 158 | 145 |
| 159 const std::string& AutofillProfileWrapper::GetLanguageCode() const { | 146 const std::string& AutofillProfileWrapper::GetLanguageCode() const { |
| 160 return profile_->language_code(); | 147 return profile_->language_code(); |
| 161 } | 148 } |
| 162 | 149 |
| 163 size_t AutofillProfileWrapper::GetVariantForType(const AutofillType& type) | |
| 164 const { | |
| 165 if (type.group() == variant_group_) | |
| 166 return variant_; | |
| 167 | |
| 168 return 0; | |
| 169 } | |
| 170 | |
| 171 // AutofillShippingAddressWrapper | 150 // AutofillShippingAddressWrapper |
| 172 | 151 |
| 173 AutofillShippingAddressWrapper::AutofillShippingAddressWrapper( | 152 AutofillShippingAddressWrapper::AutofillShippingAddressWrapper( |
| 174 const AutofillProfile* profile) | 153 const AutofillProfile* profile) |
| 175 : AutofillProfileWrapper(profile) {} | 154 : AutofillProfileWrapper(profile) {} |
| 176 | 155 |
| 177 AutofillShippingAddressWrapper::~AutofillShippingAddressWrapper() {} | 156 AutofillShippingAddressWrapper::~AutofillShippingAddressWrapper() {} |
| 178 | 157 |
| 179 base::string16 AutofillShippingAddressWrapper::GetInfo( | 158 base::string16 AutofillShippingAddressWrapper::GetInfo( |
| 180 const AutofillType& type) const { | 159 const AutofillType& type) const { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } | 375 } |
| 397 | 376 |
| 398 return base::UTF8ToUTF16(address_->GetFieldValue(field)); | 377 return base::UTF8ToUTF16(address_->GetFieldValue(field)); |
| 399 } | 378 } |
| 400 | 379 |
| 401 const std::string& I18nAddressDataWrapper::GetLanguageCode() const { | 380 const std::string& I18nAddressDataWrapper::GetLanguageCode() const { |
| 402 return address_->language_code; | 381 return address_->language_code; |
| 403 } | 382 } |
| 404 | 383 |
| 405 } // namespace autofill | 384 } // namespace autofill |
| OLD | NEW |