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