| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 blink::WebInputElement* username_element, | 958 blink::WebInputElement* username_element, |
| 959 blink::WebInputElement* password_element, | 959 blink::WebInputElement* password_element, |
| 960 const PasswordFormFillData& fill_data, | 960 const PasswordFormFillData& fill_data, |
| 961 bool exact_username_match, | 961 bool exact_username_match, |
| 962 bool set_selection) { | 962 bool set_selection) { |
| 963 base::string16 current_username = username_element->value(); | 963 base::string16 current_username = username_element->value(); |
| 964 // username and password will contain the match found if any. | 964 // username and password will contain the match found if any. |
| 965 base::string16 username; | 965 base::string16 username; |
| 966 base::string16 password; | 966 base::string16 password; |
| 967 | 967 |
| 968 // Don't fill username if password can't be set. |
| 969 if (!IsElementAutocompletable(*password_element)) |
| 970 return false; |
| 971 |
| 968 // Look for any suitable matches to current field text. | 972 // Look for any suitable matches to current field text. |
| 969 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, | 973 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, |
| 970 current_username, | 974 current_username, |
| 971 exact_username_match)) { | 975 exact_username_match)) { |
| 972 username = fill_data.basic_data.fields[0].value; | 976 username = fill_data.basic_data.fields[0].value; |
| 973 password = fill_data.basic_data.fields[1].value; | 977 password = fill_data.basic_data.fields[1].value; |
| 974 } else { | 978 } else { |
| 975 // Scan additional logins for a match. | 979 // Scan additional logins for a match. |
| 976 PasswordFormFillData::LoginCollection::const_iterator iter; | 980 PasswordFormFillData::LoginCollection::const_iterator iter; |
| 977 for (iter = fill_data.additional_logins.begin(); | 981 for (iter = fill_data.additional_logins.begin(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1004 break; | 1008 break; |
| 1005 } | 1009 } |
| 1006 } | 1010 } |
| 1007 } | 1011 } |
| 1008 if (password.empty()) | 1012 if (password.empty()) |
| 1009 return false; // No match was found. | 1013 return false; // No match was found. |
| 1010 | 1014 |
| 1011 // TODO(tkent): Check maxlength and pattern for both username and password | 1015 // TODO(tkent): Check maxlength and pattern for both username and password |
| 1012 // fields. | 1016 // fields. |
| 1013 | 1017 |
| 1014 // Don't fill username if password can't be set. | |
| 1015 if (!IsElementAutocompletable(*password_element)) { | |
| 1016 return false; | |
| 1017 } | |
| 1018 | |
| 1019 // Input matches the username, fill in required values. | 1018 // Input matches the username, fill in required values. |
| 1020 if (IsElementAutocompletable(*username_element)) { | 1019 if (IsElementAutocompletable(*username_element)) { |
| 1021 username_element->setValue(username, true); | 1020 username_element->setValue(username, true); |
| 1022 username_element->setAutofilled(true); | 1021 username_element->setAutofilled(true); |
| 1023 | 1022 |
| 1024 if (set_selection) { | 1023 if (set_selection) { |
| 1025 username_element->setSelectionRange(current_username.length(), | 1024 username_element->setSelectionRange(current_username.length(), |
| 1026 username.length()); | 1025 username.length()); |
| 1027 } | 1026 } |
| 1028 } else if (current_username != username) { | 1027 } else if (current_username != username) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); | 1134 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); |
| 1136 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1135 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
| 1137 password_form->password_value.empty() && | 1136 password_form->password_value.empty() && |
| 1138 password_form->new_password_value.empty())) { | 1137 password_form->new_password_value.empty())) { |
| 1139 return; | 1138 return; |
| 1140 } | 1139 } |
| 1141 provisionally_saved_forms_[frame].reset(password_form.release()); | 1140 provisionally_saved_forms_[frame].reset(password_form.release()); |
| 1142 } | 1141 } |
| 1143 | 1142 |
| 1144 } // namespace autofill | 1143 } // namespace autofill |
| OLD | NEW |