Chromium Code Reviews| Index: chrome/renderer/autofill/password_autofill_manager.cc |
| =================================================================== |
| --- chrome/renderer/autofill/password_autofill_manager.cc (revision 127980) |
| +++ chrome/renderer/autofill/password_autofill_manager.cc (working copy) |
| @@ -194,6 +194,38 @@ |
| return StartsWith(username1, username2, true); |
| } |
| +// 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) { |
| + if (fill_data.basic_data.fields.size() == 2) { |
| + return fill_data.basic_data.fields[1]; |
| + } |
| + NOTREACHED(); |
| + // This return expression is to make this function returns a value |
| + // in all paths. |
| + // If there is a path which doesn't return any values, |
| + // most of compiler output a warning or error. |
| + // (ex. Visual C++ compiler outputs C4715 warning.) |
| + return fill_data.basic_data.fields[1]; |
| +} |
|
Ilya Sherman
2012/03/27 00:15:28
nit: I would write this method simply as
DCHECK_G
Yumikiyo Osanai
2012/03/27 22:59:28
Thanks! I didn't know the DCHECK_** macro. It seem
|
| + |
| +// Get the password field from fill_data. |
| +const webkit::forms::FormField& GetPasswordField( |
| + const webkit::forms::PasswordFormFillData& fill_data) { |
| + if (fill_data.basic_data.fields.size() == 2 || |
| + fill_data.basic_data.fields.size() == 1) { |
| + return fill_data.basic_data.fields[0]; |
| + } |
| + NOTREACHED(); |
| + // This return expression is to make this function returns a value |
| + // in all paths. |
| + // If there is a path which doesn't return any values, |
| + // most of compiler output a warning or error. |
| + // (ex. Visual C++ compiler outputs C4715 warning.) |
| + return fill_data.basic_data.fields[0]; |
|
Ilya Sherman
2012/03/27 00:15:28
nit: I would write this method simply as
DCHECK(!
Yumikiyo Osanai
2012/03/27 22:59:28
Done.
|
| +} |
| + |
| } // namespace |
| namespace autofill { |
| @@ -423,26 +455,27 @@ |
| if (!form_data.wait_for_username) |
| FillForm(form_elements.get(), form_data.basic_data); |
|
Ilya Sherman
2012/03/27 00:15:28
nit: There's no need to do anything else on this i
Yumikiyo Osanai
2012/03/27 22:59:28
I've defined the HasUsernameField() and changed to
Ilya Sherman
2012/03/27 23:28:57
Sorry, I think my comment was a little unclear. W
Yumikiyo Osanai
2012/03/28 00:11:00
Thank you for writing the detail:)
I've moved the
|
| - // 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]; |
| - |
| // 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]; |
| - // We might have already filled this form if there are two <form> elements |
| - // with identical markup. |
| - if (login_to_password_info_.find(username_element) != |
| - login_to_password_info_.end()) |
| - continue; |
| - |
| - PasswordInfo password_info; |
| - password_info.fill_data = form_data; |
| - password_info.password_field = password_element; |
| - login_to_password_info_[username_element] = password_info; |
| + // If there is a username, set the username and login_to_password_info_. |
| + if (form_data.basic_data.fields.size() == 2) { |
| + // Attach autocomplete listener to enable selecting alternate logins. |
| + // First, get pointers to username element. |
| + WebKit::WebInputElement username_element = |
| + form_elements->input_elements[GetUsernameField(form_data).name]; |
| + // We might have already filled this form if there are two <form> elements |
| + // with identical markup. |
| + if (login_to_password_info_.find(username_element) != |
| + login_to_password_info_.end()) |
| + continue; |
| + PasswordInfo password_info; |
| + password_info.fill_data = form_data; |
| + password_info.password_field = password_element; |
| + login_to_password_info_[username_element] = password_info; |
| + } |
| } |
| } |
| @@ -453,9 +486,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 (fill_data.basic_data.fields.size() == 2) { |
| + if (StartsWith(GetUsernameField(fill_data).value, input, false)) |
|
Ilya Sherman
2012/03/27 00:15:28
nit: Please use "&&" rather than nested if-stmts
Yumikiyo Osanai
2012/03/27 22:59:28
Done.
|
| + suggestions->push_back(GetUsernameField(fill_data).value); |
| + } |
| webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |
| for (iter = fill_data.additional_logins.begin(); |
| iter != fill_data.additional_logins.end(); ++iter) { |
| @@ -501,11 +536,18 @@ |
| 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 (fill_data.basic_data.fields.size() == 1) { |
| + return false; |
|
Ilya Sherman
2012/03/27 00:15:28
nit: No need for curly braces, since this if-stmt'
Yumikiyo Osanai
2012/03/27 22:59:28
Done. And I've changed to use the HasUsernameField
|
| + } |
| + |
| // 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; |