| 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/content/renderer/password_form_conversion_utils.h" | 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } else { | 343 } else { |
| 344 found_visible_username = true; | 344 found_visible_username = true; |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 | 348 |
| 349 // Get information about a login form encapsulated in a PasswordForm struct. | 349 // Get information about a login form encapsulated in a PasswordForm struct. |
| 350 // If an element of |form| has an entry in |nonscript_modified_values|, the | 350 // If an element of |form| has an entry in |nonscript_modified_values|, the |
| 351 // associated string is used instead of the element's value to create | 351 // associated string is used instead of the element's value to create |
| 352 // the PasswordForm. | 352 // the PasswordForm. |
| 353 bool GetPasswordForm(const SyntheticForm& form, | 353 bool GetPasswordForm( |
| 354 PasswordForm* password_form, | 354 const SyntheticForm& form, |
| 355 const ModifiedValues* nonscript_modified_values, | 355 PasswordForm* password_form, |
| 356 const FormsPredictionsMap* form_predictions) { | 356 const FieldValueAndPropertiesMaskMap* nonscript_modified_values, |
| 357 const FormsPredictionsMap* form_predictions) { |
| 357 WebInputElement latest_input_element; | 358 WebInputElement latest_input_element; |
| 358 WebInputElement username_element; | 359 WebInputElement username_element; |
| 359 password_form->username_marked_by_site = false; | 360 password_form->username_marked_by_site = false; |
| 360 std::vector<WebInputElement> passwords; | 361 std::vector<WebInputElement> passwords; |
| 361 std::map<blink::WebInputElement, blink::WebInputElement> | 362 std::map<blink::WebInputElement, blink::WebInputElement> |
| 362 last_text_input_before_password; | 363 last_text_input_before_password; |
| 363 std::vector<base::string16> other_possible_usernames; | 364 std::vector<base::string16> other_possible_usernames; |
| 364 | 365 |
| 365 // Bail if this is a GAIA passwords site reauthentication form, so that | 366 // Bail if this is a GAIA passwords site reauthentication form, so that |
| 366 // the form will be ignored. | 367 // the form will be ignored. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 } | 532 } |
| 532 | 533 |
| 533 if (!username_element.isNull()) { | 534 if (!username_element.isNull()) { |
| 534 password_form->username_element = | 535 password_form->username_element = |
| 535 FieldName(username_element, "anonymous_username"); | 536 FieldName(username_element, "anonymous_username"); |
| 536 base::string16 username_value = username_element.value(); | 537 base::string16 username_value = username_element.value(); |
| 537 if (nonscript_modified_values != nullptr) { | 538 if (nonscript_modified_values != nullptr) { |
| 538 auto username_iterator = | 539 auto username_iterator = |
| 539 nonscript_modified_values->find(username_element); | 540 nonscript_modified_values->find(username_element); |
| 540 if (username_iterator != nonscript_modified_values->end()) { | 541 if (username_iterator != nonscript_modified_values->end()) { |
| 541 base::string16 typed_username_value = username_iterator->second; | 542 base::string16 typed_username_value = username_iterator->second.first; |
| 542 if (!base::StartsWith( | 543 if (!base::StartsWith( |
| 543 base::i18n::ToLower(username_value), | 544 base::i18n::ToLower(username_value), |
| 544 base::i18n::ToLower(typed_username_value), | 545 base::i18n::ToLower(typed_username_value), |
| 545 base::CompareCase::SENSITIVE)) { | 546 base::CompareCase::SENSITIVE)) { |
| 546 // We check that |username_value| was not obtained by autofilling | 547 // We check that |username_value| was not obtained by autofilling |
| 547 // |typed_username_value|. In case when it was, |typed_username_value| | 548 // |typed_username_value|. In case when it was, |typed_username_value| |
| 548 // is incomplete, so we should leave autofilled value. | 549 // is incomplete, so we should leave autofilled value. |
| 549 username_value = typed_username_value; | 550 username_value = typed_username_value; |
| 550 } | 551 } |
| 551 } | 552 } |
| 552 } | 553 } |
| 553 password_form->username_value = username_value; | 554 password_form->username_value = username_value; |
| 554 } | 555 } |
| 555 | 556 |
| 556 password_form->origin = | 557 password_form->origin = |
| 557 form_util::GetCanonicalOriginForDocument(form.document); | 558 form_util::GetCanonicalOriginForDocument(form.document); |
| 558 GURL::Replacements rep; | 559 GURL::Replacements rep; |
| 559 rep.SetPathStr(""); | 560 rep.SetPathStr(""); |
| 560 password_form->signon_realm = | 561 password_form->signon_realm = |
| 561 password_form->origin.ReplaceComponents(rep).spec(); | 562 password_form->origin.ReplaceComponents(rep).spec(); |
| 562 password_form->other_possible_usernames.swap(other_possible_usernames); | 563 password_form->other_possible_usernames.swap(other_possible_usernames); |
| 563 | 564 |
| 564 if (!password.isNull()) { | 565 if (!password.isNull()) { |
| 565 password_form->password_element = FieldName(password, "anonymous_password"); | 566 password_form->password_element = FieldName(password, "anonymous_password"); |
| 566 blink::WebString password_value = password.value(); | 567 blink::WebString password_value = password.value(); |
| 567 if (nonscript_modified_values != nullptr) { | 568 if (nonscript_modified_values != nullptr) { |
| 568 auto password_iterator = nonscript_modified_values->find(password); | 569 auto password_iterator = nonscript_modified_values->find(password); |
| 569 if (password_iterator != nonscript_modified_values->end()) | 570 if (password_iterator != nonscript_modified_values->end()) |
| 570 password_value = password_iterator->second; | 571 password_value = password_iterator->second.first; |
| 571 } | 572 } |
| 572 password_form->password_value = password_value; | 573 password_form->password_value = password_value; |
| 573 } | 574 } |
| 574 if (!new_password.isNull()) { | 575 if (!new_password.isNull()) { |
| 575 password_form->new_password_element = | 576 password_form->new_password_element = |
| 576 FieldName(new_password, "anonymous_new_password"); | 577 FieldName(new_password, "anonymous_new_password"); |
| 577 password_form->new_password_value = new_password.value(); | 578 password_form->new_password_value = new_password.value(); |
| 578 password_form->new_password_value_is_default = | 579 password_form->new_password_value_is_default = |
| 579 new_password.getAttribute("value") == new_password.value(); | 580 new_password.getAttribute("value") == new_password.value(); |
| 580 if (HasAutocompleteAttributeValue(new_password, kAutocompleteNewPassword)) | 581 if (HasAutocompleteAttributeValue(new_password, kAutocompleteNewPassword)) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 g_password_site_matcher.Get())) { | 640 g_password_site_matcher.Get())) { |
| 640 has_continue_field = true; | 641 has_continue_field = true; |
| 641 } | 642 } |
| 642 } | 643 } |
| 643 | 644 |
| 644 return has_rart_field && has_continue_field; | 645 return has_rart_field && has_continue_field; |
| 645 } | 646 } |
| 646 | 647 |
| 647 std::unique_ptr<PasswordForm> CreatePasswordFormFromWebForm( | 648 std::unique_ptr<PasswordForm> CreatePasswordFormFromWebForm( |
| 648 const WebFormElement& web_form, | 649 const WebFormElement& web_form, |
| 649 const ModifiedValues* nonscript_modified_values, | 650 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map, |
| 650 const FormsPredictionsMap* form_predictions) { | 651 const FormsPredictionsMap* form_predictions) { |
| 651 if (web_form.isNull()) | 652 if (web_form.isNull()) |
| 652 return std::unique_ptr<PasswordForm>(); | 653 return std::unique_ptr<PasswordForm>(); |
| 653 | 654 |
| 654 std::unique_ptr<PasswordForm> password_form(new PasswordForm()); | 655 std::unique_ptr<PasswordForm> password_form(new PasswordForm()); |
| 655 password_form->action = form_util::GetCanonicalActionForForm(web_form); | 656 password_form->action = form_util::GetCanonicalActionForForm(web_form); |
| 656 if (!password_form->action.is_valid()) | 657 if (!password_form->action.is_valid()) |
| 657 return std::unique_ptr<PasswordForm>(); | 658 return std::unique_ptr<PasswordForm>(); |
| 658 | 659 |
| 659 SyntheticForm synthetic_form; | 660 SyntheticForm synthetic_form; |
| 660 PopulateSyntheticFormFromWebForm(web_form, &synthetic_form); | 661 PopulateSyntheticFormFromWebForm(web_form, &synthetic_form); |
| 661 | 662 |
| 662 WebFormElementToFormData(web_form, blink::WebFormControlElement(), | 663 WebFormElementToFormData(web_form, blink::WebFormControlElement(), |
| 664 field_value_and_properties_map, |
| 663 form_util::EXTRACT_NONE, &password_form->form_data, | 665 form_util::EXTRACT_NONE, &password_form->form_data, |
| 664 NULL /* FormFieldData */); | 666 NULL /* FormFieldData */); |
| 665 | 667 |
| 666 if (!GetPasswordForm(synthetic_form, password_form.get(), | 668 if (!GetPasswordForm(synthetic_form, password_form.get(), |
| 667 nonscript_modified_values, form_predictions)) | 669 field_value_and_properties_map, form_predictions)) |
| 668 return std::unique_ptr<PasswordForm>(); | 670 return std::unique_ptr<PasswordForm>(); |
| 669 | 671 |
| 670 return password_form; | 672 return password_form; |
| 671 } | 673 } |
| 672 | 674 |
| 673 std::unique_ptr<PasswordForm> CreatePasswordFormFromUnownedInputElements( | 675 std::unique_ptr<PasswordForm> CreatePasswordFormFromUnownedInputElements( |
| 674 const WebFrame& frame, | 676 const WebFrame& frame, |
| 675 const ModifiedValues* nonscript_modified_values, | 677 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map, |
| 676 const FormsPredictionsMap* form_predictions) { | 678 const FormsPredictionsMap* form_predictions) { |
| 677 SyntheticForm synthetic_form; | 679 SyntheticForm synthetic_form; |
| 678 synthetic_form.control_elements = form_util::GetUnownedFormFieldElements( | 680 synthetic_form.control_elements = form_util::GetUnownedFormFieldElements( |
| 679 frame.document().all(), &synthetic_form.fieldsets); | 681 frame.document().all(), &synthetic_form.fieldsets); |
| 680 synthetic_form.document = frame.document(); | 682 synthetic_form.document = frame.document(); |
| 681 | 683 |
| 682 if (synthetic_form.control_elements.empty()) | 684 if (synthetic_form.control_elements.empty()) |
| 683 return std::unique_ptr<PasswordForm>(); | 685 return std::unique_ptr<PasswordForm>(); |
| 684 | 686 |
| 685 std::unique_ptr<PasswordForm> password_form(new PasswordForm()); | 687 std::unique_ptr<PasswordForm> password_form(new PasswordForm()); |
| 686 UnownedPasswordFormElementsAndFieldSetsToFormData( | 688 UnownedPasswordFormElementsAndFieldSetsToFormData( |
| 687 synthetic_form.fieldsets, synthetic_form.control_elements, nullptr, | 689 synthetic_form.fieldsets, synthetic_form.control_elements, nullptr, |
| 688 frame.document(), form_util::EXTRACT_NONE, &password_form->form_data, | 690 frame.document(), field_value_and_properties_map, form_util::EXTRACT_NONE, |
| 689 nullptr /* FormFieldData */); | 691 &password_form->form_data, nullptr /* FormFieldData */); |
| 690 if (!GetPasswordForm(synthetic_form, password_form.get(), | 692 if (!GetPasswordForm(synthetic_form, password_form.get(), |
| 691 nonscript_modified_values, form_predictions)) | 693 field_value_and_properties_map, form_predictions)) |
| 692 return std::unique_ptr<PasswordForm>(); | 694 return std::unique_ptr<PasswordForm>(); |
| 693 | 695 |
| 694 // No actual action on the form, so use the the origin as the action. | 696 // No actual action on the form, so use the the origin as the action. |
| 695 password_form->action = password_form->origin; | 697 password_form->action = password_form->origin; |
| 696 | 698 |
| 697 return password_form; | 699 return password_form; |
| 698 } | 700 } |
| 699 | 701 |
| 700 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, | 702 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, |
| 701 const char* value_in_lowercase) { | 703 const char* value_in_lowercase) { |
| 702 return base::LowerCaseEqualsASCII( | 704 return base::LowerCaseEqualsASCII( |
| 703 base::StringPiece16(element.getAttribute("autocomplete")), | 705 base::StringPiece16(element.getAttribute("autocomplete")), |
| 704 value_in_lowercase); | 706 value_in_lowercase); |
| 705 } | 707 } |
| 706 | 708 |
| 707 } // namespace autofill | 709 } // namespace autofill |
| OLD | NEW |