OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/data_model_wrapper.h" | 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 11 #include "components/autofill/browser/autofill_data_model.h" |
11 #include "components/autofill/browser/autofill_profile.h" | 12 #include "components/autofill/browser/autofill_profile.h" |
12 #include "components/autofill/browser/autofill_type.h" | 13 #include "components/autofill/browser/autofill_type.h" |
13 #include "components/autofill/browser/credit_card.h" | 14 #include "components/autofill/browser/credit_card.h" |
14 #include "components/autofill/browser/form_group.h" | |
15 #include "components/autofill/browser/form_structure.h" | 15 #include "components/autofill/browser/form_structure.h" |
16 #include "components/autofill/browser/wallet/full_wallet.h" | 16 #include "components/autofill/browser/wallet/full_wallet.h" |
17 #include "components/autofill/browser/wallet/wallet_address.h" | 17 #include "components/autofill/browser/wallet/wallet_address.h" |
18 #include "components/autofill/browser/wallet/wallet_items.h" | 18 #include "components/autofill/browser/wallet/wallet_items.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
21 | 21 |
22 namespace autofill { | 22 namespace autofill { |
23 | 23 |
24 DataModelWrapper::~DataModelWrapper() {} | 24 DataModelWrapper::~DataModelWrapper() {} |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 void DataModelWrapper::FillFormField(AutofillField* field) { | 60 void DataModelWrapper::FillFormField(AutofillField* field) { |
61 field->value = GetInfo(field->type()); | 61 field->value = GetInfo(field->type()); |
62 } | 62 } |
63 | 63 |
64 DataModelWrapper::DataModelWrapper() {} | 64 DataModelWrapper::DataModelWrapper() {} |
65 | 65 |
66 gfx::Image DataModelWrapper::GetIcon() { | 66 gfx::Image DataModelWrapper::GetIcon() { |
67 return gfx::Image(); | 67 return gfx::Image(); |
68 } | 68 } |
69 | 69 |
70 // AutofillFormGroupWrapper | 70 // AutofillDataModelWrapper |
71 | 71 |
72 AutofillFormGroupWrapper::AutofillFormGroupWrapper(const FormGroup* form_group, | 72 AutofillDataModelWrapper::AutofillDataModelWrapper( |
73 size_t variant) | 73 const AutofillDataModel* data_model, |
74 : form_group_(form_group), | 74 size_t variant) |
| 75 : data_model_(data_model), |
75 variant_(variant) {} | 76 variant_(variant) {} |
76 | 77 |
77 AutofillFormGroupWrapper::~AutofillFormGroupWrapper() {} | 78 AutofillDataModelWrapper::~AutofillDataModelWrapper() {} |
78 | 79 |
79 string16 AutofillFormGroupWrapper::GetInfo(AutofillFieldType type) { | 80 string16 AutofillDataModelWrapper::GetInfo(AutofillFieldType type) { |
80 return form_group_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 81 return data_model_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
81 } | 82 } |
82 | 83 |
83 void AutofillFormGroupWrapper::FillFormField(AutofillField* field) { | 84 void AutofillDataModelWrapper::FillFormField(AutofillField* field) { |
84 form_group_->FillFormField( | 85 data_model_->FillFormField( |
85 *field, variant_, g_browser_process->GetApplicationLocale(), field); | 86 *field, variant_, g_browser_process->GetApplicationLocale(), field); |
86 } | 87 } |
87 | 88 |
88 // AutofillProfileWrapper | 89 // AutofillProfileWrapper |
89 | 90 |
90 AutofillProfileWrapper::AutofillProfileWrapper( | 91 AutofillProfileWrapper::AutofillProfileWrapper( |
91 const AutofillProfile* profile, size_t variant) | 92 const AutofillProfile* profile, size_t variant) |
92 : AutofillFormGroupWrapper(profile, variant), | 93 : AutofillDataModelWrapper(profile, variant), |
93 profile_(profile) {} | 94 profile_(profile) {} |
94 | 95 |
95 AutofillProfileWrapper::~AutofillProfileWrapper() {} | 96 AutofillProfileWrapper::~AutofillProfileWrapper() {} |
96 | 97 |
97 void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) { | 98 void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) { |
98 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 99 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
99 for (size_t j = 0; j < inputs->size(); ++j) { | 100 for (size_t j = 0; j < inputs->size(); ++j) { |
100 std::vector<string16> values; | 101 std::vector<string16> values; |
101 profile_->GetMultiInfo((*inputs)[j].type, app_locale, &values); | 102 profile_->GetMultiInfo((*inputs)[j].type, app_locale, &values); |
102 (*inputs)[j].initial_value = values[variant()]; | 103 (*inputs)[j].initial_value = values[variant()]; |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
106 // AutofillCreditCardWrapper | 107 // AutofillCreditCardWrapper |
107 | 108 |
108 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) | 109 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) |
109 : AutofillFormGroupWrapper(card, 0), | 110 : AutofillDataModelWrapper(card, 0), |
110 card_(card) {} | 111 card_(card) {} |
111 | 112 |
112 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} | 113 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} |
113 | 114 |
114 string16 AutofillCreditCardWrapper::GetInfo(AutofillFieldType type) { | 115 string16 AutofillCreditCardWrapper::GetInfo(AutofillFieldType type) { |
115 if (type == CREDIT_CARD_EXP_MONTH) | 116 if (type == CREDIT_CARD_EXP_MONTH) |
116 return MonthComboboxModel::FormatMonth(card_->expiration_month()); | 117 return MonthComboboxModel::FormatMonth(card_->expiration_month()); |
117 | 118 |
118 return AutofillFormGroupWrapper::GetInfo(type); | 119 return AutofillDataModelWrapper::GetInfo(type); |
119 } | 120 } |
120 | 121 |
121 gfx::Image AutofillCreditCardWrapper::GetIcon() { | 122 gfx::Image AutofillCreditCardWrapper::GetIcon() { |
122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 123 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
123 return rb.GetImageNamed(card_->IconResourceId()); | 124 return rb.GetImageNamed(card_->IconResourceId()); |
124 } | 125 } |
125 | 126 |
126 string16 AutofillCreditCardWrapper::GetDisplayText() { | 127 string16 AutofillCreditCardWrapper::GetDisplayText() { |
127 return card_->TypeAndLastFourDigits(); | 128 return card_->TypeAndLastFourDigits(); |
128 } | 129 } |
129 | 130 |
130 void AutofillCreditCardWrapper::FillFormField(AutofillField* field) { | 131 void AutofillCreditCardWrapper::FillFormField(AutofillField* field) { |
131 AutofillFieldType field_type = field->type(); | 132 AutofillFieldType field_type = field->type(); |
132 | 133 |
133 if (field_type == NAME_FULL) { | 134 if (field_type == NAME_FULL) { |
134 // Requests for the user's full name are filled from the credit card data, | 135 // Requests for the user's full name are filled from the credit card data, |
135 // but the CreditCard class only knows how to fill credit card fields. So, | 136 // but the CreditCard class only knows how to fill credit card fields. So, |
136 // temporarily set the type to the corresponding credit card type. | 137 // temporarily set the type to the corresponding credit card type. |
137 field->set_heuristic_type(CREDIT_CARD_NAME); | 138 field->set_heuristic_type(CREDIT_CARD_NAME); |
138 } | 139 } |
139 | 140 |
140 AutofillFormGroupWrapper::FillFormField(field); | 141 AutofillDataModelWrapper::FillFormField(field); |
141 | 142 |
142 field->set_heuristic_type(field_type); | 143 field->set_heuristic_type(field_type); |
143 } | 144 } |
144 | 145 |
145 // WalletAddressWrapper | 146 // WalletAddressWrapper |
146 | 147 |
147 WalletAddressWrapper::WalletAddressWrapper( | 148 WalletAddressWrapper::WalletAddressWrapper( |
148 const wallet::Address* address) : address_(address) {} | 149 const wallet::Address* address) : address_(address) {} |
149 | 150 |
150 WalletAddressWrapper::~WalletAddressWrapper() {} | 151 WalletAddressWrapper::~WalletAddressWrapper() {} |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 207 } |
207 | 208 |
208 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} | 209 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} |
209 | 210 |
210 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { | 211 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { |
211 return full_wallet_->shipping_address()->GetInfo( | 212 return full_wallet_->shipping_address()->GetInfo( |
212 type, g_browser_process->GetApplicationLocale()); | 213 type, g_browser_process->GetApplicationLocale()); |
213 } | 214 } |
214 | 215 |
215 } // namespace autofill | 216 } // namespace autofill |
OLD | NEW |