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 <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 return true; | 605 return true; |
606 } | 606 } |
607 } | 607 } |
608 return false; | 608 return false; |
609 } | 609 } |
610 | 610 |
611 // Returns the closest visible autocompletable non-password text element | 611 // Returns the closest visible autocompletable non-password text element |
612 // preceding the |password_element| either in a form, if it belongs to one, or | 612 // preceding the |password_element| either in a form, if it belongs to one, or |
613 // in the |frame|. | 613 // in the |frame|. |
614 blink::WebInputElement FindUsernameElementPrecedingPasswordElement( | 614 blink::WebInputElement FindUsernameElementPrecedingPasswordElement( |
615 blink::WebFrame* frame, | 615 blink::WebLocalFrame* frame, |
616 const blink::WebInputElement& password_element) { | 616 const blink::WebInputElement& password_element) { |
617 DCHECK(!password_element.IsNull()); | 617 DCHECK(!password_element.IsNull()); |
618 | 618 |
619 std::vector<blink::WebFormControlElement> elements; | 619 std::vector<blink::WebFormControlElement> elements; |
620 if (password_element.Form().IsNull()) { | 620 if (password_element.Form().IsNull()) { |
621 elements = form_util::GetUnownedAutofillableFormFieldElements( | 621 elements = form_util::GetUnownedAutofillableFormFieldElements( |
622 frame->GetDocument().All(), nullptr); | 622 frame->GetDocument().All(), nullptr); |
623 } else { | 623 } else { |
624 blink::WebVector<blink::WebFormControlElement> web_control_elements; | 624 blink::WebVector<blink::WebFormControlElement> web_control_elements; |
625 password_element.Form().GetFormControlElements(web_control_elements); | 625 password_element.Form().GetFormControlElements(web_control_elements); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 | 756 // TODO(vabr): Get a mutable argument instead. http://crbug.com/397083 |
757 blink::WebInputElement mutable_element = element; // We need a non-const. | 757 blink::WebInputElement mutable_element = element; // We need a non-const. |
758 | 758 |
759 if (element.IsTextField()) { | 759 if (element.IsTextField()) { |
760 const base::string16 element_value = element.Value().Utf16(); | 760 const base::string16 element_value = element.Value().Utf16(); |
761 UpdateFieldValueAndPropertiesMaskMap(element, &element_value, | 761 UpdateFieldValueAndPropertiesMaskMap(element, &element_value, |
762 FieldPropertiesFlags::USER_TYPED, | 762 FieldPropertiesFlags::USER_TYPED, |
763 &field_value_and_properties_map_); | 763 &field_value_and_properties_map_); |
764 } | 764 } |
765 | 765 |
766 blink::WebFrame* const element_frame = element.GetDocument().GetFrame(); | 766 blink::WebLocalFrame* const element_frame = element.GetDocument().GetFrame(); |
767 // The element's frame might have been detached in the meantime (see | 767 // The element's frame might have been detached in the meantime (see |
768 // http://crbug.com/585363, comments 5 and 6), in which case frame() will | 768 // http://crbug.com/585363, comments 5 and 6), in which case frame() will |
769 // return null. This was hardly caused by form submission (unless the user | 769 // return null. This was hardly caused by form submission (unless the user |
770 // is supernaturally quick), so it is OK to drop the ball here. | 770 // is supernaturally quick), so it is OK to drop the ball here. |
771 if (!element_frame) | 771 if (!element_frame) |
772 return; | 772 return; |
773 DCHECK_EQ(element_frame, render_frame()->GetWebFrame()); | 773 DCHECK_EQ(element_frame, render_frame()->GetWebFrame()); |
774 | 774 |
775 // Some login forms have event handlers that put a hash of the password into | 775 // Some login forms have event handlers that put a hash of the password into |
776 // a hidden field and then clear the password (http://crbug.com/28910, | 776 // a hidden field and then clear the password (http://crbug.com/28910, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 return true; | 979 return true; |
980 | 980 |
981 // If a field declares itself a username input, show the warning. | 981 // If a field declares itself a username input, show the warning. |
982 if (HasAutocompleteAttributeValue(element, "username")) | 982 if (HasAutocompleteAttributeValue(element, "username")) |
983 return true; | 983 return true; |
984 | 984 |
985 // Otherwise, analyze the form and return true if this input element seems | 985 // Otherwise, analyze the form and return true if this input element seems |
986 // to be the username field. | 986 // to be the username field. |
987 std::unique_ptr<PasswordForm> password_form; | 987 std::unique_ptr<PasswordForm> password_form; |
988 if (element.Form().IsNull()) { | 988 if (element.Form().IsNull()) { |
989 blink::WebFrame* const element_frame = element.GetDocument().GetFrame(); | 989 blink::WebLocalFrame* const element_frame = |
| 990 element.GetDocument().GetFrame(); |
990 if (!element_frame) | 991 if (!element_frame) |
991 return false; | 992 return false; |
992 | 993 |
993 password_form = CreatePasswordFormFromUnownedInputElements( | 994 password_form = CreatePasswordFormFromUnownedInputElements( |
994 *element_frame, &field_value_and_properties_map_, &form_predictions_); | 995 *element_frame, &field_value_and_properties_map_, &form_predictions_); |
995 } else { | 996 } else { |
996 password_form = CreatePasswordFormFromWebForm( | 997 password_form = CreatePasswordFormFromWebForm( |
997 element.Form(), &field_value_and_properties_map_, &form_predictions_); | 998 element.Form(), &field_value_and_properties_map_, &form_predictions_); |
998 } | 999 } |
999 | 1000 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 PasswordForm::SubmissionIndicatorEvent::XHR_SUCCEEDED); | 1099 PasswordForm::SubmissionIndicatorEvent::XHR_SUCCEEDED); |
1099 } | 1100 } |
1100 | 1101 |
1101 void PasswordAutofillAgent::OnSameDocumentNavigationCompleted( | 1102 void PasswordAutofillAgent::OnSameDocumentNavigationCompleted( |
1102 PasswordForm::SubmissionIndicatorEvent event) { | 1103 PasswordForm::SubmissionIndicatorEvent event) { |
1103 if (!provisionally_saved_form_.IsPasswordValid()) | 1104 if (!provisionally_saved_form_.IsPasswordValid()) |
1104 return; | 1105 return; |
1105 | 1106 |
1106 // Prompt to save only if the form is now gone, either invisible or | 1107 // Prompt to save only if the form is now gone, either invisible or |
1107 // removed from the DOM. | 1108 // removed from the DOM. |
1108 blink::WebFrame* frame = render_frame()->GetWebFrame(); | 1109 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
1109 const auto& password_form = provisionally_saved_form_.password_form(); | 1110 const auto& password_form = provisionally_saved_form_.password_form(); |
1110 // TODO(crbug.com/720347): This method could be called often and checking form | 1111 // TODO(crbug.com/720347): This method could be called often and checking form |
1111 // visibility could be expesive. Add performance metrics for this. | 1112 // visibility could be expesive. Add performance metrics for this. |
1112 if (event != PasswordForm::SubmissionIndicatorEvent::DOM_MUTATION_AFTER_XHR) { | 1113 if (event != PasswordForm::SubmissionIndicatorEvent::DOM_MUTATION_AFTER_XHR) { |
1113 if (form_util::IsFormVisible(frame, | 1114 if (form_util::IsFormVisible(frame, |
1114 provisionally_saved_form_.form_element(), | 1115 provisionally_saved_form_.form_element(), |
1115 password_form.action, password_form.origin, | 1116 password_form.action, password_form.origin, |
1116 password_form.form_data) || | 1117 password_form.form_data) || |
1117 (provisionally_saved_form_.form_element().IsNull() && | 1118 (provisionally_saved_form_.form_element().IsNull() && |
1118 IsUnownedPasswordFormVisible( | 1119 IsUnownedPasswordFormVisible( |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1773 PasswordAutofillAgent::GetPasswordManagerDriver() { |
1773 if (!password_manager_driver_) { | 1774 if (!password_manager_driver_) { |
1774 render_frame()->GetRemoteInterfaces()->GetInterface( | 1775 render_frame()->GetRemoteInterfaces()->GetInterface( |
1775 mojo::MakeRequest(&password_manager_driver_)); | 1776 mojo::MakeRequest(&password_manager_driver_)); |
1776 } | 1777 } |
1777 | 1778 |
1778 return password_manager_driver_; | 1779 return password_manager_driver_; |
1779 } | 1780 } |
1780 | 1781 |
1781 } // namespace autofill | 1782 } // namespace autofill |
OLD | NEW |