 Chromium Code Reviews
 Chromium Code Reviews Issue 9625026:
  Save password without an associated username.  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/
    
  
    Issue 9625026:
  Save password without an associated username.  (Closed) 
  Base URL: http://src.chromium.org/svn/trunk/src/| Index: chrome/renderer/autofill/password_autofill_manager.cc | 
| =================================================================== | 
| --- chrome/renderer/autofill/password_autofill_manager.cc (revision 130897) | 
| +++ chrome/renderer/autofill/password_autofill_manager.cc (working copy) | 
| @@ -195,6 +195,25 @@ | 
| return StartsWith(username1, username2, true); | 
| } | 
| +// Get whether fill_data has a username or not. | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: Wording suggestion: """Returns true iff the |
 | 
| +bool HasUsernameField(const webkit::forms::PasswordFormFillData& fill_data) { | 
| + return fill_data.basic_data.fields.size() == 2; | 
| +} | 
| + | 
| +// Get the username field from fill_data. | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: Wording suggestion: "Returns the username fie
 | 
| +// If it hasn't any username, calls NOTREACHED(). | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: Please omit this line -- it's redundant with
 | 
| +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. | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: Wording suggestion: "Returns the password fie
 | 
| +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 { | 
| @@ -447,15 +466,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. | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: This comment is redundant with the code.  Ins
 | 
| + 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]; | 
| // 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. | 
| @@ -486,8 +510,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. | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: Please move this comment into the if-stmt, ri
 | 
| + 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(); | 
| @@ -551,11 +578,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. | 
| 
Ilya Sherman
2012/04/19 00:27:37
nit: Wording suggestion: """If there is no usernam
 | 
| + 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; |