Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: components/autofill/browser/wallet/full_wallet.cc

Issue 12815002: requestAutocomplete: Fill |form_structure_| from Online Wallet data (including (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/wallet/full_wallet.h" 5 #include "components/autofill/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/utf_string_conversions.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 11
11 namespace { 12 namespace {
12 13
13 const size_t kPanSize = 16; 14 const size_t kPanSize = 16;
14 const size_t kBinSize = 6; 15 const size_t kBinSize = 6;
15 const size_t kCvnSize = 3; 16 const size_t kCvnSize = 3;
16 17
17 } // anonymous namespace 18 } // anonymous namespace
18 19
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 117
117 return scoped_ptr<FullWallet>(new FullWallet(expiration_month, 118 return scoped_ptr<FullWallet>(new FullWallet(expiration_month,
118 expiration_year, 119 expiration_year,
119 iin, 120 iin,
120 encrypted_rest, 121 encrypted_rest,
121 billing_address.Pass(), 122 billing_address.Pass(),
122 shipping_address.Pass(), 123 shipping_address.Pass(),
123 required_actions)); 124 required_actions));
124 } 125 }
125 126
127 const std::string& FullWallet::GetPan() {
128 if (pan_.empty())
129 DecryptCardInfo();
130 return pan_;
131 }
132
133 const std::string& FullWallet::GetCvn() {
134 if (cvn_.empty())
135 DecryptCardInfo();
136 return cvn_;
137 }
138
139 string16 FullWallet::GetInfo(AutofillFieldType type, bool is_billing) {
140 switch (type) {
141 case CREDIT_CARD_NUMBER:
142 DCHECK(is_billing);
143 return UTF8ToUTF16(GetPan());
144
145 case CREDIT_CARD_NAME:
146 DCHECK(is_billing);
147 return billing_address()->recipient_name();
148
149 case CREDIT_CARD_VERIFICATION_CODE:
150 DCHECK(is_billing);
151 return UTF8ToUTF16(GetCvn());
152
153 case CREDIT_CARD_EXP_MONTH:
154 DCHECK(is_billing);
155 return base::IntToString16(expiration_month());
156
157 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
158 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR:
159 DCHECK(is_billing);
160 return base::IntToString16(expiration_year());
161
162 case NAME_FULL:
163 return GetAddress(is_billing)->recipient_name();
164
165 case ADDRESS_HOME_LINE1:
166 return GetAddress(is_billing)->address_line_1();
167
168 case ADDRESS_HOME_LINE2:
169 return GetAddress(is_billing)->address_line_2();
170
171 case ADDRESS_HOME_CITY:
172 return GetAddress(is_billing)->locality_name();
173
174 case ADDRESS_HOME_STATE:
175 return GetAddress(is_billing)->administrative_area_name();
176
177 case ADDRESS_HOME_ZIP:
178 return GetAddress(is_billing)->postal_code_number();
179
180 case ADDRESS_HOME_COUNTRY:
181 return UTF8ToUTF16(GetAddress(is_billing)->country_name_code());
182
183 case PHONE_HOME_WHOLE_NUMBER:
184 return GetAddress(is_billing)->phone_number();
185
186 default:
187 NOTREACHED();
188 }
189
190 return string16();
191 }
192
126 bool FullWallet::HasRequiredAction(RequiredAction action) const { 193 bool FullWallet::HasRequiredAction(RequiredAction action) const {
127 DCHECK(ActionAppliesToFullWallet(action)); 194 DCHECK(ActionAppliesToFullWallet(action));
128 return std::find(required_actions_.begin(), 195 return std::find(required_actions_.begin(),
129 required_actions_.end(), 196 required_actions_.end(),
130 action) != required_actions_.end(); 197 action) != required_actions_.end();
131 } 198 }
132 199
133 bool FullWallet::operator==(const FullWallet& other) const { 200 bool FullWallet::operator==(const FullWallet& other) const {
134 if (expiration_month_ != other.expiration_month_) 201 if (expiration_month_ != other.expiration_month_)
135 return false; 202 return false;
(...skipping 24 matching lines...) Expand all
160 if (required_actions_ != other.required_actions_) 227 if (required_actions_ != other.required_actions_)
161 return false; 228 return false;
162 229
163 return true; 230 return true;
164 } 231 }
165 232
166 bool FullWallet::operator!=(const FullWallet& other) const { 233 bool FullWallet::operator!=(const FullWallet& other) const {
167 return !(*this == other); 234 return !(*this == other);
168 } 235 }
169 236
170 const std::string& FullWallet::GetPan() {
171 if (pan_.empty())
172 DecryptCardInfo();
173 return pan_;
174 }
175
176 const std::string& FullWallet::GetCvn() {
177 if (cvn_.empty())
178 DecryptCardInfo();
179 return cvn_;
180 }
181
182 void FullWallet::DecryptCardInfo() { 237 void FullWallet::DecryptCardInfo() {
183 std::vector<uint8> operating_data; 238 std::vector<uint8> operating_data;
184 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|. 239 // Convert |encrypted_rest_| to bytes so we can decrypt it with |otp|.
185 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) { 240 if (!base::HexStringToBytes(encrypted_rest_, &operating_data)) {
186 DLOG(ERROR) << "Failed to parse encrypted rest"; 241 DLOG(ERROR) << "Failed to parse encrypted rest";
187 return; 242 return;
188 } 243 }
189 244
190 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length 245 // Ensure |one_time_pad_| and |encrypted_rest_| are of the same length
191 // otherwise something has gone wrong and we can't decrypt the data. 246 // otherwise something has gone wrong and we can't decrypt the data.
(...skipping 21 matching lines...) Expand all
213 // to be padded with 0's until it is. 268 // to be padded with 0's until it is.
214 if (card_info.size() != padded_length) 269 if (card_info.size() != padded_length)
215 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); 270 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0');
216 271
217 // Separate out the PAN from the CVN. 272 // Separate out the PAN from the CVN.
218 size_t split = kPanSize - kBinSize; 273 size_t split = kPanSize - kBinSize;
219 cvn_ = card_info.substr(split); 274 cvn_ = card_info.substr(split);
220 pan_ = iin_ + card_info.substr(0, split); 275 pan_ = iin_ + card_info.substr(0, split);
221 } 276 }
222 277
278 const wallet::Address* FullWallet::GetAddress(bool is_billing) const {
279 return is_billing ? billing_address() : shipping_address();
280 }
281
223 } // namespace wallet 282 } // namespace wallet
224 } // namespace autofill 283 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698