| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 } | 1796 } |
| 1797 | 1797 |
| 1798 // TODO(groby): Also add tests. | 1798 // TODO(groby): Also add tests. |
| 1799 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( | 1799 ValidityMessages AutofillDialogControllerImpl::InputsAreValid( |
| 1800 DialogSection section, | 1800 DialogSection section, |
| 1801 const FieldValueMap& inputs) { | 1801 const FieldValueMap& inputs) { |
| 1802 ValidityMessages messages; | 1802 ValidityMessages messages; |
| 1803 if (inputs.empty()) | 1803 if (inputs.empty()) |
| 1804 return messages; | 1804 return messages; |
| 1805 | 1805 |
| 1806 FieldValueMap field_values; | |
| 1807 | |
| 1808 if (i18ninput::Enabled() && section != SECTION_CC) { | 1806 if (i18ninput::Enabled() && section != SECTION_CC) { |
| 1809 AddressData address_data; | 1807 AddressData address_data; |
| 1810 i18ninput::CreateAddressData( | 1808 i18ninput::CreateAddressData( |
| 1811 base::Bind(&GetInfoFromInputs, base::ConstRef(inputs), section), | 1809 base::Bind(&GetInfoFromInputs, base::ConstRef(inputs), section), |
| 1812 &address_data); | 1810 &address_data); |
| 1813 | 1811 |
| 1814 AddressProblems problems; | 1812 AddressProblems problems; |
| 1815 if (GetValidator()->ValidateAddress( | 1813 if (GetValidator()->ValidateAddress( |
| 1816 address_data, | 1814 address_data, |
| 1817 AddressProblemFilter(), | 1815 AddressProblemFilter(), |
| 1818 &problems) == AddressValidator::SUCCESS) { | 1816 &problems) == AddressValidator::SUCCESS) { |
| 1819 common::AddressType address_type = section == SECTION_SHIPPING ? | 1817 common::AddressType address_type = section == SECTION_SHIPPING ? |
| 1820 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; | 1818 common::ADDRESS_TYPE_SHIPPING : common::ADDRESS_TYPE_BILLING; |
| 1821 for (size_t i = 0; i < problems.size(); ++i) { | 1819 for (size_t i = 0; i < problems.size(); ++i) { |
| 1822 const AddressProblem& problem = problems[i]; | 1820 const AddressProblem& problem = problems[i]; |
| 1823 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; | 1821 bool sure = problem.type != AddressProblem::MISSING_REQUIRED_FIELD; |
| 1824 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); | 1822 base::string16 text = l10n_util::GetStringUTF16(problem.description_id); |
| 1825 messages.Set(i18ninput::TypeForField(problem.field, address_type), | 1823 messages.Set(i18ninput::TypeForField(problem.field, address_type), |
| 1826 ValidityMessage(text, sure)); | 1824 ValidityMessage(text, sure)); |
| 1827 } | 1825 } |
| 1828 } else { | 1826 } else { |
| 1829 // TODO(dbeam): disable submit button until able to successfully validate. | 1827 // TODO(dbeam): disable submit button until able to successfully validate. |
| 1830 } | 1828 } |
| 1831 } | 1829 } |
| 1832 | 1830 |
| 1833 for (FieldValueMap::const_iterator iter = inputs.begin(); | 1831 for (FieldValueMap::const_iterator iter = inputs.begin(); |
| 1834 iter != inputs.end(); ++iter) { | 1832 iter != inputs.end(); ++iter) { |
| 1835 const ServerFieldType type = iter->first; | 1833 const ServerFieldType type = iter->first; |
| 1836 if (!messages.GetMessageOrDefault(type).text.empty()) | |
| 1837 continue; | |
| 1838 | |
| 1839 base::string16 text = InputValidityMessage(section, type, iter->second); | 1834 base::string16 text = InputValidityMessage(section, type, iter->second); |
| 1840 | 1835 |
| 1841 // Skip empty/unchanged fields in edit mode. Ignore country as it always has | 1836 // Skip empty/unchanged fields in edit mode. Ignore country as it always has |
| 1842 // a value. If the individual field does not have validation errors, assume | 1837 // a value. If the individual field does not have validation errors, assume |
| 1843 // it to be valid unless later proven otherwise. | 1838 // it to be valid unless later proven otherwise. |
| 1844 bool sure = InputWasEdited(type, iter->second) || | 1839 bool sure = InputWasEdited(type, iter->second) || |
| 1845 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY; | 1840 AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY; |
| 1846 | |
| 1847 // Consider only individually valid fields for inter-field validation. | |
| 1848 if (text.empty()) { | |
| 1849 field_values[type] = iter->second; | |
| 1850 // If the field is valid but can be invalidated by inter-field validation, | |
| 1851 // assume it to be unsure. | |
| 1852 if (type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | |
| 1853 type == CREDIT_CARD_EXP_MONTH || | |
| 1854 type == CREDIT_CARD_VERIFICATION_CODE || | |
| 1855 type == PHONE_HOME_WHOLE_NUMBER || | |
| 1856 type == PHONE_BILLING_WHOLE_NUMBER) { | |
| 1857 sure = false; | |
| 1858 } | |
| 1859 } | |
| 1860 messages.Set(type, ValidityMessage(text, sure)); | 1841 messages.Set(type, ValidityMessage(text, sure)); |
| 1861 } | 1842 } |
| 1862 | 1843 |
| 1844 // For the convenience of using operator[]. |
| 1845 FieldValueMap& field_values = const_cast<FieldValueMap&>(inputs); |
| 1863 // Validate the date formed by month and year field. (Autofill dialog is | 1846 // Validate the date formed by month and year field. (Autofill dialog is |
| 1864 // never supposed to have 2-digit years, so not checked). | 1847 // never supposed to have 2-digit years, so not checked). |
| 1865 if (field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR) && | 1848 if (field_values.count(CREDIT_CARD_EXP_4_DIGIT_YEAR) && |
| 1866 field_values.count(CREDIT_CARD_EXP_MONTH) && | 1849 field_values.count(CREDIT_CARD_EXP_MONTH) && |
| 1867 InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, | 1850 InputWasEdited(CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 1868 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR]) && | 1851 field_values[CREDIT_CARD_EXP_4_DIGIT_YEAR]) && |
| 1869 InputWasEdited(CREDIT_CARD_EXP_MONTH, | 1852 InputWasEdited(CREDIT_CARD_EXP_MONTH, |
| 1870 field_values[CREDIT_CARD_EXP_MONTH])) { | 1853 field_values[CREDIT_CARD_EXP_MONTH])) { |
| 1871 ValidityMessage year_message(base::string16(), true); | 1854 ValidityMessage year_message(base::string16(), true); |
| 1872 ValidityMessage month_message(base::string16(), true); | 1855 ValidityMessage month_message(base::string16(), true); |
| (...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3756 view_->UpdateButtonStrip(); | 3739 view_->UpdateButtonStrip(); |
| 3757 } | 3740 } |
| 3758 | 3741 |
| 3759 void AutofillDialogControllerImpl::FetchWalletCookie() { | 3742 void AutofillDialogControllerImpl::FetchWalletCookie() { |
| 3760 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); | 3743 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3761 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); | 3744 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3762 signin_helper_->StartWalletCookieValueFetch(); | 3745 signin_helper_->StartWalletCookieValueFetch(); |
| 3763 } | 3746 } |
| 3764 | 3747 |
| 3765 } // namespace autofill | 3748 } // namespace autofill |
| OLD | NEW |