Chromium Code Reviews| 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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 | 620 |
| 621 //////////////////////////////////////////////////////////////////////////////// | 621 //////////////////////////////////////////////////////////////////////////////// |
| 622 // PasswordAutofillAgent, public: | 622 // PasswordAutofillAgent, public: |
| 623 | 623 |
| 624 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) | 624 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) |
| 625 : content::RenderFrameObserver(render_frame), | 625 : content::RenderFrameObserver(render_frame), |
| 626 logging_state_active_(false), | 626 logging_state_active_(false), |
| 627 was_username_autofilled_(false), | 627 was_username_autofilled_(false), |
| 628 was_password_autofilled_(false), | 628 was_password_autofilled_(false), |
| 629 sent_request_to_store_(false), | 629 sent_request_to_store_(false), |
| 630 checked_safe_browsing_reputation_(false), | |
| 630 binding_(this) { | 631 binding_(this) { |
| 631 // PasswordAutofillAgent is guaranteed to outlive |render_frame|. | 632 // PasswordAutofillAgent is guaranteed to outlive |render_frame|. |
| 632 render_frame->GetInterfaceRegistry()->AddInterface( | 633 render_frame->GetInterfaceRegistry()->AddInterface( |
| 633 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this))); | 634 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this))); |
| 634 } | 635 } |
| 635 | 636 |
| 636 PasswordAutofillAgent::~PasswordAutofillAgent() { | 637 PasswordAutofillAgent::~PasswordAutofillAgent() { |
| 637 } | 638 } |
| 638 | 639 |
| 639 void PasswordAutofillAgent::BindRequest( | 640 void PasswordAutofillAgent::BindRequest( |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 *password_info = &iter->second; | 893 *password_info = &iter->second; |
| 893 if (password_element->IsNull()) | 894 if (password_element->IsNull()) |
| 894 *password_element = (*password_info)->password_field; | 895 *password_element = (*password_info)->password_field; |
| 895 | 896 |
| 896 return true; | 897 return true; |
| 897 } | 898 } |
| 898 | 899 |
| 899 bool PasswordAutofillAgent::ShouldShowNotSecureWarning( | 900 bool PasswordAutofillAgent::ShouldShowNotSecureWarning( |
| 900 const blink::WebInputElement& element) { | 901 const blink::WebInputElement& element) { |
| 901 // Do not show a warning if the feature is disabled or the context is secure. | 902 // Do not show a warning if the feature is disabled or the context is secure. |
| 902 if (!security_state::IsHttpWarningInFormEnabled() || | 903 return security_state::IsHttpWarningInFormEnabled() && |
| 903 content::IsOriginSecure( | 904 !content::IsOriginSecure( |
| 904 url::Origin(render_frame()->GetWebFrame()->Top()->GetSecurityOrigin()) | 905 url::Origin( |
| 905 .GetURL())) | 906 render_frame()->GetWebFrame()->Top()->GetSecurityOrigin()) |
| 906 return false; | 907 .GetURL()); |
| 908 } | |
| 907 | 909 |
| 908 // Show the warning on all Password inputs. | 910 bool PasswordAutofillAgent::IsUsernameOrPasswordField( |
| 911 const blink::WebInputElement& element) { | |
| 909 // Note: A site may use a Password field to collect a CVV or a Credit Card | 912 // Note: A site may use a Password field to collect a CVV or a Credit Card |
| 910 // number, but showing a slightly misleading warning here is better than | 913 // number, but showing a slightly misleading warning here is better than |
| 911 // showing no warning at all. | 914 // showing no warning at all. |
| 912 if (element.IsPasswordField()) | 915 if (element.IsPasswordField()) |
| 913 return true; | 916 return true; |
| 914 | 917 |
| 915 // If a field declares itself a username input, show the warning. | 918 // If a field declares itself a username input, show the warning. |
| 916 if (HasAutocompleteAttributeValue(element, "username")) | 919 if (HasAutocompleteAttributeValue(element, "username")) |
| 917 return true; | 920 return true; |
| 918 | 921 |
| 919 // Otherwise, analyze the form and return true if this input element seems | 922 // Otherwise, analyze the form and return true if this input element seems |
| 920 // to be the username field. | 923 // to be the username field. |
| 921 std::unique_ptr<PasswordForm> password_form; | 924 std::unique_ptr<PasswordForm> password_form; |
| 922 if (element.Form().IsNull()) { | 925 if (element.Form().IsNull()) { |
| 923 blink::WebFrame* const element_frame = element.GetDocument().GetFrame(); | 926 blink::WebFrame* const element_frame = element.GetDocument().GetFrame(); |
| 924 if (!element_frame) | 927 if (!element_frame) |
| 925 return false; | 928 return false; |
| 926 | 929 |
| 927 password_form = CreatePasswordFormFromUnownedInputElements( | 930 password_form = CreatePasswordFormFromUnownedInputElements( |
| 928 *element_frame, &field_value_and_properties_map_, &form_predictions_); | 931 *element_frame, &field_value_and_properties_map_, &form_predictions_); |
| 929 } else { | 932 } else { |
| 930 password_form = CreatePasswordFormFromWebForm( | 933 password_form = CreatePasswordFormFromWebForm( |
| 931 element.Form(), &field_value_and_properties_map_, &form_predictions_); | 934 element.Form(), &field_value_and_properties_map_, &form_predictions_); |
| 932 } | 935 } |
| 933 | 936 |
| 934 if (!password_form) | 937 if (!password_form) |
| 935 return false; | 938 return false; |
| 936 return (password_form->username_element == element.NameForAutofill().Utf16()); | 939 return (password_form->username_element == element.NameForAutofill().Utf16()); |
|
dvadym
2017/04/27 10:46:30
Just keep in mind, that heuristics for detecting u
Jialiu Lin
2017/04/28 00:09:08
Yes, I'm aware of that.
| |
| 937 } | 940 } |
| 938 | 941 |
| 939 bool PasswordAutofillAgent::ShowSuggestions( | 942 bool PasswordAutofillAgent::ShowSuggestions( |
| 940 const blink::WebInputElement& element, | 943 const blink::WebInputElement& element, |
| 941 bool show_all, | 944 bool show_all, |
| 942 bool generation_popup_showing) { | 945 bool generation_popup_showing) { |
| 943 blink::WebInputElement username_element; | 946 blink::WebInputElement username_element; |
| 944 blink::WebInputElement password_element; | 947 blink::WebInputElement password_element; |
| 945 PasswordInfo* password_info; | 948 PasswordInfo* password_info; |
| 946 | 949 |
| 947 if (!FindPasswordInfoForElement(element, &username_element, &password_element, | 950 if (!FindPasswordInfoForElement(element, &username_element, &password_element, |
| 948 &password_info)) { | 951 &password_info)) { |
| 949 if (ShouldShowNotSecureWarning(element)) { | 952 if (IsUsernameOrPasswordField(element)) { |
| 950 autofill_agent_->ShowNotSecureWarning(element); | 953 #if defined(SAFE_BROWSING_DB_LOCAL) |
| 951 return true; | 954 if (!checked_safe_browsing_reputation_) { |
| 955 checked_safe_browsing_reputation_ = true; | |
| 956 GetPasswordManagerDriver()->CheckSafeBrowsingReputation( | |
| 957 element.Form().IsNull() | |
|
dvadym
2017/04/27 10:46:30
Are you sure that you need form_action not frame u
Jialiu Lin
2017/04/28 00:09:08
Good to know. I'll add more fields to the CheckSa
| |
| 958 ? GURL() | |
|
dvadym
2017/04/27 10:46:30
Probably in case when a form is absent, current ur
Jialiu Lin
2017/04/28 00:09:08
Changed to pass both the action url and current fr
| |
| 959 : form_util::GetCanonicalActionForForm(element.Form())); | |
| 960 } | |
| 961 #endif | |
| 962 if (ShouldShowNotSecureWarning(element)) { | |
| 963 autofill_agent_->ShowNotSecureWarning(element); | |
| 964 return true; | |
| 965 } | |
| 952 } | 966 } |
| 953 return false; | 967 return false; |
| 954 } | 968 } |
| 955 | 969 |
| 956 // If autocomplete='off' is set on the form elements, no suggestion dialog | 970 // If autocomplete='off' is set on the form elements, no suggestion dialog |
| 957 // should be shown. However, return |true| to indicate that this is a known | 971 // should be shown. However, return |true| to indicate that this is a known |
| 958 // password form and that the request to show suggestions has been handled (as | 972 // password form and that the request to show suggestions has been handled (as |
| 959 // a no-op). | 973 // a no-op). |
| 960 if (!element.IsTextField() || !IsElementAutocompletable(element) || | 974 if (!element.IsTextField() || !IsElementAutocompletable(element) || |
| 961 !IsElementAutocompletable(password_element)) | 975 !IsElementAutocompletable(password_element)) |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1184 | 1198 |
| 1185 void PasswordAutofillAgent::WillCommitProvisionalLoad() { | 1199 void PasswordAutofillAgent::WillCommitProvisionalLoad() { |
| 1186 FrameClosing(); | 1200 FrameClosing(); |
| 1187 } | 1201 } |
| 1188 | 1202 |
| 1189 void PasswordAutofillAgent::DidCommitProvisionalLoad( | 1203 void PasswordAutofillAgent::DidCommitProvisionalLoad( |
| 1190 bool is_new_navigation, | 1204 bool is_new_navigation, |
| 1191 bool is_same_document_navigation) { | 1205 bool is_same_document_navigation) { |
| 1192 if (is_same_document_navigation) { | 1206 if (is_same_document_navigation) { |
| 1193 OnSameDocumentNavigationCompleted(); | 1207 OnSameDocumentNavigationCompleted(); |
| 1208 } else { | |
| 1209 checked_safe_browsing_reputation_ = false; | |
| 1194 } | 1210 } |
| 1195 } | 1211 } |
| 1196 | 1212 |
| 1197 void PasswordAutofillAgent::FrameDetached() { | 1213 void PasswordAutofillAgent::FrameDetached() { |
| 1198 // If a sub frame has been destroyed while the user was entering information | 1214 // If a sub frame has been destroyed while the user was entering information |
| 1199 // into a password form, try to save the data. See https://crbug.com/450806 | 1215 // into a password form, try to save the data. See https://crbug.com/450806 |
| 1200 // for examples of sites that perform login using this technique. | 1216 // for examples of sites that perform login using this technique. |
| 1201 if (render_frame()->GetWebFrame()->Parent() && | 1217 if (render_frame()->GetWebFrame()->Parent() && |
| 1202 provisionally_saved_form_.IsPasswordValid()) { | 1218 provisionally_saved_form_.IsPasswordValid()) { |
| 1203 GetPasswordManagerDriver()->InPageNavigation( | 1219 GetPasswordManagerDriver()->InPageNavigation( |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1590 } | 1606 } |
| 1591 | 1607 |
| 1592 void PasswordAutofillAgent::FrameClosing() { | 1608 void PasswordAutofillAgent::FrameClosing() { |
| 1593 for (auto const& iter : web_input_to_password_info_) { | 1609 for (auto const& iter : web_input_to_password_info_) { |
| 1594 password_to_username_.erase(iter.second.password_field); | 1610 password_to_username_.erase(iter.second.password_field); |
| 1595 } | 1611 } |
| 1596 web_input_to_password_info_.clear(); | 1612 web_input_to_password_info_.clear(); |
| 1597 provisionally_saved_form_.Reset(); | 1613 provisionally_saved_form_.Reset(); |
| 1598 field_value_and_properties_map_.clear(); | 1614 field_value_and_properties_map_.clear(); |
| 1599 sent_request_to_store_ = false; | 1615 sent_request_to_store_ = false; |
| 1616 checked_safe_browsing_reputation_ = false; | |
| 1600 } | 1617 } |
| 1601 | 1618 |
| 1602 void PasswordAutofillAgent::ClearPreview( | 1619 void PasswordAutofillAgent::ClearPreview( |
| 1603 blink::WebInputElement* username, | 1620 blink::WebInputElement* username, |
| 1604 blink::WebInputElement* password) { | 1621 blink::WebInputElement* password) { |
| 1605 if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) { | 1622 if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) { |
| 1606 username->SetSuggestedValue(blink::WebString()); | 1623 username->SetSuggestedValue(blink::WebString()); |
| 1607 username->SetAutofilled(was_username_autofilled_); | 1624 username->SetAutofilled(was_username_autofilled_); |
| 1608 username->SetSelectionRange(username_query_prefix_.length(), | 1625 username->SetSelectionRange(username_query_prefix_.length(), |
| 1609 username->Value().length()); | 1626 username->Value().length()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1637 PasswordAutofillAgent::GetPasswordManagerDriver() { | 1654 PasswordAutofillAgent::GetPasswordManagerDriver() { |
| 1638 if (!password_manager_driver_) { | 1655 if (!password_manager_driver_) { |
| 1639 render_frame()->GetRemoteInterfaces()->GetInterface( | 1656 render_frame()->GetRemoteInterfaces()->GetInterface( |
| 1640 mojo::MakeRequest(&password_manager_driver_)); | 1657 mojo::MakeRequest(&password_manager_driver_)); |
| 1641 } | 1658 } |
| 1642 | 1659 |
| 1643 return password_manager_driver_; | 1660 return password_manager_driver_; |
| 1644 } | 1661 } |
| 1645 | 1662 |
| 1646 } // namespace autofill | 1663 } // namespace autofill |
| OLD | NEW |