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/full_wallet.h" | 5 #include "components/autofill/content/browser/wallet/full_wallet.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 10 matching lines...) Expand all Loading... | |
| 21 } // anonymous namespace | 21 } // anonymous namespace |
| 22 | 22 |
| 23 namespace autofill { | 23 namespace autofill { |
| 24 namespace wallet { | 24 namespace wallet { |
| 25 | 25 |
| 26 FullWallet::FullWallet(int expiration_month, | 26 FullWallet::FullWallet(int expiration_month, |
| 27 int expiration_year, | 27 int expiration_year, |
| 28 const std::string& iin, | 28 const std::string& iin, |
| 29 const std::string& encrypted_rest, | 29 const std::string& encrypted_rest, |
| 30 scoped_ptr<Address> billing_address, | 30 scoped_ptr<Address> billing_address, |
| 31 scoped_ptr<Address> shipping_address, | 31 scoped_ptr<Address> shipping_address) |
| 32 const std::vector<RequiredAction>& required_actions) | |
| 33 : expiration_month_(expiration_month), | 32 : expiration_month_(expiration_month), |
| 34 expiration_year_(expiration_year), | 33 expiration_year_(expiration_year), |
| 35 iin_(iin), | 34 iin_(iin), |
| 36 encrypted_rest_(encrypted_rest), | 35 encrypted_rest_(encrypted_rest), |
| 37 billing_address_(billing_address.Pass()), | 36 billing_address_(billing_address.Pass()), |
| 38 shipping_address_(shipping_address.Pass()), | 37 shipping_address_(shipping_address.Pass()) { |
| 39 required_actions_(required_actions) { | 38 DCHECK(billing_address_.get()); |
|
Dan Beam
2015/08/19 19:25:02
nit: drop the .get(), it's cleaner
| |
| 40 DCHECK(required_actions_.size() > 0 || billing_address_.get()); | |
| 41 } | 39 } |
| 42 | 40 |
| 43 FullWallet::~FullWallet() {} | 41 FullWallet::~FullWallet() {} |
| 44 | 42 |
| 45 // static | 43 // static |
| 46 scoped_ptr<FullWallet> | 44 scoped_ptr<FullWallet> |
| 47 FullWallet::CreateFullWallet(const base::DictionaryValue& dictionary) { | |
| 48 const base::ListValue* required_actions_list; | |
| 49 std::vector<RequiredAction> required_actions; | |
| 50 if (dictionary.GetList("required_action", &required_actions_list)) { | |
| 51 for (size_t i = 0; i < required_actions_list->GetSize(); ++i) { | |
| 52 std::string action_string; | |
| 53 if (required_actions_list->GetString(i, &action_string)) { | |
| 54 RequiredAction action = ParseRequiredActionFromString(action_string); | |
| 55 if (!ActionAppliesToFullWallet(action)) { | |
| 56 DLOG(ERROR) << "Response from Google wallet with bad required action:" | |
| 57 " \"" << action_string << "\""; | |
| 58 return scoped_ptr<FullWallet>(); | |
| 59 } | |
| 60 required_actions.push_back(action); | |
| 61 } | |
| 62 } | |
| 63 if (required_actions.size() > 0) { | |
| 64 return scoped_ptr<FullWallet>(new FullWallet(-1, | |
| 65 -1, | |
| 66 std::string(), | |
| 67 std::string(), | |
| 68 scoped_ptr<Address>(), | |
| 69 scoped_ptr<Address>(), | |
| 70 required_actions)); | |
| 71 } | |
| 72 } else { | |
| 73 DVLOG(1) << "Response from Google wallet missing required actions"; | |
| 74 } | |
| 75 | |
| 76 int expiration_month; | |
| 77 if (!dictionary.GetInteger("expiration_month", &expiration_month)) { | |
| 78 DLOG(ERROR) << "Response from Google wallet missing expiration month"; | |
| 79 return scoped_ptr<FullWallet>(); | |
| 80 } | |
| 81 | |
| 82 int expiration_year; | |
| 83 if (!dictionary.GetInteger("expiration_year", &expiration_year)) { | |
| 84 DLOG(ERROR) << "Response from Google wallet missing expiration year"; | |
| 85 return scoped_ptr<FullWallet>(); | |
| 86 } | |
| 87 | |
| 88 std::string iin; | |
| 89 if (!dictionary.GetString("iin", &iin)) { | |
| 90 DLOG(ERROR) << "Response from Google wallet missing iin"; | |
| 91 return scoped_ptr<FullWallet>(); | |
| 92 } | |
| 93 | |
| 94 std::string encrypted_rest; | |
| 95 if (!dictionary.GetString("rest", &encrypted_rest)) { | |
| 96 DLOG(ERROR) << "Response from Google wallet missing rest"; | |
| 97 return scoped_ptr<FullWallet>(); | |
| 98 } | |
| 99 | |
| 100 const base::DictionaryValue* billing_address_dict; | |
| 101 if (!dictionary.GetDictionary("billing_address", &billing_address_dict)) { | |
| 102 DLOG(ERROR) << "Response from Google wallet missing billing address"; | |
| 103 return scoped_ptr<FullWallet>(); | |
| 104 } | |
| 105 | |
| 106 scoped_ptr<Address> billing_address = | |
| 107 Address::CreateAddress(*billing_address_dict); | |
| 108 if (!billing_address.get()) { | |
| 109 DLOG(ERROR) << "Response from Google wallet has malformed billing address"; | |
| 110 return scoped_ptr<FullWallet>(); | |
| 111 } | |
| 112 | |
| 113 const base::DictionaryValue* shipping_address_dict; | |
| 114 scoped_ptr<Address> shipping_address; | |
| 115 if (dictionary.GetDictionary("shipping_address", &shipping_address_dict)) { | |
| 116 shipping_address = | |
| 117 Address::CreateAddressWithID(*shipping_address_dict); | |
| 118 } else { | |
| 119 DVLOG(1) << "Response from Google wallet missing shipping address"; | |
| 120 } | |
| 121 | |
| 122 return scoped_ptr<FullWallet>(new FullWallet(expiration_month, | |
| 123 expiration_year, | |
| 124 iin, | |
| 125 encrypted_rest, | |
| 126 billing_address.Pass(), | |
| 127 shipping_address.Pass(), | |
| 128 required_actions)); | |
| 129 } | |
| 130 | |
| 131 // static | |
| 132 scoped_ptr<FullWallet> | |
| 133 FullWallet::CreateFullWalletFromClearText( | 45 FullWallet::CreateFullWalletFromClearText( |
|
Dan Beam
2015/08/19 19:25:02
nit: scoped_ptr<FullWallet> FullWallet::CreateFull
| |
| 134 int expiration_month, | 46 int expiration_month, |
| 135 int expiration_year, | 47 int expiration_year, |
| 136 const std::string& pan, | 48 const std::string& pan, |
| 137 const std::string& cvn, | 49 const std::string& cvn, |
| 138 scoped_ptr<Address> billing_address, | 50 scoped_ptr<Address> billing_address, |
| 139 scoped_ptr<Address> shipping_address) { | 51 scoped_ptr<Address> shipping_address) { |
| 140 DCHECK(billing_address); | 52 DCHECK(billing_address); |
| 141 DCHECK(!pan.empty()); | 53 DCHECK(!pan.empty()); |
| 142 DCHECK(!cvn.empty()); | 54 DCHECK(!cvn.empty()); |
| 143 | 55 |
| 144 scoped_ptr<FullWallet> wallet(new FullWallet( | 56 scoped_ptr<FullWallet> wallet(new FullWallet( |
| 145 expiration_month, | 57 expiration_month, |
| 146 expiration_year, | 58 expiration_year, |
| 147 std::string(), // no iin -- clear text pan/cvn are set below. | 59 std::string(), // no iin -- clear text pan/cvn are set below. |
| 148 std::string(), // no encrypted_rest -- clear text pan/cvn are set below. | 60 std::string(), // no encrypted_rest -- clear text pan/cvn are set below. |
| 149 billing_address.Pass(), | 61 billing_address.Pass(), |
| 150 shipping_address.Pass(), | 62 shipping_address.Pass())); |
| 151 std::vector<RequiredAction>())); // no required actions in clear text. | |
| 152 wallet->pan_ = pan; | 63 wallet->pan_ = pan; |
| 153 wallet->cvn_ = cvn; | 64 wallet->cvn_ = cvn; |
| 154 return wallet.Pass(); | 65 return wallet.Pass(); |
| 155 } | 66 } |
| 156 | 67 |
| 157 base::string16 FullWallet::GetInfo(const std::string& app_locale, | 68 base::string16 FullWallet::GetInfo(const std::string& app_locale, |
| 158 const AutofillType& type) { | 69 const AutofillType& type) { |
| 159 switch (type.GetStorableType()) { | 70 switch (type.GetStorableType()) { |
| 160 case CREDIT_CARD_NUMBER: | 71 case CREDIT_CARD_NUMBER: |
| 161 return base::ASCIIToUTF16(GetPan()); | 72 return base::ASCIIToUTF16(GetPan()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 case CREDIT_CARD: | 122 case CREDIT_CARD: |
| 212 NOTREACHED(); | 123 NOTREACHED(); |
| 213 | 124 |
| 214 default: | 125 default: |
| 215 return shipping_address_->GetInfo(type, app_locale); | 126 return shipping_address_->GetInfo(type, app_locale); |
| 216 } | 127 } |
| 217 } | 128 } |
| 218 } | 129 } |
| 219 } | 130 } |
| 220 | 131 |
| 221 bool FullWallet::HasRequiredAction(RequiredAction action) const { | |
| 222 DCHECK(ActionAppliesToFullWallet(action)); | |
| 223 return std::find(required_actions_.begin(), | |
| 224 required_actions_.end(), | |
| 225 action) != required_actions_.end(); | |
| 226 } | |
| 227 | |
| 228 base::string16 FullWallet::TypeAndLastFourDigits() { | 132 base::string16 FullWallet::TypeAndLastFourDigits() { |
| 229 CreditCard card; | 133 CreditCard card; |
| 230 card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan())); | 134 card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan())); |
| 231 return card.TypeAndLastFourDigits(); | 135 return card.TypeAndLastFourDigits(); |
| 232 } | 136 } |
| 233 | 137 |
| 234 const std::string& FullWallet::GetPan() { | 138 const std::string& FullWallet::GetPan() { |
| 235 if (pan_.empty()) | 139 if (pan_.empty()) |
| 236 DecryptCardInfo(); | 140 DecryptCardInfo(); |
| 237 return pan_; | 141 return pan_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 257 return false; | 161 return false; |
| 258 } | 162 } |
| 259 | 163 |
| 260 if (shipping_address_.get() && other.shipping_address_.get()) { | 164 if (shipping_address_.get() && other.shipping_address_.get()) { |
| 261 if (*shipping_address_.get() != *other.shipping_address_.get()) | 165 if (*shipping_address_.get() != *other.shipping_address_.get()) |
| 262 return false; | 166 return false; |
| 263 } else if (shipping_address_.get() || other.shipping_address_.get()) { | 167 } else if (shipping_address_.get() || other.shipping_address_.get()) { |
| 264 return false; | 168 return false; |
| 265 } | 169 } |
| 266 | 170 |
| 267 if (required_actions_ != other.required_actions_) | |
| 268 return false; | |
| 269 | |
| 270 return true; | 171 return true; |
| 271 } | 172 } |
| 272 | 173 |
| 273 bool FullWallet::operator!=(const FullWallet& other) const { | 174 bool FullWallet::operator!=(const FullWallet& other) const { |
| 274 return !(*this == other); | 175 return !(*this == other); |
| 275 } | 176 } |
| 276 | 177 |
| 277 void FullWallet::DecryptCardInfo() { | 178 void FullWallet::DecryptCardInfo() { |
| 278 // |encrypted_rest_| must be of length |kEncryptedRestSize| in order for | 179 // |encrypted_rest_| must be of length |kEncryptedRestSize| in order for |
| 279 // decryption to succeed and the server will not pad it with zeros. | 180 // decryption to succeed and the server will not pad it with zeros. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 } | 225 } |
| 325 | 226 |
| 326 const std::string& FullWallet::GetCvn() { | 227 const std::string& FullWallet::GetCvn() { |
| 327 if (cvn_.empty()) | 228 if (cvn_.empty()) |
| 328 DecryptCardInfo(); | 229 DecryptCardInfo(); |
| 329 return cvn_; | 230 return cvn_; |
| 330 } | 231 } |
| 331 | 232 |
| 332 } // namespace wallet | 233 } // namespace wallet |
| 333 } // namespace autofill | 234 } // namespace autofill |
| OLD | NEW |