| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 return username1 == username2; | 274 return username1 == username2; |
| 275 return FieldIsSuggestionSubstringStartingOnTokenBoundary(username1, username2, | 275 return FieldIsSuggestionSubstringStartingOnTokenBoundary(username1, username2, |
| 276 true); | 276 true); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Returns |true| if the given element is editable. Otherwise, returns |false|. | 279 // Returns |true| if the given element is editable. Otherwise, returns |false|. |
| 280 bool IsElementAutocompletable(const blink::WebInputElement& element) { | 280 bool IsElementAutocompletable(const blink::WebInputElement& element) { |
| 281 return IsElementEditable(element); | 281 return IsElementEditable(element); |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Returns whether the |username_element| is allowed to be autofilled. |
| 285 // |
| 286 // Note that if the user interacts with the |password_field| and the |
| 287 // |username_element| is user-defined (i.e., non-empty and non-autofilled), then |
| 288 // this function returns false. This is a precaution, to not override the field |
| 289 // if it has been classified as username by accident. |
| 290 bool IsUsernameAmendable(const blink::WebInputElement& username_element, |
| 291 bool is_password_field_selected) { |
| 292 return !username_element.IsNull() && |
| 293 IsElementAutocompletable(username_element) && |
| 294 (!is_password_field_selected || username_element.IsAutofilled() || |
| 295 username_element.Value().IsEmpty()); |
| 296 } |
| 297 |
| 284 // Return true if either password_value or new_password_value is not empty and | 298 // Return true if either password_value or new_password_value is not empty and |
| 285 // not default. | 299 // not default. |
| 286 bool FormContainsNonDefaultPasswordValue(const PasswordForm& password_form) { | 300 bool FormContainsNonDefaultPasswordValue(const PasswordForm& password_form) { |
| 287 return (!password_form.password_value.empty() && | 301 return (!password_form.password_value.empty() && |
| 288 !password_form.password_value_is_default) || | 302 !password_form.password_value_is_default) || |
| 289 (!password_form.new_password_value.empty() && | 303 (!password_form.new_password_value.empty() && |
| 290 !password_form.new_password_value_is_default); | 304 !password_form.new_password_value_is_default); |
| 291 } | 305 } |
| 292 | 306 |
| 293 // Log a message including the name, method and action of |form|. | 307 // Log a message including the name, method and action of |form|. |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 if (!FindPasswordInfoForElement(*element, &username_element, | 780 if (!FindPasswordInfoForElement(*element, &username_element, |
| 767 &password_element, &password_info) || | 781 &password_element, &password_info) || |
| 768 !IsElementAutocompletable(password_element)) { | 782 !IsElementAutocompletable(password_element)) { |
| 769 return false; | 783 return false; |
| 770 } | 784 } |
| 771 | 785 |
| 772 password_info->password_was_edited_last = false; | 786 password_info->password_was_edited_last = false; |
| 773 if (element->IsPasswordField()) { | 787 if (element->IsPasswordField()) { |
| 774 password_info->password_field_suggestion_was_accepted = true; | 788 password_info->password_field_suggestion_was_accepted = true; |
| 775 password_info->password_field = password_element; | 789 password_info->password_field = password_element; |
| 776 } else if (!username_element.IsNull() && | 790 } |
| 777 IsElementAutocompletable(username_element)) { | 791 |
| 792 if (IsUsernameAmendable(username_element, element->IsPasswordField())) { |
| 778 username_element.SetAutofillValue(blink::WebString::FromUTF16(username)); | 793 username_element.SetAutofillValue(blink::WebString::FromUTF16(username)); |
| 779 username_element.SetAutofilled(true); | 794 username_element.SetAutofilled(true); |
| 780 UpdateFieldValueAndPropertiesMaskMap(username_element, &username, | 795 UpdateFieldValueAndPropertiesMaskMap(username_element, &username, |
| 781 FieldPropertiesFlags::AUTOFILLED, | 796 FieldPropertiesFlags::AUTOFILLED, |
| 782 &field_value_and_properties_map_); | 797 &field_value_and_properties_map_); |
| 783 } | 798 } |
| 784 | 799 |
| 785 password_element.SetAutofillValue(blink::WebString::FromUTF16(password)); | 800 password_element.SetAutofillValue(blink::WebString::FromUTF16(password)); |
| 786 password_element.SetAutofilled(true); | 801 password_element.SetAutofilled(true); |
| 787 UpdateFieldValueAndPropertiesMaskMap(password_element, &password, | 802 UpdateFieldValueAndPropertiesMaskMap(password_element, &password, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 807 blink::WebInputElement username_element; | 822 blink::WebInputElement username_element; |
| 808 blink::WebInputElement password_element; | 823 blink::WebInputElement password_element; |
| 809 PasswordInfo* password_info; | 824 PasswordInfo* password_info; |
| 810 | 825 |
| 811 if (!FindPasswordInfoForElement(*element, &username_element, | 826 if (!FindPasswordInfoForElement(*element, &username_element, |
| 812 &password_element, &password_info) || | 827 &password_element, &password_info) || |
| 813 !IsElementAutocompletable(password_element)) { | 828 !IsElementAutocompletable(password_element)) { |
| 814 return false; | 829 return false; |
| 815 } | 830 } |
| 816 | 831 |
| 817 if (!element->IsPasswordField() && !username_element.IsNull() && | 832 if (IsUsernameAmendable(username_element, element->IsPasswordField())) { |
| 818 IsElementAutocompletable(username_element)) { | |
| 819 if (username_query_prefix_.empty()) | 833 if (username_query_prefix_.empty()) |
| 820 username_query_prefix_ = username_element.Value().Utf16(); | 834 username_query_prefix_ = username_element.Value().Utf16(); |
| 821 | 835 |
| 822 was_username_autofilled_ = username_element.IsAutofilled(); | 836 was_username_autofilled_ = username_element.IsAutofilled(); |
| 823 username_element.SetSuggestedValue(username); | 837 username_element.SetSuggestedValue(username); |
| 824 username_element.SetAutofilled(true); | 838 username_element.SetAutofilled(true); |
| 825 form_util::PreviewSuggestion(username_element.SuggestedValue().Utf16(), | 839 form_util::PreviewSuggestion(username_element.SuggestedValue().Utf16(), |
| 826 username_query_prefix_, &username_element); | 840 username_query_prefix_, &username_element); |
| 827 } | 841 } |
| 828 was_password_autofilled_ = password_element.IsAutofilled(); | 842 was_password_autofilled_ = password_element.IsAutofilled(); |
| 829 password_element.SetSuggestedValue(password); | 843 password_element.SetSuggestedValue(password); |
| 830 password_element.SetAutofilled(true); | 844 password_element.SetAutofilled(true); |
| 831 | 845 |
| 832 return true; | 846 return true; |
| 833 } | 847 } |
| 834 | 848 |
| 835 bool PasswordAutofillAgent::DidClearAutofillSelection( | 849 bool PasswordAutofillAgent::DidClearAutofillSelection( |
| 836 const blink::WebFormControlElement& control_element) { | 850 const blink::WebFormControlElement& control_element) { |
| 837 const blink::WebInputElement* element = ToWebInputElement(&control_element); | 851 const blink::WebInputElement* element = ToWebInputElement(&control_element); |
| 838 if (!element) | 852 if (!element) |
| 839 return false; | 853 return false; |
| 840 | 854 |
| 841 blink::WebInputElement username_element; | 855 blink::WebInputElement username_element; |
| 842 blink::WebInputElement password_element; | 856 blink::WebInputElement password_element; |
| 843 PasswordInfo* password_info; | 857 PasswordInfo* password_info; |
| 844 | 858 |
| 845 if (!FindPasswordInfoForElement(*element, &username_element, | 859 if (!FindPasswordInfoForElement(*element, &username_element, |
| 846 &password_element, &password_info)) | 860 &password_element, &password_info)) { |
| 847 return false; | 861 return false; |
| 862 } |
| 848 | 863 |
| 849 ClearPreview(&username_element, &password_element); | 864 ClearPreview(&username_element, &password_element); |
| 850 return true; | 865 return true; |
| 851 } | 866 } |
| 852 | 867 |
| 853 bool PasswordAutofillAgent::FindPasswordInfoForElement( | 868 bool PasswordAutofillAgent::FindPasswordInfoForElement( |
| 854 const blink::WebInputElement& element, | 869 const blink::WebInputElement& element, |
| 855 blink::WebInputElement* username_element, | 870 blink::WebInputElement* username_element, |
| 856 blink::WebInputElement* password_element, | 871 blink::WebInputElement* password_element, |
| 857 PasswordInfo** password_info) { | 872 PasswordInfo** password_info) { |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1732 PasswordAutofillAgent::GetPasswordManagerDriver() { |
| 1718 if (!password_manager_driver_) { | 1733 if (!password_manager_driver_) { |
| 1719 render_frame()->GetRemoteInterfaces()->GetInterface( | 1734 render_frame()->GetRemoteInterfaces()->GetInterface( |
| 1720 mojo::MakeRequest(&password_manager_driver_)); | 1735 mojo::MakeRequest(&password_manager_driver_)); |
| 1721 } | 1736 } |
| 1722 | 1737 |
| 1723 return password_manager_driver_; | 1738 return password_manager_driver_; |
| 1724 } | 1739 } |
| 1725 | 1740 |
| 1726 } // namespace autofill | 1741 } // namespace autofill |
| OLD | NEW |