Chromium Code Reviews| Index: chrome/renderer/autofill/password_autofill_manager.cc |
| =================================================================== |
| --- chrome/renderer/autofill/password_autofill_manager.cc (revision 129489) |
| +++ chrome/renderer/autofill/password_autofill_manager.cc (working copy) |
| @@ -194,6 +194,25 @@ |
| return StartsWith(username1, username2, true); |
| } |
| +// Get whether fill_data has a username or not. |
| +bool HasUsernameField(const webkit::forms::PasswordFormFillData& fill_data) { |
| + return fill_data.basic_data.fields.size() == 2; |
| +} |
| + |
| +// Get the username field from fill_data. |
| +// If it hasn't any username, calls NOTREACHED(). |
| +const webkit::forms::FormField& GetUsernameField( |
| + const webkit::forms::PasswordFormFillData& fill_data) { |
| + DCHECK(HasUsernameField(fill_data)); |
| + return fill_data.basic_data.fields[1]; |
| +} |
| + |
| +// Get the password field from fill_data. |
| +const webkit::forms::FormField& GetPasswordField( |
| + const webkit::forms::PasswordFormFillData& fill_data) { |
| + DCHECK(!fill_data.basic_data.fields.empty()); |
| + return fill_data.basic_data.fields[0]; |
| +} |
| } // namespace |
| namespace autofill { |
| @@ -438,15 +457,20 @@ |
| if (!form_data.wait_for_username) |
| FillForm(form_elements.get(), form_data.basic_data); |
| + // If there isn't any username, go to next iteration. |
| + if (!HasUsernameField(form_data)) |
| + continue; |
| + |
| + // If there is a username, set the username and login_to_password_info_. |
| // Attach autocomplete listener to enable selecting alternate logins. |
| // First, get pointers to username element. |
| WebKit::WebInputElement username_element = |
| - form_elements->input_elements[form_data.basic_data.fields[0].name]; |
| + form_elements->input_elements[GetUsernameField(form_data).name]; |
|
Ilya Sherman
2012/04/05 22:20:36
nit: The indentation here was previously correct -
Yumikiyo Osanai
2012/04/06 00:17:34
Done.
|
| // Get pointer to password element. (We currently only support single |
| // password forms). |
| WebKit::WebInputElement password_element = |
| - form_elements->input_elements[form_data.basic_data.fields[1].name]; |
| + form_elements->input_elements[GetPasswordField(form_data).name]; |
|
Ilya Sherman
2012/04/05 22:20:36
nit: Ditto.
Yumikiyo Osanai
2012/04/06 00:17:34
Done.
|
| // We might have already filled this form if there are two <form> elements |
| // with identical markup. |
| @@ -468,8 +492,11 @@ |
| const webkit::forms::PasswordFormFillData& fill_data, |
| const string16& input, |
| std::vector<string16>* suggestions) { |
| - if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) |
| - suggestions->push_back(fill_data.basic_data.fields[0].value); |
| + // There are both a password and a username. |
| + if (HasUsernameField(fill_data) && |
| + StartsWith(GetUsernameField(fill_data).value, input, false)) { |
| + suggestions->push_back(GetUsernameField(fill_data).value); |
| + } |
| webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |
| for (iter = fill_data.additional_logins.begin(); |
| @@ -516,11 +543,17 @@ |
| string16 username; |
| string16 password; |
| + // If there isn't any username form, just exit. |
| + // Because this function is used for the case |
| + // that the username form and the possword form exist. |
| + if (!HasUsernameField(fill_data)) |
| + return false; |
| + |
| // Look for any suitable matches to current field text. |
| - if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, current_username, |
| + if (DoUsernamesMatch(GetUsernameField(fill_data).value, current_username, |
| exact_username_match)) { |
| - username = fill_data.basic_data.fields[0].value; |
| - password = fill_data.basic_data.fields[1].value; |
| + username = GetUsernameField(fill_data).value; |
| + password = GetPasswordField(fill_data).value; |
| } else { |
| // Scan additional logins for a match. |
| webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |