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 dd97e9aaba7621fba147504501066f4e459358d6..3bf8b3dbc1b5e0b82d41250e56ef02a1d9491542 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 "third_party/WebKit/public/web/WebDocument.h" |
| #include "third_party/WebKit/public/web/WebFormControlElement.h" |
| #include "third_party/WebKit/public/web/WebInputElement.h" |
| +#include "third_party/re2/re2/re2.h" |
|
Ilya Sherman
2015/03/19 21:25:50
Existing Autofill code uses ICU for regexes. I do
vabr (Chromium)
2015/03/20 13:07:00
Thanks for pointing this out, I did not know about
|
| using blink::WebDocument; |
| using blink::WebFormControlElement; |
| @@ -22,6 +23,21 @@ using blink::WebVector; |
| namespace autofill { |
| namespace { |
| +// Given the sequence of non-password and password text input fields of a form, |
| +// represented as a string of Ns (non-password) and Ps (password), computes the |
| +// layout type of that form. |
| +PasswordForm::Layout SequenceToLayout(re2::StringPiece layout_sequence) { |
| + // NPN+P.* corresponds to a form which starts with a login section (NP) and |
| + // continues with a sign-up section (N+PP.*). The aim is to distinguish such |
|
Ilya Sherman
2015/03/19 21:25:50
Is the end of the regex supposed to be "PP.* or "P
vabr (Chromium)
2015/03/20 13:07:00
PP was a typo, thanks for pointing it out.
|
| + // forms from change password-forms (N*PPP?) and forms which use password |
|
Ilya Sherman
2015/03/19 21:25:50
Is there intentionally not a .* at the end of this
vabr (Chromium)
2015/03/20 13:07:00
Not intentionally. It was meant as an example. Add
|
| + // fields to store private but non-password data (could look like, e.g., |
| + // PN+P.*). This is likely not bullet-proof, and if we see a form which is |
| + // misclassified by this, we should consider improving the classification. |
| + if (RE2::FullMatch(layout_sequence, "NPN+P.*")) |
| + return PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP; |
| + return PasswordForm::Layout::LAYOUT_OTHER; |
| +} |
|
Ilya Sherman
2015/03/19 21:25:50
Honestly, I do not think this code is very clear w
vabr (Chromium)
2015/03/20 13:07:00
I'm not sure I follow you here. What do you mean b
Ilya Sherman
2015/03/20 22:43:07
After trying to write this as a C++ method, I with
vabr (Chromium)
2015/03/23 14:23:44
Thanks for explanation. I tried to emulate the ver
|
| + |
| // Checks in a case-insensitive way if the autocomplete attribute for the given |
| // |element| is present and has the specified |value_in_lowercase|. |
| bool HasAutocompleteAttributeValue(const WebInputElement& element, |
| @@ -125,6 +141,8 @@ void GetPasswordForm( |
| WebVector<WebFormControlElement> control_elements; |
| form.getFormControlElements(control_elements); |
| + std::string layout_sequence; |
| + layout_sequence.reserve(control_elements.size()); |
| for (size_t i = 0; i < control_elements.size(); ++i) { |
| WebFormControlElement control_element = control_elements[i]; |
| if (control_element.isActivatedSubmit()) |
| @@ -134,6 +152,13 @@ void GetPasswordForm( |
| if (!input_element || !input_element->isEnabled()) |
| continue; |
| + if (input_element->isTextField()) { |
| + if (input_element->isPasswordField()) |
| + layout_sequence.push_back('P'); |
| + else |
| + layout_sequence.push_back('N'); |
| + } |
| + |
| if (input_element->isPasswordField()) { |
| passwords.push_back(*input_element); |
| // If we have not yet considered any element to be the username so far, |
| @@ -194,6 +219,7 @@ void GetPasswordForm( |
| } |
| } |
| } |
| + password_form->layout = SequenceToLayout(layout_sequence); |
| if (!username_element.isNull()) { |
| password_form->username_element = username_element.nameForAutofill(); |