| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // fields. If there is a visible username before visible password, then ignore | 382 // fields. If there is a visible username before visible password, then ignore |
| 383 // invisible username fields. | 383 // invisible username fields. |
| 384 // If there is no visible password field, don't ignore any elements (i.e. use | 384 // If there is no visible password field, don't ignore any elements (i.e. use |
| 385 // the latest username field just before selected password field). | 385 // the latest username field just before selected password field). |
| 386 bool ignore_invisible_passwords = false; | 386 bool ignore_invisible_passwords = false; |
| 387 bool ignore_invisible_usernames = false; | 387 bool ignore_invisible_usernames = false; |
| 388 FoundVisiblePasswordAndVisibleUsernameBeforePassword( | 388 FoundVisiblePasswordAndVisibleUsernameBeforePassword( |
| 389 form, &ignore_invisible_passwords, &ignore_invisible_usernames); | 389 form, &ignore_invisible_passwords, &ignore_invisible_usernames); |
| 390 std::string layout_sequence; | 390 std::string layout_sequence; |
| 391 layout_sequence.reserve(form.control_elements.size()); | 391 layout_sequence.reserve(form.control_elements.size()); |
| 392 size_t number_of_non_empty_text_non_password_fields = 0; |
| 392 for (size_t i = 0; i < form.control_elements.size(); ++i) { | 393 for (size_t i = 0; i < form.control_elements.size(); ++i) { |
| 393 WebFormControlElement control_element = form.control_elements[i]; | 394 WebFormControlElement control_element = form.control_elements[i]; |
| 394 | 395 |
| 395 WebInputElement* input_element = toWebInputElement(&control_element); | 396 WebInputElement* input_element = toWebInputElement(&control_element); |
| 396 if (!input_element || !input_element->isEnabled()) | 397 if (!input_element || !input_element->isEnabled()) |
| 397 continue; | 398 continue; |
| 398 | 399 |
| 399 bool element_is_invisible = !form_util::IsWebNodeVisible(*input_element); | 400 bool element_is_invisible = !form_util::IsWebNodeVisible(*input_element); |
| 400 if (input_element->isTextField()) { | 401 if (input_element->isTextField()) { |
| 401 if (input_element->isPasswordField()) { | 402 if (input_element->isPasswordField()) { |
| 402 if (element_is_invisible && ignore_invisible_passwords) | 403 if (element_is_invisible && ignore_invisible_passwords) |
| 403 continue; | 404 continue; |
| 404 layout_sequence.push_back('P'); | 405 layout_sequence.push_back('P'); |
| 405 } else { | 406 } else { |
| 407 if (nonscript_modified_values && |
| 408 nonscript_modified_values->find(*input_element) != |
| 409 nonscript_modified_values->end()) |
| 410 ++number_of_non_empty_text_non_password_fields; |
| 406 if (element_is_invisible && ignore_invisible_usernames) | 411 if (element_is_invisible && ignore_invisible_usernames) |
| 407 continue; | 412 continue; |
| 408 layout_sequence.push_back('N'); | 413 layout_sequence.push_back('N'); |
| 409 } | 414 } |
| 410 } | 415 } |
| 411 | 416 |
| 412 bool password_marked_by_autocomplete_attribute = | 417 bool password_marked_by_autocomplete_attribute = |
| 413 HasAutocompleteAttributeValue(*input_element, | 418 HasAutocompleteAttributeValue(*input_element, |
| 414 kAutocompleteCurrentPassword) || | 419 kAutocompleteCurrentPassword) || |
| 415 HasAutocompleteAttributeValue(*input_element, kAutocompleteNewPassword); | 420 HasAutocompleteAttributeValue(*input_element, kAutocompleteNewPassword); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 "PasswordManager.EmptyUsernames.PasswordFieldCount", | 592 "PasswordManager.EmptyUsernames.PasswordFieldCount", |
| 588 std::count(layout_sequence.begin(), layout_sequence.end(), 'P')); | 593 std::count(layout_sequence.begin(), layout_sequence.end(), 'P')); |
| 589 } | 594 } |
| 590 | 595 |
| 591 password_form->scheme = PasswordForm::SCHEME_HTML; | 596 password_form->scheme = PasswordForm::SCHEME_HTML; |
| 592 password_form->ssl_valid = false; | 597 password_form->ssl_valid = false; |
| 593 password_form->preferred = false; | 598 password_form->preferred = false; |
| 594 password_form->blacklisted_by_user = false; | 599 password_form->blacklisted_by_user = false; |
| 595 password_form->type = PasswordForm::TYPE_MANUAL; | 600 password_form->type = PasswordForm::TYPE_MANUAL; |
| 596 | 601 |
| 602 // The password form is considered that it looks like SignUp form if it has |
| 603 // more than 1 text field with user input or it has a new password field and |
| 604 // no current password field. |
| 605 password_form->does_look_like_signup_form = |
| 606 number_of_non_empty_text_non_password_fields > 1 || |
| 607 (number_of_non_empty_text_non_password_fields == 1 && |
| 608 password_form->password_element.empty() && |
| 609 !password_form->new_password_element.empty()); |
| 597 return true; | 610 return true; |
| 598 } | 611 } |
| 599 | 612 |
| 600 } // namespace | 613 } // namespace |
| 601 | 614 |
| 602 bool IsGaiaReauthenticationForm( | 615 bool IsGaiaReauthenticationForm( |
| 603 const GURL& origin, | 616 const GURL& origin, |
| 604 const std::vector<blink::WebFormControlElement>& control_elements) { | 617 const std::vector<blink::WebFormControlElement>& control_elements) { |
| 605 if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin()) | 618 if (origin != GaiaUrls::GetInstance()->gaia_url().GetOrigin()) |
| 606 return false; | 619 return false; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 } | 699 } |
| 687 | 700 |
| 688 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, | 701 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, |
| 689 const char* value_in_lowercase) { | 702 const char* value_in_lowercase) { |
| 690 return base::LowerCaseEqualsASCII( | 703 return base::LowerCaseEqualsASCII( |
| 691 base::StringPiece16(element.getAttribute("autocomplete")), | 704 base::StringPiece16(element.getAttribute("autocomplete")), |
| 692 value_in_lowercase); | 705 value_in_lowercase); |
| 693 } | 706 } |
| 694 | 707 |
| 695 } // namespace autofill | 708 } // namespace autofill |
| OLD | NEW |