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 ce2f1031844cf0f582c32be523841057e09e4ebd..3a7cd14b5cce4b565843b7495ac477d35366d5b7 100644 |
| --- a/components/autofill/content/renderer/password_autofill_agent.cc |
| +++ b/components/autofill/content/renderer/password_autofill_agent.cc |
| @@ -164,39 +164,6 @@ bool IsElementEditable(const WebKit::WebInputElement& element) { |
| return element.isEnabled() && !element.isReadOnly(); |
| } |
| -void FillForm(FormElements* fe, const FormData& data) { |
| - if (!fe->form_element.autoComplete()) |
| - return; |
| - |
| - std::map<base::string16, base::string16> data_map; |
| - for (size_t i = 0; i < data.fields.size(); i++) |
| - data_map[data.fields[i].name] = data.fields[i].value; |
| - |
| - for (FormInputElementMap::iterator it = fe->input_elements.begin(); |
| - it != fe->input_elements.end(); ++it) { |
| - WebKit::WebInputElement element = it->second; |
| - // Don't fill a form that has pre-filled values distinct from the ones we |
| - // want to fill with. |
| - if (!element.value().isEmpty() && element.value() != data_map[it->first]) |
| - return; |
| - |
| - // Don't fill forms with uneditable fields or fields with autocomplete |
| - // disabled. |
| - if (!IsElementEditable(element) || !element.autoComplete()) |
| - return; |
| - } |
| - |
| - for (FormInputElementMap::iterator it = fe->input_elements.begin(); |
| - it != fe->input_elements.end(); ++it) { |
| - WebKit::WebInputElement element = it->second; |
| - |
| - // TODO(tkent): Check maxlength and pattern. |
| - element.setValue(data_map[it->first]); |
| - element.setAutofilled(true); |
| - element.dispatchFormControlChangeEvent(); |
| - } |
| -} |
| - |
| void SetElementAutofilled(WebKit::WebInputElement* element, bool autofilled) { |
| if (element->isAutofilled() == autofilled) |
| return; |
| @@ -516,11 +483,6 @@ void PasswordAutofillAgent::OnFillPasswordForm( |
| for (iter = forms.begin(); iter != forms.end(); ++iter) { |
| scoped_ptr<FormElements> form_elements(*iter); |
| - // If wait_for_username is true, we don't want to initially fill the form |
| - // until the user types in a valid username. |
| - if (!form_data.wait_for_username) |
| - FillForm(form_elements.get(), form_data.basic_data); |
| - |
| // Attach autocomplete listener to enable selecting alternate logins. |
| // First, get pointers to username element. |
| WebKit::WebInputElement username_element = |
| @@ -531,6 +493,12 @@ void PasswordAutofillAgent::OnFillPasswordForm( |
| WebKit::WebInputElement password_element = |
| form_elements->input_elements[form_data.basic_data.fields[1].name]; |
| + // If wait_for_username is true, we don't want to initially fill the form |
| + // until the user types in a valid username. |
| + if (!form_data.wait_for_username) |
| + FillFormOnPasswordRecieved(form_data, form_elements->form_element, |
| + username_element, password_element); |
|
Ilya Sherman
2013/11/04 23:10:48
nit: Please use curly braces to enclose the if-stm
Garrett Casto
2013/11/05 00:40:35
Do you know where this is spelled out? I was actua
Ilya Sherman
2013/11/05 01:25:11
The style guide is pretty flexible: "In general, c
|
| + |
| // We might have already filled this form if there are two <form> elements |
| // with identical markup. |
| if (login_to_password_info_.find(username_element) != |
| @@ -625,6 +593,31 @@ bool PasswordAutofillAgent::ShowSuggestionPopup( |
| return !suggestions.empty(); |
| } |
| +void PasswordAutofillAgent::FillFormOnPasswordRecieved( |
| + const PasswordFormFillData& fill_data, |
| + const WebKit::WebFormElement& form_element, |
| + WebKit::WebInputElement username_element, |
| + WebKit::WebInputElement password_element) { |
| + if (!form_element.autoComplete()) |
| + return; |
| + |
| + // If we can't modify the password, don't try to set the username |
| + if (!IsElementEditable(password_element) || !password_element.autoComplete()) |
| + return; |
| + |
| + // Try and set the username to the preferred name, but only if the field |
| + // can be set and isn't prefilled. |
| + if (IsElementEditable(username_element) && |
| + username_element.autoComplete() && |
| + username_element.value().isEmpty()) { |
| + username_element.setValue(fill_data.basic_data.fields[0].value); |
|
Ilya Sherman
2013/11/04 23:10:48
What happened to setAutofilled(), dispatchFormCont
Garrett Casto
2013/11/05 00:40:35
The TODO got lost, I'll add it back somewhere. The
Ilya Sherman
2013/11/05 01:25:11
Ah, sorry, I didn't read the SetElementAutofilled
|
| + } |
| + |
| + // Fill if we have an exact match for the username. |
| + FillUserNameAndPassword(&username_element, &password_element, fill_data, |
| + true, false); |
|
Ilya Sherman
2013/11/04 23:10:48
nit: The semantics of "true" and "false" are reall
Garrett Casto
2013/11/05 00:40:35
Done with comments for now.
Ilya Sherman
2013/11/05 01:25:11
Thanks :)
|
| +} |
| + |
| bool PasswordAutofillAgent::FillUserNameAndPassword( |
| WebKit::WebInputElement* username_element, |
| WebKit::WebInputElement* password_element, |