| 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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 if (iter == web_input_to_password_info_.end()) | 831 if (iter == web_input_to_password_info_.end()) |
| 832 return false; | 832 return false; |
| 833 | 833 |
| 834 *password_info = &iter->second; | 834 *password_info = &iter->second; |
| 835 if (password_element->isNull()) | 835 if (password_element->isNull()) |
| 836 *password_element = (*password_info)->password_field; | 836 *password_element = (*password_info)->password_field; |
| 837 | 837 |
| 838 return true; | 838 return true; |
| 839 } | 839 } |
| 840 | 840 |
| 841 bool PasswordAutofillAgent::ShouldShowNotSecureWarning( |
| 842 const blink::WebInputElement& element) { |
| 843 // Do not show a warning if the feature is disabled or the context is secure. |
| 844 if (!security_state::IsHttpWarningInFormEnabled() || |
| 845 content::IsOriginSecure( |
| 846 url::Origin(render_frame()->GetWebFrame()->top()->getSecurityOrigin()) |
| 847 .GetURL())) |
| 848 return false; |
| 849 |
| 850 // Show the warning on all Password inputs. |
| 851 // Note: A site may use a Password field to collect a CVV or a Credit Card |
| 852 // number, but showing a slightly misleading warning here is better than |
| 853 // showing no warning at all. |
| 854 if (element.isPasswordField()) |
| 855 return true; |
| 856 |
| 857 // If a field declares itself a username input, show the warning. |
| 858 if (HasAutocompleteAttributeValue(element, "username")) |
| 859 return true; |
| 860 |
| 861 // Otherwise, analyze the form and return true if this input element seems |
| 862 // to be the username field. |
| 863 std::unique_ptr<PasswordForm> password_form; |
| 864 if (element.form().isNull()) { |
| 865 blink::WebFrame* const element_frame = element.document().frame(); |
| 866 if (!element_frame) |
| 867 return false; |
| 868 |
| 869 password_form = CreatePasswordFormFromUnownedInputElements( |
| 870 *element_frame, &field_value_and_properties_map_, &form_predictions_); |
| 871 } else { |
| 872 password_form = CreatePasswordFormFromWebForm( |
| 873 element.form(), &field_value_and_properties_map_, &form_predictions_); |
| 874 } |
| 875 |
| 876 if (!password_form) |
| 877 return false; |
| 878 return (password_form->username_element == element.nameForAutofill().utf16()); |
| 879 } |
| 880 |
| 841 bool PasswordAutofillAgent::ShowSuggestions( | 881 bool PasswordAutofillAgent::ShowSuggestions( |
| 842 const blink::WebInputElement& element, | 882 const blink::WebInputElement& element, |
| 843 bool show_all, | 883 bool show_all, |
| 844 bool generation_popup_showing) { | 884 bool generation_popup_showing) { |
| 845 blink::WebInputElement username_element; | 885 blink::WebInputElement username_element; |
| 846 blink::WebInputElement password_element; | 886 blink::WebInputElement password_element; |
| 847 PasswordInfo* password_info; | 887 PasswordInfo* password_info; |
| 848 | 888 |
| 849 if (!FindPasswordInfoForElement(element, &username_element, &password_element, | 889 if (!FindPasswordInfoForElement(element, &username_element, &password_element, |
| 850 &password_info)) { | 890 &password_info)) { |
| 851 // If we don't have a password stored, but the form is non-secure, warn | 891 if (ShouldShowNotSecureWarning(element)) { |
| 852 // the user about the non-secure form. | |
| 853 if ((element.isPasswordField() || | |
| 854 HasAutocompleteAttributeValue(element, "username")) && | |
| 855 security_state::IsHttpWarningInFormEnabled() && | |
| 856 !content::IsOriginSecure( | |
| 857 url::Origin( | |
| 858 render_frame()->GetWebFrame()->top()->getSecurityOrigin()) | |
| 859 .GetURL())) { | |
| 860 autofill_agent_->ShowNotSecureWarning(element); | 892 autofill_agent_->ShowNotSecureWarning(element); |
| 861 return true; | 893 return true; |
| 862 } | 894 } |
| 863 return false; | 895 return false; |
| 864 } | 896 } |
| 865 | 897 |
| 866 // If autocomplete='off' is set on the form elements, no suggestion dialog | 898 // If autocomplete='off' is set on the form elements, no suggestion dialog |
| 867 // should be shown. However, return |true| to indicate that this is a known | 899 // should be shown. However, return |true| to indicate that this is a known |
| 868 // password form and that the request to show suggestions has been handled (as | 900 // password form and that the request to show suggestions has been handled (as |
| 869 // a no-op). | 901 // a no-op). |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1549 PasswordAutofillAgent::GetPasswordManagerDriver() { |
| 1518 if (!password_manager_driver_) { | 1550 if (!password_manager_driver_) { |
| 1519 render_frame()->GetRemoteInterfaces()->GetInterface( | 1551 render_frame()->GetRemoteInterfaces()->GetInterface( |
| 1520 mojo::MakeRequest(&password_manager_driver_)); | 1552 mojo::MakeRequest(&password_manager_driver_)); |
| 1521 } | 1553 } |
| 1522 | 1554 |
| 1523 return password_manager_driver_; | 1555 return password_manager_driver_; |
| 1524 } | 1556 } |
| 1525 | 1557 |
| 1526 } // namespace autofill | 1558 } // namespace autofill |
| OLD | NEW |