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

Side by Side Diff: chrome/browser/webdata/web_database.cc

Issue 2811059: AutoFill: Limit the size of form field data allowed to be saved in WebData as a (Closed)
Patch Set: PBR fix. Created 10 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/webdata/web_database.h" 5 #include "chrome/browser/webdata/web_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // image PNG encoded image data. 145 // image PNG encoded image data.
146 // 146 //
147 // web_apps 147 // web_apps
148 // url URL of the web app. 148 // url URL of the web app.
149 // has_all_images Do we have all the images? 149 // has_all_images Do we have all the images?
150 // 150 //
151 //////////////////////////////////////////////////////////////////////////////// 151 ////////////////////////////////////////////////////////////////////////////////
152 152
153 using base::Time; 153 using base::Time;
154 154
155 namespace {
156
157 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList;
158
155 // Current version number. 159 // Current version number.
156 static const int kCurrentVersionNumber = 24; 160 const int kCurrentVersionNumber = 24;
157 static const int kCompatibleVersionNumber = 21; 161 const int kCompatibleVersionNumber = 21;
158 162
159 // Keys used in the meta table. 163 // Keys used in the meta table.
160 static const char* kDefaultSearchProviderKey = "Default Search Provider ID"; 164 const char* kDefaultSearchProviderKey = "Default Search Provider ID";
161 static const char* kBuiltinKeywordVersion = "Builtin Keyword Version"; 165 const char* kBuiltinKeywordVersion = "Builtin Keyword Version";
166
167 // The maximum length allowed for form data.
168 const size_t kMaxDataLength = 1024;
162 169
163 std::string JoinStrings(const std::string& separator, 170 std::string JoinStrings(const std::string& separator,
164 const std::vector<std::string>& strings) { 171 const std::vector<std::string>& strings) {
165 if (strings.empty()) 172 if (strings.empty())
166 return std::string(); 173 return std::string();
167 std::vector<std::string>::const_iterator i(strings.begin()); 174 std::vector<std::string>::const_iterator i(strings.begin());
168 std::string result(*i); 175 std::string result(*i);
169 while (++i != strings.end()) 176 while (++i != strings.end())
170 result += separator + *i; 177 result += separator + *i;
171 return result; 178 return result;
172 } 179 }
173 180
174 namespace { 181 void BindURLToStatement(const TemplateURL& url, sql::Statement* s) {
175 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; 182 s->BindString(0, WideToUTF8(url.short_name()));
176 } 183 s->BindString(1, WideToUTF8(url.keyword()));
184 GURL favicon_url = url.GetFavIconURL();
185 if (!favicon_url.is_valid()) {
186 s->BindString(2, std::string());
187 } else {
188 s->BindString(2, history::HistoryDatabase::GURLToDatabaseURL(
189 url.GetFavIconURL()));
190 }
191 if (url.url())
192 s->BindString(3, url.url()->url());
193 else
194 s->BindString(3, std::string());
195 s->BindInt(4, url.safe_for_autoreplace() ? 1 : 0);
196 if (!url.originating_url().is_valid()) {
197 s->BindString(5, std::string());
198 } else {
199 s->BindString(5, history::HistoryDatabase::GURLToDatabaseURL(
200 url.originating_url()));
201 }
202 s->BindInt64(6, url.date_created().ToTimeT());
203 s->BindInt(7, url.usage_count());
204 s->BindString(8, JoinStrings(";", url.input_encodings()));
205 s->BindInt(9, url.show_in_default_list() ? 1 : 0);
206 if (url.suggestions_url())
207 s->BindString(10, url.suggestions_url()->url());
208 else
209 s->BindString(10, std::string());
210 s->BindInt(11, url.prepopulate_id());
211 s->BindInt(12, url.autogenerate_keyword() ? 1 : 0);
212 }
213
214 void InitPasswordFormFromStatement(PasswordForm* form, sql::Statement* s) {
215 std::string tmp;
216 string16 decrypted_password;
217 tmp = s->ColumnString(0);
218 form->origin = GURL(tmp);
219 tmp = s->ColumnString(1);
220 form->action = GURL(tmp);
221 form->username_element = s->ColumnString16(2);
222 form->username_value = s->ColumnString16(3);
223 form->password_element = s->ColumnString16(4);
224
225 int encrypted_password_len = s->ColumnByteLength(5);
226 std::string encrypted_password;
227 if (encrypted_password_len) {
228 encrypted_password.resize(encrypted_password_len);
229 memcpy(&encrypted_password[0], s->ColumnBlob(5), encrypted_password_len);
230 Encryptor::DecryptString16(encrypted_password, &decrypted_password);
231 }
232
233 form->password_value = decrypted_password;
234 form->submit_element = s->ColumnString16(6);
235 tmp = s->ColumnString(7);
236 form->signon_realm = tmp;
237 form->ssl_valid = (s->ColumnInt(8) > 0);
238 form->preferred = (s->ColumnInt(9) > 0);
239 form->date_created = Time::FromTimeT(s->ColumnInt64(10));
240 form->blacklisted_by_user = (s->ColumnInt(11) > 0);
241 int scheme_int = s->ColumnInt(12);
242 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER));
243 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int);
244 }
245
246 // TODO(jhawkins): This is a temporary stop-gap measure designed to prevent
247 // a malicious site from DOS'ing the browser with extremely large profile
248 // data. The correct solution is to parse this data asynchronously.
249 // See http://crbug.com/49332.
250 string16 LimitDataSize(const string16& data) {
251 if (data.size() > kMaxDataLength)
252 return data.substr(kMaxDataLength);
253
254 return data;
255 }
256
257 void BindAutoFillProfileToStatement(const AutoFillProfile& profile,
258 sql::Statement* s) {
259 s->BindString16(0, profile.Label());
260 s->BindInt(1, profile.unique_id());
261
262 string16 text = profile.GetFieldText(AutoFillType(NAME_FIRST));
263 s->BindString16(2, LimitDataSize(text));
264 text = profile.GetFieldText(AutoFillType(NAME_MIDDLE));
265 s->BindString16(3, LimitDataSize(text));
266 text = profile.GetFieldText(AutoFillType(NAME_LAST));
267 s->BindString16(4, LimitDataSize(text));
268 text = profile.GetFieldText(AutoFillType(EMAIL_ADDRESS));
269 s->BindString16(5, LimitDataSize(text));
270 text = profile.GetFieldText(AutoFillType(COMPANY_NAME));
271 s->BindString16(6, LimitDataSize(text));
272 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1));
273 s->BindString16(7, LimitDataSize(text));
274 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2));
275 s->BindString16(8, LimitDataSize(text));
276 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY));
277 s->BindString16(9, LimitDataSize(text));
278 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE));
279 s->BindString16(10, LimitDataSize(text));
280 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP));
281 s->BindString16(11, LimitDataSize(text));
282 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY));
283 s->BindString16(12, LimitDataSize(text));
284 text = profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER));
285 s->BindString16(13, LimitDataSize(text));
286 text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER));
287 s->BindString16(14, LimitDataSize(text));
288 }
289
290 AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
291 AutoFillProfile* profile = new AutoFillProfile(
292 s.ColumnString16(0), s.ColumnInt(1));
293 profile->SetInfo(AutoFillType(NAME_FIRST),
294 s.ColumnString16(2));
295 profile->SetInfo(AutoFillType(NAME_MIDDLE),
296 s.ColumnString16(3));
297 profile->SetInfo(AutoFillType(NAME_LAST),
298 s.ColumnString16(4));
299 profile->SetInfo(AutoFillType(EMAIL_ADDRESS),
300 s.ColumnString16(5));
301 profile->SetInfo(AutoFillType(COMPANY_NAME),
302 s.ColumnString16(6));
303 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1),
304 s.ColumnString16(7));
305 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2),
306 s.ColumnString16(8));
307 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY),
308 s.ColumnString16(9));
309 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE),
310 s.ColumnString16(10));
311 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP),
312 s.ColumnString16(11));
313 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY),
314 s.ColumnString16(12));
315 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER),
316 s.ColumnString16(13));
317 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
318 s.ColumnString16(14));
319
320 return profile;
321 }
322
323 void BindCreditCardToStatement(const CreditCard& credit_card,
324 sql::Statement* s) {
325 s->BindString16(0, credit_card.Label());
326 s->BindInt(1, credit_card.unique_id());
327
328 string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME));
329 s->BindString16(2, LimitDataSize(text));
330 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE));
331 s->BindString16(3, LimitDataSize(text));
332 text.clear(); // No unencrypted cc info.
333 s->BindString16(4, LimitDataSize(text));
334 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH));
335 s->BindString16(5, LimitDataSize(text));
336 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR));
337 s->BindString16(6, LimitDataSize(text));
338 text.clear();
339 s->BindString16(7, LimitDataSize(text));
340 s->BindString16(8, credit_card.billing_address());
341 // We don't store the shipping address anymore.
342 text.clear();
343 s->BindString16(9, LimitDataSize(text));
344 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER));
345 std::string encrypted_data;
346 Encryptor::EncryptString16(text, &encrypted_data);
347 s->BindBlob(10, encrypted_data.data(),
348 static_cast<int>(encrypted_data.length()));
349 // We don't store the CVV anymore.
350 text.clear();
351 s->BindBlob(11, text.data(), static_cast<int>(text.length()));
352 }
353
354 CreditCard* CreditCardFromStatement(const sql::Statement& s) {
355 CreditCard* credit_card = new CreditCard(
356 s.ColumnString16(0), s.ColumnInt(1));
357 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME),
358 s.ColumnString16(2));
359 credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE),
360 s.ColumnString16(3));
361 string16 credit_card_number = s.ColumnString16(4);
362 // It could be non-empty prior to version 23. After that it encrypted in
363 // the column 10.
364 if (credit_card_number.empty()) {
365 int encrypted_cc_len = s.ColumnByteLength(10);
366 std::string encrypted_cc;
367 if (encrypted_cc_len) {
368 encrypted_cc.resize(encrypted_cc_len);
369 memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len);
370 Encryptor::DecryptString16(encrypted_cc, &credit_card_number);
371 }
372 }
373 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number);
374 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
375 s.ColumnString16(5));
376 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
377 s.ColumnString16(6));
378
379 string16 credit_card_verification_code = s.ColumnString16(7);
380 // We don't store the CVV anymore.
381 credit_card->set_billing_address(s.ColumnString16(8));
382 // We don't store the shipping address anymore.
383 // Column 10 is processed above.
384 // Column 11 is processed above.
385
386 return credit_card;
387 }
388
389 } // namespace
177 390
178 WebDatabase::WebDatabase() { 391 WebDatabase::WebDatabase() {
179 } 392 }
180 393
181 WebDatabase::~WebDatabase() { 394 WebDatabase::~WebDatabase() {
182 } 395 }
183 396
184 void WebDatabase::BeginTransaction() { 397 void WebDatabase::BeginTransaction() {
185 db_.BeginTransaction(); 398 db_.BeginTransaction();
186 } 399 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 return false; 741 return false;
529 } 742 }
530 if (!db_.Execute("CREATE INDEX web_apps_url_index ON web_apps (url)")) { 743 if (!db_.Execute("CREATE INDEX web_apps_url_index ON web_apps (url)")) {
531 NOTREACHED(); 744 NOTREACHED();
532 return false; 745 return false;
533 } 746 }
534 } 747 }
535 return true; 748 return true;
536 } 749 }
537 750
538 static void BindURLToStatement(const TemplateURL& url, sql::Statement* s) {
539 s->BindString(0, WideToUTF8(url.short_name()));
540 s->BindString(1, WideToUTF8(url.keyword()));
541 GURL favicon_url = url.GetFavIconURL();
542 if (!favicon_url.is_valid()) {
543 s->BindString(2, std::string());
544 } else {
545 s->BindString(2, history::HistoryDatabase::GURLToDatabaseURL(
546 url.GetFavIconURL()));
547 }
548 if (url.url())
549 s->BindString(3, url.url()->url());
550 else
551 s->BindString(3, std::string());
552 s->BindInt(4, url.safe_for_autoreplace() ? 1 : 0);
553 if (!url.originating_url().is_valid()) {
554 s->BindString(5, std::string());
555 } else {
556 s->BindString(5, history::HistoryDatabase::GURLToDatabaseURL(
557 url.originating_url()));
558 }
559 s->BindInt64(6, url.date_created().ToTimeT());
560 s->BindInt(7, url.usage_count());
561 s->BindString(8, JoinStrings(";", url.input_encodings()));
562 s->BindInt(9, url.show_in_default_list() ? 1 : 0);
563 if (url.suggestions_url())
564 s->BindString(10, url.suggestions_url()->url());
565 else
566 s->BindString(10, std::string());
567 s->BindInt(11, url.prepopulate_id());
568 s->BindInt(12, url.autogenerate_keyword() ? 1 : 0);
569 }
570
571 bool WebDatabase::AddKeyword(const TemplateURL& url) { 751 bool WebDatabase::AddKeyword(const TemplateURL& url) {
572 DCHECK(url.id()); 752 DCHECK(url.id());
573 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 753 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
574 "INSERT INTO keywords " 754 "INSERT INTO keywords "
575 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, " 755 "(short_name, keyword, favicon_url, url, safe_for_autoreplace, "
576 "originating_url, date_created, usage_count, input_encodings, " 756 "originating_url, date_created, usage_count, input_encodings, "
577 "show_in_default_list, suggest_url, prepopulate_id, " 757 "show_in_default_list, suggest_url, prepopulate_id, "
578 "autogenerate_keyword, id) VALUES " 758 "autogenerate_keyword, id) VALUES "
579 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); 759 "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
580 if (!s) { 760 if (!s) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 s2.BindInt64(1, 1006 s2.BindInt64(1,
827 delete_end.is_null() ? 1007 delete_end.is_null() ?
828 std::numeric_limits<int64>::max() : 1008 std::numeric_limits<int64>::max() :
829 delete_end.ToTimeT()); 1009 delete_end.ToTimeT());
830 success = success && s2.Run(); 1010 success = success && s2.Run();
831 #endif 1011 #endif
832 1012
833 return success; 1013 return success;
834 } 1014 }
835 1015
836 static void InitPasswordFormFromStatement(PasswordForm* form,
837 sql::Statement* s) {
838 std::string tmp;
839 string16 decrypted_password;
840 tmp = s->ColumnString(0);
841 form->origin = GURL(tmp);
842 tmp = s->ColumnString(1);
843 form->action = GURL(tmp);
844 form->username_element = s->ColumnString16(2);
845 form->username_value = s->ColumnString16(3);
846 form->password_element = s->ColumnString16(4);
847
848 int encrypted_password_len = s->ColumnByteLength(5);
849 std::string encrypted_password;
850 if (encrypted_password_len) {
851 encrypted_password.resize(encrypted_password_len);
852 memcpy(&encrypted_password[0], s->ColumnBlob(5), encrypted_password_len);
853 Encryptor::DecryptString16(encrypted_password, &decrypted_password);
854 }
855
856 form->password_value = decrypted_password;
857 form->submit_element = s->ColumnString16(6);
858 tmp = s->ColumnString(7);
859 form->signon_realm = tmp;
860 form->ssl_valid = (s->ColumnInt(8) > 0);
861 form->preferred = (s->ColumnInt(9) > 0);
862 form->date_created = Time::FromTimeT(s->ColumnInt64(10));
863 form->blacklisted_by_user = (s->ColumnInt(11) > 0);
864 int scheme_int = s->ColumnInt(12);
865 DCHECK((scheme_int >= 0) && (scheme_int <= PasswordForm::SCHEME_OTHER));
866 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int);
867 }
868
869 bool WebDatabase::GetLogins(const PasswordForm& form, 1016 bool WebDatabase::GetLogins(const PasswordForm& form,
870 std::vector<PasswordForm*>* forms) { 1017 std::vector<PasswordForm*>* forms) {
871 DCHECK(forms); 1018 DCHECK(forms);
872 sql::Statement s(db_.GetUniqueStatement( 1019 sql::Statement s(db_.GetUniqueStatement(
873 "SELECT origin_url, action_url, " 1020 "SELECT origin_url, action_url, "
874 "username_element, username_value, " 1021 "username_element, username_value, "
875 "password_element, password_value, " 1022 "password_element, password_value, "
876 "submit_element, signon_realm, " 1023 "submit_element, signon_realm, "
877 "ssl_valid, preferred, " 1024 "ssl_valid, preferred, "
878 "date_created, blacklisted_by_user, scheme FROM logins " 1025 "date_created, blacklisted_by_user, scheme FROM logins "
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 return false; 1514 return false;
1368 } 1515 }
1369 s.BindString16(0, name); 1516 s.BindString16(0, name);
1370 s.BindString16(1, value); 1517 s.BindString16(1, value);
1371 1518
1372 if (s.Step()) 1519 if (s.Step())
1373 return RemoveFormElementForID(s.ColumnInt64(0)); 1520 return RemoveFormElementForID(s.ColumnInt64(0));
1374 return false; 1521 return false;
1375 } 1522 }
1376 1523
1377 static void BindAutoFillProfileToStatement(const AutoFillProfile& profile,
1378 sql::Statement* s) {
1379 s->BindString16(0, profile.Label());
1380 s->BindInt(1, profile.unique_id());
1381
1382 string16 text = profile.GetFieldText(AutoFillType(NAME_FIRST));
1383 s->BindString16(2, text);
1384 text = profile.GetFieldText(AutoFillType(NAME_MIDDLE));
1385 s->BindString16(3, text);
1386 text = profile.GetFieldText(AutoFillType(NAME_LAST));
1387 s->BindString16(4, text);
1388 text = profile.GetFieldText(AutoFillType(EMAIL_ADDRESS));
1389 s->BindString16(5, text);
1390 text = profile.GetFieldText(AutoFillType(COMPANY_NAME));
1391 s->BindString16(6, text);
1392 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1));
1393 s->BindString16(7, text);
1394 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2));
1395 s->BindString16(8, text);
1396 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY));
1397 s->BindString16(9, text);
1398 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE));
1399 s->BindString16(10, text);
1400 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP));
1401 s->BindString16(11, text);
1402 text = profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY));
1403 s->BindString16(12, text);
1404 text = profile.GetFieldText(AutoFillType(PHONE_HOME_WHOLE_NUMBER));
1405 s->BindString16(13, text);
1406 text = profile.GetFieldText(AutoFillType(PHONE_FAX_WHOLE_NUMBER));
1407 s->BindString16(14, text);
1408 }
1409
1410 bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) { 1524 bool WebDatabase::AddAutoFillProfile(const AutoFillProfile& profile) {
1411 sql::Statement s(db_.GetUniqueStatement( 1525 sql::Statement s(db_.GetUniqueStatement(
1412 "INSERT INTO autofill_profiles" 1526 "INSERT INTO autofill_profiles"
1413 "(label, unique_id, first_name, middle_name, last_name, email," 1527 "(label, unique_id, first_name, middle_name, last_name, email,"
1414 " company_name, address_line_1, address_line_2, city, state, zipcode," 1528 " company_name, address_line_1, address_line_2, city, state, zipcode,"
1415 " country, phone, fax)" 1529 " country, phone, fax)"
1416 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); 1530 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
1417 if (!s) { 1531 if (!s) {
1418 NOTREACHED() << "Statement prepare failed"; 1532 NOTREACHED() << "Statement prepare failed";
1419 return false; 1533 return false;
1420 } 1534 }
1421 1535
1422 BindAutoFillProfileToStatement(profile, &s); 1536 BindAutoFillProfileToStatement(profile, &s);
1423 1537
1424 if (!s.Run()) { 1538 if (!s.Run()) {
1425 NOTREACHED(); 1539 NOTREACHED();
1426 return false; 1540 return false;
1427 } 1541 }
1428 1542
1429 return s.Succeeded(); 1543 return s.Succeeded();
1430 } 1544 }
1431 1545
1432 static AutoFillProfile* AutoFillProfileFromStatement(const sql::Statement& s) {
1433 AutoFillProfile* profile = new AutoFillProfile(
1434 s.ColumnString16(0), s.ColumnInt(1));
1435 profile->SetInfo(AutoFillType(NAME_FIRST),
1436 s.ColumnString16(2));
1437 profile->SetInfo(AutoFillType(NAME_MIDDLE),
1438 s.ColumnString16(3));
1439 profile->SetInfo(AutoFillType(NAME_LAST),
1440 s.ColumnString16(4));
1441 profile->SetInfo(AutoFillType(EMAIL_ADDRESS),
1442 s.ColumnString16(5));
1443 profile->SetInfo(AutoFillType(COMPANY_NAME),
1444 s.ColumnString16(6));
1445 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1),
1446 s.ColumnString16(7));
1447 profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2),
1448 s.ColumnString16(8));
1449 profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY),
1450 s.ColumnString16(9));
1451 profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE),
1452 s.ColumnString16(10));
1453 profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP),
1454 s.ColumnString16(11));
1455 profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY),
1456 s.ColumnString16(12));
1457 profile->SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER),
1458 s.ColumnString16(13));
1459 profile->SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER),
1460 s.ColumnString16(14));
1461
1462 return profile;
1463 }
1464
1465 bool WebDatabase::GetAutoFillProfileForLabel(const string16& label, 1546 bool WebDatabase::GetAutoFillProfileForLabel(const string16& label,
1466 AutoFillProfile** profile) { 1547 AutoFillProfile** profile) {
1467 DCHECK(profile); 1548 DCHECK(profile);
1468 sql::Statement s(db_.GetUniqueStatement( 1549 sql::Statement s(db_.GetUniqueStatement(
1469 "SELECT * FROM autofill_profiles " 1550 "SELECT * FROM autofill_profiles "
1470 "WHERE label = ?")); 1551 "WHERE label = ?"));
1471 if (!s) { 1552 if (!s) {
1472 NOTREACHED() << "Statement prepare failed"; 1553 NOTREACHED() << "Statement prepare failed";
1473 return false; 1554 return false;
1474 } 1555 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 return false; 1623 return false;
1543 } 1624 }
1544 1625
1545 s.BindInt(0, profile_id); 1626 s.BindInt(0, profile_id);
1546 if (s.Step()) 1627 if (s.Step())
1547 *profile = AutoFillProfileFromStatement(s); 1628 *profile = AutoFillProfileFromStatement(s);
1548 1629
1549 return s.Succeeded(); 1630 return s.Succeeded();
1550 } 1631 }
1551 1632
1552 static void BindCreditCardToStatement(const CreditCard& credit_card,
1553 sql::Statement* s) {
1554 s->BindString16(0, credit_card.Label());
1555 s->BindInt(1, credit_card.unique_id());
1556
1557 string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME));
1558 s->BindString16(2, text);
1559 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE));
1560 s->BindString16(3, text);
1561 text.clear(); // No unencrypted cc info.
1562 s->BindString16(4, text);
1563 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH));
1564 s->BindString16(5, text);
1565 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1566 s->BindString16(6, text);
1567 text.clear();
1568 s->BindString16(7, text);
1569 s->BindString16(8, credit_card.billing_address());
1570 // We don't store the shipping address anymore.
1571 text.clear();
1572 s->BindString16(9, text);
1573 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER));
1574 std::string encrypted_data;
1575 Encryptor::EncryptString16(text, &encrypted_data);
1576 s->BindBlob(10, encrypted_data.data(),
1577 static_cast<int>(encrypted_data.length()));
1578 // We don't store the CVV anymore.
1579 text.clear();
1580 s->BindBlob(11, text.data(), static_cast<int>(text.length()));
1581 }
1582
1583 bool WebDatabase::AddCreditCard(const CreditCard& credit_card) { 1633 bool WebDatabase::AddCreditCard(const CreditCard& credit_card) {
1584 sql::Statement s(db_.GetUniqueStatement( 1634 sql::Statement s(db_.GetUniqueStatement(
1585 "INSERT INTO credit_cards" 1635 "INSERT INTO credit_cards"
1586 "(label, unique_id, name_on_card, type, card_number," 1636 "(label, unique_id, name_on_card, type, card_number,"
1587 " expiration_month, expiration_year, verification_code, billing_address," 1637 " expiration_month, expiration_year, verification_code, billing_address,"
1588 " shipping_address, card_number_encrypted, verification_code_encrypted)" 1638 " shipping_address, card_number_encrypted, verification_code_encrypted)"
1589 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)")); 1639 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"));
1590 if (!s) { 1640 if (!s) {
1591 NOTREACHED() << "Statement prepare failed"; 1641 NOTREACHED() << "Statement prepare failed";
1592 return false; 1642 return false;
1593 } 1643 }
1594 1644
1595 BindCreditCardToStatement(credit_card, &s); 1645 BindCreditCardToStatement(credit_card, &s);
1596 1646
1597 if (!s.Run()) { 1647 if (!s.Run()) {
1598 NOTREACHED(); 1648 NOTREACHED();
1599 return false; 1649 return false;
1600 } 1650 }
1601 1651
1602 DCHECK_GT(db_.GetLastChangeCount(), 0); 1652 DCHECK_GT(db_.GetLastChangeCount(), 0);
1603 return s.Succeeded(); 1653 return s.Succeeded();
1604 } 1654 }
1605 1655
1606 static CreditCard* CreditCardFromStatement(const sql::Statement& s) {
1607 CreditCard* credit_card = new CreditCard(
1608 s.ColumnString16(0), s.ColumnInt(1));
1609 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME),
1610 s.ColumnString16(2));
1611 credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE),
1612 s.ColumnString16(3));
1613 string16 credit_card_number = s.ColumnString16(4);
1614 // It could be non-empty prior to version 23. After that it encrypted in
1615 // the column 10.
1616 if (credit_card_number.empty()) {
1617 int encrypted_cc_len = s.ColumnByteLength(10);
1618 std::string encrypted_cc;
1619 if (encrypted_cc_len) {
1620 encrypted_cc.resize(encrypted_cc_len);
1621 memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len);
1622 Encryptor::DecryptString16(encrypted_cc, &credit_card_number);
1623 }
1624 }
1625 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number);
1626 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
1627 s.ColumnString16(5));
1628 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
1629 s.ColumnString16(6));
1630
1631 string16 credit_card_verification_code = s.ColumnString16(7);
1632 // We don't store the CVV anymore.
1633 credit_card->set_billing_address(s.ColumnString16(8));
1634 // We don't store the shipping address anymore.
1635 // Column 10 is processed above.
1636 // Column 11 is processed above.
1637
1638 return credit_card;
1639 }
1640
1641 bool WebDatabase::GetCreditCardForLabel(const string16& label, 1656 bool WebDatabase::GetCreditCardForLabel(const string16& label,
1642 CreditCard** credit_card) { 1657 CreditCard** credit_card) {
1643 DCHECK(credit_card); 1658 DCHECK(credit_card);
1644 sql::Statement s(db_.GetUniqueStatement( 1659 sql::Statement s(db_.GetUniqueStatement(
1645 "SELECT * FROM credit_cards " 1660 "SELECT * FROM credit_cards "
1646 "WHERE label = ?")); 1661 "WHERE label = ?"));
1647 if (!s) { 1662 if (!s) {
1648 NOTREACHED() << "Statement prepare failed"; 1663 NOTREACHED() << "Statement prepare failed";
1649 return false; 1664 return false;
1650 } 1665 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1878 1893
1879 // Add successive versions here. Each should set the version number and 1894 // Add successive versions here. Each should set the version number and
1880 // compatible version number as appropriate, then fall through to the next 1895 // compatible version number as appropriate, then fall through to the next
1881 // case. 1896 // case.
1882 1897
1883 case kCurrentVersionNumber: 1898 case kCurrentVersionNumber:
1884 // No migration needed. 1899 // No migration needed.
1885 return; 1900 return;
1886 } 1901 }
1887 } 1902 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698