Commit b7bc00ba authored by Maxim Kolosovskiy's avatar Maxim Kolosovskiy Committed by Commit Bot

[Password Manager] Show autofill signatures flag should also annotate unowned

 fields.

Bug: 824793
Change-Id: I44b8fa3da4409c692eec54ecd25f2b306f27d8ba
Reviewed-on: https://chromium-review.googlesource.com/1009903
Commit-Queue: Maxim Kolosovskiy <kolos@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550164}
parent 40a5264a
...@@ -947,4 +947,26 @@ TEST_F(PasswordGenerationAgentTestForHtmlAnnotation, AnnotateForm) { ...@@ -947,4 +947,26 @@ TEST_F(PasswordGenerationAgentTestForHtmlAnnotation, AnnotateForm) {
EXPECT_EQ("1", generation_mark.Utf8()); EXPECT_EQ("1", generation_mark.Utf8());
} }
TEST_F(PasswordGenerationAgentTestForHtmlAnnotation, AnnotateUnownedFields) {
LoadHTMLWithUserGesture(kAccountCreationNoForm);
WebDocument document = GetMainFrame()->GetDocument();
// Check field signatures are set.
blink::WebElement username_element =
document.GetElementById(blink::WebString::FromUTF8("username"));
ASSERT_FALSE(username_element.IsNull());
blink::WebString username_signature = username_element.GetAttribute(
blink::WebString::FromUTF8("field_signature"));
ASSERT_FALSE(username_signature.IsNull());
EXPECT_EQ("239111655", username_signature.Ascii());
blink::WebElement password_element =
document.GetElementById(blink::WebString::FromUTF8("first_password"));
ASSERT_FALSE(password_element.IsNull());
blink::WebString password_signature = password_element.GetAttribute(
blink::WebString::FromUTF8("field_signature"));
ASSERT_FALSE(password_signature.IsNull());
EXPECT_EQ("3933215845", password_signature.Ascii());
}
} // namespace autofill } // namespace autofill
...@@ -468,10 +468,25 @@ bool IsPublicSuffixDomainMatch(const std::string& url1, ...@@ -468,10 +468,25 @@ bool IsPublicSuffixDomainMatch(const std::string& url1,
gurl1.port() == gurl2.port(); gurl1.port() == gurl2.port();
} }
// Annotate |forms| with form and field signatures as HTML attributes. // Annotate |fields| with field signatures as HTML attributes.
void AnnotateFormsWithSignatures( void AnnotateFieldsWithSignatures(
blink::WebVector<blink::WebFormElement> forms) { std::vector<blink::WebFormControlElement>* fields) {
for (blink::WebFormElement form : forms) { for (blink::WebFormControlElement& control_element : *fields) {
FieldSignature field_signature = CalculateFieldSignatureByNameAndType(
control_element.NameForAutofill().Utf16(),
control_element.FormControlTypeForAutofill().Utf8());
control_element.SetAttribute(
blink::WebString::FromASCII(kDebugAttributeForFieldSignature),
blink::WebString::FromUTF8(base::NumberToString(field_signature)));
}
}
// Annotate |forms| and all fields in the |frame| with form and field signatures
// as HTML attributes.
void AnnotateFormsAndFieldsWithSignatures(
blink::WebLocalFrame* frame,
blink::WebVector<blink::WebFormElement>* forms) {
for (blink::WebFormElement& form : *forms) {
std::unique_ptr<PasswordForm> password_form( std::unique_ptr<PasswordForm> password_form(
CreatePasswordFormFromWebForm(form, nullptr, nullptr, nullptr)); CreatePasswordFormFromWebForm(form, nullptr, nullptr, nullptr));
if (password_form) { if (password_form) {
...@@ -479,26 +494,16 @@ void AnnotateFormsWithSignatures( ...@@ -479,26 +494,16 @@ void AnnotateFormsWithSignatures(
blink::WebString::FromASCII(kDebugAttributeForFormSignature), blink::WebString::FromASCII(kDebugAttributeForFormSignature),
blink::WebString::FromUTF8(base::NumberToString( blink::WebString::FromUTF8(base::NumberToString(
CalculateFormSignature(password_form->form_data)))); CalculateFormSignature(password_form->form_data))));
std::vector<blink::WebFormControlElement> control_elements =
form_util::ExtractAutofillableElementsInForm(form);
if (control_elements.size() != password_form->form_data.fields.size())
return;
for (size_t i = 0; i < control_elements.size(); ++i) {
blink::WebFormControlElement control_element = control_elements[i];
const FormFieldData& field = password_form->form_data.fields[i];
if (field.name != control_element.NameForAutofill().Utf16())
continue;
control_element.SetAttribute(
blink::WebString::FromASCII(kDebugAttributeForFieldSignature),
blink::WebString::FromUTF8(
base::NumberToString(CalculateFieldSignatureForField(field))));
}
} }
std::vector<blink::WebFormControlElement> form_fields =
form_util::ExtractAutofillableElementsInForm(form);
AnnotateFieldsWithSignatures(&form_fields);
} }
std::vector<blink::WebFormControlElement> unowned_elements =
form_util::GetUnownedAutofillableFormFieldElements(
frame->GetDocument().All(), nullptr);
AnnotateFieldsWithSignatures(&unowned_elements);
} }
// Returns true iff there is a password field in |frame|. // Returns true iff there is a password field in |frame|.
...@@ -1090,7 +1095,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) { ...@@ -1090,7 +1095,7 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
frame->GetDocument().Forms(forms); frame->GetDocument().Forms(forms);
if (IsShowAutofillSignaturesEnabled()) if (IsShowAutofillSignaturesEnabled())
AnnotateFormsWithSignatures(forms); AnnotateFormsAndFieldsWithSignatures(frame, &forms);
if (logger) if (logger)
logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size()); logger->LogNumber(Logger::STRING_NUMBER_OF_ALL_FORMS, forms.size());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment