| 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 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 | 664 |
| 665 // If we can't modify the password, don't try to set the username | 665 // If we can't modify the password, don't try to set the username |
| 666 if (!IsElementAutocompletable(password_element)) | 666 if (!IsElementAutocompletable(password_element)) |
| 667 return; | 667 return; |
| 668 | 668 |
| 669 // Try to set the username to the preferred name, but only if the field | 669 // Try to set the username to the preferred name, but only if the field |
| 670 // can be set and isn't prefilled. | 670 // can be set and isn't prefilled. |
| 671 if (IsElementAutocompletable(username_element) && | 671 if (IsElementAutocompletable(username_element) && |
| 672 username_element.value().isEmpty()) { | 672 username_element.value().isEmpty()) { |
| 673 // TODO(tkent): Check maxlength and pattern. | 673 // TODO(tkent): Check maxlength and pattern. |
| 674 username_element.setValue(fill_data.basic_data.fields[0].value); | 674 username_element.setValue(fill_data.basic_data.fields[0].value, true); |
| 675 } | 675 } |
| 676 | 676 |
| 677 // Fill if we have an exact match for the username. Note that this sets | 677 // Fill if we have an exact match for the username. Note that this sets |
| 678 // username to autofilled. | 678 // username to autofilled. |
| 679 FillUserNameAndPassword(&username_element, &password_element, fill_data, | 679 FillUserNameAndPassword(&username_element, &password_element, fill_data, |
| 680 true /* exact_username_match */, | 680 true /* exact_username_match */, |
| 681 false /* set_selection */); | 681 false /* set_selection */); |
| 682 } | 682 } |
| 683 | 683 |
| 684 bool PasswordAutofillAgent::FillUserNameAndPassword( | 684 bool PasswordAutofillAgent::FillUserNameAndPassword( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // TODO(tkent): Check maxlength and pattern for both username and password | 735 // TODO(tkent): Check maxlength and pattern for both username and password |
| 736 // fields. | 736 // fields. |
| 737 | 737 |
| 738 // Don't fill username if password can't be set. | 738 // Don't fill username if password can't be set. |
| 739 if (!IsElementAutocompletable(*password_element)) { | 739 if (!IsElementAutocompletable(*password_element)) { |
| 740 return false; | 740 return false; |
| 741 } | 741 } |
| 742 | 742 |
| 743 // Input matches the username, fill in required values. | 743 // Input matches the username, fill in required values. |
| 744 if (IsElementAutocompletable(*username_element)) { | 744 if (IsElementAutocompletable(*username_element)) { |
| 745 username_element->setValue(username); | 745 username_element->setValue(username, true); |
| 746 SetElementAutofilled(username_element, true); | 746 SetElementAutofilled(username_element, true); |
| 747 | 747 |
| 748 if (set_selection) { | 748 if (set_selection) { |
| 749 username_element->setSelectionRange(current_username.length(), | 749 username_element->setSelectionRange(current_username.length(), |
| 750 username.length()); | 750 username.length()); |
| 751 } | 751 } |
| 752 } else if (current_username != username) { | 752 } else if (current_username != username) { |
| 753 // If the username can't be filled and it doesn't match a saved password | 753 // If the username can't be filled and it doesn't match a saved password |
| 754 // as is, don't autofill a password. | 754 // as is, don't autofill a password. |
| 755 return false; | 755 return false; |
| 756 } | 756 } |
| 757 | 757 |
| 758 // If a user gesture has not occurred, we setup a handler to listen for the | 758 // If a user gesture has not occurred, we setup a handler to listen for the |
| 759 // next user gesture, at which point we then fill in the password. This is to | 759 // next user gesture, at which point we then fill in the password. This is to |
| 760 // make sure that we do not fill in the DOM with a password until we believe | 760 // make sure that we do not fill in the DOM with a password until we believe |
| 761 // the user is intentionally interacting with the page. | 761 // the user is intentionally interacting with the page. |
| 762 if (!user_gesture_occurred_) { | 762 if (!user_gesture_occurred_) { |
| 763 gesture_handler_->addElement(*password_element); | 763 gesture_handler_->addElement(*password_element); |
| 764 password_element->setSuggestedValue(password); | 764 password_element->setSuggestedValue(password); |
| 765 } else { | 765 } else { |
| 766 password_element->setValue(password); | 766 password_element->setValue(password, true); |
| 767 } | 767 } |
| 768 SetElementAutofilled(password_element, true); | 768 // Note: Don't call SetElementAutofilled() here, as that dispatches an |
| 769 // onChange event in JavaScript, which is not appropriate for the password |
| 770 // element if a user gesture has not yet occured. |
| 771 password_element->setAutofilled(true); |
| 769 return true; | 772 return true; |
| 770 } | 773 } |
| 771 | 774 |
| 772 void PasswordAutofillAgent::PerformInlineAutocomplete( | 775 void PasswordAutofillAgent::PerformInlineAutocomplete( |
| 773 const blink::WebInputElement& username_input, | 776 const blink::WebInputElement& username_input, |
| 774 const blink::WebInputElement& password_input, | 777 const blink::WebInputElement& password_input, |
| 775 const PasswordFormFillData& fill_data) { | 778 const PasswordFormFillData& fill_data) { |
| 776 DCHECK(!fill_data.wait_for_username); | 779 DCHECK(!fill_data.wait_for_username); |
| 777 | 780 |
| 778 // We need non-const versions of the username and password inputs. | 781 // We need non-const versions of the username and password inputs. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 *found_password = iter->second; | 839 *found_password = iter->second; |
| 837 return true; | 840 return true; |
| 838 } | 841 } |
| 839 | 842 |
| 840 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { | 843 void PasswordAutofillAgent::AutofillWebUserGestureHandler::onGesture() { |
| 841 agent_->set_user_gesture_occurred(true); | 844 agent_->set_user_gesture_occurred(true); |
| 842 | 845 |
| 843 std::vector<blink::WebInputElement>::iterator iter; | 846 std::vector<blink::WebInputElement>::iterator iter; |
| 844 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { | 847 for (iter = elements_.begin(); iter != elements_.end(); ++iter) { |
| 845 if (!iter->isNull() && !iter->suggestedValue().isNull()) | 848 if (!iter->isNull() && !iter->suggestedValue().isNull()) |
| 846 iter->setValue(iter->suggestedValue()); | 849 iter->setValue(iter->suggestedValue(), true); |
| 847 } | 850 } |
| 848 | 851 |
| 849 elements_.clear(); | 852 elements_.clear(); |
| 850 } | 853 } |
| 851 | 854 |
| 852 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 855 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 853 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) | 856 AutofillWebUserGestureHandler(PasswordAutofillAgent* agent) |
| 854 : agent_(agent) {} | 857 : agent_(agent) {} |
| 855 | 858 |
| 856 PasswordAutofillAgent::AutofillWebUserGestureHandler:: | 859 PasswordAutofillAgent::AutofillWebUserGestureHandler:: |
| 857 ~AutofillWebUserGestureHandler() {} | 860 ~AutofillWebUserGestureHandler() {} |
| 858 | 861 |
| 859 } // namespace autofill | 862 } // namespace autofill |
| OLD | NEW |