Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 2902113004: Autofill username when the user interacts with the password field. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return username1 == username2; 299 return username1 == username2;
300 return FieldIsSuggestionSubstringStartingOnTokenBoundary(username1, username2, 300 return FieldIsSuggestionSubstringStartingOnTokenBoundary(username1, username2,
301 true); 301 true);
302 } 302 }
303 303
304 // Returns |true| if the given element is editable. Otherwise, returns |false|. 304 // Returns |true| if the given element is editable. Otherwise, returns |false|.
305 bool IsElementAutocompletable(const blink::WebInputElement& element) { 305 bool IsElementAutocompletable(const blink::WebInputElement& element) {
306 return IsElementEditable(element); 306 return IsElementEditable(element);
307 } 307 }
308 308
309 bool IsUsernameAmendable(const blink::WebInputElement& username_element,
pkalinnikov 2017/05/24 10:43:31 nit: Add comment?
310 bool is_password_field_selected) {
311 return !username_element.IsNull() &&
312 IsElementAutocompletable(username_element) &&
313 (!is_password_field_selected || username_element.IsAutofilled() ||
314 username_element.Value().IsEmpty());
315 }
316
309 // Return true if either password_value or new_password_value is not empty and 317 // Return true if either password_value or new_password_value is not empty and
310 // not default. 318 // not default.
311 bool FormContainsNonDefaultPasswordValue(const PasswordForm& password_form) { 319 bool FormContainsNonDefaultPasswordValue(const PasswordForm& password_form) {
312 return (!password_form.password_value.empty() && 320 return (!password_form.password_value.empty() &&
313 !password_form.password_value_is_default) || 321 !password_form.password_value_is_default) ||
314 (!password_form.new_password_value.empty() && 322 (!password_form.new_password_value.empty() &&
315 !password_form.new_password_value_is_default); 323 !password_form.new_password_value_is_default);
316 } 324 }
317 325
318 // Log a message including the name, method and action of |form|. 326 // Log a message including the name, method and action of |form|.
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if (!FindPasswordInfoForElement(*element, &username_element, 799 if (!FindPasswordInfoForElement(*element, &username_element,
792 &password_element, &password_info) || 800 &password_element, &password_info) ||
793 !IsElementAutocompletable(password_element)) { 801 !IsElementAutocompletable(password_element)) {
794 return false; 802 return false;
795 } 803 }
796 804
797 password_info->password_was_edited_last = false; 805 password_info->password_was_edited_last = false;
798 if (element->IsPasswordField()) { 806 if (element->IsPasswordField()) {
799 password_info->password_field_suggestion_was_accepted = true; 807 password_info->password_field_suggestion_was_accepted = true;
800 password_info->password_field = password_element; 808 password_info->password_field = password_element;
801 } else if (!username_element.IsNull() && 809 }
802 IsElementAutocompletable(username_element)) { 810
811 if (IsUsernameAmendable(username_element, element->IsPasswordField())) {
803 username_element.SetAutofillValue(blink::WebString::FromUTF16(username)); 812 username_element.SetAutofillValue(blink::WebString::FromUTF16(username));
804 username_element.SetAutofilled(true); 813 username_element.SetAutofilled(true);
805 UpdateFieldValueAndPropertiesMaskMap(username_element, &username, 814 UpdateFieldValueAndPropertiesMaskMap(username_element, &username,
806 FieldPropertiesFlags::AUTOFILLED, 815 FieldPropertiesFlags::AUTOFILLED,
807 &field_value_and_properties_map_); 816 &field_value_and_properties_map_);
808 } 817 }
809 818
810 password_element.SetAutofillValue(blink::WebString::FromUTF16(password)); 819 password_element.SetAutofillValue(blink::WebString::FromUTF16(password));
811 password_element.SetAutofilled(true); 820 password_element.SetAutofilled(true);
812 UpdateFieldValueAndPropertiesMaskMap(password_element, &password, 821 UpdateFieldValueAndPropertiesMaskMap(password_element, &password,
(...skipping 19 matching lines...) Expand all
832 blink::WebInputElement username_element; 841 blink::WebInputElement username_element;
833 blink::WebInputElement password_element; 842 blink::WebInputElement password_element;
834 PasswordInfo* password_info; 843 PasswordInfo* password_info;
835 844
836 if (!FindPasswordInfoForElement(*element, &username_element, 845 if (!FindPasswordInfoForElement(*element, &username_element,
837 &password_element, &password_info) || 846 &password_element, &password_info) ||
838 !IsElementAutocompletable(password_element)) { 847 !IsElementAutocompletable(password_element)) {
839 return false; 848 return false;
840 } 849 }
841 850
842 if (!element->IsPasswordField() && !username_element.IsNull() && 851 if (IsUsernameAmendable(username_element, element->IsPasswordField())) {
843 IsElementAutocompletable(username_element)) {
844 if (username_query_prefix_.empty()) 852 if (username_query_prefix_.empty())
845 username_query_prefix_ = username_element.Value().Utf16(); 853 username_query_prefix_ = username_element.Value().Utf16();
846 854
847 was_username_autofilled_ = username_element.IsAutofilled(); 855 was_username_autofilled_ = username_element.IsAutofilled();
848 username_element.SetSuggestedValue(username); 856 username_element.SetSuggestedValue(username);
849 username_element.SetAutofilled(true); 857 username_element.SetAutofilled(true);
850 form_util::PreviewSuggestion(username_element.SuggestedValue().Utf16(), 858 form_util::PreviewSuggestion(username_element.SuggestedValue().Utf16(),
851 username_query_prefix_, &username_element); 859 username_query_prefix_, &username_element);
852 } 860 }
853 was_password_autofilled_ = password_element.IsAutofilled(); 861 was_password_autofilled_ = password_element.IsAutofilled();
854 password_element.SetSuggestedValue(password); 862 password_element.SetSuggestedValue(password);
855 password_element.SetAutofilled(true); 863 password_element.SetAutofilled(true);
856 864
857 return true; 865 return true;
858 } 866 }
859 867
860 bool PasswordAutofillAgent::DidClearAutofillSelection( 868 bool PasswordAutofillAgent::DidClearAutofillSelection(
861 const blink::WebFormControlElement& control_element) { 869 const blink::WebFormControlElement& control_element) {
862 const blink::WebInputElement* element = ToWebInputElement(&control_element); 870 const blink::WebInputElement* element = ToWebInputElement(&control_element);
863 if (!element) 871 if (!element)
864 return false; 872 return false;
865 873
866 blink::WebInputElement username_element; 874 blink::WebInputElement username_element;
867 blink::WebInputElement password_element; 875 blink::WebInputElement password_element;
868 PasswordInfo* password_info; 876 PasswordInfo* password_info;
869 877
870 if (!FindPasswordInfoForElement(*element, &username_element, 878 if (!FindPasswordInfoForElement(*element, &username_element,
871 &password_element, &password_info)) 879 &password_element, &password_info)) {
872 return false; 880 return false;
881 }
873 882
874 ClearPreview(&username_element, &password_element); 883 ClearPreview(&username_element, &password_element);
875 return true; 884 return true;
876 } 885 }
877 886
878 bool PasswordAutofillAgent::FindPasswordInfoForElement( 887 bool PasswordAutofillAgent::FindPasswordInfoForElement(
879 const blink::WebInputElement& element, 888 const blink::WebInputElement& element,
880 blink::WebInputElement* username_element, 889 blink::WebInputElement* username_element,
881 blink::WebInputElement* password_element, 890 blink::WebInputElement* password_element,
882 PasswordInfo** password_info) { 891 PasswordInfo** password_info) {
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 PasswordAutofillAgent::GetPasswordManagerDriver() { 1733 PasswordAutofillAgent::GetPasswordManagerDriver() {
1725 if (!password_manager_driver_) { 1734 if (!password_manager_driver_) {
1726 render_frame()->GetRemoteInterfaces()->GetInterface( 1735 render_frame()->GetRemoteInterfaces()->GetInterface(
1727 mojo::MakeRequest(&password_manager_driver_)); 1736 mojo::MakeRequest(&password_manager_driver_));
1728 } 1737 }
1729 1738
1730 return password_manager_driver_; 1739 return password_manager_driver_;
1731 } 1740 }
1732 1741
1733 } // namespace autofill 1742 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698