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

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: Enable going from icon to no icon 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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // Generate a random card number in a user displayable format. 522 // Generate a random card number in a user displayable format.
523 base::string16 GenerateRandomCardNumber() { 523 base::string16 GenerateRandomCardNumber() {
524 std::string card_number; 524 std::string card_number;
525 for (size_t i = 0; i < 4; ++i) { 525 for (size_t i = 0; i < 4; ++i) {
526 int part = base::RandInt(0, 10000); 526 int part = base::RandInt(0, 10000);
527 base::StringAppendF(&card_number, "%04d ", part); 527 base::StringAppendF(&card_number, "%04d ", part);
528 } 528 }
529 return ASCIIToUTF16(card_number); 529 return ASCIIToUTF16(card_number);
530 } 530 }
531 531
532 gfx::Image CreditCardIconForType(const std::string& credit_card_type) {
533 const int input_card_idr = CreditCard::IconResourceId(credit_card_type);
534 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
535 gfx::Image result = rb.GetImageNamed(input_card_idr);
536 if (input_card_idr == IDR_AUTOFILL_CC_GENERIC) {
537 // When the credit card type is unknown, no image should be shown. However,
538 // to simplify the view code on Mac, save space for the credit card image by
539 // returning a transparent image of the appropriate size.
540 result = gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(
541 result.AsImageSkia(), 0));
542 }
543 return result;
544 }
545
546 gfx::Image CvcIconForCreditCardType(const std::string& credit_card_type) {
547 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
548 if (credit_card_type == autofill::kAmericanExpressCard)
549 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT_AMEX);
550
551 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
552 }
553
532 } // namespace 554 } // namespace
533 555
534 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} 556 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {}
535 557
536 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 558 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
537 if (popup_controller_) 559 if (popup_controller_)
538 popup_controller_->Hide(); 560 popup_controller_->Hide();
539 561
540 GetMetricLogger().LogDialogInitialUserState(initial_user_state_); 562 GetMetricLogger().LogDialogInitialUserState(initial_user_state_);
541 } 563 }
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection( 1522 gfx::Image AutofillDialogControllerImpl::SuggestionIconForSection(
1501 DialogSection section) { 1523 DialogSection section) {
1502 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 1524 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
1503 if (!model.get()) 1525 if (!model.get())
1504 return gfx::Image(); 1526 return gfx::Image();
1505 1527
1506 return model->GetIcon(); 1528 return model->GetIcon();
1507 } 1529 }
1508 1530
1509 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( 1531 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection(
1510 DialogSection section) const { 1532 DialogSection section) {
1511 if (section == SECTION_CC || section == SECTION_CC_BILLING) 1533 if (section != SECTION_CC && section != SECTION_CC_BILLING)
1512 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16()); 1534 return gfx::Image();
Evan Stade 2013/09/17 19:59:06 \n
please use gerrit instead 2013/09/17 20:32:24 Done.
1513 1535 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
1514 return gfx::Image(); 1536 if (!model.get())
1537 return gfx::Image();
Evan Stade 2013/09/17 19:59:06 \n
please use gerrit instead 2013/09/17 20:32:24 Done.
1538 return CvcIconForCreditCardType(
1539 UTF16ToUTF8(model->GetInfo(AutofillType(CREDIT_CARD_TYPE))));
1515 } 1540 }
1516 1541
1542 // TODO(groby): Remove this deprecated method after Mac starts using
1543 // IconsForFields. http://crbug.com/292876
1517 gfx::Image AutofillDialogControllerImpl::IconForField( 1544 gfx::Image AutofillDialogControllerImpl::IconForField(
1518 ServerFieldType type, const string16& user_input) const { 1545 ServerFieldType type, const string16& user_input) const {
1519 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1546 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1520 if (type == CREDIT_CARD_VERIFICATION_CODE) 1547 if (type == CREDIT_CARD_VERIFICATION_CODE)
1521 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); 1548 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT);
1522 1549
1523 if (type == CREDIT_CARD_NUMBER) { 1550 if (type == CREDIT_CARD_NUMBER) {
1524 const int input_card_idr = CreditCard::IconResourceId( 1551 const int input_card_idr = CreditCard::IconResourceId(
1525 CreditCard::GetCreditCardType(user_input)); 1552 CreditCard::GetCreditCardType(user_input));
1526 if (input_card_idr != IDR_AUTOFILL_CC_GENERIC) 1553 if (input_card_idr != IDR_AUTOFILL_CC_GENERIC)
1527 return rb.GetImageNamed(input_card_idr); 1554 return rb.GetImageNamed(input_card_idr);
1528 1555
1529 // When the credit card type is unknown, no image should be shown. However, 1556 // When the credit card type is unknown, no image should be shown. However,
1530 // to simplify the view code on Mac, save space for the credit card image by 1557 // to simplify the view code on Mac, save space for the credit card image by
1531 // returning a transparent image of the appropriate size. 1558 // returning a transparent image of the appropriate size.
1532 gfx::ImageSkia image = *rb.GetImageSkiaNamed(input_card_idr); 1559 gfx::ImageSkia image = *rb.GetImageSkiaNamed(input_card_idr);
1533 return 1560 return
1534 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(image, 0)); 1561 gfx::Image(gfx::ImageSkiaOperations::CreateTransparentImage(image, 0));
1535 } 1562 }
1536 1563
1537 return gfx::Image(); 1564 return gfx::Image();
1538 } 1565 }
1539 1566
1567 FieldIconMap AutofillDialogControllerImpl::IconsForFields(
1568 const FieldValueMap& user_inputs) const {
1569 FieldIconMap result;
1570 std::string credit_card_type = autofill::kGenericCard;
1571
1572 FieldValueMap::const_iterator credit_card_iter =
1573 user_inputs.find(CREDIT_CARD_NUMBER);
1574 if (credit_card_iter != user_inputs.end()) {
1575 const string16& credit_card_number = credit_card_iter->second;
1576 credit_card_type = CreditCard::GetCreditCardType(credit_card_number);
1577 result[CREDIT_CARD_NUMBER] = CreditCardIconForType(credit_card_type);
1578 }
1579
1580 if (!user_inputs.count(CREDIT_CARD_VERIFICATION_CODE))
1581 return result;
1582
1583 result[CREDIT_CARD_VERIFICATION_CODE] =
1584 CvcIconForCreditCardType(credit_card_type);
1585
1586 return result;
1587 }
1588
1589 bool AutofillDialogControllerImpl::FieldControlsIcons(
1590 ServerFieldType type) const {
1591 return type == CREDIT_CARD_NUMBER;
1592 }
1593
1540 // TODO(estade): Replace all the error messages here with more helpful and 1594 // TODO(estade): Replace all the error messages here with more helpful and
1541 // translateable ones. TODO(groby): Also add tests. 1595 // translateable ones. TODO(groby): Also add tests.
1542 string16 AutofillDialogControllerImpl::InputValidityMessage( 1596 string16 AutofillDialogControllerImpl::InputValidityMessage(
1543 DialogSection section, 1597 DialogSection section,
1544 ServerFieldType type, 1598 ServerFieldType type,
1545 const string16& value) { 1599 const string16& value) {
1546 // If the field is edited, clear any Wallet errors. 1600 // If the field is edited, clear any Wallet errors.
1547 if (IsPayingWithWallet()) { 1601 if (IsPayingWithWallet()) {
1548 WalletValidationErrors::iterator it = wallet_errors_.find(section); 1602 WalletValidationErrors::iterator it = wallet_errors_.find(section);
1549 if (it != wallet_errors_.end()) { 1603 if (it != wallet_errors_.end()) {
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after
3360 } 3414 }
3361 3415
3362 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { 3416 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() {
3363 if (!view_) 3417 if (!view_)
3364 return; 3418 return;
3365 ScopedViewUpdates updates(view_.get()); 3419 ScopedViewUpdates updates(view_.get());
3366 view_->UpdateButtonStrip(); 3420 view_->UpdateButtonStrip();
3367 } 3421 }
3368 3422
3369 } // namespace autofill 3423 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698