OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/autofill/autofill_dialog.h" | 10 #include "chrome/browser/autofill/autofill_dialog.h" |
11 #include "chrome/browser/autofill/autofill_infobar_delegate.h" | 11 #include "chrome/browser/autofill/autofill_infobar_delegate.h" |
12 #include "chrome/browser/autofill/form_structure.h" | 12 #include "chrome/browser/autofill/form_structure.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/renderer_host/render_view_host.h" | 14 #include "chrome/browser/renderer_host/render_view_host.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/pref_service.h" | 18 #include "chrome/common/pref_service.h" |
| 19 #include "webkit/glue/form_data.h" |
19 #include "webkit/glue/form_field.h" | 20 #include "webkit/glue/form_field.h" |
20 #include "webkit/glue/form_field_values.h" | 21 #include "webkit/glue/form_field_values.h" |
21 | 22 |
22 AutoFillManager::AutoFillManager(TabContents* tab_contents) | 23 AutoFillManager::AutoFillManager(TabContents* tab_contents) |
23 : tab_contents_(tab_contents), | 24 : tab_contents_(tab_contents), |
24 infobar_(NULL) { | 25 infobar_(NULL) { |
25 personal_data_ = tab_contents_->profile()->GetPersonalDataManager(); | 26 personal_data_ = tab_contents_->profile()->GetPersonalDataManager(); |
26 } | 27 } |
27 | 28 |
28 AutoFillManager::~AutoFillManager() { | 29 AutoFillManager::~AutoFillManager() { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // No suggestions. | 141 // No suggestions. |
141 if (names.empty()) | 142 if (names.empty()) |
142 return false; | 143 return false; |
143 | 144 |
144 // TODO(jhawkins): If the default profile is in this list, set it as the | 145 // TODO(jhawkins): If the default profile is in this list, set it as the |
145 // default suggestion index. | 146 // default suggestion index. |
146 host->AutoFillSuggestionsReturned(query_id, names, labels, -1); | 147 host->AutoFillSuggestionsReturned(query_id, names, labels, -1); |
147 return true; | 148 return true; |
148 } | 149 } |
149 | 150 |
| 151 bool AutoFillManager::FillAutoFillFormData(int query_id, |
| 152 const FormData& form, |
| 153 const string16& name, |
| 154 const string16& label) { |
| 155 // TODO(jhawkins): Use the autofill preference. |
| 156 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 157 switches::kEnableNewAutoFill)) |
| 158 return false; |
| 159 |
| 160 RenderViewHost* host = tab_contents_->render_view_host(); |
| 161 if (!host) |
| 162 return false; |
| 163 |
| 164 const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles(); |
| 165 if (profiles.empty()) |
| 166 return false; |
| 167 |
| 168 const AutoFillProfile* profile = NULL; |
| 169 for (std::vector<AutoFillProfile*>::const_iterator iter = profiles.begin(); |
| 170 iter != profiles.end(); ++iter) { |
| 171 if ((*iter)->Label() != label) |
| 172 continue; |
| 173 |
| 174 if ((*iter)->GetFieldText(AutoFillType(NAME_FIRST)) != name && |
| 175 (*iter)->GetFieldText(AutoFillType(NAME_FULL)) != name) |
| 176 continue; |
| 177 |
| 178 profile = *iter; |
| 179 break; |
| 180 } |
| 181 |
| 182 if (!profile) |
| 183 return false; |
| 184 |
| 185 FormData result = form; |
| 186 for (std::vector<FormStructure*>::const_iterator iter = |
| 187 form_structures_.begin(); |
| 188 iter != form_structures_.end(); ++iter) { |
| 189 const FormStructure* form_structure = *iter; |
| 190 if (*form_structure != form) |
| 191 continue; |
| 192 |
| 193 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 194 const AutoFillField* field = form_structure->field(i); |
| 195 |
| 196 for (size_t j = 0; j < result.values.size(); ++j) { |
| 197 if (field->name() == result.elements[j]) { |
| 198 result.values[j] = |
| 199 profile->GetFieldText(AutoFillType(field->heuristic_type())); |
| 200 break; |
| 201 } |
| 202 } |
| 203 } |
| 204 } |
| 205 |
| 206 host->AutoFillFormDataFilled(query_id, result); |
| 207 return true; |
| 208 } |
| 209 |
150 void AutoFillManager::OnAutoFillDialogApply( | 210 void AutoFillManager::OnAutoFillDialogApply( |
151 std::vector<AutoFillProfile>* profiles, | 211 std::vector<AutoFillProfile>* profiles, |
152 std::vector<CreditCard>* credit_cards) { | 212 std::vector<CreditCard>* credit_cards) { |
153 // Save the personal data. | 213 // Save the personal data. |
154 personal_data_->SetProfiles(profiles); | 214 personal_data_->SetProfiles(profiles); |
155 personal_data_->SetCreditCards(credit_cards); | 215 personal_data_->SetCreditCards(credit_cards); |
156 | 216 |
157 HandleSubmit(); | 217 HandleSubmit(); |
158 } | 218 } |
159 | 219 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 std::string xml; | 274 std::string xml; |
215 bool ok = upload_form_structure_->EncodeUploadRequest(false, &xml); | 275 bool ok = upload_form_structure_->EncodeUploadRequest(false, &xml); |
216 DCHECK(ok); | 276 DCHECK(ok); |
217 | 277 |
218 // TODO(jhawkins): Initiate the upload request thread. | 278 // TODO(jhawkins): Initiate the upload request thread. |
219 } | 279 } |
220 | 280 |
221 void AutoFillManager::Reset() { | 281 void AutoFillManager::Reset() { |
222 upload_form_structure_.reset(); | 282 upload_form_structure_.reset(); |
223 } | 283 } |
OLD | NEW |