| 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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 base::Owned(submitted_form.release()), | 375 base::Owned(submitted_form.release()), |
| 376 forms_loaded_timestamps_[form], | 376 forms_loaded_timestamps_[form], |
| 377 initial_interaction_timestamp_, | 377 initial_interaction_timestamp_, |
| 378 timestamp)); | 378 timestamp)); |
| 379 } | 379 } |
| 380 | 380 |
| 381 return true; | 381 return true; |
| 382 } | 382 } |
| 383 | 383 |
| 384 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 384 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
| 385 size_t unowned_form_index, |
| 385 const TimeTicks& timestamp) { | 386 const TimeTicks& timestamp) { |
| 387 if (unowned_form_index > forms.size()) |
| 388 return; |
| 389 |
| 386 if (!IsValidFormDataVector(forms)) | 390 if (!IsValidFormDataVector(forms)) |
| 387 return; | 391 return; |
| 388 | 392 |
| 389 if (!driver_->RendererIsAvailable()) | 393 if (!driver_->RendererIsAvailable()) |
| 390 return; | 394 return; |
| 391 | 395 |
| 392 bool enabled = IsAutofillEnabled(); | 396 bool enabled = IsAutofillEnabled(); |
| 393 if (!has_logged_autofill_enabled_) { | 397 if (!has_logged_autofill_enabled_) { |
| 394 AutofillMetrics::LogIsAutofillEnabledAtPageLoad(enabled); | 398 AutofillMetrics::LogIsAutofillEnabledAtPageLoad(enabled); |
| 395 has_logged_autofill_enabled_ = true; | 399 has_logged_autofill_enabled_ = true; |
| 396 } | 400 } |
| 397 | 401 |
| 398 if (!enabled) | 402 if (!enabled) |
| 399 return; | 403 return; |
| 400 | 404 |
| 401 for (size_t i = 0; i < forms.size(); ++i) { | 405 for (size_t i = 0; i < forms.size(); ++i) { |
| 402 forms_loaded_timestamps_[forms[i]] = timestamp; | 406 forms_loaded_timestamps_[forms[i]] = timestamp; |
| 403 } | 407 } |
| 404 | 408 |
| 405 ParseForms(forms); | 409 ParseForms(forms, unowned_form_index); |
| 406 } | 410 } |
| 407 | 411 |
| 408 void AutofillManager::OnTextFieldDidChange(const FormData& form, | 412 void AutofillManager::OnTextFieldDidChange(const FormData& form, |
| 409 const FormFieldData& field, | 413 const FormFieldData& field, |
| 410 const TimeTicks& timestamp) { | 414 const TimeTicks& timestamp) { |
| 411 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 415 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
| 412 return; | 416 return; |
| 413 | 417 |
| 414 FormStructure* form_structure = NULL; | 418 FormStructure* form_structure = NULL; |
| 415 AutofillField* autofill_field = NULL; | 419 AutofillField* autofill_field = NULL; |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 const AutofillType& type) const { | 1204 const AutofillType& type) const { |
| 1201 std::vector<Suggestion> suggestions = | 1205 std::vector<Suggestion> suggestions = |
| 1202 personal_data_->GetCreditCardSuggestions(type, field.value); | 1206 personal_data_->GetCreditCardSuggestions(type, field.value); |
| 1203 for (size_t i = 0; i < suggestions.size(); i++) { | 1207 for (size_t i = 0; i < suggestions.size(); i++) { |
| 1204 suggestions[i].frontend_id = | 1208 suggestions[i].frontend_id = |
| 1205 MakeFrontendID(suggestions[i].backend_id, SuggestionBackendID()); | 1209 MakeFrontendID(suggestions[i].backend_id, SuggestionBackendID()); |
| 1206 } | 1210 } |
| 1207 return suggestions; | 1211 return suggestions; |
| 1208 } | 1212 } |
| 1209 | 1213 |
| 1210 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1214 void AutofillManager::ParseForms(const std::vector<FormData>& forms, |
| 1215 size_t unowned_form_index) { |
| 1211 std::vector<FormStructure*> non_queryable_forms; | 1216 std::vector<FormStructure*> non_queryable_forms; |
| 1212 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1217 for (size_t i = 0; i < forms.size(); ++i) { |
| 1213 iter != forms.end(); ++iter) { | 1218 scoped_ptr<FormStructure> form_structure(new FormStructure(forms[i])); |
| 1214 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | |
| 1215 if (!form_structure->ShouldBeParsed()) | 1219 if (!form_structure->ShouldBeParsed()) |
| 1216 continue; | 1220 continue; |
| 1217 | 1221 |
| 1222 if (i == unowned_form_index) |
| 1223 form_structure->set_is_unowned(); |
| 1224 |
| 1218 form_structure->DetermineHeuristicTypes(); | 1225 form_structure->DetermineHeuristicTypes(); |
| 1219 | 1226 |
| 1220 if (form_structure->ShouldBeCrowdsourced()) | 1227 if (form_structure->ShouldBeCrowdsourced()) |
| 1221 form_structures_.push_back(form_structure.release()); | 1228 form_structures_.push_back(form_structure.release()); |
| 1222 else | 1229 else |
| 1223 non_queryable_forms.push_back(form_structure.release()); | 1230 non_queryable_forms.push_back(form_structure.release()); |
| 1224 } | 1231 } |
| 1225 | 1232 |
| 1226 if (!form_structures_.empty() && download_manager_) { | 1233 if (!form_structures_.empty() && download_manager_) { |
| 1227 // Query the server if at least one of the forms was parsed. | 1234 // Query the server if at least one of the forms was parsed. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 return false; | 1328 return false; |
| 1322 | 1329 |
| 1323 // Disregard forms that we wouldn't ever autofill in the first place. | 1330 // Disregard forms that we wouldn't ever autofill in the first place. |
| 1324 if (!form.ShouldBeParsed()) | 1331 if (!form.ShouldBeParsed()) |
| 1325 return false; | 1332 return false; |
| 1326 | 1333 |
| 1327 return true; | 1334 return true; |
| 1328 } | 1335 } |
| 1329 | 1336 |
| 1330 } // namespace autofill | 1337 } // namespace autofill |
| OLD | NEW |