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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 // This is a pseudo-scientifically chosen maximum amount we want a fronting | 74 // This is a pseudo-scientifically chosen maximum amount we want a fronting |
75 // (proxy) card to be able to charge. The current actual max is $2000. Using | 75 // (proxy) card to be able to charge. The current actual max is $2000. Using |
76 // only $1850 leaves some room for tax and shipping, etc. TODO(dbeam): send a | 76 // only $1850 leaves some room for tax and shipping, etc. TODO(dbeam): send a |
77 // special value to the server to just ask for the maximum so we don't need to | 77 // special value to the server to just ask for the maximum so we don't need to |
78 // hardcode it here (http://crbug.com/180731). TODO(dbeam): also maybe allow | 78 // hardcode it here (http://crbug.com/180731). TODO(dbeam): also maybe allow |
79 // users to give us this number via an <input> (http://crbug.com/180733). | 79 // users to give us this number via an <input> (http://crbug.com/180733). |
80 const int kCartMax = 1850; | 80 const int kCartMax = 1850; |
81 const char kCartCurrency[] = "USD"; | 81 const char kCartCurrency[] = "USD"; |
82 | 82 |
83 const char kAddNewItemKey[] = "add-new-item"; | |
84 const char kManageItemsKey[] = "manage-items"; | |
85 const char kSameAsBillingKey[] = "same-as-billing"; | |
86 | |
87 // Returns true if |input| should be shown when |field| has been requested. | 83 // Returns true if |input| should be shown when |field| has been requested. |
88 bool InputTypeMatchesFieldType(const DetailInput& input, | 84 bool InputTypeMatchesFieldType(const DetailInput& input, |
89 const AutofillField& field) { | 85 const AutofillField& field) { |
90 // If any credit card expiration info is asked for, show both month and year | 86 // If any credit card expiration info is asked for, show both month and year |
91 // inputs. | 87 // inputs. |
92 if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 88 if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
93 field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 89 field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
94 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | 90 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
95 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 91 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
96 field.type() == CREDIT_CARD_EXP_MONTH) { | 92 field.type() == CREDIT_CARD_EXP_MONTH) { |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 // AutofillDialogController implementation. | 405 // AutofillDialogController implementation. |
410 | 406 |
411 string16 AutofillDialogControllerImpl::DialogTitle() const { | 407 string16 AutofillDialogControllerImpl::DialogTitle() const { |
412 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); | 408 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); |
413 } | 409 } |
414 | 410 |
415 string16 AutofillDialogControllerImpl::EditSuggestionText() const { | 411 string16 AutofillDialogControllerImpl::EditSuggestionText() const { |
416 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); | 412 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); |
417 } | 413 } |
418 | 414 |
| 415 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const { |
| 416 return l10n_util::GetStringUTF16( |
| 417 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING); |
| 418 } |
| 419 |
419 string16 AutofillDialogControllerImpl::CancelButtonText() const { | 420 string16 AutofillDialogControllerImpl::CancelButtonText() const { |
420 return l10n_util::GetStringUTF16(IDS_CANCEL); | 421 return l10n_util::GetStringUTF16(IDS_CANCEL); |
421 } | 422 } |
422 | 423 |
423 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { | 424 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { |
424 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ? | 425 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ? |
425 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); | 426 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); |
426 } | 427 } |
427 | 428 |
428 string16 AutofillDialogControllerImpl::CancelSignInText() const { | 429 string16 AutofillDialogControllerImpl::CancelSignInText() const { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); | 718 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); |
718 default: | 719 default: |
719 NOTREACHED(); | 720 NOTREACHED(); |
720 return string16(); | 721 return string16(); |
721 } | 722 } |
722 } | 723 } |
723 | 724 |
724 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( | 725 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( |
725 DialogSection section) { | 726 DialogSection section) { |
726 return SuggestionState(SuggestionTextForSection(section), | 727 return SuggestionState(SuggestionTextForSection(section), |
727 SuggestionTextStyleForSection(section), | |
728 SuggestionIconForSection(section), | 728 SuggestionIconForSection(section), |
729 ExtraSuggestionTextForSection(section), | 729 ExtraSuggestionTextForSection(section), |
730 ExtraSuggestionIconForSection(section), | 730 ExtraSuggestionIconForSection(section), |
731 EditEnabledForSection(section)); | 731 EditEnabledForSection(section)); |
732 } | 732 } |
733 | 733 |
734 string16 AutofillDialogControllerImpl::SuggestionTextForSection( | 734 string16 AutofillDialogControllerImpl::SuggestionTextForSection( |
735 DialogSection section) { | 735 DialogSection section) { |
736 string16 action_text = RequiredActionTextForSection(section); | 736 string16 action_text = RequiredActionTextForSection(section); |
737 if (!action_text.empty()) | 737 if (!action_text.empty()) |
738 return action_text; | 738 return action_text; |
739 | 739 |
740 // When the user has clicked 'edit', don't show a suggestion (even though | 740 // When the user has clicked 'edit', don't show a suggestion (even though |
741 // there is a profile selected in the model). | 741 // there is a profile selected in the model). |
742 if (section_editing_state_[section]) | 742 if (section_editing_state_[section]) |
743 return string16(); | 743 return string16(); |
744 | 744 |
745 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 745 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
746 std::string item_key = model->GetItemKeyForCheckedItem(); | 746 std::string item_key = model->GetItemKeyForCheckedItem(); |
747 if (item_key == kSameAsBillingKey) { | 747 if (item_key.empty()) |
748 return l10n_util::GetStringUTF16( | |
749 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); | |
750 } | |
751 | |
752 if (!IsASuggestionItemKey(item_key)) | |
753 return string16(); | 748 return string16(); |
754 | 749 |
755 if (section == SECTION_EMAIL) | 750 if (section == SECTION_EMAIL) |
756 return model->GetLabelAt(model->checked_item()); | 751 return model->GetLabelAt(model->checked_item()); |
757 | 752 |
758 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); | 753 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
759 return wrapper->GetDisplayText(); | 754 return wrapper->GetDisplayText(); |
760 } | 755 } |
761 | 756 |
762 gfx::Font::FontStyle | |
763 AutofillDialogControllerImpl::SuggestionTextStyleForSection( | |
764 DialogSection section) const { | |
765 const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | |
766 if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey) | |
767 return gfx::Font::ITALIC; | |
768 | |
769 return gfx::Font::NORMAL; | |
770 } | |
771 | |
772 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( | 757 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( |
773 DialogSection section) const { | 758 DialogSection section) const { |
774 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 759 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
775 const wallet::WalletItems::MaskedInstrument* current_instrument = | 760 const wallet::WalletItems::MaskedInstrument* current_instrument = |
776 wallet_items_->GetInstrumentById(active_instrument_id_); | 761 wallet_items_->GetInstrumentById(active_instrument_id_); |
777 if (current_instrument) | 762 if (current_instrument) |
778 return current_instrument->TypeAndLastFourDigits(); | 763 return current_instrument->TypeAndLastFourDigits(); |
779 | 764 |
780 DetailOutputMap output; | 765 DetailOutputMap output; |
781 view_->GetUserInput(section, &output); | 766 view_->GetUserInput(section, &output); |
(...skipping 22 matching lines...) Expand all Loading... |
804 if (section == SECTION_CC_BILLING) { | 789 if (section == SECTION_CC_BILLING) { |
805 return scoped_ptr<DataModelWrapper>( | 790 return scoped_ptr<DataModelWrapper>( |
806 new FullWalletBillingWrapper(full_wallet_.get())); | 791 new FullWalletBillingWrapper(full_wallet_.get())); |
807 } | 792 } |
808 if (section == SECTION_SHIPPING) { | 793 if (section == SECTION_SHIPPING) { |
809 return scoped_ptr<DataModelWrapper>( | 794 return scoped_ptr<DataModelWrapper>( |
810 new FullWalletShippingWrapper(full_wallet_.get())); | 795 new FullWalletShippingWrapper(full_wallet_.get())); |
811 } | 796 } |
812 } | 797 } |
813 | 798 |
| 799 if (IsManuallyEditingSection(section)) |
| 800 return scoped_ptr<DataModelWrapper>(); |
| 801 |
814 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 802 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
815 std::string item_key = model->GetItemKeyForCheckedItem(); | 803 std::string item_key = model->GetItemKeyForCheckedItem(); |
816 if (!IsASuggestionItemKey(item_key) || IsManuallyEditingSection(section)) | |
817 return scoped_ptr<DataModelWrapper>(); | |
818 | 804 |
819 if (IsPayingWithWallet()) { | 805 if (IsPayingWithWallet()) { |
820 int index; | 806 int index; |
821 bool success = base::StringToInt(item_key, &index); | 807 bool success = base::StringToInt(item_key, &index); |
822 DCHECK(success); | 808 DCHECK(success); |
823 | 809 |
824 if (section == SECTION_CC_BILLING) { | 810 if (section == SECTION_CC_BILLING) { |
825 return scoped_ptr<DataModelWrapper>( | 811 return scoped_ptr<DataModelWrapper>( |
826 new WalletInstrumentWrapper(wallet_items_->instruments()[index])); | 812 new WalletInstrumentWrapper(wallet_items_->instruments()[index])); |
827 } | 813 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( | 855 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( |
870 DialogSection section) const { | 856 DialogSection section) const { |
871 if (section == SECTION_CC || section == SECTION_CC_BILLING) | 857 if (section == SECTION_CC || section == SECTION_CC_BILLING) |
872 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16()); | 858 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16()); |
873 | 859 |
874 return gfx::Image(); | 860 return gfx::Image(); |
875 } | 861 } |
876 | 862 |
877 bool AutofillDialogControllerImpl::EditEnabledForSection( | 863 bool AutofillDialogControllerImpl::EditEnabledForSection( |
878 DialogSection section) const { | 864 DialogSection section) const { |
879 if (SuggestionsMenuModelForSection(section)->GetItemKeyForCheckedItem() == | 865 return section != SECTION_CC_BILLING || !IsSubmitPausedOn(wallet::VERIFY_CVV); |
880 kSameAsBillingKey) { | |
881 return false; | |
882 } | |
883 | |
884 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) | |
885 return false; | |
886 | |
887 return true; | |
888 } | 866 } |
889 | 867 |
890 void AutofillDialogControllerImpl::EditClickedForSection( | 868 void AutofillDialogControllerImpl::EditClickedForSection( |
891 DialogSection section) { | 869 DialogSection section) { |
892 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 870 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
893 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 871 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
894 model->FillInputs(inputs); | 872 model->FillInputs(inputs); |
895 section_editing_state_[section] = true; | 873 section_editing_state_[section] = true; |
896 view_->UpdateSection(section, CLEAR_USER_INPUT); | 874 view_->UpdateSection(section, CLEAR_USER_INPUT); |
897 | 875 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 // to the Wallet. This will trigger AccountChoiceChanged. | 1350 // to the Wallet. This will trigger AccountChoiceChanged. |
1373 account_chooser_model_.SelectActiveWalletAccount(); | 1351 account_chooser_model_.SelectActiveWalletAccount(); |
1374 } | 1352 } |
1375 } | 1353 } |
1376 } | 1354 } |
1377 | 1355 |
1378 //////////////////////////////////////////////////////////////////////////////// | 1356 //////////////////////////////////////////////////////////////////////////////// |
1379 // SuggestionsMenuModelDelegate implementation. | 1357 // SuggestionsMenuModelDelegate implementation. |
1380 | 1358 |
1381 void AutofillDialogControllerImpl::SuggestionItemSelected( | 1359 void AutofillDialogControllerImpl::SuggestionItemSelected( |
1382 SuggestionsMenuModel* model, | 1360 const SuggestionsMenuModel& model) { |
1383 size_t index) { | 1361 const DialogSection section = SectionForSuggestionsMenuModel(model); |
1384 if (model->GetItemKeyAt(index) == kManageItemsKey) { | 1362 EditCancelledForSection(section); |
1385 // TODO(estade): show chrome://settings or a wallet URL. | |
1386 return; | |
1387 } | |
1388 | 1363 |
1389 model->SetCheckedIndex(index); | 1364 LogSuggestionItemSelectedMetric(model); |
1390 EditCancelledForSection(SectionForSuggestionsMenuModel(*model)); | |
1391 | |
1392 LogSuggestionItemSelectedMetric(*model); | |
1393 } | 1365 } |
1394 | 1366 |
1395 //////////////////////////////////////////////////////////////////////////////// | 1367 //////////////////////////////////////////////////////////////////////////////// |
1396 // wallet::WalletClientDelegate implementation. | 1368 // wallet::WalletClientDelegate implementation. |
1397 | 1369 |
1398 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { | 1370 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { |
1399 return metric_logger_; | 1371 return metric_logger_; |
1400 } | 1372 } |
1401 | 1373 |
1402 DialogType AutofillDialogControllerImpl::GetDialogType() const { | 1374 DialogType AutofillDialogControllerImpl::GetDialogType() const { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 } | 1671 } |
1700 | 1672 |
1701 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 1673 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
1702 suggested_email_.Reset(); | 1674 suggested_email_.Reset(); |
1703 suggested_cc_.Reset(); | 1675 suggested_cc_.Reset(); |
1704 suggested_billing_.Reset(); | 1676 suggested_billing_.Reset(); |
1705 suggested_cc_billing_.Reset(); | 1677 suggested_cc_billing_.Reset(); |
1706 suggested_shipping_.Reset(); | 1678 suggested_shipping_.Reset(); |
1707 HidePopup(); | 1679 HidePopup(); |
1708 | 1680 |
1709 suggested_shipping_.AddKeyedItem( | |
1710 kSameAsBillingKey, | |
1711 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING)); | |
1712 | |
1713 if (IsPayingWithWallet()) { | 1681 if (IsPayingWithWallet()) { |
1714 if (!account_chooser_model_.active_wallet_account_name().empty()) { | 1682 if (!account_chooser_model_.active_wallet_account_name().empty()) { |
1715 suggested_email_.AddKeyedItem( | 1683 suggested_email_.AddKeyedItem( |
1716 base::IntToString(0), | 1684 base::IntToString(0), |
1717 account_chooser_model_.active_wallet_account_name()); | 1685 account_chooser_model_.active_wallet_account_name()); |
1718 } | 1686 } |
1719 | 1687 |
1720 const std::vector<wallet::Address*>& addresses = | 1688 const std::vector<wallet::Address*>& addresses = |
1721 wallet_items_->addresses(); | 1689 wallet_items_->addresses(); |
1722 for (size_t i = 0; i < addresses.size(); ++i) { | 1690 for (size_t i = 0; i < addresses.size(); ++i) { |
1723 // TODO(dbeam): respect the default instrument ID. http://crbug.com/232954 | 1691 // TODO(dbeam): respect the default instrument ID. http://crbug.com/232954 |
1724 suggested_shipping_.AddKeyedItemWithSublabel( | 1692 suggested_shipping_.AddKeyedItemWithSublabel( |
1725 base::IntToString(i), | 1693 base::IntToString(i), |
1726 addresses[i]->DisplayName(), | 1694 addresses[i]->DisplayName(), |
1727 addresses[i]->DisplayNameDetail()); | 1695 addresses[i]->DisplayNameDetail()); |
1728 | |
1729 } | 1696 } |
1730 | 1697 |
1731 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { | 1698 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { |
1732 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = | 1699 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = |
1733 wallet_items_->instruments(); | 1700 wallet_items_->instruments(); |
1734 for (size_t i = 0; i < instruments.size(); ++i) { | 1701 for (size_t i = 0; i < instruments.size(); ++i) { |
1735 // TODO(dbeam): respect the default address ID. http://crbug.com/232954 | 1702 // TODO(dbeam): respect the default address ID. http://crbug.com/232954 |
1736 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( | 1703 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( |
1737 base::IntToString(i), | 1704 base::IntToString(i), |
1738 instruments[i]->DisplayName(), | 1705 instruments[i]->DisplayName(), |
1739 instruments[i]->DisplayNameDetail(), | 1706 instruments[i]->DisplayNameDetail(), |
1740 instruments[i]->CardIcon()); | 1707 instruments[i]->CardIcon()); |
1741 } | 1708 } |
1742 | 1709 |
1743 // TODO(estade): this should have a URL sublabel. | |
1744 suggested_cc_billing_.AddKeyedItem( | 1710 suggested_cc_billing_.AddKeyedItem( |
1745 kAddNewItemKey, | 1711 std::string(), |
1746 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); | 1712 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); |
1747 suggested_cc_billing_.AddKeyedItem( | |
1748 kManageItemsKey, | |
1749 l10n_util::GetStringUTF16( | |
1750 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS)); | |
1751 } | 1713 } |
1752 } else { | 1714 } else { |
1753 PersonalDataManager* manager = GetManager(); | 1715 PersonalDataManager* manager = GetManager(); |
1754 const std::vector<CreditCard*>& cards = manager->credit_cards(); | 1716 const std::vector<CreditCard*>& cards = manager->credit_cards(); |
1755 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1717 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1756 for (size_t i = 0; i < cards.size(); ++i) { | 1718 for (size_t i = 0; i < cards.size(); ++i) { |
1757 suggested_cc_.AddKeyedItemWithIcon( | 1719 suggested_cc_.AddKeyedItemWithIcon( |
1758 cards[i]->guid(), | 1720 cards[i]->guid(), |
1759 cards[i]->Label(), | 1721 cards[i]->Label(), |
1760 rb.GetImageNamed(cards[i]->IconResourceId())); | 1722 rb.GetImageNamed(cards[i]->IconResourceId())); |
(...skipping 16 matching lines...) Expand all Loading... |
1777 // Don't add variants for addresses: the email variants are handled above, | 1739 // Don't add variants for addresses: the email variants are handled above, |
1778 // name is part of credit card and we'll just ignore phone number | 1740 // name is part of credit card and we'll just ignore phone number |
1779 // variants. | 1741 // variants. |
1780 suggested_billing_.AddKeyedItem(profiles[i]->guid(), | 1742 suggested_billing_.AddKeyedItem(profiles[i]->guid(), |
1781 profiles[i]->Label()); | 1743 profiles[i]->Label()); |
1782 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), | 1744 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), |
1783 profiles[i]->Label()); | 1745 profiles[i]->Label()); |
1784 } | 1746 } |
1785 | 1747 |
1786 suggested_cc_.AddKeyedItem( | 1748 suggested_cc_.AddKeyedItem( |
1787 kAddNewItemKey, | 1749 std::string(), |
1788 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); | 1750 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); |
1789 suggested_cc_.AddKeyedItem( | |
1790 kManageItemsKey, | |
1791 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD)); | |
1792 suggested_billing_.AddKeyedItem( | 1751 suggested_billing_.AddKeyedItem( |
1793 kAddNewItemKey, | 1752 std::string(), |
1794 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); | 1753 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); |
1795 suggested_billing_.AddKeyedItem( | |
1796 kManageItemsKey, | |
1797 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS)); | |
1798 } | 1754 } |
1799 | 1755 |
1800 suggested_email_.AddKeyedItem( | 1756 suggested_email_.AddKeyedItem( |
1801 kAddNewItemKey, | 1757 std::string(), |
1802 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); | 1758 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); |
1803 if (!IsPayingWithWallet()) { | |
1804 suggested_email_.AddKeyedItem( | |
1805 kManageItemsKey, | |
1806 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS)); | |
1807 } | |
1808 | |
1809 suggested_shipping_.AddKeyedItem( | 1759 suggested_shipping_.AddKeyedItem( |
1810 kAddNewItemKey, | 1760 std::string(), |
1811 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 1761 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
1812 suggested_shipping_.AddKeyedItem( | |
1813 kManageItemsKey, | |
1814 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); | |
1815 | |
1816 // Default shipping address is the first suggestion, if one exists. Otherwise | |
1817 // it's the "Use shipping for billing" item. | |
1818 const std::string& first_real_suggestion_item_key = | |
1819 suggested_shipping_.GetItemKeyAt(1); | |
1820 if (IsASuggestionItemKey(first_real_suggestion_item_key)) | |
1821 suggested_shipping_.SetCheckedItem(first_real_suggestion_item_key); | |
1822 | 1762 |
1823 if (view_) | 1763 if (view_) |
1824 view_->ModelChanged(); | 1764 view_->ModelChanged(); |
1825 } | 1765 } |
1826 | 1766 |
1827 bool AutofillDialogControllerImpl::IsCompleteProfile( | 1767 bool AutofillDialogControllerImpl::IsCompleteProfile( |
1828 const AutofillProfile& profile) { | 1768 const AutofillProfile& profile) { |
1829 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 1769 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
1830 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { | 1770 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { |
1831 AutofillFieldType type = requested_shipping_fields_[i].type; | 1771 AutofillFieldType type = requested_shipping_fields_[i].type; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 AutofillField* field = form_structure_.field(i); | 1853 AutofillField* field = form_structure_.field(i); |
1914 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { | 1854 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { |
1915 field->value = cvc; | 1855 field->value = cvc; |
1916 break; | 1856 break; |
1917 } | 1857 } |
1918 } | 1858 } |
1919 } | 1859 } |
1920 | 1860 |
1921 SuggestionsMenuModel* AutofillDialogControllerImpl:: | 1861 SuggestionsMenuModel* AutofillDialogControllerImpl:: |
1922 SuggestionsMenuModelForSection(DialogSection section) { | 1862 SuggestionsMenuModelForSection(DialogSection section) { |
| 1863 const AutofillDialogControllerImpl* const_this = |
| 1864 static_cast<const AutofillDialogControllerImpl*>(this); |
| 1865 return const_cast<SuggestionsMenuModel*>( |
| 1866 const_this->SuggestionsMenuModelForSection(section)); |
| 1867 } |
| 1868 |
| 1869 const SuggestionsMenuModel* AutofillDialogControllerImpl:: |
| 1870 SuggestionsMenuModelForSection(DialogSection section) const { |
1923 switch (section) { | 1871 switch (section) { |
1924 case SECTION_EMAIL: | 1872 case SECTION_EMAIL: |
1925 return &suggested_email_; | 1873 return &suggested_email_; |
1926 case SECTION_CC: | 1874 case SECTION_CC: |
1927 return &suggested_cc_; | 1875 return &suggested_cc_; |
1928 case SECTION_BILLING: | 1876 case SECTION_BILLING: |
1929 return &suggested_billing_; | 1877 return &suggested_billing_; |
1930 case SECTION_SHIPPING: | 1878 case SECTION_SHIPPING: |
1931 return &suggested_shipping_; | 1879 return &suggested_shipping_; |
1932 case SECTION_CC_BILLING: | 1880 case SECTION_CC_BILLING: |
1933 return &suggested_cc_billing_; | 1881 return &suggested_cc_billing_; |
1934 } | 1882 } |
1935 | 1883 |
1936 NOTREACHED(); | 1884 NOTREACHED(); |
1937 return NULL; | 1885 return NULL; |
1938 } | 1886 } |
1939 | 1887 |
1940 const SuggestionsMenuModel* AutofillDialogControllerImpl:: | |
1941 SuggestionsMenuModelForSection(DialogSection section) const { | |
1942 return const_cast<AutofillDialogControllerImpl*>(this)-> | |
1943 SuggestionsMenuModelForSection(section); | |
1944 } | |
1945 | |
1946 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( | 1888 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( |
1947 const SuggestionsMenuModel& model) { | 1889 const SuggestionsMenuModel& model) { |
1948 if (&model == &suggested_email_) | 1890 if (&model == &suggested_email_) |
1949 return SECTION_EMAIL; | 1891 return SECTION_EMAIL; |
1950 | 1892 |
1951 if (&model == &suggested_cc_) | 1893 if (&model == &suggested_cc_) |
1952 return SECTION_CC; | 1894 return SECTION_CC; |
1953 | 1895 |
1954 if (&model == &suggested_billing_) | 1896 if (&model == &suggested_billing_) |
1955 return SECTION_BILLING; | 1897 return SECTION_BILLING; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 scoped_ptr<risk::Fingerprint> fingerprint) { | 1947 scoped_ptr<risk::Fingerprint> fingerprint) { |
2006 NOTIMPLEMENTED(); | 1948 NOTIMPLEMENTED(); |
2007 } | 1949 } |
2008 | 1950 |
2009 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 1951 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
2010 DialogSection section) const { | 1952 DialogSection section) const { |
2011 std::map<DialogSection, bool>::const_iterator it = | 1953 std::map<DialogSection, bool>::const_iterator it = |
2012 section_editing_state_.find(section); | 1954 section_editing_state_.find(section); |
2013 return (it != section_editing_state_.end() && it->second) || | 1955 return (it != section_editing_state_.end() && it->second) || |
2014 SuggestionsMenuModelForSection(section)-> | 1956 SuggestionsMenuModelForSection(section)-> |
2015 GetItemKeyForCheckedItem() == kAddNewItemKey; | 1957 GetItemKeyForCheckedItem().empty(); |
2016 } | |
2017 | |
2018 bool AutofillDialogControllerImpl::IsASuggestionItemKey( | |
2019 const std::string& key) { | |
2020 return !key.empty() && | |
2021 key != kAddNewItemKey && | |
2022 key != kManageItemsKey && | |
2023 key != kSameAsBillingKey; | |
2024 } | 1958 } |
2025 | 1959 |
2026 bool AutofillDialogControllerImpl::IsManuallyEditingAnySection() const { | 1960 bool AutofillDialogControllerImpl::IsManuallyEditingAnySection() const { |
2027 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { | 1961 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { |
2028 if (IsManuallyEditingSection(static_cast<DialogSection>(section))) | 1962 if (IsManuallyEditingSection(static_cast<DialogSection>(section))) |
2029 return true; | 1963 return true; |
2030 } | 1964 } |
2031 return false; | 1965 return false; |
2032 } | 1966 } |
2033 | 1967 |
2034 bool AutofillDialogControllerImpl::AllSectionsAreValid() const { | 1968 bool AutofillDialogControllerImpl::AllSectionsAreValid() const { |
2035 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { | 1969 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { |
2036 if (!SectionIsValid(static_cast<DialogSection>(section))) | 1970 if (!SectionIsValid(static_cast<DialogSection>(section))) |
2037 return false; | 1971 return false; |
2038 } | 1972 } |
2039 return true; | 1973 return true; |
2040 } | 1974 } |
2041 | 1975 |
2042 bool AutofillDialogControllerImpl::SectionIsValid( | 1976 bool AutofillDialogControllerImpl::SectionIsValid( |
2043 DialogSection section) const { | 1977 DialogSection section) const { |
2044 if (!IsManuallyEditingSection(section)) | 1978 if (!IsManuallyEditingSection(section)) |
2045 return true; | 1979 return true; |
2046 | 1980 |
2047 DetailOutputMap detail_outputs; | 1981 DetailOutputMap detail_outputs; |
2048 view_->GetUserInput(SECTION_EMAIL, &detail_outputs); | 1982 view_->GetUserInput(SECTION_EMAIL, &detail_outputs); |
2049 return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty(); | 1983 return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty(); |
2050 } | 1984 } |
2051 | 1985 |
2052 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { | 1986 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { |
2053 return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey; | 1987 // If the user is editing or inputting data, ask the view. |
| 1988 if (IsManuallyEditingSection(SECTION_SHIPPING)) |
| 1989 return view_->UseBillingForShipping(); |
| 1990 |
| 1991 // Otherwise, the checkbox should be hidden so its state is irrelevant. |
| 1992 // Always use the shipping suggestion model. |
| 1993 return false; |
2054 } | 1994 } |
2055 | 1995 |
2056 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { | 1996 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { |
2057 // It's possible that the user checked [X] Save details locally before | 1997 // It's possible that the user checked [X] Save details locally before |
2058 // switching payment methods, so only ask the view whether to save details | 1998 // switching payment methods, so only ask the view whether to save details |
2059 // locally if that checkbox is showing (currently if not paying with wallet). | 1999 // locally if that checkbox is showing (currently if not paying with wallet). |
2060 // Also, if the user isn't editing any sections, there's no data to save | 2000 // Also, if the user isn't editing any sections, there's no data to save |
2061 // locally. | 2001 // locally. |
2062 return ShouldOfferToSaveInChrome() && view_->SaveDetailsLocally(); | 2002 return ShouldOfferToSaveInChrome() && view_->SaveDetailsLocally(); |
2063 } | 2003 } |
(...skipping 14 matching lines...) Expand all Loading... |
2078 // TODO(dbeam): disallow interacting with the dialog while submitting. | 2018 // TODO(dbeam): disallow interacting with the dialog while submitting. |
2079 // http://crbug.com/230932 | 2019 // http://crbug.com/230932 |
2080 | 2020 |
2081 active_instrument_id_.clear(); | 2021 active_instrument_id_.clear(); |
2082 active_address_id_.clear(); | 2022 active_address_id_.clear(); |
2083 full_wallet_.reset(); | 2023 full_wallet_.reset(); |
2084 | 2024 |
2085 if (!section_editing_state_[SECTION_CC_BILLING]) { | 2025 if (!section_editing_state_[SECTION_CC_BILLING]) { |
2086 SuggestionsMenuModel* billing = | 2026 SuggestionsMenuModel* billing = |
2087 SuggestionsMenuModelForSection(SECTION_CC_BILLING); | 2027 SuggestionsMenuModelForSection(SECTION_CC_BILLING); |
2088 if (IsASuggestionItemKey(billing->GetItemKeyForCheckedItem()) && | 2028 if (!billing->GetItemKeyForCheckedItem().empty() && |
2089 billing->checked_item() < | 2029 billing->checked_item() < |
2090 static_cast<int>(wallet_items_->instruments().size())) { | 2030 static_cast<int>(wallet_items_->instruments().size())) { |
2091 const wallet::WalletItems::MaskedInstrument* active_instrument = | 2031 const wallet::WalletItems::MaskedInstrument* active_instrument = |
2092 wallet_items_->instruments()[billing->checked_item()]; | 2032 wallet_items_->instruments()[billing->checked_item()]; |
2093 active_instrument_id_ = active_instrument->object_id(); | 2033 active_instrument_id_ = active_instrument->object_id(); |
2094 | 2034 |
2095 // TODO(dbeam): save this as a shipping address. http://crbug.com/225442 | 2035 // TODO(dbeam): save this as a shipping address. http://crbug.com/225442 |
2096 if (ShouldUseBillingForShipping()) | 2036 if (ShouldUseBillingForShipping()) |
2097 active_address_id_ = active_instrument->address().object_id(); | 2037 active_address_id_ = active_instrument->address().object_id(); |
2098 } | 2038 } |
2099 } | 2039 } |
2100 | 2040 |
2101 if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) { | 2041 if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) { |
2102 SuggestionsMenuModel* shipping = | 2042 SuggestionsMenuModel* shipping = |
2103 SuggestionsMenuModelForSection(SECTION_SHIPPING); | 2043 SuggestionsMenuModelForSection(SECTION_SHIPPING); |
2104 if (IsASuggestionItemKey(shipping->GetItemKeyForCheckedItem()) && | 2044 if (!shipping->GetItemKeyForCheckedItem().empty() && |
2105 shipping->checked_item() - 1 < | 2045 shipping->checked_item() < |
2106 static_cast<int>(wallet_items_->addresses().size())) { | 2046 static_cast<int>(wallet_items_->addresses().size())) { |
2107 active_address_id_ = | 2047 active_address_id_ = |
2108 wallet_items_->addresses()[shipping->checked_item() - 1]->object_id(); | 2048 wallet_items_->addresses()[shipping->checked_item()]->object_id(); |
2109 } | 2049 } |
2110 } | 2050 } |
2111 | 2051 |
2112 GetWalletClient()->AcceptLegalDocuments( | 2052 GetWalletClient()->AcceptLegalDocuments( |
2113 wallet_items_->legal_documents(), | 2053 wallet_items_->legal_documents(), |
2114 wallet_items_->google_transaction_id(), | 2054 wallet_items_->google_transaction_id(), |
2115 source_url_); | 2055 source_url_); |
2116 | 2056 |
2117 scoped_ptr<wallet::Instrument> new_instrument; | 2057 scoped_ptr<wallet::Instrument> new_instrument; |
2118 if (active_instrument_id_.empty()) { | 2058 if (active_instrument_id_.empty()) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2255 base::Time::Now() - dialog_shown_timestamp_, | 2195 base::Time::Now() - dialog_shown_timestamp_, |
2256 dialog_type_, | 2196 dialog_type_, |
2257 AutofillMetrics::DIALOG_CANCELED); | 2197 AutofillMetrics::DIALOG_CANCELED); |
2258 } | 2198 } |
2259 | 2199 |
2260 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( | 2200 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( |
2261 const SuggestionsMenuModel& model) { | 2201 const SuggestionsMenuModel& model) { |
2262 DialogSection section = SectionForSuggestionsMenuModel(model); | 2202 DialogSection section = SectionForSuggestionsMenuModel(model); |
2263 | 2203 |
2264 AutofillMetrics::DialogUiEvent dialog_ui_event; | 2204 AutofillMetrics::DialogUiEvent dialog_ui_event; |
2265 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) { | 2205 if (model.GetItemKeyForCheckedItem().empty()) { |
2266 // Selected to add a new item. | 2206 // Selected to add a new item. |
2267 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); | 2207 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); |
2268 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) { | 2208 } else { |
2269 // Selected an existing item. | 2209 // Selected an existing item. |
2270 DCHECK(!section_editing_state_[section]); | 2210 DCHECK(!section_editing_state_[section]); |
2271 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); | 2211 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); |
2272 } else { | |
2273 // TODO(estade): add logging for "Manage items" or "Use billing for | |
2274 // shipping"? | |
2275 return; | |
2276 } | 2212 } |
2277 | 2213 |
2278 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); | 2214 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); |
2279 } | 2215 } |
2280 | 2216 |
2281 AutofillMetrics::DialogInitialUserStateMetric | 2217 AutofillMetrics::DialogInitialUserStateMetric |
2282 AutofillDialogControllerImpl::GetInitialUserState() const { | 2218 AutofillDialogControllerImpl::GetInitialUserState() const { |
2283 // Consider a user to be an Autofill user if the user has any credit cards | 2219 // Consider a user to be an Autofill user if the user has any credit cards |
2284 // or addresses saved. Check that the item count is greater than 2 because | 2220 // or addresses saved. Check that the item count is greater than 1 because |
2285 // an "empty" menu still has the "add new" menu item and "manage" menu item. | 2221 // an "empty" menu still has the "add new" menu item. |
2286 const bool has_autofill_profiles = | 2222 const bool has_autofill_profiles = |
2287 suggested_cc_.GetItemCount() > 2 || | 2223 suggested_cc_.GetItemCount() > 1 || |
2288 suggested_billing_.GetItemCount() > 2; | 2224 suggested_billing_.GetItemCount() > 1; |
2289 | 2225 |
2290 if (SignedInState() != SIGNED_IN) { | 2226 if (SignedInState() != SIGNED_IN) { |
2291 // Not signed in. | 2227 // Not signed in. |
2292 return has_autofill_profiles ? | 2228 return has_autofill_profiles ? |
2293 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL : | 2229 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_HAS_AUTOFILL : |
2294 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL; | 2230 AutofillMetrics::DIALOG_USER_NOT_SIGNED_IN_NO_AUTOFILL; |
2295 } | 2231 } |
2296 | 2232 |
2297 // Signed in. | 2233 // Signed in. |
2298 if (wallet_items_->instruments().empty()) { | 2234 if (wallet_items_->instruments().empty()) { |
2299 // No Wallet items. | 2235 // No Wallet items. |
2300 return has_autofill_profiles ? | 2236 return has_autofill_profiles ? |
2301 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL : | 2237 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_HAS_AUTOFILL : |
2302 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 2238 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
2303 } | 2239 } |
2304 | 2240 |
2305 // Has Wallet items. | 2241 // Has Wallet items. |
2306 return has_autofill_profiles ? | 2242 return has_autofill_profiles ? |
2307 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 2243 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
2308 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 2244 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
2309 } | 2245 } |
2310 | 2246 |
2311 } // namespace autofill | 2247 } // namespace autofill |
OLD | NEW |