Commit 2efafdbf authored by Vadym Doroshenko's avatar Vadym Doroshenko Committed by Commit Bot

Adding unique_renderer_id to FormData.

On CL https://chromium-review.googlesource.com/c/chromium/src/+/1002847
unique ids were implemented for WebFormElement and WebFormControlElement.
This CL adds them to FormData and propagates them to the browser process.


Bug: 831123

Change-Id: Ibe63e5bc39b126e509508103d5725ccd91fc85dc
Reviewed-on: https://chromium-review.googlesource.com/1055491Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Commit-Queue: Vadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#559482}
parent 20a94e7f
......@@ -2675,6 +2675,7 @@ TEST_F(FormAutofillTest, WebFormElementToFormData) {
EXPECT_TRUE(WebFormElementToFormData(forms[0], input_element, nullptr,
EXTRACT_VALUE, &form, &field));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
EXPECT_EQ(forms[0].UniqueRendererFormId(), form.unique_renderer_id);
EXPECT_EQ(GetCanonicalOriginForDocument(frame->GetDocument()), form.origin);
EXPECT_FALSE(form.origin.is_empty());
EXPECT_EQ(GURL("http://cnn.com/submit/"), form.action);
......@@ -2724,6 +2725,13 @@ TEST_F(FormAutofillTest, WebFormElementToFormData) {
expected.form_control_type = "month";
expected.max_length = 0;
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]);
// Check unique_renderer_id.
WebVector<WebFormControlElement> form_control_elements;
forms[0].GetFormControlElements(form_control_elements);
for (size_t i = 0; i < fields.size(); ++i)
EXPECT_EQ(form_control_elements[i].UniqueRendererFormControlId(),
fields[i].unique_renderer_id);
}
TEST_F(FormAutofillTest, WebFormElementConsiderNonControlLabelableElements) {
......
......@@ -111,6 +111,7 @@ struct FormFieldData {
string autocomplete_attribute;
mojo_base.mojom.String16 placeholder;
mojo_base.mojom.String16 css_classes;
uint32 unique_renderer_id;
uint32 properties_mask;
uint64 max_length;
......@@ -141,6 +142,7 @@ struct FormData {
url.mojom.Origin main_frame_origin;
bool is_form_tag;
bool is_formless_checkout;
uint32 unique_renderer_id;
array<FormFieldData> fields;
};
......
......@@ -574,7 +574,7 @@ bool StructTraits<
return false;
out->properties_mask = data.properties_mask();
out->unique_renderer_id = data.unique_renderer_id();
out->max_length = data.max_length();
out->is_autofilled = data.is_autofilled();
......@@ -622,6 +622,7 @@ bool StructTraits<autofill::mojom::FormDataDataView, autofill::FormData>::Read(
out->is_form_tag = data.is_form_tag();
out->is_formless_checkout = data.is_formless_checkout();
out->unique_renderer_id = data.unique_renderer_id();
if (!data.ReadFields(&out->fields))
return false;
......
......@@ -155,6 +155,10 @@ struct StructTraits<autofill::mojom::FormFieldDataDataView,
return r.css_classes;
}
static uint32_t unique_renderer_id(const autofill::FormFieldData& r) {
return r.unique_renderer_id;
}
static uint32_t properties_mask(const autofill::FormFieldData& r) {
return r.properties_mask;
}
......@@ -249,6 +253,10 @@ struct StructTraits<autofill::mojom::FormDataDataView, autofill::FormData> {
return r.is_formless_checkout;
}
static uint32_t unique_renderer_id(const autofill::FormData& r) {
return r.unique_renderer_id;
}
static const std::vector<autofill::FormFieldData>& fields(
const autofill::FormData& r) {
return r.fields;
......
......@@ -1472,6 +1472,7 @@ void WebFormControlElementToFormField(
if (id != field->name)
field->id = id;
field->unique_renderer_id = element.UniqueRendererFormControlId();
field->form_control_type = element.FormControlTypeForAutofill().Utf8();
field->autocomplete_attribute = element.GetAttribute(kAutocomplete).Utf8();
if (field->autocomplete_attribute.size() > kMaxDataLength) {
......@@ -1595,6 +1596,7 @@ bool WebFormElementToFormData(
return false;
form->name = GetFormIdentifier(form_element);
form->unique_renderer_id = form_element.UniqueRendererFormId();
form->origin = GetCanonicalOriginForDocument(frame->GetDocument());
form->action = GetCanonicalActionForForm(form_element);
if (frame->Top()) {
......
......@@ -110,6 +110,7 @@ bool FormData::SimilarFormAs(const FormData& form) const {
bool FormData::operator==(const FormData& form) const {
return name == form.name && origin == form.origin && action == form.action &&
unique_renderer_id == form.unique_renderer_id &&
is_form_tag == form.is_form_tag &&
is_formless_checkout == form.is_formless_checkout &&
fields == form.fields;
......
......@@ -5,6 +5,7 @@
#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_FORM_DATA_H_
#define COMPONENTS_AUTOFILL_CORE_COMMON_FORM_DATA_H_
#include <limits>
#include <vector>
#include "base/strings/string16.h"
......@@ -16,6 +17,9 @@ namespace autofill {
// Holds information about a form to be filled and/or submitted.
struct FormData {
static constexpr uint32_t kNotSetFormRendererId =
std::numeric_limits<uint32_t>::max();
FormData();
FormData(const FormData& data);
~FormData();
......@@ -51,6 +55,10 @@ struct FormData {
// and used if features::kAutofillRestrictUnownedFieldsToFormlessCheckout is
// enabled, to prevent heuristics from running on formless non-checkout.
bool is_formless_checkout;
// Unique renderer id which is returned by function
// WebFormElement::UniqueRendererFormId(). It is not persistant between page
// loads, so it is not saved and not used in comparison in SameFormAs().
uint32_t unique_renderer_id = kNotSetFormRendererId;
// A vector of all the input fields in the form.
std::vector<FormFieldData> fields;
};
......
......@@ -196,7 +196,8 @@ bool FormFieldData::IsTextInputElement() const {
}
bool FormFieldData::operator==(const FormFieldData& field) const {
return SameFieldAs(field) && is_autofilled == field.is_autofilled &&
return SameFieldAs(field) && unique_renderer_id == field.unique_renderer_id &&
is_autofilled == field.is_autofilled &&
check_status == field.check_status &&
option_values == field.option_values &&
option_contents == field.option_contents &&
......
......@@ -7,6 +7,7 @@
#include <stddef.h>
#include <limits>
#include <vector>
#include "base/i18n/rtl.h"
......@@ -68,6 +69,9 @@ struct FormFieldData {
VALUE, // label is the value of element.
};
static constexpr uint32_t kNotSetFormControlRendererId =
std::numeric_limits<uint32_t>::max();
FormFieldData();
FormFieldData(const FormFieldData& other);
~FormFieldData();
......@@ -107,6 +111,11 @@ struct FormFieldData {
std::string autocomplete_attribute;
base::string16 placeholder;
base::string16 css_classes;
// Unique renderer id which is returned by function
// WebFormControlElement::UniqueRendererFormControlId(). It is not persistant
// between page loads, so it is not saved and not used in comparison in
// SameFieldAs().
uint32_t unique_renderer_id = kNotSetFormControlRendererId;
// The unique identifier of the section (e.g. billing vs. shipping address)
// of this field.
......
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