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 12 matching lines...) Expand all Loading... | |
23 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 23 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
24 #include "chrome/browser/ui/base_window.h" | 24 #include "chrome/browser/ui/base_window.h" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_navigator.h" | 27 #include "chrome/browser/ui/browser_navigator.h" |
28 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
29 #include "chrome/browser/ui/extensions/native_app_window.h" | 29 #include "chrome/browser/ui/extensions/native_app_window.h" |
30 #include "chrome/browser/ui/extensions/shell_window.h" | 30 #include "chrome/browser/ui/extensions/shell_window.h" |
31 #include "chrome/common/chrome_version_info.h" | 31 #include "chrome/common/chrome_version_info.h" |
32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
33 #include "components/autofill/browser/autofill_country.h" | |
34 #include "components/autofill/browser/autofill_manager.h" | 33 #include "components/autofill/browser/autofill_manager.h" |
35 #include "components/autofill/browser/autofill_type.h" | 34 #include "components/autofill/browser/autofill_type.h" |
36 #include "components/autofill/browser/personal_data_manager.h" | 35 #include "components/autofill/browser/personal_data_manager.h" |
37 #include "components/autofill/browser/risk/fingerprint.h" | 36 #include "components/autofill/browser/risk/fingerprint.h" |
38 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" | 37 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" |
39 #include "components/autofill/browser/validation.h" | 38 #include "components/autofill/browser/validation.h" |
40 #include "components/autofill/browser/wallet/cart.h" | 39 #include "components/autofill/browser/wallet/cart.h" |
41 #include "components/autofill/browser/wallet/full_wallet.h" | 40 #include "components/autofill/browser/wallet/full_wallet.h" |
42 #include "components/autofill/browser/wallet/instrument.h" | 41 #include "components/autofill/browser/wallet/instrument.h" |
43 #include "components/autofill/browser/wallet/wallet_address.h" | 42 #include "components/autofill/browser/wallet/wallet_address.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 DetailInputs* inputs) { | 133 DetailInputs* inputs) { |
135 for (size_t i = 0; i < template_size; ++i) { | 134 for (size_t i = 0; i < template_size; ++i) { |
136 const DetailInput* input = &input_template[i]; | 135 const DetailInput* input = &input_template[i]; |
137 inputs->push_back(*input); | 136 inputs->push_back(*input); |
138 } | 137 } |
139 } | 138 } |
140 | 139 |
141 // Uses |group| to fill in the |initial_value| for all inputs in |all_inputs| | 140 // Uses |group| to fill in the |initial_value| for all inputs in |all_inputs| |
142 // (an out-param). | 141 // (an out-param). |
143 void FillInputFromFormGroup(FormGroup* group, DetailInputs* inputs) { | 142 void FillInputFromFormGroup(FormGroup* group, DetailInputs* inputs) { |
144 const std::string app_locale = AutofillCountry::ApplicationLocale(); | |
145 for (size_t j = 0; j < inputs->size(); ++j) { | 143 for (size_t j = 0; j < inputs->size(); ++j) { |
146 (*inputs)[j].initial_value = | 144 (*inputs)[j].initial_value = group->GetInfo( |
147 group->GetInfo((*inputs)[j].type, app_locale); | 145 (*inputs)[j].type, g_browser_process->GetApplicationLocale()); |
Ilya Sherman
2013/04/04 04:27:38
nit: Please continue to cache this outside of the
jam
2013/04/04 17:58:12
Done.
| |
148 } | 146 } |
149 } | 147 } |
150 | 148 |
151 // Initializes |form_group| from user-entered data. | 149 // Initializes |form_group| from user-entered data. |
152 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, | 150 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, |
153 FormGroup* form_group) { | 151 FormGroup* form_group) { |
154 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); | 152 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); |
155 iter != detail_outputs.end(); ++iter) { | 153 iter != detail_outputs.end(); ++iter) { |
156 if (!iter->second.empty()) | 154 if (!iter->second.empty()) |
157 form_group->SetRawInfo(iter->first->type, iter->second); | 155 form_group->SetRawInfo(iter->first->type, iter->second); |
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1648 const std::vector<CreditCard*>& cards = manager->credit_cards(); | 1646 const std::vector<CreditCard*>& cards = manager->credit_cards(); |
1649 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1647 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1650 for (size_t i = 0; i < cards.size(); ++i) { | 1648 for (size_t i = 0; i < cards.size(); ++i) { |
1651 suggested_cc_.AddKeyedItemWithIcon( | 1649 suggested_cc_.AddKeyedItemWithIcon( |
1652 cards[i]->guid(), | 1650 cards[i]->guid(), |
1653 cards[i]->Label(), | 1651 cards[i]->Label(), |
1654 rb.GetImageNamed(cards[i]->IconResourceId())); | 1652 rb.GetImageNamed(cards[i]->IconResourceId())); |
1655 } | 1653 } |
1656 | 1654 |
1657 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 1655 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
1658 const std::string app_locale = AutofillCountry::ApplicationLocale(); | |
1659 for (size_t i = 0; i < profiles.size(); ++i) { | 1656 for (size_t i = 0; i < profiles.size(); ++i) { |
1660 if (!IsCompleteProfile(*profiles[i])) | 1657 if (!IsCompleteProfile(*profiles[i])) |
1661 continue; | 1658 continue; |
1662 | 1659 |
1663 // Add all email addresses. | 1660 // Add all email addresses. |
1664 std::vector<string16> values; | 1661 std::vector<string16> values; |
1665 profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values); | 1662 profiles[i]->GetMultiInfo( |
1663 EMAIL_ADDRESS, g_browser_process->GetApplicationLocale(), &values); | |
1666 for (size_t j = 0; j < values.size(); ++j) { | 1664 for (size_t j = 0; j < values.size(); ++j) { |
1667 if (!values[j].empty()) | 1665 if (!values[j].empty()) |
1668 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); | 1666 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); |
1669 } | 1667 } |
1670 | 1668 |
1671 // Don't add variants for addresses: the email variants are handled above, | 1669 // Don't add variants for addresses: the email variants are handled above, |
1672 // name is part of credit card and we'll just ignore phone number | 1670 // name is part of credit card and we'll just ignore phone number |
1673 // variants. | 1671 // variants. |
1674 suggested_billing_.AddKeyedItem(profiles[i]->guid(), | 1672 suggested_billing_.AddKeyedItem(profiles[i]->guid(), |
1675 profiles[i]->Label()); | 1673 profiles[i]->Label()); |
(...skipping 12 matching lines...) Expand all Loading... | |
1688 suggested_email_.AddKeyedItem( | 1686 suggested_email_.AddKeyedItem( |
1689 std::string(), | 1687 std::string(), |
1690 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); | 1688 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_EMAIL_ADDRESS)); |
1691 suggested_shipping_.AddKeyedItem( | 1689 suggested_shipping_.AddKeyedItem( |
1692 std::string(), | 1690 std::string(), |
1693 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 1691 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
1694 } | 1692 } |
1695 | 1693 |
1696 bool AutofillDialogControllerImpl::IsCompleteProfile( | 1694 bool AutofillDialogControllerImpl::IsCompleteProfile( |
1697 const AutofillProfile& profile) { | 1695 const AutofillProfile& profile) { |
1698 const std::string app_locale = AutofillCountry::ApplicationLocale(); | |
1699 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { | 1696 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { |
1700 AutofillFieldType type = requested_shipping_fields_[i].type; | 1697 AutofillFieldType type = requested_shipping_fields_[i].type; |
1701 if (type != ADDRESS_HOME_LINE2 && | 1698 if (type != ADDRESS_HOME_LINE2 && |
1702 profile.GetInfo(type, app_locale).empty()) { | 1699 profile.GetInfo(type, |
1700 g_browser_process->GetApplicationLocale()).empty()) { | |
1703 return false; | 1701 return false; |
1704 } | 1702 } |
1705 } | 1703 } |
1706 | 1704 |
1707 return true; | 1705 return true; |
1708 } | 1706 } |
1709 | 1707 |
1710 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 1708 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
1711 DialogSection section, | 1709 DialogSection section, |
1712 const InputFieldComparator& compare) { | 1710 const InputFieldComparator& compare) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1765 const FormGroup& form_group, | 1763 const FormGroup& form_group, |
1766 size_t variant, | 1764 size_t variant, |
1767 DialogSection section, | 1765 DialogSection section, |
1768 const InputFieldComparator& compare) { | 1766 const InputFieldComparator& compare) { |
1769 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 1767 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
1770 AutofillField* field = form_structure_.field(i); | 1768 AutofillField* field = form_structure_.field(i); |
1771 // Only fill in data that is associated with this section. | 1769 // Only fill in data that is associated with this section. |
1772 const DetailInputs& inputs = RequestedFieldsForSection(section); | 1770 const DetailInputs& inputs = RequestedFieldsForSection(section); |
1773 for (size_t j = 0; j < inputs.size(); ++j) { | 1771 for (size_t j = 0; j < inputs.size(); ++j) { |
1774 if (compare.Run(inputs[j], *field)) { | 1772 if (compare.Run(inputs[j], *field)) { |
1775 form_group.FillFormField(*field, variant, field); | 1773 form_group.FillFormField( |
1774 *field, variant, g_browser_process->GetApplicationLocale(), field); | |
1776 break; | 1775 break; |
1777 } | 1776 } |
1778 } | 1777 } |
1779 } | 1778 } |
1780 } | 1779 } |
1781 | 1780 |
1782 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { | 1781 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { |
1783 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 1782 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
1784 AutofillField* field = form_structure_.field(i); | 1783 AutofillField* field = form_structure_.field(i); |
1785 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { | 1784 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2059 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 2058 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
2060 } | 2059 } |
2061 | 2060 |
2062 // Has Wallet items. | 2061 // Has Wallet items. |
2063 return has_autofill_profiles ? | 2062 return has_autofill_profiles ? |
2064 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 2063 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
2065 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 2064 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
2066 } | 2065 } |
2067 | 2066 |
2068 } // namespace autofill | 2067 } // namespace autofill |
OLD | NEW |