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