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