OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/browser/wallet/wallet_address.h" | 5 #include "components/autofill/content/browser/wallet/wallet_address.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 const string16& postal_code_number, | 120 const string16& postal_code_number, |
121 const string16& phone_number, | 121 const string16& phone_number, |
122 const std::string& object_id) | 122 const std::string& object_id) |
123 : country_name_code_(country_name_code), | 123 : country_name_code_(country_name_code), |
124 recipient_name_(recipient_name), | 124 recipient_name_(recipient_name), |
125 address_line_1_(address_line_1), | 125 address_line_1_(address_line_1), |
126 address_line_2_(address_line_2), | 126 address_line_2_(address_line_2), |
127 locality_name_(locality_name), | 127 locality_name_(locality_name), |
128 administrative_area_name_(administrative_area_name), | 128 administrative_area_name_(administrative_area_name), |
129 postal_code_number_(postal_code_number), | 129 postal_code_number_(postal_code_number), |
130 phone_number_(phone_number), | |
131 object_id_(object_id), | 130 object_id_(object_id), |
132 is_complete_address_(true) { | 131 is_complete_address_(true) { |
| 132 // Wallet doesn't store user phone number formatting, so just strip all |
| 133 // formatting. |
| 134 i18n::PhoneObject phone(phone_number, country_name_code); |
| 135 phone_number_ = phone.GetWholeNumber(); |
133 } | 136 } |
134 | 137 |
135 Address::~Address() {} | 138 Address::~Address() {} |
136 | 139 |
137 // static | 140 // static |
138 scoped_ptr<Address> Address::CreateAddressWithID( | 141 scoped_ptr<Address> Address::CreateAddressWithID( |
139 const base::DictionaryValue& dictionary) { | 142 const base::DictionaryValue& dictionary) { |
140 std::string object_id; | 143 std::string object_id; |
141 if (!dictionary.GetString("id", &object_id)) { | 144 if (!dictionary.GetString("id", &object_id)) { |
142 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 145 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 258 |
256 string16 Address::DisplayNameDetail() const { | 259 string16 Address::DisplayNameDetail() const { |
257 #if defined(OS_ANDROID) | 260 #if defined(OS_ANDROID) |
258 // TODO(aruslan): improve this stub implementation. | 261 // TODO(aruslan): improve this stub implementation. |
259 return address_line_1(); | 262 return address_line_1(); |
260 #else | 263 #else |
261 return string16(); | 264 return string16(); |
262 #endif | 265 #endif |
263 } | 266 } |
264 | 267 |
| 268 string16 Address::DisplayPhoneNumber() const { |
| 269 // Return a formatted phone number. Wallet doesn't store user formatting, so |
| 270 // impose our own. phone_number() always includes a country code, so using |
| 271 // PhoneObject to format it would result in an internationalized format. Since |
| 272 // Wallet only supports the US right now, stick to national formatting. |
| 273 return i18n::FormatPhoneNumberForRegion(phone_number(), country_name_code()); |
| 274 } |
| 275 |
265 string16 Address::GetInfo(const AutofillType& type, | 276 string16 Address::GetInfo(const AutofillType& type, |
266 const std::string& app_locale) const { | 277 const std::string& app_locale) const { |
267 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { | 278 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { |
268 DCHECK(IsStringASCII(country_name_code())); | 279 DCHECK(IsStringASCII(country_name_code())); |
269 return ASCIIToUTF16(country_name_code()); | 280 return ASCIIToUTF16(country_name_code()); |
270 } else if (type.html_type() == HTML_TYPE_STREET_ADDRESS) { | 281 } else if (type.html_type() == HTML_TYPE_STREET_ADDRESS) { |
271 base::string16 address = address_line_1(); | 282 base::string16 address = address_line_1(); |
272 if (!address_line_2().empty()) | 283 if (!address_line_2().empty()) |
273 address += ASCIIToUTF16(", ") + address_line_2(); | 284 address += ASCIIToUTF16(", ") + address_line_2(); |
274 return address; | 285 return address; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 bool Address::operator==(const Address& other) const { | 334 bool Address::operator==(const Address& other) const { |
324 return object_id_ == other.object_id_ && EqualsIgnoreID(other); | 335 return object_id_ == other.object_id_ && EqualsIgnoreID(other); |
325 } | 336 } |
326 | 337 |
327 bool Address::operator!=(const Address& other) const { | 338 bool Address::operator!=(const Address& other) const { |
328 return !(*this == other); | 339 return !(*this == other); |
329 } | 340 } |
330 | 341 |
331 } // namespace wallet | 342 } // namespace wallet |
332 } // namespace autofill | 343 } // namespace autofill |
OLD | NEW |