| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 const string16& postal_code_number, | 121 const string16& postal_code_number, |
| 121 const string16& phone_number, | 122 const string16& phone_number, |
| 122 const std::string& object_id) | 123 const std::string& object_id) |
| 123 : country_name_code_(country_name_code), | 124 : country_name_code_(country_name_code), |
| 124 recipient_name_(recipient_name), | 125 recipient_name_(recipient_name), |
| 125 address_line_1_(address_line_1), | 126 address_line_1_(address_line_1), |
| 126 address_line_2_(address_line_2), | 127 address_line_2_(address_line_2), |
| 127 locality_name_(locality_name), | 128 locality_name_(locality_name), |
| 128 administrative_area_name_(administrative_area_name), | 129 administrative_area_name_(administrative_area_name), |
| 129 postal_code_number_(postal_code_number), | 130 postal_code_number_(postal_code_number), |
| 130 phone_number_(phone_number), | |
| 131 object_id_(object_id), | 131 object_id_(object_id), |
| 132 is_complete_address_(true) { | 132 is_complete_address_(true) { |
| 133 // Wallet doesn't store user phone number formatting, so just strip all |
| 134 // formatting. |
| 135 i18n::PhoneObject phone(phone_number, country_name_code); |
| 136 phone_number_ = phone.GetWholeNumber(); |
| 133 } | 137 } |
| 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"; |
| (...skipping 112 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |