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

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

Issue 14425010: Handle expired Autofill credit cards in autofill dialog (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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 view_.reset(CreateView()); 380 view_.reset(CreateView());
381 view_->Show(); 381 view_->Show();
382 GetManager()->AddObserver(this); 382 GetManager()->AddObserver(this);
383 383
384 // Try to see if the user is already signed-in. 384 // Try to see if the user is already signed-in.
385 // If signed-in, fetch the user's Wallet data. 385 // If signed-in, fetch the user's Wallet data.
386 // Otherwise, see if the user could be signed in passively. 386 // Otherwise, see if the user could be signed in passively.
387 // TODO(aruslan): UMA metrics for sign-in. 387 // TODO(aruslan): UMA metrics for sign-in.
388 if (account_chooser_model_.WalletIsSelected()) 388 if (account_chooser_model_.WalletIsSelected())
389 GetWalletItems(); 389 GetWalletItems();
390
391 // Some suggestions may be invalid to start. Run |SuggestionItemSelected()|
392 // for each section to make sure the edit UI is shown for these suggestions.
393 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
394 DialogSection section = static_cast<DialogSection>(i);
395 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
396 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()))
397 SuggestionItemSelected(model, model->checked_item());
398 }
390 } 399 }
391 400
392 void AutofillDialogControllerImpl::Hide() { 401 void AutofillDialogControllerImpl::Hide() {
393 if (view_) 402 if (view_)
394 view_->Hide(); 403 view_->Hide();
395 } 404 }
396 405
397 void AutofillDialogControllerImpl::UpdateProgressBar(double value) { 406 void AutofillDialogControllerImpl::UpdateProgressBar(double value) {
398 view_->UpdateProgressBar(value); 407 view_->UpdateProgressBar(value);
399 } 408 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 link_start, link_start + documents[i]->display_name().size())); 634 link_start, link_start + documents[i]->display_name().size()));
626 } 635 }
627 legal_documents_text_ = text; 636 legal_documents_text_ = text;
628 } 637 }
629 638
630 void AutofillDialogControllerImpl::ResetManualInputForSection( 639 void AutofillDialogControllerImpl::ResetManualInputForSection(
631 DialogSection section) { 640 DialogSection section) {
632 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 641 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
633 for (size_t i = 0; i < inputs->size(); ++i) 642 for (size_t i = 0; i < inputs->size(); ++i)
634 (*inputs)[i].initial_value.clear(); 643 (*inputs)[i].initial_value.clear();
644 // TODO(dbeam): why is this here rather than in EditCancelledForSection()?
635 section_editing_state_[section] = false; 645 section_editing_state_[section] = false;
636 } 646 }
637 647
638 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( 648 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection(
639 DialogSection section) const { 649 DialogSection section) const {
640 switch (section) { 650 switch (section) {
641 case SECTION_EMAIL: 651 case SECTION_EMAIL:
642 return requested_email_fields_; 652 return requested_email_fields_;
643 case SECTION_CC: 653 case SECTION_CC:
644 return requested_cc_fields_; 654 return requested_cc_fields_;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 ExtraSuggestionIconForSection(section), 740 ExtraSuggestionIconForSection(section),
731 EditEnabledForSection(section)); 741 EditEnabledForSection(section));
732 } 742 }
733 743
734 string16 AutofillDialogControllerImpl::SuggestionTextForSection( 744 string16 AutofillDialogControllerImpl::SuggestionTextForSection(
735 DialogSection section) { 745 DialogSection section) {
736 string16 action_text = RequiredActionTextForSection(section); 746 string16 action_text = RequiredActionTextForSection(section);
737 if (!action_text.empty()) 747 if (!action_text.empty())
738 return action_text; 748 return action_text;
739 749
740 // When the user has clicked 'edit', don't show a suggestion (even though 750 // When the user has clicked 'edit' or a suggestion is somehow invalid (e.g. a
741 // there is a profile selected in the model). 751 // user selects a credit card that has expired), don't show a suggestion (even
752 // though there is a profile selected in the model).
742 if (section_editing_state_[section]) 753 if (section_editing_state_[section])
743 return string16(); 754 return string16();
744 755
745 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 756 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
746 std::string item_key = model->GetItemKeyForCheckedItem(); 757 std::string item_key = model->GetItemKeyForCheckedItem();
747 if (item_key == kSameAsBillingKey) { 758 if (item_key == kSameAsBillingKey) {
748 return l10n_util::GetStringUTF16( 759 return l10n_util::GetStringUTF16(
749 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); 760 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING);
750 } 761 }
751 762
752 if (!IsASuggestionItemKey(item_key)) 763 if (!IsASuggestionItemKey(item_key))
753 return string16(); 764 return string16();
754 765
755 if (section == SECTION_EMAIL) 766 if (section == SECTION_EMAIL)
756 return model->GetLabelAt(model->checked_item()); 767 return model->GetLabelAt(model->checked_item());
757 768
758 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); 769 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
759 return wrapper->GetDisplayText(); 770 return wrapper->IsValid() ? wrapper->GetDisplayText() : string16();
760 } 771 }
761 772
762 gfx::Font::FontStyle 773 gfx::Font::FontStyle
763 AutofillDialogControllerImpl::SuggestionTextStyleForSection( 774 AutofillDialogControllerImpl::SuggestionTextStyleForSection(
764 DialogSection section) const { 775 DialogSection section) const {
765 const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 776 const SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
766 if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey) 777 if (model->GetItemKeyForCheckedItem() == kSameAsBillingKey)
767 return gfx::Font::ITALIC; 778 return gfx::Font::ITALIC;
768 779
769 return gfx::Font::NORMAL; 780 return gfx::Font::NORMAL;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 } 893 }
883 894
884 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) 895 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV))
885 return false; 896 return false;
886 897
887 return true; 898 return true;
888 } 899 }
889 900
890 void AutofillDialogControllerImpl::EditClickedForSection( 901 void AutofillDialogControllerImpl::EditClickedForSection(
891 DialogSection section) { 902 DialogSection section) {
892 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 903 ShowEditingMode(section);
893 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); 904 GetMetricLogger().LogDialogUiEvent(
894 model->FillInputs(inputs); 905 dialog_type_, DialogSectionToUiEditEvent(section));
906 }
907
908 void AutofillDialogControllerImpl::ShowEditingMode(DialogSection section) {
Evan Stade 2013/04/24 22:00:17 make functions match header order
Dan Beam 2013/04/26 02:11:32 Done.
909 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
910 wrapper->FillInputs(MutableRequestedFieldsForSection(section));
895 section_editing_state_[section] = true; 911 section_editing_state_[section] = true;
896 view_->UpdateSection(section); 912 view_->UpdateSection(section);
897
898 GetMetricLogger().LogDialogUiEvent(
899 dialog_type_, DialogSectionToUiEditEvent(section));
900 } 913 }
901 914
902 void AutofillDialogControllerImpl::EditCancelledForSection( 915 void AutofillDialogControllerImpl::EditCancelledForSection(
903 DialogSection section) { 916 DialogSection section) {
904 ResetManualInputForSection(section); 917 ResetManualInputForSection(section);
905 view_->UpdateSection(section); 918 view_->UpdateSection(section);
906 } 919 }
907 920
908 gfx::Image AutofillDialogControllerImpl::IconForField( 921 gfx::Image AutofillDialogControllerImpl::IconForField(
909 AutofillFieldType type, const string16& user_input) const { 922 AutofillFieldType type, const string16& user_input) const {
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 1390
1378 void AutofillDialogControllerImpl::SuggestionItemSelected( 1391 void AutofillDialogControllerImpl::SuggestionItemSelected(
1379 SuggestionsMenuModel* model, 1392 SuggestionsMenuModel* model,
1380 size_t index) { 1393 size_t index) {
1381 if (model->GetItemKeyAt(index) == kManageItemsKey) { 1394 if (model->GetItemKeyAt(index) == kManageItemsKey) {
1382 // TODO(estade): show chrome://settings or a wallet URL. 1395 // TODO(estade): show chrome://settings or a wallet URL.
1383 return; 1396 return;
1384 } 1397 }
1385 1398
1386 model->SetCheckedIndex(index); 1399 model->SetCheckedIndex(index);
1387 EditCancelledForSection(SectionForSuggestionsMenuModel(*model)); 1400
1401 const DialogSection section = SectionForSuggestionsMenuModel(*model);
1402 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) &&
Evan Stade 2013/04/24 22:00:17 I can't for the life of me figure out what this is
Dan Beam 2013/04/26 02:11:32 Done.
1403 SuggestionTextForSection(section).empty()) {
1404 ResetManualInputForSection(section);
1405 ShowEditingMode(section);
1406 } else {
1407 EditCancelledForSection(section);
1408 }
1388 1409
1389 LogSuggestionItemSelectedMetric(*model); 1410 LogSuggestionItemSelectedMetric(*model);
1390 } 1411 }
1391 1412
1392 //////////////////////////////////////////////////////////////////////////////// 1413 ////////////////////////////////////////////////////////////////////////////////
1393 // wallet::WalletClientDelegate implementation. 1414 // wallet::WalletClientDelegate implementation.
1394 1415
1395 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { 1416 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const {
1396 return metric_logger_; 1417 return metric_logger_;
1397 } 1418 }
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1576
1556 void AutofillDialogControllerImpl::OnPersonalDataChanged() { 1577 void AutofillDialogControllerImpl::OnPersonalDataChanged() {
1557 SuggestionsUpdated(); 1578 SuggestionsUpdated();
1558 } 1579 }
1559 1580
1560 //////////////////////////////////////////////////////////////////////////////// 1581 ////////////////////////////////////////////////////////////////////////////////
1561 // AccountChooserModelDelegate implementation. 1582 // AccountChooserModelDelegate implementation.
1562 1583
1563 void AutofillDialogControllerImpl::AccountChoiceChanged() { 1584 void AutofillDialogControllerImpl::AccountChoiceChanged() {
1564 // Whenever the user changes the account, all manual inputs should be reset. 1585 // Whenever the user changes the account, all manual inputs should be reset.
1565 ResetManualInputForSection(SECTION_EMAIL); 1586 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) {
1566 ResetManualInputForSection(SECTION_CC); 1587 ResetManualInputForSection(static_cast<DialogSection>(section));
1567 ResetManualInputForSection(SECTION_BILLING); 1588 }
1568 ResetManualInputForSection(SECTION_CC_BILLING);
1569 ResetManualInputForSection(SECTION_SHIPPING);
1570 1589
1571 if (is_submitting_) 1590 if (is_submitting_)
1572 GetWalletClient()->CancelRequests(); 1591 GetWalletClient()->CancelRequests();
1573 1592
1574 SetIsSubmitting(false); 1593 SetIsSubmitting(false);
1575 1594
1576 if (!signin_helper_ && account_chooser_model_.WalletIsSelected()) { 1595 if (!signin_helper_ && account_chooser_model_.WalletIsSelected()) {
1577 if (account_chooser_model_.IsActiveWalletAccountSelected()) { 1596 if (account_chooser_model_.IsActiveWalletAccountSelected()) {
1578 // If the user has chosen an already active Wallet account, and we don't 1597 // If the user has chosen an already active Wallet account, and we don't
1579 // have the Wallet items, an attempt to fetch the Wallet data is made to 1598 // have the Wallet items, an attempt to fetch the Wallet data is made to
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 } 1734 }
1716 1735
1717 const std::vector<wallet::Address*>& addresses = 1736 const std::vector<wallet::Address*>& addresses =
1718 wallet_items_->addresses(); 1737 wallet_items_->addresses();
1719 for (size_t i = 0; i < addresses.size(); ++i) { 1738 for (size_t i = 0; i < addresses.size(); ++i) {
1720 // TODO(dbeam): respect the default instrument ID. http://crbug.com/232954 1739 // TODO(dbeam): respect the default instrument ID. http://crbug.com/232954
1721 suggested_shipping_.AddKeyedItemWithSublabel( 1740 suggested_shipping_.AddKeyedItemWithSublabel(
1722 base::IntToString(i), 1741 base::IntToString(i),
1723 addresses[i]->DisplayName(), 1742 addresses[i]->DisplayName(),
1724 addresses[i]->DisplayNameDetail()); 1743 addresses[i]->DisplayNameDetail());
1725
1726 } 1744 }
1727 1745
1728 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) { 1746 if (!IsSubmitPausedOn(wallet::VERIFY_CVV)) {
1729 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments = 1747 const std::vector<wallet::WalletItems::MaskedInstrument*>& instruments =
1730 wallet_items_->instruments(); 1748 wallet_items_->instruments();
1731 for (size_t i = 0; i < instruments.size(); ++i) { 1749 for (size_t i = 0; i < instruments.size(); ++i) {
1732 // TODO(dbeam): respect the default address ID. http://crbug.com/232954 1750 // TODO(dbeam): respect the default address ID. http://crbug.com/232954
1733 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon( 1751 suggested_cc_billing_.AddKeyedItemWithSublabelAndIcon(
1734 base::IntToString(i), 1752 base::IntToString(i),
1735 instruments[i]->DisplayName(), 1753 instruments[i]->DisplayName(),
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
2265 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( 2283 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric(
2266 const SuggestionsMenuModel& model) { 2284 const SuggestionsMenuModel& model) {
2267 DialogSection section = SectionForSuggestionsMenuModel(model); 2285 DialogSection section = SectionForSuggestionsMenuModel(model);
2268 2286
2269 AutofillMetrics::DialogUiEvent dialog_ui_event; 2287 AutofillMetrics::DialogUiEvent dialog_ui_event;
2270 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) { 2288 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) {
2271 // Selected to add a new item. 2289 // Selected to add a new item.
2272 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); 2290 dialog_ui_event = DialogSectionToUiItemAddedEvent(section);
2273 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) { 2291 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) {
2274 // Selected an existing item. 2292 // Selected an existing item.
2275 DCHECK(!section_editing_state_[section]);
2276 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); 2293 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section);
2277 } else { 2294 } else {
2278 // TODO(estade): add logging for "Manage items" or "Use billing for 2295 // TODO(estade): add logging for "Manage items" or "Use billing for
2279 // shipping"? 2296 // shipping"?
2280 return; 2297 return;
2281 } 2298 }
2282 2299
2283 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); 2300 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event);
2284 } 2301 }
2285 2302
(...skipping 21 matching lines...) Expand all
2307 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; 2324 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL;
2308 } 2325 }
2309 2326
2310 // Has Wallet items. 2327 // Has Wallet items.
2311 return has_autofill_profiles ? 2328 return has_autofill_profiles ?
2312 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : 2329 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL :
2313 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; 2330 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL;
2314 } 2331 }
2315 2332
2316 } // namespace autofill 2333 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698