Chromium Code Reviews| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 | 98 |
| 98 Address::Address(const AutofillProfile& profile) | 99 Address::Address(const AutofillProfile& profile) |
| 99 : country_name_code_( | 100 : country_name_code_( |
| 100 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))), | 101 UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))), |
| 101 recipient_name_(profile.GetRawInfo(NAME_FULL)), | 102 recipient_name_(profile.GetRawInfo(NAME_FULL)), |
| 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)), |
| 108 phone_object_(phone_number_, country_name_code_), | |
| 107 is_complete_address_(true) { | 109 is_complete_address_(true) { |
| 108 state_names::GetNameAndAbbreviation(profile.GetRawInfo(ADDRESS_HOME_STATE), | 110 state_names::GetNameAndAbbreviation(profile.GetRawInfo(ADDRESS_HOME_STATE), |
| 109 NULL, | 111 NULL, |
| 110 &administrative_area_name_); | 112 &administrative_area_name_); |
| 111 StringToUpperASCII(&administrative_area_name_); | 113 StringToUpperASCII(&administrative_area_name_); |
| 112 } | 114 } |
| 113 | 115 |
| 114 Address::Address(const std::string& country_name_code, | 116 Address::Address(const std::string& country_name_code, |
| 115 const string16& recipient_name, | 117 const string16& recipient_name, |
| 116 const string16& address_line_1, | 118 const string16& address_line_1, |
| 117 const string16& address_line_2, | 119 const string16& address_line_2, |
| 118 const string16& locality_name, | 120 const string16& locality_name, |
| 119 const string16& administrative_area_name, | 121 const string16& administrative_area_name, |
| 120 const string16& postal_code_number, | 122 const string16& postal_code_number, |
| 121 const string16& phone_number, | 123 const string16& phone_number, |
| 122 const std::string& object_id) | 124 const std::string& object_id) |
| 123 : country_name_code_(country_name_code), | 125 : country_name_code_(country_name_code), |
| 124 recipient_name_(recipient_name), | 126 recipient_name_(recipient_name), |
| 125 address_line_1_(address_line_1), | 127 address_line_1_(address_line_1), |
| 126 address_line_2_(address_line_2), | 128 address_line_2_(address_line_2), |
| 127 locality_name_(locality_name), | 129 locality_name_(locality_name), |
| 128 administrative_area_name_(administrative_area_name), | 130 administrative_area_name_(administrative_area_name), |
| 129 postal_code_number_(postal_code_number), | 131 postal_code_number_(postal_code_number), |
| 130 phone_number_(phone_number), | 132 phone_number_(phone_number), |
| 133 phone_object_(phone_number_, country_name_code_), | |
|
aruslan
2013/10/01 01:51:17
We couldn't have any issues with the field declara
Evan Stade
2013/10/01 02:00:36
I did this to match L108, and yes it's safe.
| |
| 131 object_id_(object_id), | 134 object_id_(object_id), |
| 132 is_complete_address_(true) { | 135 is_complete_address_(true) {} |
| 133 } | |
| 134 | 136 |
| 135 Address::~Address() {} | 137 Address::~Address() {} |
| 136 | 138 |
| 137 // static | 139 // static |
| 138 scoped_ptr<Address> Address::CreateAddressWithID( | 140 scoped_ptr<Address> Address::CreateAddressWithID( |
| 139 const base::DictionaryValue& dictionary) { | 141 const base::DictionaryValue& dictionary) { |
| 140 std::string object_id; | 142 std::string object_id; |
| 141 if (!dictionary.GetString("id", &object_id)) { | 143 if (!dictionary.GetString("id", &object_id)) { |
| 142 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 144 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
| 143 return scoped_ptr<Address>(); | 145 return scoped_ptr<Address>(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 | 257 |
| 256 string16 Address::DisplayNameDetail() const { | 258 string16 Address::DisplayNameDetail() const { |
| 257 #if defined(OS_ANDROID) | 259 #if defined(OS_ANDROID) |
| 258 // TODO(aruslan): improve this stub implementation. | 260 // TODO(aruslan): improve this stub implementation. |
| 259 return address_line_1(); | 261 return address_line_1(); |
| 260 #else | 262 #else |
| 261 return string16(); | 263 return string16(); |
| 262 #endif | 264 #endif |
| 263 } | 265 } |
| 264 | 266 |
| 267 string16 Address::DisplayPhoneNumber() const { | |
| 268 // Return a formatted phone number. Wallet doesn't store user formatting, so | |
| 269 // impose our own. phone_number() always includes a country code, so using | |
| 270 // PhoneObject to format it would result in an internationalized format. Since | |
| 271 // Wallet only supports the US right now, stick to national formatting. | |
| 272 return i18n::PhoneObject(phone_number(), country_name_code()). | |
| 273 GetNationallyFormattedNumber(); | |
| 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 17 matching lines...) Expand all Loading... | |
| 292 | 303 |
| 293 case ADDRESS_HOME_ZIP: | 304 case ADDRESS_HOME_ZIP: |
| 294 return postal_code_number(); | 305 return postal_code_number(); |
| 295 | 306 |
| 296 case ADDRESS_HOME_COUNTRY: { | 307 case ADDRESS_HOME_COUNTRY: { |
| 297 AutofillCountry country(country_name_code(), app_locale); | 308 AutofillCountry country(country_name_code(), app_locale); |
| 298 return country.name(); | 309 return country.name(); |
| 299 } | 310 } |
| 300 | 311 |
| 301 case PHONE_HOME_WHOLE_NUMBER: | 312 case PHONE_HOME_WHOLE_NUMBER: |
| 302 return phone_number(); | 313 // Wallet doesn't store user phone number formatting, so just strip all |
| 314 // formatting. | |
| 315 return phone_object_.GetWholeNumber(); | |
| 303 | 316 |
| 304 // TODO(estade): implement more. | 317 // TODO(estade): implement more. |
| 305 default: | 318 default: |
| 306 NOTREACHED(); | 319 NOTREACHED(); |
| 307 return string16(); | 320 return string16(); |
| 308 } | 321 } |
| 309 } | 322 } |
| 310 | 323 |
| 311 bool Address::EqualsIgnoreID(const Address& other) const { | 324 bool Address::EqualsIgnoreID(const Address& other) const { |
| 312 return country_name_code_ == other.country_name_code_ && | 325 return country_name_code_ == other.country_name_code_ && |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 323 bool Address::operator==(const Address& other) const { | 336 bool Address::operator==(const Address& other) const { |
| 324 return object_id_ == other.object_id_ && EqualsIgnoreID(other); | 337 return object_id_ == other.object_id_ && EqualsIgnoreID(other); |
| 325 } | 338 } |
| 326 | 339 |
| 327 bool Address::operator!=(const Address& other) const { | 340 bool Address::operator!=(const Address& other) const { |
| 328 return !(*this == other); | 341 return !(*this == other); |
| 329 } | 342 } |
| 330 | 343 |
| 331 } // namespace wallet | 344 } // namespace wallet |
| 332 } // namespace autofill | 345 } // namespace autofill |
| OLD | NEW |