| 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 unique_id, &data_model, &variant, &is_credit_card) || | 543 unique_id, &data_model, &variant, &is_credit_card) || |
| 544 !GetCachedFormAndField(form, field, &form_structure, &autofill_field)) | 544 !GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
| 545 return; | 545 return; |
| 546 | 546 |
| 547 DCHECK(form_structure); | 547 DCHECK(form_structure); |
| 548 DCHECK(autofill_field); | 548 DCHECK(autofill_field); |
| 549 | 549 |
| 550 FormData result = form; | 550 FormData result = form; |
| 551 | 551 |
| 552 base::string16 profile_full_name; | 552 base::string16 profile_full_name; |
| 553 std::string profile_language_code; |
| 553 if (!is_credit_card) { | 554 if (!is_credit_card) { |
| 554 profile_full_name = data_model->GetInfo( | 555 profile_full_name = data_model->GetInfo( |
| 555 AutofillType(NAME_FULL), app_locale_); | 556 AutofillType(NAME_FULL), app_locale_); |
| 557 profile_language_code = |
| 558 static_cast<const AutofillProfile*>(data_model)->language_code(); |
| 556 } | 559 } |
| 557 | 560 |
| 558 // If the relevant section is auto-filled, we should fill |field| but not the | 561 // If the relevant section is auto-filled, we should fill |field| but not the |
| 559 // rest of the form. | 562 // rest of the form. |
| 560 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { | 563 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { |
| 561 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); | 564 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); |
| 562 iter != result.fields.end(); ++iter) { | 565 iter != result.fields.end(); ++iter) { |
| 563 if ((*iter) == field) { | 566 if ((*iter) == field) { |
| 564 base::string16 value = data_model->GetInfoForVariant( | 567 base::string16 value = data_model->GetInfoForVariant( |
| 565 autofill_field->Type(), variant, app_locale_); | 568 autofill_field->Type(), variant, app_locale_); |
| 566 if (AutofillField::FillFormField( | 569 if (AutofillField::FillFormField(*autofill_field, |
| 567 *autofill_field, value, app_locale_, &(*iter))) { | 570 value, |
| 571 profile_language_code, |
| 572 app_locale_, |
| 573 &(*iter))) { |
| 568 // Mark the cached field as autofilled, so that we can detect when a | 574 // Mark the cached field as autofilled, so that we can detect when a |
| 569 // user edits an autofilled field (for metrics). | 575 // user edits an autofilled field (for metrics). |
| 570 autofill_field->is_autofilled = true; | 576 autofill_field->is_autofilled = true; |
| 571 | 577 |
| 572 // Mark the field as autofilled when a non-empty value is assigned to | 578 // Mark the field as autofilled when a non-empty value is assigned to |
| 573 // it. This allows the renderer to distinguish autofilled fields from | 579 // it. This allows the renderer to distinguish autofilled fields from |
| 574 // fields with non-empty values, such as select-one fields. | 580 // fields with non-empty values, such as select-one fields. |
| 575 iter->is_autofilled = true; | 581 iter->is_autofilled = true; |
| 576 | 582 |
| 577 if (!is_credit_card && !value.empty()) | 583 if (!is_credit_card && !value.empty()) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // Must match ForEachMatchingFormField() in form_autofill_util.cc. | 619 // Must match ForEachMatchingFormField() in form_autofill_util.cc. |
| 614 // Only notify autofilling of empty fields and the field that initiated | 620 // Only notify autofilling of empty fields and the field that initiated |
| 615 // the filling (note that "select-one" controls may not be empty but will | 621 // the filling (note that "select-one" controls may not be empty but will |
| 616 // still be autofilled). | 622 // still be autofilled). |
| 617 bool should_notify = | 623 bool should_notify = |
| 618 !is_credit_card && | 624 !is_credit_card && |
| 619 !value.empty() && | 625 !value.empty() && |
| 620 (result.fields[i] == field || | 626 (result.fields[i] == field || |
| 621 result.fields[i].form_control_type == "select-one" || | 627 result.fields[i].form_control_type == "select-one" || |
| 622 result.fields[i].value.empty()); | 628 result.fields[i].value.empty()); |
| 623 if (AutofillField::FillFormField( | 629 if (AutofillField::FillFormField(*cached_field, |
| 624 *cached_field, value, app_locale_, &result.fields[i])) { | 630 value, |
| 631 profile_language_code, |
| 632 app_locale_, |
| 633 &result.fields[i])) { |
| 625 // Mark the cached field as autofilled, so that we can detect when a | 634 // Mark the cached field as autofilled, so that we can detect when a |
| 626 // user edits an autofilled field (for metrics). | 635 // user edits an autofilled field (for metrics). |
| 627 form_structure->field(i)->is_autofilled = true; | 636 form_structure->field(i)->is_autofilled = true; |
| 628 | 637 |
| 629 // Mark the field as autofilled when a non-empty value is assigned to | 638 // Mark the field as autofilled when a non-empty value is assigned to |
| 630 // it. This allows the renderer to distinguish autofilled fields from | 639 // it. This allows the renderer to distinguish autofilled fields from |
| 631 // fields with non-empty values, such as select-one fields. | 640 // fields with non-empty values, such as select-one fields. |
| 632 result.fields[i].is_autofilled = true; | 641 result.fields[i].is_autofilled = true; |
| 633 | 642 |
| 634 if (should_notify) | 643 if (should_notify) |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 return false; | 1220 return false; |
| 1212 | 1221 |
| 1213 // Disregard forms that we wouldn't ever autofill in the first place. | 1222 // Disregard forms that we wouldn't ever autofill in the first place. |
| 1214 if (!form.ShouldBeParsed()) | 1223 if (!form.ShouldBeParsed()) |
| 1215 return false; | 1224 return false; |
| 1216 | 1225 |
| 1217 return true; | 1226 return true; |
| 1218 } | 1227 } |
| 1219 | 1228 |
| 1220 } // namespace autofill | 1229 } // namespace autofill |
| OLD | NEW |