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" |
11 #include "components/autofill/core/browser/autofill_country.h" | 11 #include "components/autofill/core/browser/autofill_country.h" |
12 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
13 #include "components/autofill/core/browser/autofill_type.h" | 13 #include "components/autofill/core/browser/autofill_type.h" |
| 14 #include "components/autofill/core/browser/phone_number.h" |
14 #include "components/autofill/core/browser/state_names.h" | 15 #include "components/autofill/core/browser/state_names.h" |
15 | 16 |
16 namespace autofill { | 17 namespace autofill { |
17 namespace wallet { | 18 namespace wallet { |
18 | 19 |
19 // Server specified type for address with complete details. | 20 // Server specified type for address with complete details. |
20 const char kFullAddress[] = "FULL"; | 21 const char kFullAddress[] = "FULL"; |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 address_line_1_(profile.GetRawInfo(ADDRESS_HOME_LINE1)), | 103 address_line_1_(profile.GetRawInfo(ADDRESS_HOME_LINE1)), |
103 address_line_2_(profile.GetRawInfo(ADDRESS_HOME_LINE2)), | 104 address_line_2_(profile.GetRawInfo(ADDRESS_HOME_LINE2)), |
104 locality_name_(profile.GetRawInfo(ADDRESS_HOME_CITY)), | 105 locality_name_(profile.GetRawInfo(ADDRESS_HOME_CITY)), |
105 postal_code_number_(profile.GetRawInfo(ADDRESS_HOME_ZIP)), | 106 postal_code_number_(profile.GetRawInfo(ADDRESS_HOME_ZIP)), |
106 phone_number_(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)), | 107 phone_number_(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)), |
107 is_complete_address_(true) { | 108 is_complete_address_(true) { |
108 state_names::GetNameAndAbbreviation(profile.GetRawInfo(ADDRESS_HOME_STATE), | 109 state_names::GetNameAndAbbreviation(profile.GetRawInfo(ADDRESS_HOME_STATE), |
109 NULL, | 110 NULL, |
110 &administrative_area_name_); | 111 &administrative_area_name_); |
111 StringToUpperASCII(&administrative_area_name_); | 112 StringToUpperASCII(&administrative_area_name_); |
| 113 |
| 114 if (!country_name_code_.empty()) |
| 115 phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); |
112 } | 116 } |
113 | 117 |
114 Address::Address(const std::string& country_name_code, | 118 Address::Address(const std::string& country_name_code, |
115 const string16& recipient_name, | 119 const string16& recipient_name, |
116 const string16& address_line_1, | 120 const string16& address_line_1, |
117 const string16& address_line_2, | 121 const string16& address_line_2, |
118 const string16& locality_name, | 122 const string16& locality_name, |
119 const string16& administrative_area_name, | 123 const string16& administrative_area_name, |
120 const string16& postal_code_number, | 124 const string16& postal_code_number, |
121 const string16& phone_number, | 125 const string16& phone_number, |
122 const std::string& object_id) | 126 const std::string& object_id) |
123 : country_name_code_(country_name_code), | 127 : country_name_code_(country_name_code), |
124 recipient_name_(recipient_name), | 128 recipient_name_(recipient_name), |
125 address_line_1_(address_line_1), | 129 address_line_1_(address_line_1), |
126 address_line_2_(address_line_2), | 130 address_line_2_(address_line_2), |
127 locality_name_(locality_name), | 131 locality_name_(locality_name), |
128 administrative_area_name_(administrative_area_name), | 132 administrative_area_name_(administrative_area_name), |
129 postal_code_number_(postal_code_number), | 133 postal_code_number_(postal_code_number), |
130 phone_number_(phone_number), | 134 phone_number_(phone_number), |
| 135 phone_object_(phone_number, country_name_code), |
131 object_id_(object_id), | 136 object_id_(object_id), |
132 is_complete_address_(true) { | 137 is_complete_address_(true) {} |
133 } | |
134 | 138 |
135 Address::~Address() {} | 139 Address::~Address() {} |
136 | 140 |
137 // static | 141 // static |
138 scoped_ptr<Address> Address::CreateAddressWithID( | 142 scoped_ptr<Address> Address::CreateAddressWithID( |
139 const base::DictionaryValue& dictionary) { | 143 const base::DictionaryValue& dictionary) { |
140 std::string object_id; | 144 std::string object_id; |
141 if (!dictionary.GetString("id", &object_id)) { | 145 if (!dictionary.GetString("id", &object_id)) { |
142 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 146 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
143 return scoped_ptr<Address>(); | 147 return scoped_ptr<Address>(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 259 |
256 string16 Address::DisplayNameDetail() const { | 260 string16 Address::DisplayNameDetail() const { |
257 #if defined(OS_ANDROID) | 261 #if defined(OS_ANDROID) |
258 // TODO(aruslan): improve this stub implementation. | 262 // TODO(aruslan): improve this stub implementation. |
259 return address_line_1(); | 263 return address_line_1(); |
260 #else | 264 #else |
261 return string16(); | 265 return string16(); |
262 #endif | 266 #endif |
263 } | 267 } |
264 | 268 |
| 269 string16 Address::DisplayPhoneNumber() const { |
| 270 // Return a formatted phone number. Wallet doesn't store user formatting, so |
| 271 // impose our own. phone_number() always includes a country code, so using |
| 272 // PhoneObject to format it would result in an internationalized format. Since |
| 273 // Wallet only supports the US right now, stick to national formatting. |
| 274 return i18n::PhoneObject(phone_number(), country_name_code()). |
| 275 GetNationallyFormattedNumber(); |
| 276 } |
| 277 |
265 string16 Address::GetInfo(const AutofillType& type, | 278 string16 Address::GetInfo(const AutofillType& type, |
266 const std::string& app_locale) const { | 279 const std::string& app_locale) const { |
267 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { | 280 if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { |
268 DCHECK(IsStringASCII(country_name_code())); | 281 DCHECK(IsStringASCII(country_name_code())); |
269 return ASCIIToUTF16(country_name_code()); | 282 return ASCIIToUTF16(country_name_code()); |
270 } else if (type.html_type() == HTML_TYPE_STREET_ADDRESS) { | 283 } else if (type.html_type() == HTML_TYPE_STREET_ADDRESS) { |
271 base::string16 address = address_line_1(); | 284 base::string16 address = address_line_1(); |
272 if (!address_line_2().empty()) | 285 if (!address_line_2().empty()) |
273 address += ASCIIToUTF16(", ") + address_line_2(); | 286 address += ASCIIToUTF16(", ") + address_line_2(); |
274 return address; | 287 return address; |
(...skipping 17 matching lines...) Expand all Loading... |
292 | 305 |
293 case ADDRESS_HOME_ZIP: | 306 case ADDRESS_HOME_ZIP: |
294 return postal_code_number(); | 307 return postal_code_number(); |
295 | 308 |
296 case ADDRESS_HOME_COUNTRY: { | 309 case ADDRESS_HOME_COUNTRY: { |
297 AutofillCountry country(country_name_code(), app_locale); | 310 AutofillCountry country(country_name_code(), app_locale); |
298 return country.name(); | 311 return country.name(); |
299 } | 312 } |
300 | 313 |
301 case PHONE_HOME_WHOLE_NUMBER: | 314 case PHONE_HOME_WHOLE_NUMBER: |
302 return phone_number(); | 315 // Wallet doesn't store user phone number formatting, so just strip all |
| 316 // formatting. |
| 317 return phone_object_.GetWholeNumber(); |
303 | 318 |
304 // TODO(estade): implement more. | 319 // TODO(estade): implement more. |
305 default: | 320 default: |
306 NOTREACHED(); | 321 NOTREACHED(); |
307 return string16(); | 322 return string16(); |
308 } | 323 } |
309 } | 324 } |
310 | 325 |
| 326 void Address::SetPhoneNumber(const base::string16& phone_number) { |
| 327 phone_number_ = phone_number; |
| 328 phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); |
| 329 } |
| 330 |
311 bool Address::EqualsIgnoreID(const Address& other) const { | 331 bool Address::EqualsIgnoreID(const Address& other) const { |
312 return country_name_code_ == other.country_name_code_ && | 332 return country_name_code_ == other.country_name_code_ && |
313 recipient_name_ == other.recipient_name_ && | 333 recipient_name_ == other.recipient_name_ && |
314 address_line_1_ == other.address_line_1_ && | 334 address_line_1_ == other.address_line_1_ && |
315 address_line_2_ == other.address_line_2_ && | 335 address_line_2_ == other.address_line_2_ && |
316 locality_name_ == other.locality_name_ && | 336 locality_name_ == other.locality_name_ && |
317 administrative_area_name_ == other.administrative_area_name_ && | 337 administrative_area_name_ == other.administrative_area_name_ && |
318 postal_code_number_ == other.postal_code_number_ && | 338 postal_code_number_ == other.postal_code_number_ && |
319 phone_number_ == other.phone_number_ && | 339 phone_number_ == other.phone_number_ && |
320 is_complete_address_ == other.is_complete_address_; | 340 is_complete_address_ == other.is_complete_address_; |
321 } | 341 } |
322 | 342 |
323 bool Address::operator==(const Address& other) const { | 343 bool Address::operator==(const Address& other) const { |
324 return object_id_ == other.object_id_ && EqualsIgnoreID(other); | 344 return object_id_ == other.object_id_ && EqualsIgnoreID(other); |
325 } | 345 } |
326 | 346 |
327 bool Address::operator!=(const Address& other) const { | 347 bool Address::operator!=(const Address& other) const { |
328 return !(*this == other); | 348 return !(*this == other); |
329 } | 349 } |
330 | 350 |
331 } // namespace wallet | 351 } // namespace wallet |
332 } // namespace autofill | 352 } // namespace autofill |
OLD | NEW |