Commit 2c03ed4e authored by gcasto's avatar gcasto Committed by Commit bot

[Password Manager] Relax matching for username overrides.

Currently if the form changes in any way between parsing and form submission
any server overrides for the form will be ignored. Relax the matching to only
take into account name and action for the form and name for the field. This
is similar to how Autofill matches.

BUG=476092

Review URL: https://codereview.chromium.org/1088973003

Cr-Commit-Position: refs/heads/master@{#325380}
parent 3d79d9d3
...@@ -1919,6 +1919,17 @@ TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) { ...@@ -1919,6 +1919,17 @@ TEST_F(PasswordAutofillAgentTest, FindingUsernameWithAutofillPredictions) {
AutofillMsg_AutofillUsernameDataReceived msg(0, predictions); AutofillMsg_AutofillUsernameDataReceived msg(0, predictions);
static_cast<content::RenderFrameObserver*>(password_autofill_agent_) static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
->OnMessageReceived(msg); ->OnMessageReceived(msg);
// The prediction should still match even if the form changes, as long
// as the particular element doesn't change.
std::string add_field_to_form =
"var form = document.getElementById('LoginTestForm');"
"var new_input = document.createElement('input');"
"new_input.setAttribute('type', 'text');"
"new_input.setAttribute('id', 'other_field');"
"form.appendChild(new_input);";
ExecuteJavaScript(add_field_to_form.c_str());
static_cast<content::RenderFrameObserver*>(password_autofill_agent_) static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
->WillSendSubmitEvent(username_element_.form()); ->WillSendSubmitEvent(username_element_.form());
static_cast<content::RenderFrameObserver*>(password_autofill_agent_) static_cast<content::RenderFrameObserver*>(password_autofill_agent_)
......
...@@ -192,21 +192,27 @@ void FindPredictedUsernameElement( ...@@ -192,21 +192,27 @@ void FindPredictedUsernameElement(
return; return;
} }
// Prediction forms are not user submitted, but |form| can be user submitted. // Matching only requires that action and name of the form match to allow
// We don't care about this flag for finding predictions, so set it to false. // the username to be updated even if the form is changed after page load.
form_data.user_submitted = false; // See https://crbug.com/476092 for more details.
auto predictions_iterator = form_predictions.find(form_data); auto predictions_iterator = form_predictions.begin();
for (;predictions_iterator != form_predictions.end();
++predictions_iterator) {
if (predictions_iterator->first.action == form_data.action &&
predictions_iterator->first.name == form_data.name) {
break;
}
}
if (predictions_iterator == form_predictions.end()) if (predictions_iterator == form_predictions.end())
return; return;
std::vector<blink::WebFormControlElement> autofillable_elements = std::vector<blink::WebFormControlElement> autofillable_elements =
ExtractAutofillableElementsFromSet(*control_elements); ExtractAutofillableElementsFromSet(*control_elements);
DCHECK_EQ(autofillable_elements.size(), form_data.fields.size());
const autofill::FormFieldData& username_field = predictions_iterator->second; const autofill::FormFieldData& username_field = predictions_iterator->second;
autofill::FormFieldData form_field;
for (size_t i = 0; i < autofillable_elements.size(); ++i) { for (size_t i = 0; i < autofillable_elements.size(); ++i) {
if (form_data.fields[i].SameFieldAs(username_field)) { if (autofillable_elements[i].nameForAutofill() == username_field.name) {
WebInputElement* input_element = WebInputElement* input_element =
toWebInputElement(&autofillable_elements[i]); toWebInputElement(&autofillable_elements[i]);
if (input_element) { if (input_element) {
......
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