| 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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 | 638 |
| 639 legal_document_link_ranges_.clear(); | 639 legal_document_link_ranges_.clear(); |
| 640 for (size_t i = 0; i < documents.size(); ++i) { | 640 for (size_t i = 0; i < documents.size(); ++i) { |
| 641 size_t link_start = text.find(documents[i]->display_name()); | 641 size_t link_start = text.find(documents[i]->display_name()); |
| 642 legal_document_link_ranges_.push_back(ui::Range( | 642 legal_document_link_ranges_.push_back(ui::Range( |
| 643 link_start, link_start + documents[i]->display_name().size())); | 643 link_start, link_start + documents[i]->display_name().size())); |
| 644 } | 644 } |
| 645 legal_documents_text_ = text; | 645 legal_documents_text_ = text; |
| 646 } | 646 } |
| 647 | 647 |
| 648 void AutofillDialogControllerImpl::ResetManualInputForSection( | 648 void AutofillDialogControllerImpl::PrepareDetailInputsForSection( |
| 649 DialogSection section) { | 649 DialogSection section) { |
| 650 // Reset all previously entered data and stop editing |section|. |
| 650 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | 651 DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| 651 for (size_t i = 0; i < inputs->size(); ++i) | 652 for (size_t i = 0; i < inputs->size(); ++i) { |
| 652 (*inputs)[i].initial_value.clear(); | 653 (*inputs)[i].initial_value.clear(); |
| 654 } |
| 653 section_editing_state_[section] = false; | 655 section_editing_state_[section] = false; |
| 656 |
| 657 // If the chosen item in |model| yields an empty suggestion text, it is |
| 658 // invalid. In this case, show the editing UI with invalid fields highlighted. |
| 659 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 660 if (IsASuggestionItemKey(model->GetItemKeyForCheckedItem()) && |
| 661 SuggestionTextForSection(section).empty()) { |
| 662 scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| 663 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); |
| 664 section_editing_state_[section] = true; |
| 665 } |
| 666 |
| 667 if (view_) |
| 668 view_->UpdateSection(section); |
| 654 } | 669 } |
| 655 | 670 |
| 656 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 671 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
| 657 DialogSection section) const { | 672 DialogSection section) const { |
| 658 switch (section) { | 673 switch (section) { |
| 659 case SECTION_EMAIL: | 674 case SECTION_EMAIL: |
| 660 return requested_email_fields_; | 675 return requested_email_fields_; |
| 661 case SECTION_CC: | 676 case SECTION_CC: |
| 662 return requested_cc_fields_; | 677 return requested_cc_fields_; |
| 663 case SECTION_BILLING: | 678 case SECTION_BILLING: |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 ExtraSuggestionIconForSection(section), | 763 ExtraSuggestionIconForSection(section), |
| 749 EditEnabledForSection(section)); | 764 EditEnabledForSection(section)); |
| 750 } | 765 } |
| 751 | 766 |
| 752 string16 AutofillDialogControllerImpl::SuggestionTextForSection( | 767 string16 AutofillDialogControllerImpl::SuggestionTextForSection( |
| 753 DialogSection section) { | 768 DialogSection section) { |
| 754 string16 action_text = RequiredActionTextForSection(section); | 769 string16 action_text = RequiredActionTextForSection(section); |
| 755 if (!action_text.empty()) | 770 if (!action_text.empty()) |
| 756 return action_text; | 771 return action_text; |
| 757 | 772 |
| 758 // When the user has clicked 'edit', don't show a suggestion (even though | 773 // When the user has clicked 'edit' or a suggestion is somehow invalid (e.g. a |
| 759 // there is a profile selected in the model). | 774 // user selects a credit card that has expired), don't show a suggestion (even |
| 775 // though there is a profile selected in the model). |
| 760 if (section_editing_state_[section]) | 776 if (section_editing_state_[section]) |
| 761 return string16(); | 777 return string16(); |
| 762 | 778 |
| 763 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 779 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
| 764 std::string item_key = model->GetItemKeyForCheckedItem(); | 780 std::string item_key = model->GetItemKeyForCheckedItem(); |
| 765 if (item_key == kSameAsBillingKey) { | 781 if (item_key == kSameAsBillingKey) { |
| 766 return l10n_util::GetStringUTF16( | 782 return l10n_util::GetStringUTF16( |
| 767 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); | 783 IDS_AUTOFILL_DIALOG_USING_BILLING_FOR_SHIPPING); |
| 768 } | 784 } |
| 769 | 785 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 } | 915 } |
| 900 | 916 |
| 901 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) | 917 if (section == SECTION_CC_BILLING && IsSubmitPausedOn(wallet::VERIFY_CVV)) |
| 902 return false; | 918 return false; |
| 903 | 919 |
| 904 return true; | 920 return true; |
| 905 } | 921 } |
| 906 | 922 |
| 907 void AutofillDialogControllerImpl::EditClickedForSection( | 923 void AutofillDialogControllerImpl::EditClickedForSection( |
| 908 DialogSection section) { | 924 DialogSection section) { |
| 909 DetailInputs* inputs = MutableRequestedFieldsForSection(section); | |
| 910 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); | 925 scoped_ptr<DataModelWrapper> model = CreateWrapper(section); |
| 911 model->FillInputs(inputs); | 926 model->FillInputs(MutableRequestedFieldsForSection(section)); |
| 912 section_editing_state_[section] = true; | 927 section_editing_state_[section] = true; |
| 913 view_->UpdateSection(section); | 928 view_->UpdateSection(section); |
| 914 | 929 |
| 915 GetMetricLogger().LogDialogUiEvent( | 930 GetMetricLogger().LogDialogUiEvent( |
| 916 dialog_type_, DialogSectionToUiEditEvent(section)); | 931 dialog_type_, DialogSectionToUiEditEvent(section)); |
| 917 } | 932 } |
| 918 | 933 |
| 919 void AutofillDialogControllerImpl::EditCancelledForSection( | 934 void AutofillDialogControllerImpl::EditCancelledForSection( |
| 920 DialogSection section) { | 935 DialogSection section) { |
| 921 ResetManualInputForSection(section); | 936 PrepareDetailInputsForSection(section); |
| 922 view_->UpdateSection(section); | |
| 923 } | 937 } |
| 924 | 938 |
| 925 gfx::Image AutofillDialogControllerImpl::IconForField( | 939 gfx::Image AutofillDialogControllerImpl::IconForField( |
| 926 AutofillFieldType type, const string16& user_input) const { | 940 AutofillFieldType type, const string16& user_input) const { |
| 927 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 941 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 928 if (type == CREDIT_CARD_VERIFICATION_CODE) | 942 if (type == CREDIT_CARD_VERIFICATION_CODE) |
| 929 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); | 943 return rb.GetImageNamed(IDR_CREDIT_CARD_CVC_HINT); |
| 930 | 944 |
| 931 // For the credit card, we show a few grayscale images, and possibly one | 945 // For the credit card, we show a few grayscale images, and possibly one |
| 932 // color image if |user_input| is a valid card number. | 946 // color image if |user_input| is a valid card number. |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 chrome::kAutofillSubPage)); | 1408 chrome::kAutofillSubPage)); |
| 1395 } else { | 1409 } else { |
| 1396 // TODO(estade): show a wallet URL. | 1410 // TODO(estade): show a wallet URL. |
| 1397 NOTIMPLEMENTED(); | 1411 NOTIMPLEMENTED(); |
| 1398 } | 1412 } |
| 1399 | 1413 |
| 1400 return; | 1414 return; |
| 1401 } | 1415 } |
| 1402 | 1416 |
| 1403 model->SetCheckedIndex(index); | 1417 model->SetCheckedIndex(index); |
| 1404 EditCancelledForSection(SectionForSuggestionsMenuModel(*model)); | 1418 PrepareDetailInputsForSection(SectionForSuggestionsMenuModel(*model)); |
| 1405 | 1419 |
| 1406 LogSuggestionItemSelectedMetric(*model); | 1420 LogSuggestionItemSelectedMetric(*model); |
| 1407 } | 1421 } |
| 1408 | 1422 |
| 1409 //////////////////////////////////////////////////////////////////////////////// | 1423 //////////////////////////////////////////////////////////////////////////////// |
| 1410 // wallet::WalletClientDelegate implementation. | 1424 // wallet::WalletClientDelegate implementation. |
| 1411 | 1425 |
| 1412 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { | 1426 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { |
| 1413 return metric_logger_; | 1427 return metric_logger_; |
| 1414 } | 1428 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 // PersonalDataManagerObserver implementation. | 1585 // PersonalDataManagerObserver implementation. |
| 1572 | 1586 |
| 1573 void AutofillDialogControllerImpl::OnPersonalDataChanged() { | 1587 void AutofillDialogControllerImpl::OnPersonalDataChanged() { |
| 1574 SuggestionsUpdated(); | 1588 SuggestionsUpdated(); |
| 1575 } | 1589 } |
| 1576 | 1590 |
| 1577 //////////////////////////////////////////////////////////////////////////////// | 1591 //////////////////////////////////////////////////////////////////////////////// |
| 1578 // AccountChooserModelDelegate implementation. | 1592 // AccountChooserModelDelegate implementation. |
| 1579 | 1593 |
| 1580 void AutofillDialogControllerImpl::AccountChoiceChanged() { | 1594 void AutofillDialogControllerImpl::AccountChoiceChanged() { |
| 1581 // Whenever the user changes the account, all manual inputs should be reset. | |
| 1582 ResetManualInputForSection(SECTION_EMAIL); | |
| 1583 ResetManualInputForSection(SECTION_CC); | |
| 1584 ResetManualInputForSection(SECTION_BILLING); | |
| 1585 ResetManualInputForSection(SECTION_CC_BILLING); | |
| 1586 ResetManualInputForSection(SECTION_SHIPPING); | |
| 1587 | |
| 1588 if (is_submitting_) | 1595 if (is_submitting_) |
| 1589 GetWalletClient()->CancelRequests(); | 1596 GetWalletClient()->CancelRequests(); |
| 1590 | 1597 |
| 1591 SetIsSubmitting(false); | 1598 SetIsSubmitting(false); |
| 1592 | 1599 |
| 1593 if (!signin_helper_ && account_chooser_model_.WalletIsSelected()) { | 1600 if (!signin_helper_ && account_chooser_model_.WalletIsSelected()) { |
| 1594 if (account_chooser_model_.IsActiveWalletAccountSelected()) { | 1601 if (account_chooser_model_.IsActiveWalletAccountSelected()) { |
| 1595 // If the user has chosen an already active Wallet account, and we don't | 1602 // If the user has chosen an already active Wallet account, and we don't |
| 1596 // have the Wallet items, an attempt to fetch the Wallet data is made to | 1603 // have the Wallet items, an attempt to fetch the Wallet data is made to |
| 1597 // see if the user is still signed in. This will trigger a passive sign-in | 1604 // see if the user is still signed in. This will trigger a passive sign-in |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1827 kManageItemsKey, | 1834 kManageItemsKey, |
| 1828 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS)); | 1835 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_EMAIL_ADDRESS)); |
| 1829 } | 1836 } |
| 1830 | 1837 |
| 1831 suggested_shipping_.AddKeyedItem( | 1838 suggested_shipping_.AddKeyedItem( |
| 1832 kAddNewItemKey, | 1839 kAddNewItemKey, |
| 1833 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 1840 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
| 1834 suggested_shipping_.AddKeyedItem( | 1841 suggested_shipping_.AddKeyedItem( |
| 1835 kManageItemsKey, | 1842 kManageItemsKey, |
| 1836 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); | 1843 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_MANAGE_SHIPPING_ADDRESS)); |
| 1844 |
| 1837 if (!IsPayingWithWallet()) { | 1845 if (!IsPayingWithWallet()) { |
| 1838 // When using Autofill, the default option is the first suggestion, if | 1846 // When using Autofill, the default option is the first suggestion, if |
| 1839 // one exists. Otherwise it's the "Use shipping for billing" item. | 1847 // one exists. Otherwise it's the "Use shipping for billing" item. |
| 1840 const std::string& first_real_suggestion_item_key = | 1848 const std::string& first_real_suggestion_item_key = |
| 1841 suggested_shipping_.GetItemKeyAt(1); | 1849 suggested_shipping_.GetItemKeyAt(1); |
| 1842 if (IsASuggestionItemKey(first_real_suggestion_item_key)) | 1850 if (IsASuggestionItemKey(first_real_suggestion_item_key)) |
| 1843 suggested_shipping_.SetCheckedItem(first_real_suggestion_item_key); | 1851 suggested_shipping_.SetCheckedItem(first_real_suggestion_item_key); |
| 1844 } | 1852 } |
| 1845 | 1853 |
| 1846 if (view_) | 1854 if (view_) |
| 1847 view_->ModelChanged(); | 1855 view_->ModelChanged(); |
| 1856 |
| 1857 for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { |
| 1858 PrepareDetailInputsForSection(static_cast<DialogSection>(section)); |
| 1859 } |
| 1848 } | 1860 } |
| 1849 | 1861 |
| 1850 bool AutofillDialogControllerImpl::IsCompleteProfile( | 1862 bool AutofillDialogControllerImpl::IsCompleteProfile( |
| 1851 const AutofillProfile& profile) { | 1863 const AutofillProfile& profile) { |
| 1852 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 1864 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 1853 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { | 1865 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { |
| 1854 AutofillFieldType type = requested_shipping_fields_[i].type; | 1866 AutofillFieldType type = requested_shipping_fields_[i].type; |
| 1855 if (type != ADDRESS_HOME_LINE2 && | 1867 if (type != ADDRESS_HOME_LINE2 && |
| 1856 profile.GetInfo(type, app_locale).empty()) { | 1868 profile.GetInfo(type, app_locale).empty()) { |
| 1857 return false; | 1869 return false; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( | 2331 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( |
| 2320 const SuggestionsMenuModel& model) { | 2332 const SuggestionsMenuModel& model) { |
| 2321 DialogSection section = SectionForSuggestionsMenuModel(model); | 2333 DialogSection section = SectionForSuggestionsMenuModel(model); |
| 2322 | 2334 |
| 2323 AutofillMetrics::DialogUiEvent dialog_ui_event; | 2335 AutofillMetrics::DialogUiEvent dialog_ui_event; |
| 2324 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) { | 2336 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) { |
| 2325 // Selected to add a new item. | 2337 // Selected to add a new item. |
| 2326 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); | 2338 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); |
| 2327 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) { | 2339 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) { |
| 2328 // Selected an existing item. | 2340 // Selected an existing item. |
| 2329 DCHECK(!section_editing_state_[section]); | |
| 2330 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); | 2341 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); |
| 2331 } else { | 2342 } else { |
| 2332 // TODO(estade): add logging for "Manage items" or "Use billing for | 2343 // TODO(estade): add logging for "Manage items" or "Use billing for |
| 2333 // shipping"? | 2344 // shipping"? |
| 2334 return; | 2345 return; |
| 2335 } | 2346 } |
| 2336 | 2347 |
| 2337 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); | 2348 GetMetricLogger().LogDialogUiEvent(dialog_type_, dialog_ui_event); |
| 2338 } | 2349 } |
| 2339 | 2350 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2384 url, | 2395 url, |
| 2385 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 2396 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 2386 params.disposition = NEW_FOREGROUND_TAB; | 2397 params.disposition = NEW_FOREGROUND_TAB; |
| 2387 chrome::Navigate(¶ms); | 2398 chrome::Navigate(¶ms); |
| 2388 #else | 2399 #else |
| 2389 // TODO(estade): use TabModelList? | 2400 // TODO(estade): use TabModelList? |
| 2390 #endif | 2401 #endif |
| 2391 } | 2402 } |
| 2392 | 2403 |
| 2393 } // namespace autofill | 2404 } // namespace autofill |
| OLD | NEW |