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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 23756007: [rac] Show amex specific cvc hint (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename StringFromType to StringIconIdentifierFromType Created 7 years, 3 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 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 "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 // Generate a random card number in a user displayable format. 525 // Generate a random card number in a user displayable format.
526 base::string16 GenerateRandomCardNumber() { 526 base::string16 GenerateRandomCardNumber() {
527 std::string card_number; 527 std::string card_number;
528 for (size_t i = 0; i < 4; ++i) { 528 for (size_t i = 0; i < 4; ++i) {
529 int part = base::RandInt(0, 10000); 529 int part = base::RandInt(0, 10000);
530 base::StringAppendF(&card_number, "%04d ", part); 530 base::StringAppendF(&card_number, "%04d ", part);
531 } 531 }
532 return ASCIIToUTF16(card_number); 532 return ASCIIToUTF16(card_number);
533 } 533 }
534 534
535 gfx::Image CreditCardIconForType(const std::string& credit_card_type) {
536 const int input_card_idr = CreditCard::IconResourceId(credit_card_type);
537 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
538 gfx::Image result = rb.GetImageNamed(input_card_idr);
539 if (input_card_idr == IDR_AUTOFILL_CC_GENERIC) {
540 // When the credit card type is unknown, no image should be shown. However,
541 // to simplify the view code on Mac, save space for the credit card image by
542 // returning a transparent image of the appropriate size.
543 result = gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(
544 result.AsImageSkia(), 0));
545 }
546 return result;
547 }
548
549 gfx::Image CvcIconForCreditCardType(const std::string& credit_card_type) {
550 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
551 if (credit_card_type == autofill::kAmericanExpressCard)
552 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX);
553
554 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
555 }
556
535 } // namespace 557 } // namespace
536 558
537 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} 559 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {}
538 560
539 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 561 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
540 if (popup_controller_) 562 if (popup_controller_)
541 popup_controller_->Hide(); 563 popup_controller_->Hide();
542 564
543 GetMetricLogger().LogDialogInitialUserState(initial_user_state_); 565 GetMetricLogger().LogDialogInitialUserState(initial_user_state_);
544 } 566 }
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( 1525 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection(
1504 DialogSection section) { 1526 DialogSection section) {
1505 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 1527 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
1506 if (!model.get()) 1528 if (!model.get())
1507 return gfx::Image(); 1529 return gfx::Image();
1508 1530
1509 return model->GetIcon(); 1531 return model->GetIcon();
1510 } 1532 }
1511 1533
1512 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( 1534 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection(
1513 DialogSection section) const { 1535 DialogSection section) {
1514 if (section == SECTION_CC || section == SECTION_CC_BILLING) 1536 if (section != SECTION_CC && section != SECTION_CC_BILLING)
1515 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16()); 1537 return gfx::Image();
1516 1538
1517 return gfx::Image(); 1539 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
1540 if (!model.get())
1541 return gfx::Image();
1542
1543 return CvcIconForCreditCardType(
1544 UTF16ToUTF8(model->GetInfo(AutofillType(CREDIT_CARD_TYPE))));
1518 } 1545 }
1519 1546
1547 // TODO(groby): Remove this deprecated method after Mac starts using
1548 // IconsForFields. http://crbug.com/292876
1520 gfx::Image AutofillDialogControllerImpl::IconForField( 1549 gfx::Image AutofillDialogControllerImpl::IconForField(
1521 ServerFieldType type, const string16& user_input) const { 1550 ServerFieldType type, const string16& user_input) const {
1522 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1551 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1523 if (type == CREDIT_CARD_VERIFICATION_CODE) 1552 if (type == CREDIT_CARD_VERIFICATION_CODE)
1524 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); 1553 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
1525 1554
1526 if (type == CREDIT_CARD_NUMBER) { 1555 if (type == CREDIT_CARD_NUMBER) {
1527 const int input_card_idr = CreditCard::IconResourceId( 1556 const int input_card_idr = CreditCard::IconResourceId(
1528 CreditCard::GetCreditCardType(user_input)); 1557 CreditCard::GetCreditCardType(user_input));
1529 if (input_card_idr != IDR_AUTOFILL_CC_GENERIC) 1558 if (input_card_idr != IDR_AUTOFILL_CC_GENERIC)
1530 return rb.GetImageNamed(input_card_idr); 1559 return rb.GetImageNamed(input_card_idr);
1531 1560
1532 // When the credit card type is unknown, no image should be shown. However, 1561 // When the credit card type is unknown, no image should be shown. However,
1533 // to simplify the view code on Mac, save space for the credit card image by 1562 // to simplify the view code on Mac, save space for the credit card image by
1534 // returning a transparent image of the appropriate size. 1563 // returning a transparent image of the appropriate size.
1535 gfx::ImageSkia image = *rb.GetImageSkiaNamed(input_card_idr); 1564 gfx::ImageSkia image = *rb.GetImageSkiaNamed(input_card_idr);
1536 return 1565 return
1537 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(image, 0)); 1566 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(image, 0));
1538 } 1567 }
1539 1568
1540 return gfx::Image(); 1569 return gfx::Image();
1541 } 1570 }
1542 1571
1572 FieldIconMap AutofillDialogControllerImpl::IconsForFields(
1573 const FieldValueMap& user_inputs) const {
1574 FieldIconMap result;
1575 std::string credit_card_type = autofill::kGenericCard;
1576
1577 FieldValueMap::const_iterator credit_card_iter =
1578 user_inputs.find(CREDIT_CARD_NUMBER);
1579 if (credit_card_iter != user_inputs.end()) {
1580 const string16& credit_card_number = credit_card_iter->second;
1581 credit_card_type = CreditCard::GetCreditCardType(credit_card_number);
1582 result[CREDIT_CARD_NUMBER] = CreditCardIconForType(credit_card_type);
1583 }
1584
1585 if (!user_inputs.count(CREDIT_CARD_VERIFICATION_CODE))
1586 return result;
1587
1588 result[CREDIT_CARD_VERIFICATION_CODE] =
1589 CvcIconForCreditCardType(credit_card_type);
1590
1591 return result;
1592 }
1593
1594 bool AutofillDialogControllerImpl::FieldControlsIcons(
1595 ServerFieldType type) const {
1596 return type == CREDIT_CARD_NUMBER;
1597 }
1598
1543 // TODO(estade): Replace all the error messages here with more helpful and 1599 // TODO(estade): Replace all the error messages here with more helpful and
1544 // translateable ones. TODO(groby): Also add tests. 1600 // translateable ones. TODO(groby): Also add tests.
1545 string16 AutofillDialogControllerImpl::InputValidityMessage( 1601 string16 AutofillDialogControllerImpl::InputValidityMessage(
1546 DialogSection section, 1602 DialogSection section,
1547 ServerFieldType type, 1603 ServerFieldType type,
1548 const string16& value) { 1604 const string16& value) {
1549 // If the field is edited, clear any Wallet errors. 1605 // If the field is edited, clear any Wallet errors.
1550 if (IsPayingWithWallet()) { 1606 if (IsPayingWithWallet()) {
1551 WalletValidationErrors::iterator it = wallet_errors_.find(section); 1607 WalletValidationErrors::iterator it = wallet_errors_.find(section);
1552 if (it != wallet_errors_.end()) { 1608 if (it != wallet_errors_.end()) {
(...skipping 1811 matching lines...) Expand 10 before | Expand all | Expand 10 after
3364 } 3420 }
3365 3421
3366 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { 3422 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() {
3367 if (!view_) 3423 if (!view_)
3368 return; 3424 return;
3369 ScopedViewUpdates updates(view_.get()); 3425 ScopedViewUpdates updates(view_.get());
3370 view_->UpdateButtonStrip(); 3426 view_->UpdateButtonStrip();
3371 } 3427 }
3372 3428
3373 } // namespace autofill 3429 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698