| 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_items.h" | 5 #include "components/autofill/content/browser/wallet/wallet_items.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.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" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 DLOG(ERROR) << "Response from Google Wallet missing status"; | 148 DLOG(ERROR) << "Response from Google Wallet missing status"; |
| 149 return scoped_ptr<MaskedInstrument>(); | 149 return scoped_ptr<MaskedInstrument>(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 std::string object_id; | 152 std::string object_id; |
| 153 if (!dictionary.GetString("object_id", &object_id)) { | 153 if (!dictionary.GetString("object_id", &object_id)) { |
| 154 DLOG(ERROR) << "Response from Google Wallet missing object id"; | 154 DLOG(ERROR) << "Response from Google Wallet missing object id"; |
| 155 return scoped_ptr<MaskedInstrument>(); | 155 return scoped_ptr<MaskedInstrument>(); |
| 156 } | 156 } |
| 157 | 157 |
| 158 const DictionaryValue* address_dict; | 158 const base::DictionaryValue* address_dict; |
| 159 if (!dictionary.GetDictionary("billing_address", &address_dict)) { | 159 if (!dictionary.GetDictionary("billing_address", &address_dict)) { |
| 160 DLOG(ERROR) << "Response from Google wallet missing address"; | 160 DLOG(ERROR) << "Response from Google wallet missing address"; |
| 161 return scoped_ptr<MaskedInstrument>(); | 161 return scoped_ptr<MaskedInstrument>(); |
| 162 } | 162 } |
| 163 scoped_ptr<Address> address = Address::CreateDisplayAddress(*address_dict); | 163 scoped_ptr<Address> address = Address::CreateDisplayAddress(*address_dict); |
| 164 | 164 |
| 165 if (!address) { | 165 if (!address) { |
| 166 DLOG(ERROR) << "Response from Google wallet contained malformed address"; | 166 DLOG(ERROR) << "Response from Google wallet contained malformed address"; |
| 167 return scoped_ptr<MaskedInstrument>(); | 167 return scoped_ptr<MaskedInstrument>(); |
| 168 } | 168 } |
| 169 | 169 |
| 170 std::vector<base::string16> supported_currencies; | 170 std::vector<base::string16> supported_currencies; |
| 171 const ListValue* supported_currency_list; | 171 const base::ListValue* supported_currency_list; |
| 172 if (dictionary.GetList("supported_currency", &supported_currency_list)) { | 172 if (dictionary.GetList("supported_currency", &supported_currency_list)) { |
| 173 for (size_t i = 0; i < supported_currency_list->GetSize(); ++i) { | 173 for (size_t i = 0; i < supported_currency_list->GetSize(); ++i) { |
| 174 base::string16 currency; | 174 base::string16 currency; |
| 175 if (supported_currency_list->GetString(i, ¤cy)) | 175 if (supported_currency_list->GetString(i, ¤cy)) |
| 176 supported_currencies.push_back(currency); | 176 supported_currencies.push_back(currency); |
| 177 } | 177 } |
| 178 } else { | 178 } else { |
| 179 DVLOG(1) << "Response from Google Wallet missing supported currency"; | 179 DVLOG(1) << "Response from Google Wallet missing supported currency"; |
| 180 } | 180 } |
| 181 | 181 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 default_instrument_id_(default_instrument_id), | 430 default_instrument_id_(default_instrument_id), |
| 431 default_address_id_(default_address_id), | 431 default_address_id_(default_address_id), |
| 432 active_account_index_(std::numeric_limits<size_t>::max()), | 432 active_account_index_(std::numeric_limits<size_t>::max()), |
| 433 amex_permission_(amex_permission) {} | 433 amex_permission_(amex_permission) {} |
| 434 | 434 |
| 435 WalletItems::~WalletItems() {} | 435 WalletItems::~WalletItems() {} |
| 436 | 436 |
| 437 scoped_ptr<WalletItems> | 437 scoped_ptr<WalletItems> |
| 438 WalletItems::CreateWalletItems(const base::DictionaryValue& dictionary) { | 438 WalletItems::CreateWalletItems(const base::DictionaryValue& dictionary) { |
| 439 std::vector<RequiredAction> required_action; | 439 std::vector<RequiredAction> required_action; |
| 440 const ListValue* required_action_list; | 440 const base::ListValue* required_action_list; |
| 441 if (dictionary.GetList("required_action", &required_action_list)) { | 441 if (dictionary.GetList("required_action", &required_action_list)) { |
| 442 for (size_t i = 0; i < required_action_list->GetSize(); ++i) { | 442 for (size_t i = 0; i < required_action_list->GetSize(); ++i) { |
| 443 std::string action_string; | 443 std::string action_string; |
| 444 if (required_action_list->GetString(i, &action_string)) { | 444 if (required_action_list->GetString(i, &action_string)) { |
| 445 RequiredAction action = ParseRequiredActionFromString(action_string); | 445 RequiredAction action = ParseRequiredActionFromString(action_string); |
| 446 if (!ActionAppliesToWalletItems(action)) { | 446 if (!ActionAppliesToWalletItems(action)) { |
| 447 DLOG(ERROR) << "Response from Google wallet with bad required action:" | 447 DLOG(ERROR) << "Response from Google wallet with bad required action:" |
| 448 " \"" << action_string << "\""; | 448 " \"" << action_string << "\""; |
| 449 return scoped_ptr<WalletItems>(); | 449 return scoped_ptr<WalletItems>(); |
| 450 } | 450 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 494 |
| 495 scoped_ptr<GaiaAccount> gaia_account( | 495 scoped_ptr<GaiaAccount> gaia_account( |
| 496 GaiaAccount::Create(*account_dict)); | 496 GaiaAccount::Create(*account_dict)); |
| 497 if (gaia_account) | 497 if (gaia_account) |
| 498 wallet_items->AddAccount(gaia_account.Pass()); | 498 wallet_items->AddAccount(gaia_account.Pass()); |
| 499 } | 499 } |
| 500 } else { | 500 } else { |
| 501 DVLOG(1) << "Response from Google wallet missing GAIA accounts"; | 501 DVLOG(1) << "Response from Google wallet missing GAIA accounts"; |
| 502 } | 502 } |
| 503 | 503 |
| 504 const ListValue* legal_docs; | 504 const base::ListValue* legal_docs; |
| 505 if (dictionary.GetList("required_legal_document", &legal_docs)) { | 505 if (dictionary.GetList("required_legal_document", &legal_docs)) { |
| 506 for (size_t i = 0; i < legal_docs->GetSize(); ++i) { | 506 for (size_t i = 0; i < legal_docs->GetSize(); ++i) { |
| 507 const DictionaryValue* legal_doc_dict; | 507 const base::DictionaryValue* legal_doc_dict; |
| 508 if (legal_docs->GetDictionary(i, &legal_doc_dict)) { | 508 if (legal_docs->GetDictionary(i, &legal_doc_dict)) { |
| 509 scoped_ptr<LegalDocument> legal_doc( | 509 scoped_ptr<LegalDocument> legal_doc( |
| 510 LegalDocument::CreateLegalDocument(*legal_doc_dict)); | 510 LegalDocument::CreateLegalDocument(*legal_doc_dict)); |
| 511 if (legal_doc) | 511 if (legal_doc) |
| 512 wallet_items->AddLegalDocument(legal_doc.Pass()); | 512 wallet_items->AddLegalDocument(legal_doc.Pass()); |
| 513 else | 513 else |
| 514 return scoped_ptr<WalletItems>(); | 514 return scoped_ptr<WalletItems>(); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 | 517 |
| 518 if (!legal_docs->empty()) { | 518 if (!legal_docs->empty()) { |
| 519 // Always append the privacy policy link as well. | 519 // Always append the privacy policy link as well. |
| 520 wallet_items->AddLegalDocument( | 520 wallet_items->AddLegalDocument( |
| 521 LegalDocument::CreatePrivacyPolicyDocument()); | 521 LegalDocument::CreatePrivacyPolicyDocument()); |
| 522 } | 522 } |
| 523 } else { | 523 } else { |
| 524 DVLOG(1) << "Response from Google wallet missing legal docs"; | 524 DVLOG(1) << "Response from Google wallet missing legal docs"; |
| 525 } | 525 } |
| 526 | 526 |
| 527 const ListValue* instruments; | 527 const base::ListValue* instruments; |
| 528 if (dictionary.GetList("instrument", &instruments)) { | 528 if (dictionary.GetList("instrument", &instruments)) { |
| 529 for (size_t i = 0; i < instruments->GetSize(); ++i) { | 529 for (size_t i = 0; i < instruments->GetSize(); ++i) { |
| 530 const DictionaryValue* instrument_dict; | 530 const base::DictionaryValue* instrument_dict; |
| 531 if (instruments->GetDictionary(i, &instrument_dict)) { | 531 if (instruments->GetDictionary(i, &instrument_dict)) { |
| 532 scoped_ptr<MaskedInstrument> instrument( | 532 scoped_ptr<MaskedInstrument> instrument( |
| 533 MaskedInstrument::CreateMaskedInstrument(*instrument_dict)); | 533 MaskedInstrument::CreateMaskedInstrument(*instrument_dict)); |
| 534 if (instrument) | 534 if (instrument) |
| 535 wallet_items->AddInstrument(instrument.Pass()); | 535 wallet_items->AddInstrument(instrument.Pass()); |
| 536 } | 536 } |
| 537 } | 537 } |
| 538 } else { | 538 } else { |
| 539 DVLOG(1) << "Response from Google wallet missing instruments"; | 539 DVLOG(1) << "Response from Google wallet missing instruments"; |
| 540 } | 540 } |
| 541 | 541 |
| 542 const ListValue* addresses; | 542 const base::ListValue* addresses; |
| 543 if (dictionary.GetList("address", &addresses)) { | 543 if (dictionary.GetList("address", &addresses)) { |
| 544 for (size_t i = 0; i < addresses->GetSize(); ++i) { | 544 for (size_t i = 0; i < addresses->GetSize(); ++i) { |
| 545 const DictionaryValue* address_dict; | 545 const base::DictionaryValue* address_dict; |
| 546 if (addresses->GetDictionary(i, &address_dict)) { | 546 if (addresses->GetDictionary(i, &address_dict)) { |
| 547 scoped_ptr<Address> address( | 547 scoped_ptr<Address> address( |
| 548 Address::CreateAddressWithID(*address_dict)); | 548 Address::CreateAddressWithID(*address_dict)); |
| 549 if (address) | 549 if (address) |
| 550 wallet_items->AddAddress(address.Pass()); | 550 wallet_items->AddAddress(address.Pass()); |
| 551 } | 551 } |
| 552 } | 552 } |
| 553 } else { | 553 } else { |
| 554 DVLOG(1) << "Response from Google wallet missing addresses"; | 554 DVLOG(1) << "Response from Google wallet missing addresses"; |
| 555 } | 555 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 585 VectorsAreEqual<LegalDocument>(legal_documents(), | 585 VectorsAreEqual<LegalDocument>(legal_documents(), |
| 586 other.legal_documents()); | 586 other.legal_documents()); |
| 587 } | 587 } |
| 588 | 588 |
| 589 bool WalletItems::operator!=(const WalletItems& other) const { | 589 bool WalletItems::operator!=(const WalletItems& other) const { |
| 590 return !(*this == other); | 590 return !(*this == other); |
| 591 } | 591 } |
| 592 | 592 |
| 593 } // namespace wallet | 593 } // namespace wallet |
| 594 } // namespace autofill | 594 } // namespace autofill |
| OLD | NEW |