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

Side by Side Diff: chrome/browser/autofill/credit_card.cc

Issue 6033010: Support autocompletion for HTMl5 tags:"email", "month" and "tel". (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add more tests, fix some format errors and change parsing. Created 9 years, 11 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) 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/autofill/credit_card.h" 5 #include "chrome/browser/autofill/credit_card.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/string_split.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
13 #include "base/string16.h" 14 #include "base/string16.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/autofill/autofill_type.h" 16 #include "chrome/browser/autofill/autofill_type.h"
16 #include "chrome/browser/autofill/field_types.h" 17 #include "chrome/browser/autofill/field_types.h"
17 #include "chrome/common/guid.h" 18 #include "chrome/common/guid.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "third_party/WebKit/WebKit/chromium/public/WebRegularExpression.h"
21 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
19 22
20 namespace { 23 namespace {
21 24
22 const char* kCreditCardObfuscationString = "************"; 25 const char* kCreditCardObfuscationString = "************";
23 26
24 const AutoFillFieldType kAutoFillCreditCardTypes[] = { 27 const AutoFillFieldType kAutoFillCreditCardTypes[] = {
25 CREDIT_CARD_NAME, 28 CREDIT_CARD_NAME,
26 CREDIT_CARD_NUMBER, 29 CREDIT_CARD_NUMBER,
27 CREDIT_CARD_TYPE, 30 CREDIT_CARD_TYPE,
28 CREDIT_CARD_EXP_MONTH, 31 CREDIT_CARD_EXP_MONTH,
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 451
449 return (sum % 10) == 0; 452 return (sum % 10) == 0;
450 } 453 }
451 454
452 bool CreditCard::IsEmpty() const { 455 bool CreditCard::IsEmpty() const {
453 FieldTypeSet types; 456 FieldTypeSet types;
454 GetAvailableFieldTypes(&types); 457 GetAvailableFieldTypes(&types);
455 return types.empty(); 458 return types.empty();
456 } 459 }
457 460
461 void CreditCard::SetMonthInputInfo(const string16& value) {
462 // Check if |text| is "yyyy-mm" format first, and check normal month format.
463 WebKit::WebRegularExpression re(WebKit::WebString("^[0-9]{4}\\-[0-9]{1,2}$"),
464 WebKit::WebTextCaseInsensitive);
465 bool match = re.match(WebKit::WebString(StringToLowerASCII(value))) != -1;
466 if (match) {
467 std::vector<string16> year_month;
468 base::SplitString(value, L'-', &year_month);
469 DCHECK(year_month.size() == 2);
470 int num = 0;
471 bool converted = false;
472 converted = base::StringToInt(year_month[0], &num);
473 DCHECK(converted);
474 set_expiration_year(num);
475 converted = base::StringToInt(year_month[1], &num);
476 DCHECK(converted);
477 set_expiration_month(num);
478 }
479 }
480
honten.org 2011/01/06 07:04:54 Use regular expression to check yyyy-mm.
dhollowa 2011/01/07 03:47:15 Nice. On 2011/01/06 07:04:54, honten wrote:
458 string16 CreditCard::ExpirationMonthAsString() const { 481 string16 CreditCard::ExpirationMonthAsString() const {
459 if (expiration_month_ == 0) 482 if (expiration_month_ == 0)
460 return string16(); 483 return string16();
461 484
462 string16 month = base::IntToString16(expiration_month_); 485 string16 month = base::IntToString16(expiration_month_);
463 if (expiration_month_ >= 10) 486 if (expiration_month_ >= 10)
464 return month; 487 return month;
465 488
466 string16 zero = ASCIIToUTF16("0"); 489 string16 zero = ASCIIToUTF16("0");
467 zero.append(month); 490 zero.append(month);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE))) 659 << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)))
637 << " " 660 << " "
638 << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER))) 661 << UTF16ToUTF8(credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)))
639 << " " 662 << " "
640 << UTF16ToUTF8(credit_card.GetFieldText( 663 << UTF16ToUTF8(credit_card.GetFieldText(
641 AutoFillType(CREDIT_CARD_EXP_MONTH))) 664 AutoFillType(CREDIT_CARD_EXP_MONTH)))
642 << " " 665 << " "
643 << UTF16ToUTF8(credit_card.GetFieldText( 666 << UTF16ToUTF8(credit_card.GetFieldText(
644 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR))); 667 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)));
645 } 668 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698