[email protected] | 0407b4b | 2013-06-10 19:02:01 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 0407b4b | 2013-06-10 19:02:01 | [diff] [blame] | 5 | #include "components/autofill/content/browser/wallet/wallet_address.h" |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 6 | |
| 7 | #include "base/logging.h" |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 8 | #include "base/strings/string_split.h" |
[email protected] | c72674b | 2013-06-11 04:16:43 | [diff] [blame] | 9 | #include "base/strings/string_util.h" |
[email protected] | d2d79d5 | 2013-06-07 22:23:48 | [diff] [blame] | 10 | #include "base/strings/utf_string_conversions.h" |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 11 | #include "base/values.h" |
[email protected] | 526a16b | 2013-06-20 11:44:33 | [diff] [blame] | 12 | #include "components/autofill/core/browser/autofill_country.h" |
| 13 | #include "components/autofill/core/browser/autofill_profile.h" |
[email protected] | fbd42ec | 2013-08-07 04:56:18 | [diff] [blame] | 14 | #include "components/autofill/core/browser/autofill_type.h" |
[email protected] | fa8acde7 | 2013-10-02 07:21:36 | [diff] [blame] | 15 | #include "components/autofill/core/browser/phone_number.h" |
[email protected] | 526a16b | 2013-06-20 11:44:33 | [diff] [blame] | 16 | #include "components/autofill/core/browser/state_names.h" |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 17 | |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 18 | namespace autofill { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 19 | namespace wallet { |
| 20 | |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 21 | // Server specified type for address with complete details. |
| 22 | const char kFullAddress[] = "FULL"; |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 23 | |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | Address* CreateAddressInternal(const base::DictionaryValue& dictionary, |
| 27 | const std::string& object_id) { |
| 28 | std::string country_name_code; |
| 29 | if (!dictionary.GetString("postal_address.country_name_code", |
| 30 | &country_name_code)) { |
| 31 | DLOG(ERROR) << "Response from Google Wallet missing country name"; |
| 32 | return NULL; |
| 33 | } |
| 34 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 35 | base::string16 recipient_name; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 36 | if (!dictionary.GetString("postal_address.recipient_name", |
| 37 | &recipient_name)) { |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 38 | DLOG(ERROR) << "Response from Google Wallet missing recipient name"; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 39 | return NULL; |
| 40 | } |
| 41 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 42 | base::string16 postal_code_number; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 43 | if (!dictionary.GetString("postal_address.postal_code_number", |
| 44 | &postal_code_number)) { |
| 45 | DLOG(ERROR) << "Response from Google Wallet missing postal code number"; |
| 46 | return NULL; |
| 47 | } |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 48 | // TODO(estade): what about postal_code_number_extension? |
| 49 | |
| 50 | base::string16 sorting_code; |
| 51 | if (!dictionary.GetString("postal_address.sorting_code", |
| 52 | &sorting_code)) { |
| 53 | DVLOG(1) << "Response from Google Wallet missing sorting code"; |
| 54 | } |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 55 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 56 | base::string16 phone_number; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 57 | if (!dictionary.GetString("phone_number", &phone_number)) |
| 58 | DVLOG(1) << "Response from Google Wallet missing phone number"; |
| 59 | |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 60 | std::vector<base::string16> street_address; |
[email protected] | 85ecd7e | 2013-12-23 21:58:45 | [diff] [blame] | 61 | const base::ListValue* address_line_list; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 62 | if (dictionary.GetList("postal_address.address_line", &address_line_list)) { |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 63 | for (size_t i = 0; i < address_line_list->GetSize(); ++i) { |
| 64 | base::string16 line; |
| 65 | address_line_list->GetString(i, &line); |
| 66 | street_address.push_back(line); |
| 67 | } |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 68 | } else { |
| 69 | DVLOG(1) << "Response from Google Wallet missing address lines"; |
| 70 | } |
| 71 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 72 | base::string16 locality_name; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 73 | if (!dictionary.GetString("postal_address.locality_name", |
| 74 | &locality_name)) { |
| 75 | DVLOG(1) << "Response from Google Wallet missing locality name"; |
| 76 | } |
| 77 | |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 78 | base::string16 dependent_locality_name; |
| 79 | if (!dictionary.GetString("postal_address.dependent_locality_name", |
| 80 | &dependent_locality_name)) { |
| 81 | DVLOG(1) << "Response from Google Wallet missing dependent locality name"; |
| 82 | } |
| 83 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 84 | base::string16 administrative_area_name; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 85 | if (!dictionary.GetString("postal_address.administrative_area_name", |
| 86 | &administrative_area_name)) { |
| 87 | DVLOG(1) << "Response from Google Wallet missing administrative area name"; |
| 88 | } |
| 89 | |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 90 | std::string language_code; |
| 91 | if (!dictionary.GetString("postal_address.language_code", |
| 92 | &language_code)) { |
| 93 | DVLOG(1) << "Response from Google Wallet missing language code"; |
| 94 | } |
| 95 | |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 96 | Address* address = new Address(country_name_code, |
| 97 | recipient_name, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 98 | street_address, |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 99 | locality_name, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 100 | dependent_locality_name, |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 101 | administrative_area_name, |
| 102 | postal_code_number, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 103 | sorting_code, |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 104 | phone_number, |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 105 | object_id, |
| 106 | language_code); |
[email protected] | e1af3b6 | 2013-05-31 20:26:45 | [diff] [blame] | 107 | |
| 108 | bool is_minimal_address = false; |
| 109 | if (dictionary.GetBoolean("is_minimal_address", &is_minimal_address)) |
| 110 | address->set_is_complete_address(!is_minimal_address); |
| 111 | else |
| 112 | DVLOG(1) << "Response from Google Wallet missing is_minimal_address bit"; |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 113 | |
| 114 | return address; |
[email protected] | eab4e3c | 2013-03-05 00:54:48 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | } // namespace |
| 118 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 119 | Address::Address() {} |
| 120 | |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 121 | Address::Address(const AutofillProfile& profile) |
[email protected] | ed005f6f | 2013-04-05 17:03:56 | [diff] [blame] | 122 | : country_name_code_( |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 123 | base::UTF16ToASCII(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))), |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 124 | recipient_name_(profile.GetRawInfo(NAME_FULL)), |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 125 | locality_name_(profile.GetRawInfo(ADDRESS_HOME_CITY)), |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 126 | dependent_locality_name_( |
| 127 | profile.GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)), |
[email protected] | b847dd7 | 2014-02-06 11:12:47 | [diff] [blame] | 128 | administrative_area_name_(profile.GetRawInfo(ADDRESS_HOME_STATE)), |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 129 | postal_code_number_(profile.GetRawInfo(ADDRESS_HOME_ZIP)), |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 130 | sorting_code_(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)), |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 131 | phone_number_(profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER)), |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 132 | is_complete_address_(true), |
| 133 | language_code_(profile.language_code()) { |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 134 | base::SplitString( |
| 135 | profile.GetRawInfo(ADDRESS_HOME_STREET_ADDRESS), '\n', &street_address_); |
| 136 | |
[email protected] | fa8acde7 | 2013-10-02 07:21:36 | [diff] [blame] | 137 | if (!country_name_code_.empty()) |
| 138 | phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); |
[email protected] | d102bc5 | 2013-06-11 10:35:41 | [diff] [blame] | 139 | } |
[email protected] | 5a9ff50 | 2013-03-12 06:06:16 | [diff] [blame] | 140 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 141 | Address::Address(const std::string& country_name_code, |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 142 | const base::string16& recipient_name, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 143 | const std::vector<base::string16>& street_address, |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 144 | const base::string16& locality_name, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 145 | const base::string16& dependent_locality_name, |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 146 | const base::string16& administrative_area_name, |
| 147 | const base::string16& postal_code_number, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 148 | const base::string16& sorting_code, |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 149 | const base::string16& phone_number, |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 150 | const std::string& object_id, |
| 151 | const std::string& language_code) |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 152 | : country_name_code_(country_name_code), |
| 153 | recipient_name_(recipient_name), |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 154 | street_address_(street_address), |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 155 | locality_name_(locality_name), |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 156 | dependent_locality_name_(dependent_locality_name), |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 157 | administrative_area_name_(administrative_area_name), |
| 158 | postal_code_number_(postal_code_number), |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 159 | sorting_code_(sorting_code), |
[email protected] | 216062c | 2013-09-30 18:59:38 | [diff] [blame] | 160 | phone_number_(phone_number), |
[email protected] | fa8acde7 | 2013-10-02 07:21:36 | [diff] [blame] | 161 | phone_object_(phone_number, country_name_code), |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 162 | object_id_(object_id), |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 163 | is_complete_address_(true), |
| 164 | language_code_(language_code) {} |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 165 | |
| 166 | Address::~Address() {} |
| 167 | |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 168 | // static |
| 169 | scoped_ptr<Address> Address::CreateAddressWithID( |
| 170 | const base::DictionaryValue& dictionary) { |
| 171 | std::string object_id; |
| 172 | if (!dictionary.GetString("id", &object_id)) { |
| 173 | DLOG(ERROR) << "Response from Google Wallet missing object id"; |
| 174 | return scoped_ptr<Address>(); |
| 175 | } |
| 176 | return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); |
| 177 | } |
| 178 | |
| 179 | // static |
| 180 | scoped_ptr<Address> Address::CreateAddress( |
| 181 | const base::DictionaryValue& dictionary) { |
| 182 | std::string object_id; |
| 183 | dictionary.GetString("id", &object_id); |
| 184 | return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); |
| 185 | } |
| 186 | |
| 187 | // static |
| 188 | scoped_ptr<Address> Address::CreateDisplayAddress( |
| 189 | const base::DictionaryValue& dictionary) { |
| 190 | std::string country_code; |
| 191 | if (!dictionary.GetString("country_code", &country_code)) { |
| 192 | DLOG(ERROR) << "Reponse from Google Wallet missing country code"; |
| 193 | return scoped_ptr<Address>(); |
| 194 | } |
| 195 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 196 | base::string16 name; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 197 | if (!dictionary.GetString("name", &name)) { |
| 198 | DLOG(ERROR) << "Reponse from Google Wallet missing name"; |
| 199 | return scoped_ptr<Address>(); |
| 200 | } |
| 201 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 202 | base::string16 postal_code; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 203 | if (!dictionary.GetString("postal_code", &postal_code)) { |
| 204 | DLOG(ERROR) << "Reponse from Google Wallet missing postal code"; |
| 205 | return scoped_ptr<Address>(); |
| 206 | } |
| 207 | |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 208 | base::string16 sorting_code; |
| 209 | if (!dictionary.GetString("sorting_code", &sorting_code)) { |
| 210 | DVLOG(1) << "Reponse from Google Wallet missing sorting code"; |
| 211 | } |
| 212 | |
| 213 | std::vector<base::string16> street_address; |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 214 | base::string16 address1; |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 215 | if (dictionary.GetString("address1", &address1)) |
| 216 | street_address.push_back(address1); |
| 217 | else |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 218 | DVLOG(1) << "Reponse from Google Wallet missing address1"; |
| 219 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 220 | base::string16 address2; |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 221 | if (dictionary.GetString("address2", &address2) && !address2.empty()) { |
| 222 | street_address.resize(2); |
| 223 | street_address[1] = address2; |
| 224 | } else { |
| 225 | DVLOG(1) << "Reponse from Google Wallet missing or empty address2"; |
| 226 | } |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 227 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 228 | base::string16 city; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 229 | if (!dictionary.GetString("city", &city)) |
| 230 | DVLOG(1) << "Reponse from Google Wallet missing city"; |
| 231 | |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 232 | base::string16 dependent_locality_name; |
| 233 | if (!dictionary.GetString("dependent_locality_name", |
| 234 | &dependent_locality_name)) { |
| 235 | DVLOG(1) << "Reponse from Google Wallet missing district"; |
| 236 | } |
| 237 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 238 | base::string16 state; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 239 | if (!dictionary.GetString("state", &state)) |
| 240 | DVLOG(1) << "Reponse from Google Wallet missing state"; |
| 241 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 242 | base::string16 phone_number; |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 243 | if (!dictionary.GetString("phone_number", &phone_number)) |
| 244 | DVLOG(1) << "Reponse from Google Wallet missing phone number"; |
| 245 | |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 246 | std::string address_state; |
| 247 | if (!dictionary.GetString("type", &address_state)) |
| 248 | DVLOG(1) << "Response from Google Wallet missing type/state of address"; |
| 249 | |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 250 | std::string language_code; |
| 251 | if (!dictionary.GetString("language_code", &language_code)) |
| 252 | DVLOG(1) << "Response from Google Wallet missing language code"; |
| 253 | |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 254 | scoped_ptr<Address> address( |
| 255 | new Address(country_code, |
| 256 | name, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 257 | street_address, |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 258 | city, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 259 | dependent_locality_name, |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 260 | state, |
| 261 | postal_code, |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 262 | sorting_code, |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 263 | phone_number, |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 264 | std::string(), |
| 265 | language_code)); |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 266 | address->set_is_complete_address(address_state == kFullAddress); |
| 267 | |
| 268 | return address.Pass(); |
[email protected] | ca2fcbb | 2013-03-09 02:39:33 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | 1a04c12 | 2013-01-19 03:44:47 | [diff] [blame] | 271 | scoped_ptr<base::DictionaryValue> Address::ToDictionaryWithID() const { |
| 272 | scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 273 | |
| 274 | if (!object_id_.empty()) |
| 275 | dict->SetString("id", object_id_); |
| 276 | dict->SetString("phone_number", phone_number_); |
| 277 | dict->Set("postal_address", ToDictionaryWithoutID().release()); |
| 278 | |
| 279 | return dict.Pass(); |
| 280 | } |
| 281 | |
| 282 | scoped_ptr<base::DictionaryValue> Address::ToDictionaryWithoutID() const { |
| 283 | scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 284 | |
| 285 | scoped_ptr<base::ListValue> address_lines(new base::ListValue()); |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 286 | address_lines->AppendStrings(street_address_); |
[email protected] | 1a04c12 | 2013-01-19 03:44:47 | [diff] [blame] | 287 | dict->Set("address_line", address_lines.release()); |
| 288 | |
| 289 | dict->SetString("country_name_code", country_name_code_); |
| 290 | dict->SetString("recipient_name", recipient_name_); |
| 291 | dict->SetString("locality_name", locality_name_); |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 292 | dict->SetString("dependent_locality_name", dependent_locality_name_); |
[email protected] | 1a04c12 | 2013-01-19 03:44:47 | [diff] [blame] | 293 | dict->SetString("administrative_area_name", |
| 294 | administrative_area_name_); |
| 295 | dict->SetString("postal_code_number", postal_code_number_); |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 296 | dict->SetString("sorting_code", sorting_code_); |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 297 | dict->SetString("language_code", language_code_); |
[email protected] | 1a04c12 | 2013-01-19 03:44:47 | [diff] [blame] | 298 | |
| 299 | return dict.Pass(); |
| 300 | } |
| 301 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 302 | base::string16 Address::DisplayName() const { |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 303 | #if defined(OS_ANDROID) |
| 304 | // TODO(aruslan): improve this stub implementation. |
| 305 | return recipient_name(); |
| 306 | #else |
| 307 | // TODO(estade): improve this stub implementation + l10n. |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 308 | return recipient_name() + base::ASCIIToUTF16(", ") + GetStreetAddressLine(0); |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 309 | #endif |
| 310 | } |
| 311 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 312 | base::string16 Address::DisplayNameDetail() const { |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 313 | #if defined(OS_ANDROID) |
| 314 | // TODO(aruslan): improve this stub implementation. |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 315 | return GetStreetAddressLine(0); |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 316 | #else |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 317 | return base::string16(); |
[email protected] | 009c276 | 2013-03-15 10:55:48 | [diff] [blame] | 318 | #endif |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 319 | } |
| 320 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 321 | base::string16 Address::DisplayPhoneNumber() const { |
[email protected] | fa8acde7 | 2013-10-02 07:21:36 | [diff] [blame] | 322 | // Return a formatted phone number. Wallet doesn't store user formatting, so |
| 323 | // impose our own. phone_number() always includes a country code, so using |
| 324 | // PhoneObject to format it would result in an internationalized format. Since |
| 325 | // Wallet only supports the US right now, stick to national formatting. |
| 326 | return i18n::PhoneObject(phone_number(), country_name_code()). |
| 327 | GetNationallyFormattedNumber(); |
| 328 | } |
| 329 | |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 330 | base::string16 Address::GetInfo(const AutofillType& type, |
| 331 | const std::string& app_locale) const { |
[email protected] | 16f1159 | 2013-08-09 10:14:36 | [diff] [blame] | 332 | if (type.html_type() == HTML_TYPE_COUNTRY_CODE) { |
[email protected] | 52796541 | 2014-05-07 14:38:26 | [diff] [blame^] | 333 | DCHECK(base::IsStringASCII(country_name_code())); |
[email protected] | d519b81 | 2013-12-25 18:15:40 | [diff] [blame] | 334 | return base::ASCIIToUTF16(country_name_code()); |
[email protected] | 16f1159 | 2013-08-09 10:14:36 | [diff] [blame] | 335 | } |
| 336 | |
[email protected] | 792866efc | 2013-08-07 10:17:15 | [diff] [blame] | 337 | switch (type.GetStorableType()) { |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 338 | case NAME_FULL: |
[email protected] | e4da531 | 2013-02-20 08:11:18 | [diff] [blame] | 339 | return recipient_name(); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 340 | |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 341 | case ADDRESS_HOME_STREET_ADDRESS: |
| 342 | return JoinString(street_address_, base::ASCIIToUTF16("\n")); |
[email protected] | ab6a2391 | 2014-01-09 01:24:54 | [diff] [blame] | 343 | |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 344 | case ADDRESS_HOME_LINE1: |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 345 | return GetStreetAddressLine(0); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 346 | |
| 347 | case ADDRESS_HOME_LINE2: |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 348 | return GetStreetAddressLine(1); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 349 | |
| 350 | case ADDRESS_HOME_CITY: |
[email protected] | e4da531 | 2013-02-20 08:11:18 | [diff] [blame] | 351 | return locality_name(); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 352 | |
| 353 | case ADDRESS_HOME_STATE: |
[email protected] | 12d5a38 | 2013-03-05 09:05:43 | [diff] [blame] | 354 | return administrative_area_name(); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 355 | |
| 356 | case ADDRESS_HOME_ZIP: |
[email protected] | e4da531 | 2013-02-20 08:11:18 | [diff] [blame] | 357 | return postal_code_number(); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 358 | |
[email protected] | 87a9fb4 | 2013-03-04 23:08:38 | [diff] [blame] | 359 | case ADDRESS_HOME_COUNTRY: { |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 360 | AutofillCountry country(country_name_code(), app_locale); |
[email protected] | 87a9fb4 | 2013-03-04 23:08:38 | [diff] [blame] | 361 | return country.name(); |
| 362 | } |
| 363 | |
| 364 | case PHONE_HOME_WHOLE_NUMBER: |
[email protected] | fa8acde7 | 2013-10-02 07:21:36 | [diff] [blame] | 365 | // Wallet doesn't store user phone number formatting, so just strip all |
| 366 | // formatting. |
| 367 | return phone_object_.GetWholeNumber(); |
[email protected] | 87a9fb4 | 2013-03-04 23:08:38 | [diff] [blame] | 368 | |
[email protected] | 8319085 | 2013-12-05 06:53:24 | [diff] [blame] | 369 | case ADDRESS_HOME_DEPENDENT_LOCALITY: |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 370 | return dependent_locality_name_; |
| 371 | |
[email protected] | 8319085 | 2013-12-05 06:53:24 | [diff] [blame] | 372 | case ADDRESS_HOME_SORTING_CODE: |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 373 | return sorting_code_; |
| 374 | |
[email protected] | 8319085 | 2013-12-05 06:53:24 | [diff] [blame] | 375 | case COMPANY_NAME: |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 376 | // A field that Wallet doesn't support. TODO(dbeam): can it be supported? |
[email protected] | 8319085 | 2013-12-05 06:53:24 | [diff] [blame] | 377 | return base::string16(); |
| 378 | |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 379 | default: |
| 380 | NOTREACHED(); |
[email protected] | ca77581 | 2013-12-06 20:43:31 | [diff] [blame] | 381 | return base::string16(); |
[email protected] | b5093a7 | 2013-02-14 00:16:58 | [diff] [blame] | 382 | } |
| 383 | } |
[email protected] | 1a04c12 | 2013-01-19 03:44:47 | [diff] [blame] | 384 | |
[email protected] | fa8acde7 | 2013-10-02 07:21:36 | [diff] [blame] | 385 | void Address::SetPhoneNumber(const base::string16& phone_number) { |
| 386 | phone_number_ = phone_number; |
| 387 | phone_object_ = i18n::PhoneObject(phone_number_, country_name_code_); |
| 388 | } |
| 389 | |
[email protected] | df9751c | 2013-05-25 04:05:57 | [diff] [blame] | 390 | bool Address::EqualsIgnoreID(const Address& other) const { |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 391 | return country_name_code_ == other.country_name_code_ && |
| 392 | recipient_name_ == other.recipient_name_ && |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 393 | street_address_ == other.street_address_ && |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 394 | locality_name_ == other.locality_name_ && |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 395 | dependent_locality_name_ == other.dependent_locality_name_ && |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 396 | administrative_area_name_ == other.administrative_area_name_ && |
| 397 | postal_code_number_ == other.postal_code_number_ && |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 398 | sorting_code_ == other.sorting_code_ && |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 399 | phone_number_ == other.phone_number_ && |
[email protected] | 40c251e | 2013-05-23 22:34:20 | [diff] [blame] | 400 | is_complete_address_ == other.is_complete_address_; |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | 9cf2127 | 2014-02-15 04:56:27 | [diff] [blame] | 403 | base::string16 Address::GetStreetAddressLine(size_t line) const { |
| 404 | return street_address_.size() > line ? street_address_[line] : |
| 405 | base::string16(); |
| 406 | } |
| 407 | |
[email protected] | df9751c | 2013-05-25 04:05:57 | [diff] [blame] | 408 | bool Address::operator==(const Address& other) const { |
[email protected] | 0d66b19 | 2014-04-14 18:27:45 | [diff] [blame] | 409 | return object_id_ == other.object_id_ && |
| 410 | language_code_ == other.language_code_ && |
| 411 | EqualsIgnoreID(other); |
[email protected] | df9751c | 2013-05-25 04:05:57 | [diff] [blame] | 412 | } |
| 413 | |
[email protected] | ce63d6b | 2012-12-20 02:46:28 | [diff] [blame] | 414 | bool Address::operator!=(const Address& other) const { |
| 415 | return !(*this == other); |
| 416 | } |
| 417 | |
| 418 | } // namespace wallet |
[email protected] | 34517564 | 2013-02-20 19:25:52 | [diff] [blame] | 419 | } // namespace autofill |