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

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: 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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 // AutofillDialogController implementation. 406 // AutofillDialogController implementation.
403 407
404 string16 AutofillDialogControllerImpl::DialogTitle() const { 408 string16 AutofillDialogControllerImpl::DialogTitle() const {
405 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE); 409 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_TITLE);
406 } 410 }
407 411
408 string16 AutofillDialogControllerImpl::EditSuggestionText() const { 412 string16 AutofillDialogControllerImpl::EditSuggestionText() const {
409 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT); 413 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_EDIT);
410 } 414 }
411 415
412 string16 AutofillDialogControllerImpl::UseBillingForShippingText() const {
413 return l10n_util::GetStringUTF16(
414 IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING);
415 }
416
417 string16 AutofillDialogControllerImpl::CancelButtonText() const { 416 string16 AutofillDialogControllerImpl::CancelButtonText() const {
418 return l10n_util::GetStringUTF16(IDS_CANCEL); 417 return l10n_util::GetStringUTF16(IDS_CANCEL);
419 } 418 }
420 419
421 string16 AutofillDialogControllerImpl::ConfirmButtonText() const { 420 string16 AutofillDialogControllerImpl::ConfirmButtonText() const {
422 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ? 421 return l10n_util::GetStringUTF16(IsSubmitPausedOn(wallet::VERIFY_CVV) ?
423 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON); 422 IDS_AUTOFILL_DIALOG_VERIFY_BUTTON : IDS_AUTOFILL_DIALOG_SUBMIT_BUTTON);
424 } 423 }
425 424
426 string16 AutofillDialogControllerImpl::CancelSignInText() const { 425 string16 AutofillDialogControllerImpl::CancelSignInText() const {
(...skipping 277 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 EndSignInFlow(); 1343 EndSignInFlow();
1321 if (account_chooser_model_.WalletIsSelected()) 1344 if (account_chooser_model_.WalletIsSelected())
1322 GetWalletItems(); 1345 GetWalletItems();
1323 } 1346 }
1324 } 1347 }
1325 1348
1326 //////////////////////////////////////////////////////////////////////////////// 1349 ////////////////////////////////////////////////////////////////////////////////
1327 // SuggestionsMenuModelDelegate implementation. 1350 // SuggestionsMenuModelDelegate implementation.
1328 1351
1329 void AutofillDialogControllerImpl::SuggestionItemSelected( 1352 void AutofillDialogControllerImpl::SuggestionItemSelected(
1330 const SuggestionsMenuModel& model) { 1353 SuggestionsMenuModel* model,
1331 const DialogSection section = SectionForSuggestionsMenuModel(model); 1354 const std::string& item_key) {
1332 EditCancelledForSection(section); 1355 if (item_key == kManageItemsKey) {
1356 // TODO(estade): show chrome://settings or a wallet URL.
1357 return;
1358 }
1359
1360 model->SetCheckedItem(item_key);
1361 EditCancelledForSection(SectionForSuggestionsMenuModel(*model));
1333 } 1362 }
1334 1363
1335 //////////////////////////////////////////////////////////////////////////////// 1364 ////////////////////////////////////////////////////////////////////////////////
1336 // wallet::WalletClientDelegate implementation. 1365 // wallet::WalletClientDelegate implementation.
1337 1366
1338 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { 1367 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const {
1339 return metric_logger_; 1368 return metric_logger_;
1340 } 1369 }
1341 1370
1342 DialogType AutofillDialogControllerImpl::GetDialogType() const { 1371 DialogType AutofillDialogControllerImpl::GetDialogType() const {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 } 1647 }
1619 1648
1620 void AutofillDialogControllerImpl::SuggestionsUpdated() { 1649 void AutofillDialogControllerImpl::SuggestionsUpdated() {
1621 suggested_email_.Reset(); 1650 suggested_email_.Reset();
1622 suggested_cc_.Reset(); 1651 suggested_cc_.Reset();
1623 suggested_billing_.Reset(); 1652 suggested_billing_.Reset();
1624 suggested_cc_billing_.Reset(); 1653 suggested_cc_billing_.Reset();
1625 suggested_shipping_.Reset(); 1654 suggested_shipping_.Reset();
1626 HidePopup(); 1655 HidePopup();
1627 1656
1657 suggested_shipping_.AddKeyedItem(
1658 kSameAsBillingKey,
1659 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_USE_BILLING_FOR_SHIPPING));
1660
1628 if (IsPayingWithWallet()) { 1661 if (IsPayingWithWallet()) {
1629 // TODO(estade): fill in the email address. 1662 // TODO(estade): fill in the email address.
1630 1663
1631 const std::vector<wallet::Address*>& addresses = 1664 const std::vector<wallet::Address*>& addresses =
1632 wallet_items_->addresses(); 1665 wallet_items_->addresses();
1633 for (size_t i = 0; i < addresses.size(); ++i) { 1666 for (size_t i = 0; i < addresses.size(); ++i) {
1634 // TODO(dbeam): respect wallet_items_->default_instrument_id(). 1667 // TODO(dbeam): respect wallet_items_->default_instrument_id().
1635 suggested_shipping_.AddKeyedItemWithSublabel( 1668 suggested_shipping_.AddKeyedItemWithSublabel(
1636 base::IntToString(i), 1669 base::IntToString(i),
1637 addresses[i]->DisplayName(), 1670 addresses[i]->DisplayName(),
1638 addresses[i]->DisplayNameDetail()); 1671 addresses[i]->DisplayNameDetail());
1639 } 1672 }
1640 1673
1641 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { 1674 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1642 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = 1675 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments =
1643 wallet_items_->instruments(); 1676 wallet_items_->instruments();
1644 for (size_t i = 0; i < instruments.size(); ++i) { 1677 for (size_t i = 0; i < instruments.size(); ++i) {
1645 // TODO(dbeam): respect wallet_items_->default_address_id(). 1678 // TODO(dbeam): respect wallet_items_->default_address_id().
1646 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( 1679 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon(
1647 base::IntToString(i), 1680 base::IntToString(i),
1648 instruments[i]->DisplayName(), 1681 instruments[i]->DisplayName(),
1649 instruments[i]->DisplayNameDetail(), 1682 instruments[i]->DisplayNameDetail(),
1650 instruments[i]->CardIcon()); 1683 instruments[i]->CardIcon());
1651 } 1684 }
1652 1685
1686 // TODO(estade): this should have a URL sublabel.
1653 suggested_cc_billing_.AddKeyedItem( 1687 suggested_cc_billing_.AddKeyedItem(
1654 std::string(), 1688 kAddNewItemKey,
1655 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS)); 1689 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_DETAILS));
1690 suggested_cc_billing_.AddKeyedItem(
1691 kManageItemsKey,
1692 l10n_util::GetStringUTF16(
1693 IDS_AUTOFILL_DIALOG_MANAGE_BILLING_DETAILS));
1656 } 1694 }
1657 } else { 1695 } else {
1658 PersonalDataManager* manager = GetManager(); 1696 PersonalDataManager* manager = GetManager();
1659 const std::vector<CreditCard*>& cards = manager->credit_cards(); 1697 const std::vector<CreditCard*>& cards = manager->credit_cards();
1660 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1698 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1661 for (size_t i = 0; i < cards.size(); ++i) { 1699 for (size_t i = 0; i < cards.size(); ++i) {
1662 suggested_cc_.AddKeyedItemWithIcon( 1700 suggested_cc_.AddKeyedItemWithIcon(
1663 cards[i]->guid(), 1701 cards[i]->guid(),
1664 cards[i]->Label(), 1702 cards[i]->Label(),
1665 rb.GetImageNamed(cards[i]->IconResourceId())); 1703 rb.GetImageNamed(cards[i]->IconResourceId()));
(...skipping 16 matching lines...) Expand all
1682 // Don't add variants for addresses: the email variants are handled above, 1720 // Don't add variants for addresses: the email variants are handled above,
1683 // name is part of credit card and we'll just ignore phone number 1721 // name is part of credit card and we'll just ignore phone number
1684 // variants. 1722 // variants.
1685 suggested_billing_.AddKeyedItem(profiles[i]->guid(), 1723 suggested_billing_.AddKeyedItem(profiles[i]->guid(),
1686 profiles[i]->Label()); 1724 profiles[i]->Label());
1687 suggested_shipping_.AddKeyedItem(profiles[i]->guid(), 1725 suggested_shipping_.AddKeyedItem(profiles[i]->guid(),
1688 profiles[i]->Label()); 1726 profiles[i]->Label());
1689 } 1727 }
1690 1728
1691 suggested_cc_.AddKeyedItem( 1729 suggested_cc_.AddKeyedItem(
1692 std::string(), 1730 kAddNewItemKey,
1731 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD));
1732 suggested_cc_.AddKeyedItem(
1733 kManageItemsKey,
1693 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD)); 1734 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_CREDIT_CARD));
1694 suggested_billing_.AddKeyedItem( 1735 suggested_billing_.AddKeyedItem(
1695 std::string(), 1736 kAddNewItemKey,
1696 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS)); 1737 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_BILLING_ADDRESS));
1738 suggested_billing_.AddKeyedItem(
1739 kManageItemsKey,
1740 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_BILLING_ADDRESS));
1697 } 1741 }
1698 1742
1699 suggested_email_.AddKeyedItem( 1743 suggested_email_.AddKeyedItem(
1700 std::string(), 1744 kAddNewItemKey,
1701 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); 1745 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS));
1746 if (!IsPayingWithWallet()) {
1747 suggested_email_.AddKeyedItem(
1748 kManageItemsKey,
1749 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS));
1750 }
1751
1702 suggested_shipping_.AddKeyedItem( 1752 suggested_shipping_.AddKeyedItem(
1703 std::string(), 1753 kAddNewItemKey,
1704 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); 1754 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS));
1755 suggested_shipping_.AddKeyedItem(
1756 kManageItemsKey,
1757 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS));
1705 1758
1706 if (view_) 1759 if (view_)
1707 view_->ModelChanged(); 1760 view_->ModelChanged();
1708 } 1761 }
1709 1762
1710 bool AutofillDialogControllerImpl::IsCompleteProfile( 1763 bool AutofillDialogControllerImpl::IsCompleteProfile(
1711 const AutofillProfile& profile) { 1764 const AutofillProfile& profile) {
1712 const std::string app_locale = g_browser_process->GetApplicationLocale(); 1765 const std::string app_locale = g_browser_process->GetApplicationLocale();
1713 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { 1766 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) {
1714 AutofillFieldType type = requested_shipping_fields_[i].type; 1767 AutofillFieldType type = requested_shipping_fields_[i].type;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 case SECTION_SHIPPING: 1866 case SECTION_SHIPPING:
1814 return &suggested_shipping_; 1867 return &suggested_shipping_;
1815 case SECTION_CC_BILLING: 1868 case SECTION_CC_BILLING:
1816 return &suggested_cc_billing_; 1869 return &suggested_cc_billing_;
1817 } 1870 }
1818 1871
1819 NOTREACHED(); 1872 NOTREACHED();
1820 return NULL; 1873 return NULL;
1821 } 1874 }
1822 1875
1876 const SuggestionsMenuModel* AutofillDialogControllerImpl::
1877 SuggestionsMenuModelForSection(DialogSection section) const {
1878 return const_cast<AutofillDialogControllerImpl*>(this)->
1879 SuggestionsMenuModelForSection(section);
1880 }
1881
1823 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel( 1882 DialogSection AutofillDialogControllerImpl::SectionForSuggestionsMenuModel(
1824 const SuggestionsMenuModel& model) { 1883 const SuggestionsMenuModel& model) {
1825 if (&model == &suggested_email_) 1884 if (&model == &suggested_email_)
1826 return SECTION_EMAIL; 1885 return SECTION_EMAIL;
1827 1886
1828 if (&model == &suggested_cc_) 1887 if (&model == &suggested_cc_)
1829 return SECTION_CC; 1888 return SECTION_CC;
1830 1889
1831 if (&model == &suggested_billing_) 1890 if (&model == &suggested_billing_)
1832 return SECTION_BILLING; 1891 return SECTION_BILLING;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 1938
1880 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( 1939 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData(
1881 scoped_ptr<risk::Fingerprint> fingerprint) { 1940 scoped_ptr<risk::Fingerprint> fingerprint) {
1882 NOTIMPLEMENTED(); 1941 NOTIMPLEMENTED();
1883 } 1942 }
1884 1943
1885 bool AutofillDialogControllerImpl::IsManuallyEditingSection( 1944 bool AutofillDialogControllerImpl::IsManuallyEditingSection(
1886 DialogSection section) { 1945 DialogSection section) {
1887 return section_editing_state_[section] || 1946 return section_editing_state_[section] ||
1888 SuggestionsMenuModelForSection(section)-> 1947 SuggestionsMenuModelForSection(section)->
1889 GetItemKeyForCheckedItem().empty(); 1948 GetItemKeyForCheckedItem() == kAddNewItemKey;
1949 }
1950
1951 bool AutofillDialogControllerImpl::IsASuggestionItemKey(
1952 const std::string& key) {
1953 return !key.empty() &&
1954 key != kAddNewItemKey &&
1955 key != kManageItemsKey &&
1956 key != kSameAsBillingKey;
1890 } 1957 }
1891 1958
1892 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() { 1959 bool AutofillDialogControllerImpl::ShouldUseBillingForShipping() {
1893 // If the user is editing or inputting data, ask the view. 1960 return suggested_shipping_.GetItemKeyForCheckedItem() == kSameAsBillingKey;
1894 if (IsManuallyEditingSection(SECTION_SHIPPING))
1895 return view_->UseBillingForShipping();
1896
1897 // Otherwise, the checkbox should be hidden so its state is irrelevant.
1898 // Always use the shipping suggestion model.
1899 return false;
1900 } 1961 }
1901 1962
1902 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() { 1963 bool AutofillDialogControllerImpl::ShouldSaveDetailsLocally() {
1903 // It's possible that the user checked [X] Save details locally before 1964 // It's possible that the user checked [X] Save details locally before
1904 // switching payment methods, so only ask the view whether to save details 1965 // switching payment methods, so only ask the view whether to save details
1905 // locally if that checkbox is showing (currently if not paying with wallet). 1966 // locally if that checkbox is showing (currently if not paying with wallet).
1906 return !IsPayingWithWallet() && view_->SaveDetailsLocally(); 1967 return !IsPayingWithWallet() && view_->SaveDetailsLocally();
1907 } 1968 }
1908 1969
1909 void AutofillDialogControllerImpl::SetIsSubmitting(bool submitting) { 1970 void AutofillDialogControllerImpl::SetIsSubmitting(bool submitting) {
(...skipping 11 matching lines...) Expand all
1921 void AutofillDialogControllerImpl::SubmitWithWallet() { 1982 void AutofillDialogControllerImpl::SubmitWithWallet() {
1922 // TODO(dbeam): disallow interacting with the dialog while submitting. 1983 // TODO(dbeam): disallow interacting with the dialog while submitting.
1923 1984
1924 active_instrument_id_.clear(); 1985 active_instrument_id_.clear();
1925 active_address_id_.clear(); 1986 active_address_id_.clear();
1926 full_wallet_.reset(); 1987 full_wallet_.reset();
1927 1988
1928 if (!section_editing_state_[SECTION_CC_BILLING]) { 1989 if (!section_editing_state_[SECTION_CC_BILLING]) {
1929 SuggestionsMenuModel* billing = 1990 SuggestionsMenuModel* billing =
1930 SuggestionsMenuModelForSection(SECTION_CC_BILLING); 1991 SuggestionsMenuModelForSection(SECTION_CC_BILLING);
1931 if (!billing->GetItemKeyForCheckedItem().empty() && 1992 if (IsASuggestionItemKey(billing->GetItemKeyForCheckedItem()) &&
1932 billing->checked_item() < 1993 billing->checked_item() <
1933 static_cast<int>(wallet_items_->instruments().size())) { 1994 static_cast<int>(wallet_items_->instruments().size())) {
1934 const wallet::WalletItems::MaskedInstrument* active_instrument = 1995 const wallet::WalletItems::MaskedInstrument* active_instrument =
1935 wallet_items_->instruments()[billing->checked_item()]; 1996 wallet_items_->instruments()[billing->checked_item()];
1936 active_instrument_id_ = active_instrument->object_id(); 1997 active_instrument_id_ = active_instrument->object_id();
1937 1998
1938 // TODO(dbeam): does re-using instrument address IDs work? 1999 // TODO(dbeam): does re-using instrument address IDs work?
1939 if (ShouldUseBillingForShipping()) 2000 if (ShouldUseBillingForShipping())
1940 active_address_id_ = active_instrument->address().object_id(); 2001 active_address_id_ = active_instrument->address().object_id();
1941 } 2002 }
1942 } 2003 }
1943 2004
1944 if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) { 2005 if (!section_editing_state_[SECTION_SHIPPING] && active_address_id_.empty()) {
1945 SuggestionsMenuModel* shipping = 2006 SuggestionsMenuModel* shipping =
1946 SuggestionsMenuModelForSection(SECTION_SHIPPING); 2007 SuggestionsMenuModelForSection(SECTION_SHIPPING);
1947 if (!shipping->GetItemKeyForCheckedItem().empty() && 2008 if (IsASuggestionItemKey(shipping->GetItemKeyForCheckedItem()) &&
1948 shipping->checked_item() < 2009 shipping->checked_item() <
1949 static_cast<int>(wallet_items_->addresses().size())) { 2010 static_cast<int>(wallet_items_->addresses().size())) {
1950 active_address_id_ = 2011 active_address_id_ =
1951 wallet_items_->addresses()[shipping->checked_item()]->object_id(); 2012 wallet_items_->addresses()[shipping->checked_item()]->object_id();
1952 } 2013 }
1953 } 2014 }
1954 2015
1955 GetWalletClient()->AcceptLegalDocuments( 2016 GetWalletClient()->AcceptLegalDocuments(
1956 wallet_items_->legal_documents(), 2017 wallet_items_->legal_documents(),
1957 wallet_items_->google_transaction_id(), 2018 wallet_items_->google_transaction_id(),
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2085 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2146 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
2086 } 2147 }
2087 2148
2088 // Has Wallet items. 2149 // Has Wallet items.
2089 return has_autofill_profiles ? 2150 return has_autofill_profiles ?
2090 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2151 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
2091 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2152 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
2092 } 2153 }
2093 2154
2094 } // namespace autofill 2155 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698