Chromium Code Reviews| Index: components/autofill/content/renderer/password_form_conversion_utils.cc |
| diff --git a/components/autofill/content/renderer/password_form_conversion_utils.cc b/components/autofill/content/renderer/password_form_conversion_utils.cc |
| index 6a19e504e3e9fc949d990dd3fce55c4fdd29207f..ac26c1ab325fd2699502991a5fb30a89d12dca57 100644 |
| --- a/components/autofill/content/renderer/password_form_conversion_utils.cc |
| +++ b/components/autofill/content/renderer/password_form_conversion_utils.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/strings/string_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "components/autofill/content/renderer/form_autofill_util.h" |
| #include "components/autofill/core/common/password_form.h" |
| #include "components/autofill/core/common/password_form_field_prediction_map.h" |
| @@ -61,6 +62,9 @@ const char kLoginAndSignupRegex[] = |
| const char kAutocompleteUsername[] = "username"; |
| const char kAutocompleteCurrentPassword[] = "current-password"; |
| const char kAutocompleteNewPassword[] = "new-password"; |
| +const char kDummyUsernameField[] = "anonymous_username"; |
|
dvadym
2015/08/24 13:32:08
Probably it's better to make fake names that are n
Pritam Nikam
2015/08/25 09:01:10
Acknowledged.
According to W3C spec, <input name>
dvadym
2015/09/07 15:19:58
Ok, I agree, that we hardly can do something with
Pritam Nikam
2015/09/08 15:09:36
Acknowledged.
|
| +const char kDummyPasswordField[] = "anonymous_password"; |
| +const char kDummyNewPasswordField[] = "anonymous_new_password"; |
| struct LoginAndSignupLazyInstanceTraits |
| : public base::DefaultLazyInstanceTraits<icu::RegexMatcher> { |
| @@ -261,6 +265,13 @@ void FindPredictedElements( |
| } |
| } |
| +// Returns the |input_field| name if its non-empty; otherwise a |dummy_name|. |
| +base::string16 FieldName(const WebInputElement& input_field, |
| + const char dummy_name[]) { |
| + base::string16 field_name = input_field.nameForAutofill(); |
| + return field_name.empty() ? base::ASCIIToUTF16(dummy_name) : field_name; |
| +} |
| + |
| // Get information about a login form encapsulated in a PasswordForm struct. |
| // If an element of |form| has an entry in |nonscript_modified_values|, the |
| // associated string is used instead of the element's value to create |
| @@ -420,7 +431,8 @@ void GetPasswordForm( |
| } |
| if (!username_element.isNull()) { |
| - password_form->username_element = username_element.nameForAutofill(); |
| + password_form->username_element = |
| + FieldName(username_element, kDummyUsernameField); |
| base::string16 username_value = username_element.value(); |
| if (nonscript_modified_values != nullptr) { |
| auto username_iterator = |
| @@ -458,7 +470,7 @@ void GetPasswordForm( |
| password_form->other_possible_usernames.swap(other_possible_usernames); |
| if (!password.isNull()) { |
| - password_form->password_element = password.nameForAutofill(); |
| + password_form->password_element = FieldName(password, kDummyPasswordField); |
| blink::WebString password_value = password.value(); |
| if (nonscript_modified_values != nullptr) { |
| auto password_iterator = nonscript_modified_values->find(password); |
| @@ -468,7 +480,8 @@ void GetPasswordForm( |
| password_form->password_value = password_value; |
| } |
| if (!new_password.isNull()) { |
| - password_form->new_password_element = new_password.nameForAutofill(); |
| + password_form->new_password_element = |
| + FieldName(new_password, kDummyNewPasswordField); |
| password_form->new_password_value = new_password.value(); |
| if (HasAutocompleteAttributeValue(new_password, kAutocompleteNewPassword)) |
| password_form->new_password_marked_by_site = true; |