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(); | 143 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
145 for (size_t j = 0; j < inputs->size(); ++j) { | 144 for (size_t j = 0; j < inputs->size(); ++j) { |
146 (*inputs)[j].initial_value = | 145 (*inputs)[j].initial_value = group->GetInfo((*inputs)[j].type, app_locale); |
147 group->GetInfo((*inputs)[j].type, app_locale); | |
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 if (iter->first->type == ADDRESS_HOME_COUNTRY || | 155 if (iter->first->type == ADDRESS_HOME_COUNTRY || |
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 const std::vector<CreditCard*>& cards = manager->credit_cards(); | 1650 const std::vector<CreditCard*>& cards = manager->credit_cards(); |
1653 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1651 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1654 for (size_t i = 0; i < cards.size(); ++i) { | 1652 for (size_t i = 0; i < cards.size(); ++i) { |
1655 suggested_cc_.AddKeyedItemWithIcon( | 1653 suggested_cc_.AddKeyedItemWithIcon( |
1656 cards[i]->guid(), | 1654 cards[i]->guid(), |
1657 cards[i]->Label(), | 1655 cards[i]->Label(), |
1658 rb.GetImageNamed(cards[i]->IconResourceId())); | 1656 rb.GetImageNamed(cards[i]->IconResourceId())); |
1659 } | 1657 } |
1660 | 1658 |
1661 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 1659 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
1662 const std::string app_locale = AutofillCountry::ApplicationLocale(); | 1660 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
1663 for (size_t i = 0; i < profiles.size(); ++i) { | 1661 for (size_t i = 0; i < profiles.size(); ++i) { |
1664 if (!IsCompleteProfile(*profiles[i])) | 1662 if (!IsCompleteProfile(*profiles[i])) |
1665 continue; | 1663 continue; |
1666 | 1664 |
1667 // Add all email addresses. | 1665 // Add all email addresses. |
1668 std::vector<string16> values; | 1666 std::vector<string16> values; |
1669 profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values); | 1667 profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values); |
1670 for (size_t j = 0; j < values.size(); ++j) { | 1668 for (size_t j = 0; j < values.size(); ++j) { |
1671 if (!values[j].empty()) | 1669 if (!values[j].empty()) |
1672 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); | 1670 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); |
(...skipping 22 matching lines...) Expand all Loading... |
1695 suggested_shipping_.AddKeyedItem( | 1693 suggested_shipping_.AddKeyedItem( |
1696 std::string(), | 1694 std::string(), |
1697 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); | 1695 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ADD_SHIPPING_ADDRESS)); |
1698 | 1696 |
1699 if (view_) | 1697 if (view_) |
1700 view_->ModelChanged(); | 1698 view_->ModelChanged(); |
1701 } | 1699 } |
1702 | 1700 |
1703 bool AutofillDialogControllerImpl::IsCompleteProfile( | 1701 bool AutofillDialogControllerImpl::IsCompleteProfile( |
1704 const AutofillProfile& profile) { | 1702 const AutofillProfile& profile) { |
1705 const std::string app_locale = AutofillCountry::ApplicationLocale(); | 1703 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
1706 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { | 1704 for (size_t i = 0; i < requested_shipping_fields_.size(); ++i) { |
1707 AutofillFieldType type = requested_shipping_fields_[i].type; | 1705 AutofillFieldType type = requested_shipping_fields_[i].type; |
1708 if (type != ADDRESS_HOME_LINE2 && | 1706 if (type != ADDRESS_HOME_LINE2 && |
1709 profile.GetInfo(type, app_locale).empty()) { | 1707 profile.GetInfo(type, app_locale).empty()) { |
1710 return false; | 1708 return false; |
1711 } | 1709 } |
1712 } | 1710 } |
1713 | 1711 |
1714 return true; | 1712 return true; |
1715 } | 1713 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 1764 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
1767 FillOutputForSectionWithComparator(section, | 1765 FillOutputForSectionWithComparator(section, |
1768 base::Bind(DetailInputMatchesField)); | 1766 base::Bind(DetailInputMatchesField)); |
1769 } | 1767 } |
1770 | 1768 |
1771 void AutofillDialogControllerImpl::FillFormStructureForSection( | 1769 void AutofillDialogControllerImpl::FillFormStructureForSection( |
1772 const FormGroup& form_group, | 1770 const FormGroup& form_group, |
1773 size_t variant, | 1771 size_t variant, |
1774 DialogSection section, | 1772 DialogSection section, |
1775 const InputFieldComparator& compare) { | 1773 const InputFieldComparator& compare) { |
| 1774 std::string app_locale = g_browser_process->GetApplicationLocale(); |
1776 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 1775 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
1777 AutofillField* field = form_structure_.field(i); | 1776 AutofillField* field = form_structure_.field(i); |
1778 // Only fill in data that is associated with this section. | 1777 // Only fill in data that is associated with this section. |
1779 const DetailInputs& inputs = RequestedFieldsForSection(section); | 1778 const DetailInputs& inputs = RequestedFieldsForSection(section); |
1780 for (size_t j = 0; j < inputs.size(); ++j) { | 1779 for (size_t j = 0; j < inputs.size(); ++j) { |
1781 if (compare.Run(inputs[j], *field)) { | 1780 if (compare.Run(inputs[j], *field)) { |
1782 form_group.FillFormField(*field, variant, field); | 1781 form_group.FillFormField(*field, variant, app_locale, field); |
1783 break; | 1782 break; |
1784 } | 1783 } |
1785 } | 1784 } |
1786 } | 1785 } |
1787 } | 1786 } |
1788 | 1787 |
1789 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { | 1788 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { |
1790 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 1789 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
1791 AutofillField* field = form_structure_.field(i); | 1790 AutofillField* field = form_structure_.field(i); |
1792 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { | 1791 if (field->type() == CREDIT_CARD_VERIFICATION_CODE) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; | 2077 AutofillMetrics::DIALOG_USER_SIGNED_IN_NO_WALLET_NO_AUTOFILL; |
2079 } | 2078 } |
2080 | 2079 |
2081 // Has Wallet items. | 2080 // Has Wallet items. |
2082 return has_autofill_profiles ? | 2081 return has_autofill_profiles ? |
2083 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : | 2082 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_HAS_AUTOFILL : |
2084 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; | 2083 AutofillMetrics::DIALOG_USER_SIGNED_IN_HAS_WALLET_NO_AUTOFILL; |
2085 } | 2084 } |
2086 | 2085 |
2087 } // namespace autofill | 2086 } // namespace autofill |
OLD | NEW |