| 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_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // Server specified type for address with complete details. | 21 // Server specified type for address with complete details. |
| 22 const char kFullAddress[] = "FULL"; | 22 const char kFullAddress[] = "FULL"; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 Address* CreateAddressInternal(const base::DictionaryValue& dictionary, | 26 Address* CreateAddressInternal(const base::DictionaryValue& dictionary, |
| 27 const std::string& object_id) { | 27 const std::string& object_id) { |
| 28 std::string country_name_code; | 28 std::string country_name_code; |
| 29 if (!dictionary.GetString("postal_address.country_name_code", | 29 if (!dictionary.GetString("postal_address.country_name_code", |
| 30 &country_name_code)) { | 30 &country_name_code)) { |
| 31 DLOG(ERROR) << "Response from Google Wallet missing country name"; | 31 DLOG(ERROR) << "Response from Google Payments missing country name"; |
| 32 return NULL; | 32 return NULL; |
| 33 } | 33 } |
| 34 | 34 |
| 35 base::string16 recipient_name; | 35 base::string16 recipient_name; |
| 36 if (!dictionary.GetString("postal_address.recipient_name", | 36 if (!dictionary.GetString("postal_address.recipient_name", |
| 37 &recipient_name)) { | 37 &recipient_name)) { |
| 38 DLOG(ERROR) << "Response from Google Wallet missing recipient name"; | 38 DLOG(ERROR) << "Response from Google Payments missing recipient name"; |
| 39 return NULL; | 39 return NULL; |
| 40 } | 40 } |
| 41 | 41 |
| 42 base::string16 postal_code_number; | 42 base::string16 postal_code_number; |
| 43 if (!dictionary.GetString("postal_address.postal_code_number", | 43 if (!dictionary.GetString("postal_address.postal_code_number", |
| 44 &postal_code_number)) { | 44 &postal_code_number)) { |
| 45 DLOG(ERROR) << "Response from Google Wallet missing postal code number"; | 45 DLOG(ERROR) << "Response from Google Payments missing postal code number"; |
| 46 return NULL; | 46 return NULL; |
| 47 } | 47 } |
| 48 // TODO(estade): what about postal_code_number_extension? | 48 // TODO(estade): what about postal_code_number_extension? |
| 49 | 49 |
| 50 base::string16 sorting_code; | 50 base::string16 sorting_code; |
| 51 if (!dictionary.GetString("postal_address.sorting_code", | 51 if (!dictionary.GetString("postal_address.sorting_code", |
| 52 &sorting_code)) { | 52 &sorting_code)) { |
| 53 DVLOG(1) << "Response from Google Wallet missing sorting code"; | 53 DVLOG(1) << "Response from Google Payments missing sorting code"; |
| 54 } | 54 } |
| 55 | 55 |
| 56 base::string16 phone_number; | 56 base::string16 phone_number; |
| 57 if (!dictionary.GetString("phone_number", &phone_number)) | 57 if (!dictionary.GetString("phone_number", &phone_number)) |
| 58 DVLOG(1) << "Response from Google Wallet missing phone number"; | 58 DVLOG(1) << "Response from Google Payments missing phone number"; |
| 59 | 59 |
| 60 std::vector<base::string16> street_address; | 60 std::vector<base::string16> street_address; |
| 61 const base::ListValue* address_line_list; | 61 const base::ListValue* address_line_list; |
| 62 if (dictionary.GetList("postal_address.address_line", &address_line_list)) { | 62 if (dictionary.GetList("postal_address.address_line", &address_line_list)) { |
| 63 for (size_t i = 0; i < address_line_list->GetSize(); ++i) { | 63 for (size_t i = 0; i < address_line_list->GetSize(); ++i) { |
| 64 base::string16 line; | 64 base::string16 line; |
| 65 address_line_list->GetString(i, &line); | 65 address_line_list->GetString(i, &line); |
| 66 street_address.push_back(line); | 66 street_address.push_back(line); |
| 67 } | 67 } |
| 68 } else { | 68 } else { |
| 69 DVLOG(1) << "Response from Google Wallet missing address lines"; | 69 DVLOG(1) << "Response from Google Payments missing address lines"; |
| 70 } | 70 } |
| 71 | 71 |
| 72 base::string16 locality_name; | 72 base::string16 locality_name; |
| 73 if (!dictionary.GetString("postal_address.locality_name", | 73 if (!dictionary.GetString("postal_address.locality_name", |
| 74 &locality_name)) { | 74 &locality_name)) { |
| 75 DVLOG(1) << "Response from Google Wallet missing locality name"; | 75 DVLOG(1) << "Response from Google Payments missing locality name"; |
| 76 } | 76 } |
| 77 | 77 |
| 78 base::string16 dependent_locality_name; | 78 base::string16 dependent_locality_name; |
| 79 if (!dictionary.GetString("postal_address.dependent_locality_name", | 79 if (!dictionary.GetString("postal_address.dependent_locality_name", |
| 80 &dependent_locality_name)) { | 80 &dependent_locality_name)) { |
| 81 DVLOG(1) << "Response from Google Wallet missing dependent locality name"; | 81 DVLOG(1) << "Response from Google Payments missing dependent locality name"; |
| 82 } | 82 } |
| 83 | 83 |
| 84 base::string16 administrative_area_name; | 84 base::string16 administrative_area_name; |
| 85 if (!dictionary.GetString("postal_address.administrative_area_name", | 85 if (!dictionary.GetString("postal_address.administrative_area_name", |
| 86 &administrative_area_name)) { | 86 &administrative_area_name)) { |
| 87 DVLOG(1) << "Response from Google Wallet missing administrative area name"; | 87 DVLOG(1) |
| 88 << "Response from Google Payments missing administrative area name"; |
| 88 } | 89 } |
| 89 | 90 |
| 90 std::string language_code; | 91 std::string language_code; |
| 91 if (!dictionary.GetString("postal_address.language_code", | 92 if (!dictionary.GetString("postal_address.language_code", |
| 92 &language_code)) { | 93 &language_code)) { |
| 93 DVLOG(1) << "Response from Google Wallet missing language code"; | 94 DVLOG(1) << "Response from Google Payments missing language code"; |
| 94 } | 95 } |
| 95 | 96 |
| 96 Address* address = new Address(country_name_code, | 97 Address* address = new Address(country_name_code, |
| 97 recipient_name, | 98 recipient_name, |
| 98 street_address, | 99 street_address, |
| 99 locality_name, | 100 locality_name, |
| 100 dependent_locality_name, | 101 dependent_locality_name, |
| 101 administrative_area_name, | 102 administrative_area_name, |
| 102 postal_code_number, | 103 postal_code_number, |
| 103 sorting_code, | 104 sorting_code, |
| 104 phone_number, | 105 phone_number, |
| 105 object_id, | 106 object_id, |
| 106 language_code); | 107 language_code); |
| 107 | 108 |
| 108 bool is_minimal_address = false; | 109 bool is_minimal_address = false; |
| 109 if (dictionary.GetBoolean("is_minimal_address", &is_minimal_address)) | 110 if (dictionary.GetBoolean("is_minimal_address", &is_minimal_address)) |
| 110 address->set_is_complete_address(!is_minimal_address); | 111 address->set_is_complete_address(!is_minimal_address); |
| 111 else | 112 else |
| 112 DVLOG(1) << "Response from Google Wallet missing is_minimal_address bit"; | 113 DVLOG(1) << "Response from Google Payments missing is_minimal_address bit"; |
| 113 | 114 |
| 114 return address; | 115 return address; |
| 115 } | 116 } |
| 116 | 117 |
| 117 } // namespace | 118 } // namespace |
| 118 | 119 |
| 119 Address::Address() {} | 120 Address::Address() {} |
| 120 | 121 |
| 121 Address::Address(const AutofillProfile& profile) | 122 Address::Address(const AutofillProfile& profile) |
| 122 : country_name_code_( | 123 : country_name_code_( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 is_complete_address_(true), | 164 is_complete_address_(true), |
| 164 language_code_(language_code) {} | 165 language_code_(language_code) {} |
| 165 | 166 |
| 166 Address::~Address() {} | 167 Address::~Address() {} |
| 167 | 168 |
| 168 // static | 169 // static |
| 169 scoped_ptr<Address> Address::CreateAddressWithID( | 170 scoped_ptr<Address> Address::CreateAddressWithID( |
| 170 const base::DictionaryValue& dictionary) { | 171 const base::DictionaryValue& dictionary) { |
| 171 std::string object_id; | 172 std::string object_id; |
| 172 if (!dictionary.GetString("id", &object_id)) { | 173 if (!dictionary.GetString("id", &object_id)) { |
| 173 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 174 DLOG(ERROR) << "Response from Google Payments missing object id"; |
| 174 return scoped_ptr<Address>(); | 175 return scoped_ptr<Address>(); |
| 175 } | 176 } |
| 176 return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); | 177 return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); |
| 177 } | 178 } |
| 178 | 179 |
| 179 // static | 180 // static |
| 180 scoped_ptr<Address> Address::CreateAddress( | 181 scoped_ptr<Address> Address::CreateAddress( |
| 181 const base::DictionaryValue& dictionary) { | 182 const base::DictionaryValue& dictionary) { |
| 182 std::string object_id; | 183 std::string object_id; |
| 183 dictionary.GetString("id", &object_id); | 184 dictionary.GetString("id", &object_id); |
| 184 return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); | 185 return scoped_ptr<Address>(CreateAddressInternal(dictionary, object_id)); |
| 185 } | 186 } |
| 186 | 187 |
| 187 // static | 188 // static |
| 188 scoped_ptr<Address> Address::CreateDisplayAddress( | 189 scoped_ptr<Address> Address::CreateDisplayAddress( |
| 189 const base::DictionaryValue& dictionary) { | 190 const base::DictionaryValue& dictionary) { |
| 190 std::string country_code; | 191 std::string country_code; |
| 191 if (!dictionary.GetString("country_code", &country_code)) { | 192 if (!dictionary.GetString("country_code", &country_code)) { |
| 192 DLOG(ERROR) << "Reponse from Google Wallet missing country code"; | 193 DLOG(ERROR) << "Reponse from Google Payments missing country code"; |
| 193 return scoped_ptr<Address>(); | 194 return scoped_ptr<Address>(); |
| 194 } | 195 } |
| 195 | 196 |
| 196 base::string16 name; | 197 base::string16 name; |
| 197 if (!dictionary.GetString("name", &name)) { | 198 if (!dictionary.GetString("name", &name)) { |
| 198 DLOG(ERROR) << "Reponse from Google Wallet missing name"; | 199 DLOG(ERROR) << "Reponse from Google Payments missing name"; |
| 199 return scoped_ptr<Address>(); | 200 return scoped_ptr<Address>(); |
| 200 } | 201 } |
| 201 | 202 |
| 202 base::string16 postal_code; | 203 base::string16 postal_code; |
| 203 if (!dictionary.GetString("postal_code", &postal_code)) { | 204 if (!dictionary.GetString("postal_code", &postal_code)) { |
| 204 DLOG(ERROR) << "Reponse from Google Wallet missing postal code"; | 205 DLOG(ERROR) << "Reponse from Google Payments missing postal code"; |
| 205 return scoped_ptr<Address>(); | 206 return scoped_ptr<Address>(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 base::string16 sorting_code; | 209 base::string16 sorting_code; |
| 209 if (!dictionary.GetString("sorting_code", &sorting_code)) { | 210 if (!dictionary.GetString("sorting_code", &sorting_code)) { |
| 210 DVLOG(1) << "Reponse from Google Wallet missing sorting code"; | 211 DVLOG(1) << "Reponse from Google Payments missing sorting code"; |
| 211 } | 212 } |
| 212 | 213 |
| 213 std::vector<base::string16> street_address; | 214 std::vector<base::string16> street_address; |
| 214 base::string16 address1; | 215 base::string16 address1; |
| 215 if (dictionary.GetString("address1", &address1)) | 216 if (dictionary.GetString("address1", &address1)) |
| 216 street_address.push_back(address1); | 217 street_address.push_back(address1); |
| 217 else | 218 else |
| 218 DVLOG(1) << "Reponse from Google Wallet missing address1"; | 219 DVLOG(1) << "Reponse from Google Payments missing address1"; |
| 219 | 220 |
| 220 base::string16 address2; | 221 base::string16 address2; |
| 221 if (dictionary.GetString("address2", &address2) && !address2.empty()) { | 222 if (dictionary.GetString("address2", &address2) && !address2.empty()) { |
| 222 street_address.resize(2); | 223 street_address.resize(2); |
| 223 street_address[1] = address2; | 224 street_address[1] = address2; |
| 224 } else { | 225 } else { |
| 225 DVLOG(1) << "Reponse from Google Wallet missing or empty address2"; | 226 DVLOG(1) << "Reponse from Google Payments missing or empty address2"; |
| 226 } | 227 } |
| 227 | 228 |
| 228 base::string16 city; | 229 base::string16 city; |
| 229 if (!dictionary.GetString("city", &city)) | 230 if (!dictionary.GetString("city", &city)) |
| 230 DVLOG(1) << "Reponse from Google Wallet missing city"; | 231 DVLOG(1) << "Reponse from Google Payments missing city"; |
| 231 | 232 |
| 232 base::string16 dependent_locality_name; | 233 base::string16 dependent_locality_name; |
| 233 if (!dictionary.GetString("dependent_locality_name", | 234 if (!dictionary.GetString("dependent_locality_name", |
| 234 &dependent_locality_name)) { | 235 &dependent_locality_name)) { |
| 235 DVLOG(1) << "Reponse from Google Wallet missing district"; | 236 DVLOG(1) << "Reponse from Google Payments missing district"; |
| 236 } | 237 } |
| 237 | 238 |
| 238 base::string16 state; | 239 base::string16 state; |
| 239 if (!dictionary.GetString("state", &state)) | 240 if (!dictionary.GetString("state", &state)) |
| 240 DVLOG(1) << "Reponse from Google Wallet missing state"; | 241 DVLOG(1) << "Reponse from Google Payments missing state"; |
| 241 | 242 |
| 242 base::string16 phone_number; | 243 base::string16 phone_number; |
| 243 if (!dictionary.GetString("phone_number", &phone_number)) | 244 if (!dictionary.GetString("phone_number", &phone_number)) |
| 244 DVLOG(1) << "Reponse from Google Wallet missing phone number"; | 245 DVLOG(1) << "Reponse from Google Payments missing phone number"; |
| 245 | 246 |
| 246 std::string address_state; | 247 std::string address_state; |
| 247 if (!dictionary.GetString("type", &address_state)) | 248 if (!dictionary.GetString("type", &address_state)) |
| 248 DVLOG(1) << "Response from Google Wallet missing type/state of address"; | 249 DVLOG(1) << "Response from Google Payments missing type/state of address"; |
| 249 | 250 |
| 250 std::string language_code; | 251 std::string language_code; |
| 251 if (!dictionary.GetString("language_code", &language_code)) | 252 if (!dictionary.GetString("language_code", &language_code)) |
| 252 DVLOG(1) << "Response from Google Wallet missing language code"; | 253 DVLOG(1) << "Response from Google Payments missing language code"; |
| 253 | 254 |
| 254 scoped_ptr<Address> address( | 255 scoped_ptr<Address> address( |
| 255 new Address(country_code, | 256 new Address(country_code, |
| 256 name, | 257 name, |
| 257 street_address, | 258 street_address, |
| 258 city, | 259 city, |
| 259 dependent_locality_name, | 260 dependent_locality_name, |
| 260 state, | 261 state, |
| 261 postal_code, | 262 postal_code, |
| 262 sorting_code, | 263 sorting_code, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 language_code_ == other.language_code_ && | 411 language_code_ == other.language_code_ && |
| 411 EqualsIgnoreID(other); | 412 EqualsIgnoreID(other); |
| 412 } | 413 } |
| 413 | 414 |
| 414 bool Address::operator!=(const Address& other) const { | 415 bool Address::operator!=(const Address& other) const { |
| 415 return !(*this == other); | 416 return !(*this == other); |
| 416 } | 417 } |
| 417 | 418 |
| 418 } // namespace wallet | 419 } // namespace wallet |
| 419 } // namespace autofill | 420 } // namespace autofill |
| OLD | NEW |