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_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 !password_element.autoComplete())) | 650 !password_element.autoComplete())) |
651 return; | 651 return; |
652 | 652 |
653 // Try to set the username to the preferred name, but only if the field | 653 // Try to set the username to the preferred name, but only if the field |
654 // can be set and isn't prefilled. | 654 // can be set and isn't prefilled. |
655 if (IsElementEditable(username_element) && | 655 if (IsElementEditable(username_element) && |
656 (ShouldIgnoreAutocompleteOffForPasswordFields() || | 656 (ShouldIgnoreAutocompleteOffForPasswordFields() || |
657 username_element.autoComplete()) && | 657 username_element.autoComplete()) && |
658 username_element.value().isEmpty()) { | 658 username_element.value().isEmpty()) { |
659 // TODO(tkent): Check maxlength and pattern. | 659 // TODO(tkent): Check maxlength and pattern. |
660 username_element.setValue(fill_data.basic_data.fields[0].value); | 660 username_element.setValue(fill_data.basic_data.fields[0].value, true); |
661 } | 661 } |
662 | 662 |
663 // Fill if we have an exact match for the username. Note that this sets | 663 // Fill if we have an exact match for the username. Note that this sets |
664 // username to autofilled. | 664 // username to autofilled. |
665 FillUserNameAndPassword(&username_element, &password_element, fill_data, | 665 FillUserNameAndPassword(&username_element, &password_element, fill_data, |
666 true /* exact_username_match */, | 666 true /* exact_username_match */, |
667 false /* set_selection */); | 667 false /* set_selection */); |
668 } | 668 } |
669 | 669 |
670 bool PasswordAutofillAgent::FillUserNameAndPassword( | 670 bool PasswordAutofillAgent::FillUserNameAndPassword( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 if (!IsElementEditable(*password_element) || | 725 if (!IsElementEditable(*password_element) || |
726 (!ShouldIgnoreAutocompleteOffForPasswordFields() && | 726 (!ShouldIgnoreAutocompleteOffForPasswordFields() && |
727 !password_element->autoComplete())) { | 727 !password_element->autoComplete())) { |
728 return false; | 728 return false; |
729 } | 729 } |
730 | 730 |
731 // Input matches the username, fill in required values. | 731 // Input matches the username, fill in required values. |
732 if (IsElementEditable(*username_element) && | 732 if (IsElementEditable(*username_element) && |
733 (ShouldIgnoreAutocompleteOffForPasswordFields() || | 733 (ShouldIgnoreAutocompleteOffForPasswordFields() || |
734 username_element->autoComplete())) { | 734 username_element->autoComplete())) { |
735 username_element->setValue(username); | 735 username_element->setValue(username, true); |
736 SetElementAutofilled(username_element, true); | 736 SetElementAutofilled(username_element, true); |
737 | 737 |
738 if (set_selection) { | 738 if (set_selection) { |
739 username_element->setSelectionRange(current_username.length(), | 739 username_element->setSelectionRange(current_username.length(), |
740 username.length()); | 740 username.length()); |
741 } | 741 } |
742 } else if (current_username != username) { | 742 } else if (current_username != username) { |
743 // If the username can't be filled and it doesn't match a saved password | 743 // If the username can't be filled and it doesn't match a saved password |
744 // as is, don't autofill a password. | 744 // as is, don't autofill a password. |
745 return false; | 745 return false; |
746 } | 746 } |
747 | 747 |
748 // If a user gesture has not occurred, we setup a handler to listen for the | 748 // If a user gesture has not occurred, we setup a handler to listen for the |
749 // next user gesture, at which point we then fill in the password. This is to | 749 // next user gesture, at which point we then fill in the password. This is to |
750 // make sure that we do not fill in the DOM with a password until we believe | 750 // make sure that we do not fill in the DOM with a password until we believe |
751 // the user is intentionally interacting with the page. | 751 // the user is intentionally interacting with the page. |
752 if (!user_gesture_occurred_) { | 752 if (!user_gesture_occurred_) { |
753 gesture_handler_->addElement(*password_element); | 753 gesture_handler_->addElement(*password_element); |
754 password_element->setSuggestedValue(password); | 754 password_element->setSuggestedValue(password); |
755 } else { | 755 } else { |
756 password_element->setValue(password); | 756 password_element->setValue(password, true); |
757 } | 757 } |
758 SetElementAutofilled(password_element, true); | 758 // Note: Don't call SetElementAutofilled() here, as that dispatches an |
| 759 // onChange event in JavaScript, which is not appropriate for the password |
| 760 // element if a user gesture has not yet occured. |
| 761 password_element->setAutofilled(true); |
759 return true; | 762 return true; |
760 } | 763 } |
761 | 764 |
762 void PasswordAutofillAgent::PerformInlineAutocomplete( | 765 void PasswordAutofillAgent::PerformInlineAutocomplete( |
763 const blink::WebInputElement& username_input, | 766 const blink::WebInputElement& username_input, |
764 const blink::WebInputElement& password_input, | 767 const blink::WebInputElement& password_input, |
765 const PasswordFormFillData& fill_data) { | 768 const PasswordFormFillData& fill_data) { |
766 DCHECK(!fill_data.wait_for_username); | 769 DCHECK(!fill_data.wait_for_username); |
767 | 770 |
768 // We need non-const versions of the username and password inputs. | 771 // We need non-const versions of the username and password inputs. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 *found_password = iter->second; | 829 *found_password = iter->second; |
827 return true; | 830 return true; |
828 } | 831 } |
829 | 832 |
830 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { | 833 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { |
831 agent_->set_user_gesture_occurred(true); | 834 agent_->set_user_gesture_occurred(true); |
832 | 835 |
833 std::vector<blink::WebInputElement>::iterator iter; | 836 std::vector<blink::WebInputElement>::iterator iter; |
834 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { | 837 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { |
835 if (!iter->isNull() && !iter->suggestedValue().isNull()) | 838 if (!iter->isNull() && !iter->suggestedValue().isNull()) |
836 iter->setValue(iter->suggestedValue()); | 839 iter->setValue(iter->suggestedValue(), true); |
837 } | 840 } |
838 | 841 |
839 elements_.clear(); | 842 elements_.clear(); |
840 } | 843 } |
841 | 844 |
842 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 845 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
843 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) | 846 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) |
844 : agent_(agent) {} | 847 : agent_(agent) {} |
845 | 848 |
846 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 849 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
847 ~AutofillWebUserGestureHandler() {} | 850 ~AutofillWebUserGestureHandler() {} |
848 | 851 |
849 } // namespace autofill | 852 } // namespace autofill |
OLD | NEW |