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

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

Issue 14129005: Remove "Use billing for shipping" checkbox in favor of item in suggestions menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dbeam review Created 7 years, 8 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 <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 // This is a pseudo-scientifically chosen maximum amount we want a fronting 73 // This is a pseudo-scientifically chosen maximum amount we want a fronting
74 // (proxy) card to be able to charge. The current actual max is $2000. Using 74 // (proxy) card to be able to charge. The current actual max is $2000. Using
75 // only $1850 leaves some room for tax and shipping, etc. TODO(dbeam): send a 75 // only $1850 leaves some room for tax and shipping, etc. TODO(dbeam): send a
76 // special value to the server to just ask for the maximum so we don't need to 76 // special value to the server to just ask for the maximum so we don't need to
77 // hardcode it here (http://crbug.com/180731). TODO(dbeam): also maybe allow 77 // hardcode it here (http://crbug.com/180731). TODO(dbeam): also maybe allow
78 // users to give us this number via an <input> (http://crbug.com/180733). 78 // users to give us this number via an <input> (http://crbug.com/180733).
79 const int kCartMax = 1850; 79 const int kCartMax = 1850;
80 const char kCartCurrency[] = "USD"; 80 const char kCartCurrency[] = "USD";
81 81
82 const char kAddNewItemKey[] = "add-new-item";
83 const char kManageItemsKey[] = "manage-items";
84 const char kSameAsBillingKey[] = "same-as-billing";
85
82 // Returns true if |input| should be shown when |field| has been requested. 86 // Returns true if |input| should be shown when |field| has been requested.
83 bool InputTypeMatchesFieldType(const DetailInput& input, 87 bool InputTypeMatchesFieldType(const DetailInput& input,
84 const AutofillField& field) { 88 const AutofillField& field) {
85 // If any credit card expiration info is asked for, show both month and year 89 // If any credit card expiration info is asked for, show both month and year
86 // inputs. 90 // inputs.
87 if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || 91 if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
88 field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || 92 field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
89 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || 93 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
90 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || 94 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
91 field.type() == CREDIT_CARD_EXP_MONTH) { 95 field.type() == CREDIT_CARD_EXP_MONTH) {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // AutofillDialogController implementation. 408 // AutofillDialogController implementation.
405 409
406 string16 AutofillDialogControllerImpl::DialogTitle() const { 410 string16 AutofillDialogControllerImpl::DialogTitle() const {
407 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); 411 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE);
408 } 412 }
409 413
410 string16 AutofillDialogControllerImpl::EditSuggestionText() const { 414 string16 AutofillDialogControllerImpl::EditSuggestionText() const {
411 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); 415 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT);
412 } 416 }
413 417
414 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const {
415 return l10n_util::GetStringUTF16(
416 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING);
417 }
418
419 string16 AutofillDialogControllerImpl::CancelButtonText() const { 418 string16 AutofillDialogControllerImpl::CancelButtonText() const {
420 return l10n_util::GetStringUTF16(IDS_CANCEL); 419 return l10n_util::GetStringUTF16(IDS_CANCEL);
421 } 420 }
422 421
423 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { 422 string16 AutofillDialogControllerImpl::ConfirmButtonText() const {
424 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ? 423 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ?
425 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); 424 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON);
426 } 425 }
427 426
428 string16 AutofillDialogControllerImpl::CancelSignInText() const { 427 string16 AutofillDialogControllerImpl::CancelSignInText() const {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING); 703 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECTION_SHIPPING);
705 default: 704 default:
706 NOTREACHED(); 705 NOTREACHED();
707 return string16(); 706 return string16();
708 } 707 }
709 } 708 }
710 709
711 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection( 710 SuggestionState AutofillDialogControllerImpl::SuggestionStateForSection(
712 DialogSection section) { 711 DialogSection section) {
713 return SuggestionState(SuggestionTextForSection(section), 712 return SuggestionState(SuggestionTextForSection(section),
713 SuggestionTextStyleForSection(section),
714 SuggestionIconForSection(section), 714 SuggestionIconForSection(section),
715 ExtraSuggestionTextForSection(section), 715 ExtraSuggestionTextForSection(section),
716 ExtraSuggestionIconForSection(section), 716 ExtraSuggestionIconForSection(section),
717 EditEnabledForSection(section)); 717 EditEnabledForSection(section));
718 } 718 }
719 719
720 string16 AutofillDialogControllerImpl::SuggestionTextForSection( 720 string16 AutofillDialogControllerImpl::SuggestionTextForSection(
721 DialogSection section) { 721 DialogSection section) {
722 string16 action_text = RequiredActionTextForSection(section); 722 string16 action_text = RequiredActionTextForSection(section);
723 if (!action_text.empty()) 723 if (!action_text.empty())
724 return action_text; 724 return action_text;
725 725
726 // When the user has clicked 'edit', don't show a suggestion (even though 726 // When the user has clicked 'edit', don't show a suggestion (even though
727 // there is a profile selected in the model). 727 // there is a profile selected in the model).
728 if (section_editing_state_[section]) 728 if (section_editing_state_[section])
729 return string16(); 729 return string16();
730 730
731 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 731 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
732 std::string item_key = model->GetItemKeyForCheckedItem(); 732 std::string item_key = model->GetItemKeyForCheckedItem();
733 if (item_key.empty()) 733 if (item_key == kSameAsBillingKey) {
734 return l10n_util::GetStringUTF16(
735 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING);
736 }
737
738 if (!IsASuggestionItemKey(item_key))
734 return string16(); 739 return string16();
735 740
736 if (section == SECTION_EMAIL) 741 if (section == SECTION_EMAIL)
737 return model->GetLabelAt(model->checked_item()); 742 return model->GetLabelAt(model->checked_item());
738 743
739 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 744 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
740 return wrapper->GetDisplayText(); 745 return wrapper->GetDisplayText();
741 } 746 }
742 747
748 gfx::Font::FontStyle
749 AutofillDialogControllerImpl::SuggestionTextStyleForSection(
750 DialogSection section) const {
751 const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
752 if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey)
753 return gfx::Font::ITALIC;
754
755 return gfx::Font::NORMAL;
756 }
757
743 string16 AutofillDialogControllerImpl::RequiredActionTextForSection( 758 string16 AutofillDialogControllerImpl::RequiredActionTextForSection(
744 DialogSection section) const { 759 DialogSection section) const {
745 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) { 760 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) {
746 const wallet::WalletItems::MaskedInstrument* current_instrument = 761 const wallet::WalletItems::MaskedInstrument* current_instrument =
747 wallet_items_->GetInstrumentById(active_instrument_id_); 762 wallet_items_->GetInstrumentById(active_instrument_id_);
748 if (current_instrument) 763 if (current_instrument)
749 return current_instrument->TypeAndLastFourDigits(); 764 return current_instrument->TypeAndLastFourDigits();
750 765
751 DetailOutputMap output; 766 DetailOutputMap output;
752 view_->GetUserInput(section, &output); 767 view_->GetUserInput(section, &output);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection( 851 gfx::Image AutofillDialogControllerImpl::ExtraSuggestionIconForSection(
837 DialogSection section) const { 852 DialogSection section) const {
838 if (section == SECTION_CC || section == SECTION_CC_BILLING) 853 if (section == SECTION_CC || section == SECTION_CC_BILLING)
839 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16()); 854 return IconForField(CREDIT_CARD_VERIFICATION_CODE, string16());
840 855
841 return gfx::Image(); 856 return gfx::Image();
842 } 857 }
843 858
844 bool AutofillDialogControllerImpl::EditEnabledForSection( 859 bool AutofillDialogControllerImpl::EditEnabledForSection(
845 DialogSection section) const { 860 DialogSection section) const {
846 return section != SECTION_CC_BILLING || !IsSubmitPausedOn(wallet::VERIFY_CVV); 861 if (SuggestionsMenuModelForSection(section)->GetItemKeyForCheckedItem() ==
862 kSameAsBillingKey) {
863 return false;
864 }
865
866 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV))
867 return false;
868
869 return true;
847 } 870 }
848 871
849 void AutofillDialogControllerImpl::EditClickedForSection( 872 void AutofillDialogControllerImpl::EditClickedForSection(
850 DialogSection section) { 873 DialogSection section) {
851 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 874 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
852 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 875 scoped_ptr<DataModelWrapper> model = CreateWrapper(section);
853 model->FillInputs(inputs); 876 model->FillInputs(inputs);
854 section_editing_state_[section] = true; 877 section_editing_state_[section] = true;
855 view_->UpdateSection(section, CLEAR_USER_INPUT); 878 view_->UpdateSection(section, CLEAR_USER_INPUT);
856 879
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 EndSignInFlow(); 1346 EndSignInFlow();
1324 if (account_chooser_model_.WalletIsSelected()) 1347 if (account_chooser_model_.WalletIsSelected())
1325 GetWalletItems(); 1348 GetWalletItems();
1326 } 1349 }
1327 } 1350 }
1328 1351
1329 //////////////////////////////////////////////////////////////////////////////// 1352 ////////////////////////////////////////////////////////////////////////////////
1330 // SuggestionsMenuModelDelegate implementation. 1353 // SuggestionsMenuModelDelegate implementation.
1331 1354
1332 void AutofillDialogControllerImpl::SuggestionItemSelected( 1355 void AutofillDialogControllerImpl::SuggestionItemSelected(
1333 const SuggestionsMenuModel& model) { 1356 SuggestionsMenuModel* model,
1334 const DialogSection section = SectionForSuggestionsMenuModel(model); 1357 const std::string& item_key) {
1335 EditCancelledForSection(section); 1358 if (item_key == kManageItemsKey) {
1359 // TODO(estade): show chrome://settings or a wallet URL.
Dan Beam 2013/04/17 22:24:26 can you file a bug for this?
1360 return;
1361 }
1336 1362
1337 LogSuggestionItemSelectedMetric(model); 1363 model->SetCheckedItem(item_key);
1364 EditCancelledForSection(SectionForSuggestionsMenuModel(*model));
1365
1366 LogSuggestionItemSelectedMetric(*model);
1338 } 1367 }
1339 1368
1340 //////////////////////////////////////////////////////////////////////////////// 1369 ////////////////////////////////////////////////////////////////////////////////
1341 // wallet::WalletClientDelegate implementation. 1370 // wallet::WalletClientDelegate implementation.
1342 1371
1343 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { 1372 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const {
1344 return metric_logger_; 1373 return metric_logger_;
1345 } 1374 }
1346 1375
1347 DialogType AutofillDialogControllerImpl::GetDialogType() const { 1376 DialogType AutofillDialogControllerImpl::GetDialogType() const {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 } 1653 }
1625 1654
1626 void AutofillDialogControllerImpl::SuggestionsUpdated() { 1655 void AutofillDialogControllerImpl::SuggestionsUpdated() {
1627 suggested_email_.Reset(); 1656 suggested_email_.Reset();
1628 suggested_cc_.Reset(); 1657 suggested_cc_.Reset();
1629 suggested_billing_.Reset(); 1658 suggested_billing_.Reset();
1630 suggested_cc_billing_.Reset(); 1659 suggested_cc_billing_.Reset();
1631 suggested_shipping_.Reset(); 1660 suggested_shipping_.Reset();
1632 HidePopup(); 1661 HidePopup();
1633 1662
1663 suggested_shipping_.AddKeyedItem(
1664 kSameAsBillingKey,
1665 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING));
1666
1634 if (IsPayingWithWallet()) { 1667 if (IsPayingWithWallet()) {
1635 // TODO(estade): fill in the email address. 1668 // TODO(estade): fill in the email address.
1636 1669
1637 const std::vector<wallet::Address*>& addresses = 1670 const std::vector<wallet::Address*>& addresses =
1638 wallet_items_->addresses(); 1671 wallet_items_->addresses();
1639 for (size_t i = 0; i < addresses.size(); ++i) { 1672 for (size_t i = 0; i < addresses.size(); ++i) {
1640 // TODO(dbeam): respect wallet_items_->default_instrument_id(). 1673 // TODO(dbeam): respect wallet_items_->default_instrument_id().
1641 suggested_shipping_.AddKeyedItemWithSublabel( 1674 suggested_shipping_.AddKeyedItemWithSublabel(
1642 base::IntToString(i), 1675 base::IntToString(i),
1643 addresses[i]->DisplayName(), 1676 addresses[i]->DisplayName(),
1644 addresses[i]->DisplayNameDetail()); 1677 addresses[i]->DisplayNameDetail());
1645 } 1678 }
1646 1679
1647 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { 1680 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1648 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = 1681 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments =
1649 wallet_items_->instruments(); 1682 wallet_items_->instruments();
1650 for (size_t i = 0; i < instruments.size(); ++i) { 1683 for (size_t i = 0; i < instruments.size(); ++i) {
1651 // TODO(dbeam): respect wallet_items_->default_address_id(). 1684 // TODO(dbeam): respect wallet_items_->default_address_id().
1652 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( 1685 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon(
1653 base::IntToString(i), 1686 base::IntToString(i),
1654 instruments[i]->DisplayName(), 1687 instruments[i]->DisplayName(),
1655 instruments[i]->DisplayNameDetail(), 1688 instruments[i]->DisplayNameDetail(),
1656 instruments[i]->CardIcon()); 1689 instruments[i]->CardIcon());
1657 } 1690 }
1658 1691
1692 // TODO(estade): this should have a URL sublabel.
1659 suggested_cc_billing_.AddKeyedItem( 1693 suggested_cc_billing_.AddKeyedItem(
1660 std::string(), 1694 kAddNewItemKey,
1661 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); 1695 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS));
1696 suggested_cc_billing_.AddKeyedItem(
1697 kManageItemsKey,
1698 l10n_util::GetStringUTF16(
1699 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS));
1662 } 1700 }
1663 } else { 1701 } else {
1664 PersonalDataManager* manager = GetManager(); 1702 PersonalDataManager* manager = GetManager();
1665 const std::vector<CreditCard*>& cards = manager->credit_cards(); 1703 const std::vector<CreditCard*>& cards = manager->credit_cards();
1666 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1704 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1667 for (size_t i = 0; i < cards.size(); ++i) { 1705 for (size_t i = 0; i < cards.size(); ++i) {
1668 suggested_cc_.AddKeyedItemWithIcon( 1706 suggested_cc_.AddKeyedItemWithIcon(
1669 cards[i]->guid(), 1707 cards[i]->guid(),
1670 cards[i]->Label(), 1708 cards[i]->Label(),
1671 rb.GetImageNamed(cards[i]->IconResourceId())); 1709 rb.GetImageNamed(cards[i]->IconResourceId()));
(...skipping 16 matching lines...) Expand all
1688 // Don't add variants for addresses: the email variants are handled above, 1726 // Don't add variants for addresses: the email variants are handled above,
1689 // name is part of credit card and we'll just ignore phone number 1727 // name is part of credit card and we'll just ignore phone number
1690 // variants. 1728 // variants.
1691 suggested_billing_.AddKeyedItem(profiles[i]->guid(), 1729 suggested_billing_.AddKeyedItem(profiles[i]->guid(),
1692 profiles[i]->Label()); 1730 profiles[i]->Label());
1693 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), 1731 suggested_shipping_.AddKeyedItem(profiles[i]->guid(),
1694 profiles[i]->Label()); 1732 profiles[i]->Label());
1695 } 1733 }
1696 1734
1697 suggested_cc_.AddKeyedItem( 1735 suggested_cc_.AddKeyedItem(
1698 std::string(), 1736 kAddNewItemKey,
1699 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); 1737 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD));
1738 suggested_cc_.AddKeyedItem(
1739 kManageItemsKey,
1740 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_CREDIT_CARD));
1700 suggested_billing_.AddKeyedItem( 1741 suggested_billing_.AddKeyedItem(
1701 std::string(), 1742 kAddNewItemKey,
1702 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); 1743 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS));
1744 suggested_billing_.AddKeyedItem(
1745 kManageItemsKey,
1746 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS));
1703 } 1747 }
1704 1748
1705 suggested_email_.AddKeyedItem( 1749 suggested_email_.AddKeyedItem(
1706 std::string(), 1750 kAddNewItemKey,
1707 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); 1751 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS));
1752 if (!IsPayingWithWallet()) {
1753 suggested_email_.AddKeyedItem(
1754 kManageItemsKey,
1755 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS));
1756 }
1757
1708 suggested_shipping_.AddKeyedItem( 1758 suggested_shipping_.AddKeyedItem(
1709 std::string(), 1759 kAddNewItemKey,
1710 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); 1760 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS));
1761 suggested_shipping_.AddKeyedItem(
1762 kManageItemsKey,
1763 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS));
1711 1764
1712 if (view_) 1765 if (view_)
1713 view_->ModelChanged(); 1766 view_->ModelChanged();
1714 } 1767 }
1715 1768
1716 bool AutofillDialogControllerImpl::IsCompleteProfile( 1769 bool AutofillDialogControllerImpl::IsCompleteProfile(
1717 const AutofillProfile& profile) { 1770 const AutofillProfile& profile) {
1718 const std::string app_locale = g_browser_process->GetApplicationLocale(); 1771 const std::string app_locale = g_browser_process->GetApplicationLocale();
1719 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { 1772 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) {
1720 AutofillFieldType type = requested_shipping_fields_[i].type; 1773 AutofillFieldType type = requested_shipping_fields_[i].type;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 AutofillField* field = form_structure_.field(i); 1855 AutofillField* field = form_structure_.field(i);
1803 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { 1856 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) {
1804 field->value = cvc; 1857 field->value = cvc;
1805 break; 1858 break;
1806 } 1859 }
1807 } 1860 }
1808 } 1861 }
1809 1862
1810 SuggestionsMenuModel* AutofillDialogControllerImpl:: 1863 SuggestionsMenuModel* AutofillDialogControllerImpl::
1811 SuggestionsMenuModelForSection(DialogSection section) { 1864 SuggestionsMenuModelForSection(DialogSection section) {
1812 const AutofillDialogControllerImpl* const_this =
1813 static_cast<const AutofillDialogControllerImpl*>(this);
1814 return const_cast<SuggestionsMenuModel*>(
1815 const_this->SuggestionsMenuModelForSection(section));
1816 }
1817
1818 const SuggestionsMenuModel* AutofillDialogControllerImpl::
1819 SuggestionsMenuModelForSection(DialogSection section) const {
1820 switch (section) { 1865 switch (section) {
1821 case SECTION_EMAIL: 1866 case SECTION_EMAIL:
1822 return &suggested_email_; 1867 return &suggested_email_;
1823 case SECTION_CC: 1868 case SECTION_CC:
1824 return &suggested_cc_; 1869 return &suggested_cc_;
1825 case SECTION_BILLING: 1870 case SECTION_BILLING:
1826 return &suggested_billing_; 1871 return &suggested_billing_;
1827 case SECTION_SHIPPING: 1872 case SECTION_SHIPPING:
1828 return &suggested_shipping_; 1873 return &suggested_shipping_;
1829 case SECTION_CC_BILLING: 1874 case SECTION_CC_BILLING:
1830 return &suggested_cc_billing_; 1875 return &suggested_cc_billing_;
1831 } 1876 }
1832 1877
1833 NOTREACHED(); 1878 NOTREACHED();
1834 return NULL; 1879 return NULL;
1835 } 1880 }
1836 1881
1882 const SuggestionsMenuModel* AutofillDialogControllerImpl::
1883 SuggestionsMenuModelForSection(DialogSection section) const {
1884 return const_cast<AutofillDialogControllerImpl*>(this)->
1885 SuggestionsMenuModelForSection(section);
1886 }
1887
1837 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( 1888 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel(
1838 const SuggestionsMenuModel& model) { 1889 const SuggestionsMenuModel& model) {
1839 if (&model == &suggested_email_) 1890 if (&model == &suggested_email_)
1840 return SECTION_EMAIL; 1891 return SECTION_EMAIL;
1841 1892
1842 if (&model == &suggested_cc_) 1893 if (&model == &suggested_cc_)
1843 return SECTION_CC; 1894 return SECTION_CC;
1844 1895
1845 if (&model == &suggested_billing_) 1896 if (&model == &suggested_billing_)
1846 return SECTION_BILLING; 1897 return SECTION_BILLING;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 scoped_ptr<risk::Fingerprint> fingerprint) { 1947 scoped_ptr<risk::Fingerprint> fingerprint) {
1897 NOTIMPLEMENTED(); 1948 NOTIMPLEMENTED();
1898 } 1949 }
1899 1950
1900 bool AutofillDialogControllerImpl::IsManuallyEditingSection( 1951 bool AutofillDialogControllerImpl::IsManuallyEditingSection(
1901 DialogSection section) const { 1952 DialogSection section) const {
1902 std::map<DialogSection, bool>::const_iterator it = 1953 std::map<DialogSection, bool>::const_iterator it =
1903 section_editing_state_.find(section); 1954 section_editing_state_.find(section);
1904 return (it != section_editing_state_.end() && it->second) || 1955 return (it != section_editing_state_.end() && it->second) ||
1905 SuggestionsMenuModelForSection(section)-> 1956 SuggestionsMenuModelForSection(section)->
1906 GetItemKeyForCheckedItem().empty(); 1957 GetItemKeyForCheckedItem() == kAddNewItemKey;
1958 }
1959
1960 bool AutofillDialogControllerImpl::IsASuggestionItemKey(
1961 const std::string& key) {
1962 return !key.empty() &&
1963 key != kAddNewItemKey &&
1964 key != kManageItemsKey &&
1965 key != kSameAsBillingKey;
1907 } 1966 }
1908 1967
1909 bool AutofillDialogControllerImpl::IsManuallyEditingAnySection() const { 1968 bool AutofillDialogControllerImpl::IsManuallyEditingAnySection() const {
1910 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { 1969 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) {
1911 if (IsManuallyEditingSection(static_cast<DialogSection>(section))) 1970 if (IsManuallyEditingSection(static_cast<DialogSection>(section)))
1912 return true; 1971 return true;
1913 } 1972 }
1914 return false; 1973 return false;
1915 } 1974 }
1916 1975
1917 bool AutofillDialogControllerImpl::AllSectionsAreValid() const { 1976 bool AutofillDialogControllerImpl::AllSectionsAreValid() const {
1918 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { 1977 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) {
1919 if (!SectionIsValid(static_cast<DialogSection>(section))) 1978 if (!SectionIsValid(static_cast<DialogSection>(section)))
1920 return false; 1979 return false;
1921 } 1980 }
1922 return true; 1981 return true;
1923 } 1982 }
1924 1983
1925 bool AutofillDialogControllerImpl::SectionIsValid( 1984 bool AutofillDialogControllerImpl::SectionIsValid(
1926 DialogSection section) const { 1985 DialogSection section) const {
1927 if (!IsManuallyEditingSection(section)) 1986 if (!IsManuallyEditingSection(section))
1928 return true; 1987 return true;
1929 1988
1930 DetailOutputMap detail_outputs; 1989 DetailOutputMap detail_outputs;
1931 view_->GetUserInput(SECTION_EMAIL, &detail_outputs); 1990 view_->GetUserInput(SECTION_EMAIL, &detail_outputs);
1932 return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty(); 1991 return InputsAreValid(detail_outputs, VALIDATE_EDIT).empty();
1933 } 1992 }
1934 1993
1935 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { 1994 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
1936 // If the user is editing or inputting data, ask the view. 1995 return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
1937 if (IsManuallyEditingSection(SECTION_SHIPPING))
1938 return view_->UseBillingForShipping();
1939
1940 // Otherwise, the checkbox should be hidden so its state is irrelevant.
1941 // Always use the shipping suggestion model.
1942 return false;
1943 } 1996 }
1944 1997
1945 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { 1998 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() {
1946 // It's possible that the user checked [X] Save details locally before 1999 // It's possible that the user checked [X] Save details locally before
1947 // switching payment methods, so only ask the view whether to save details 2000 // switching payment methods, so only ask the view whether to save details
1948 // locally if that checkbox is showing (currently if not paying with wallet). 2001 // locally if that checkbox is showing (currently if not paying with wallet).
1949 // Also, if the user isn't editing any sections, there's no data to save 2002 // Also, if the user isn't editing any sections, there's no data to save
1950 // locally. 2003 // locally.
1951 return ShouldOfferToSaveInChrome() && view_->SaveDetailsLocally(); 2004 return ShouldOfferToSaveInChrome() && view_->SaveDetailsLocally();
1952 } 2005 }
(...skipping 13 matching lines...) Expand all
1966 void AutofillDialogControllerImpl::SubmitWithWallet() { 2019 void AutofillDialogControllerImpl::SubmitWithWallet() {
1967 // TODO(dbeam): disallow interacting with the dialog while submitting. 2020 // TODO(dbeam): disallow interacting with the dialog while submitting.
1968 2021
1969 active_instrument_id_.clear(); 2022 active_instrument_id_.clear();
1970 active_address_id_.clear(); 2023 active_address_id_.clear();
1971 full_wallet_.reset(); 2024 full_wallet_.reset();
1972 2025
1973 if (!section_editing_state_[SECTION_CC_BILLING]) { 2026 if (!section_editing_state_[SECTION_CC_BILLING]) {
1974 SuggestionsMenuModel* billing = 2027 SuggestionsMenuModel* billing =
1975 SuggestionsMenuModelForSection(SECTION_CC_BILLING); 2028 SuggestionsMenuModelForSection(SECTION_CC_BILLING);
1976 if (!billing->GetItemKeyForCheckedItem().empty() && 2029 if (IsASuggestionItemKey(billing->GetItemKeyForCheckedItem()) &&
1977 billing->checked_item() < 2030 billing->checked_item() <
1978 static_cast<int>(wallet_items_->instruments().size())) { 2031 static_cast<int>(wallet_items_->instruments().size())) {
1979 const wallet::WalletItems::MaskedInstrument* active_instrument = 2032 const wallet::WalletItems::MaskedInstrument* active_instrument =
1980 wallet_items_->instruments()[billing->checked_item()]; 2033 wallet_items_->instruments()[billing->checked_item()];
1981 active_instrument_id_ = active_instrument->object_id(); 2034 active_instrument_id_ = active_instrument->object_id();
1982 2035
1983 // TODO(dbeam): does re-using instrument address IDs work? 2036 // TODO(dbeam): does re-using instrument address IDs work?
1984 if (ShouldUseBillingForShipping()) 2037 if (ShouldUseBillingForShipping())
1985 active_address_id_ = active_instrument->address().object_id(); 2038 active_address_id_ = active_instrument->address().object_id();
1986 } 2039 }
1987 } 2040 }
1988 2041
1989 if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) { 2042 if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) {
1990 SuggestionsMenuModel* shipping = 2043 SuggestionsMenuModel* shipping =
1991 SuggestionsMenuModelForSection(SECTION_SHIPPING); 2044 SuggestionsMenuModelForSection(SECTION_SHIPPING);
1992 if (!shipping->GetItemKeyForCheckedItem().empty() && 2045 if (IsASuggestionItemKey(shipping->GetItemKeyForCheckedItem()) &&
1993 shipping->checked_item() < 2046 shipping->checked_item() <
1994 static_cast<int>(wallet_items_->addresses().size())) { 2047 static_cast<int>(wallet_items_->addresses().size())) {
1995 active_address_id_ = 2048 active_address_id_ =
1996 wallet_items_->addresses()[shipping->checked_item()]->object_id(); 2049 wallet_items_->addresses()[shipping->checked_item()]->object_id();
1997 } 2050 }
1998 } 2051 }
1999 2052
2000 GetWalletClient()->AcceptLegalDocuments( 2053 GetWalletClient()->AcceptLegalDocuments(
2001 wallet_items_->legal_documents(), 2054 wallet_items_->legal_documents(),
2002 wallet_items_->google_transaction_id(), 2055 wallet_items_->google_transaction_id(),
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2143 base::Time::Now() - dialog_shown_timestamp_, 2196 base::Time::Now() - dialog_shown_timestamp_,
2144 dialog_type_, 2197 dialog_type_,
2145 AutofillMetrics::DIALOG_CANCELED); 2198 AutofillMetrics::DIALOG_CANCELED);
2146 } 2199 }
2147 2200
2148 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( 2201 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric(
2149 const SuggestionsMenuModel& model) { 2202 const SuggestionsMenuModel& model) {
2150 DialogSection section = SectionForSuggestionsMenuModel(model); 2203 DialogSection section = SectionForSuggestionsMenuModel(model);
2151 2204
2152 AutofillMetrics::DialogUiEvent dialog_ui_event; 2205 AutofillMetrics::DialogUiEvent dialog_ui_event;
2153 if (model.GetItemKeyForCheckedItem().empty()) { 2206 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) {
2154 // Selected to add a new item. 2207 // Selected to add a new item.
2155 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); 2208 dialog_ui_event = DialogSectionToUiItemAddedEvent(section);
2156 } else { 2209 } else if (base::IsValidGUID(model.GetItemKeyForCheckedItem())) {
2157 // Selected an existing item. 2210 // Selected an existing item.
2158 DCHECK(!section_editing_state_[section]); 2211 DCHECK(!section_editing_state_[section]);
2159 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); 2212 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section);
2213 } else {
2214 // TODO(estade): add logging for "Manage items" or "Use billing for
2215 // shipping"?
Dan Beam 2013/04/17 22:24:26 can you file a bug for this?
2216 return;
2160 } 2217 }
2161 2218
2162 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); 2219 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event);
2163 } 2220 }
2164 2221
2165 AutofillMetrics::DialogInitialUserStateMetric 2222 AutofillMetrics::DialogInitialUserStateMetric
2166 AutofillDialogControllerImpl::GetInitialUserState() const { 2223 AutofillDialogControllerImpl::GetInitialUserState() const {
2167 // Consider a user to be an Autofill user if the user has any credit cards 2224 // Consider a user to be an Autofill user if the user has any credit cards
2168 // or addresses saved. Check that the item count is greater than 1 because 2225 // or addresses saved. Check that the item count is greater than 1 because
2169 // an "empty" menu still has the "add new" menu item. 2226 // an "empty" menu still has the "add new" menu item.
(...skipping 16 matching lines...) Expand all
2186 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2243 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
2187 } 2244 }
2188 2245
2189 // Has Wallet items. 2246 // Has Wallet items.
2190 return has_autofill_profiles ? 2247 return has_autofill_profiles ?
2191 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2248 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
2192 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2249 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
2193 } 2250 }
2194 2251
2195 } // namespace autofill 2252 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698