Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6251)

Unified Diff: chrome/renderer/autofill/password_autofill_manager.cc

Issue 9625026: Save password without an associated username. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Refine the detail of the patch Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,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 {
@@ -423,22 +442,25 @@
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 =
- form_elements->input_elements[form_data.basic_data.fields[0].name];
+ // If there isn't any username, go to next iteration.
+ if (!HasUsernameField(form_data))
+ continue;
// 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];
+ // 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[GetUsernameField(form_data).name];
Ilya Sherman 2012/03/28 00:21:54 nit: I would avoid moving this block of code relat
Yumikiyo Osanai 2012/03/29 00:14:33 Oh! I understand it. It means we'd like to set the
// 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())
Ilya Sherman 2012/03/28 00:21:54 nit: This indentation was correct previously (thou
Yumikiyo Osanai 2012/03/29 00:14:33 Done.
+ login_to_password_info_.end())
continue;
-
Ilya Sherman 2012/03/28 00:21:54 nit: Please preserve this line break.
Yumikiyo Osanai 2012/03/29 00:14:33 Done.
PasswordInfo password_info;
password_info.fill_data = form_data;
password_info.password_field = password_element;
@@ -453,8 +475,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();
@@ -501,11 +526,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;

Powered by Google App Engine
This is Rietveld 408576698