Chromium Code Reviews| Index: components/autofill/content/renderer/password_autofill_agent.cc |
| diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc |
| index e301934db586c958ef57714d8f59cbf7f53f2320..341574fd6aa416ad1289161dcc72c1a799994534 100644 |
| --- a/components/autofill/content/renderer/password_autofill_agent.cc |
| +++ b/components/autofill/content/renderer/password_autofill_agent.cc |
| @@ -306,6 +306,14 @@ bool IsElementAutocompletable(const blink::WebInputElement& element) { |
| return IsElementEditable(element); |
| } |
| +bool IsUsernameAmendable(const blink::WebInputElement& username_element, |
|
pkalinnikov
2017/05/24 10:43:31
nit: Add comment?
|
| + bool is_password_field_selected) { |
| + return !username_element.IsNull() && |
| + IsElementAutocompletable(username_element) && |
| + (!is_password_field_selected || username_element.IsAutofilled() || |
| + username_element.Value().IsEmpty()); |
| +} |
| + |
| // Return true if either password_value or new_password_value is not empty and |
| // not default. |
| bool FormContainsNonDefaultPasswordValue(const PasswordForm& password_form) { |
| @@ -798,8 +806,9 @@ bool PasswordAutofillAgent::FillSuggestion( |
| if (element->IsPasswordField()) { |
| password_info->password_field_suggestion_was_accepted = true; |
| password_info->password_field = password_element; |
| - } else if (!username_element.IsNull() && |
| - IsElementAutocompletable(username_element)) { |
| + } |
| + |
| + if (IsUsernameAmendable(username_element, element->IsPasswordField())) { |
| username_element.SetAutofillValue(blink::WebString::FromUTF16(username)); |
| username_element.SetAutofilled(true); |
| UpdateFieldValueAndPropertiesMaskMap(username_element, &username, |
| @@ -839,8 +848,7 @@ bool PasswordAutofillAgent::PreviewSuggestion( |
| return false; |
| } |
| - if (!element->IsPasswordField() && !username_element.IsNull() && |
| - IsElementAutocompletable(username_element)) { |
| + if (IsUsernameAmendable(username_element, element->IsPasswordField())) { |
| if (username_query_prefix_.empty()) |
| username_query_prefix_ = username_element.Value().Utf16(); |
| @@ -868,8 +876,9 @@ bool PasswordAutofillAgent::DidClearAutofillSelection( |
| PasswordInfo* password_info; |
| if (!FindPasswordInfoForElement(*element, &username_element, |
| - &password_element, &password_info)) |
| + &password_element, &password_info)) { |
| return false; |
| + } |
| ClearPreview(&username_element, &password_element); |
| return true; |