Commit 8bf35ae9 authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

[Autofill Assistant] Fix selector when using Autofill in an iframe.

Before this patch, WebController could not find the form data if that
form data was in an iframe. The logic that cleaned up the selector of
the element that was clicked on to pass to GetElementFormAndFieldData
didn't trigger, as the frame index reported in FindElementResult was 0.

This patch takes another approach: it always only pass the last selector
to GetElementFormAndFieldData, which should make sense, since we're in
the same context as the element that was clicked on.

With this patch, Autofill works even when forms are in an iframe.

Bug: 806868
Change-Id: Ic7deaf863373659e9143c38cf01a6ca1406e6521
Reviewed-on: https://chromium-review.googlesource.com/c/1264600
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597164}
parent 35137ea8
...@@ -507,17 +507,14 @@ void WebController::OnClickObjectForFillingForm( ...@@ -507,17 +507,14 @@ void WebController::OnClickObjectForFillingForm(
DLOG(ERROR) << "Failed to click the element for filling form."; DLOG(ERROR) << "Failed to click the element for filling form.";
OnResult(false, std::move(callback)); OnResult(false, std::move(callback));
} }
std::vector<std::string> element_selectors = selectors;
DCHECK(element_selectors.size() >
element_result->container_frame_selector_index);
for (size_t i = element_result->container_frame_selector_index; i > 0; i++) {
element_selectors.erase(element_selectors.begin());
}
ContentAutofillDriver* driver = ContentAutofillDriver::GetForRenderFrameHost( ContentAutofillDriver* driver = ContentAutofillDriver::GetForRenderFrameHost(
element_result->container_frame_host); element_result->container_frame_host);
DCHECK(!selectors.empty());
// TODO(crbug.com/806868): Figure out whether there are cases where we need
// more than one selector, and come up with a solution that can figure out the
// right number of selectors to include.
driver->GetAutofillAgent()->GetElementFormAndFieldData( driver->GetAutofillAgent()->GetElementFormAndFieldData(
element_selectors, std::vector<std::string>(1, selectors.back()),
base::BindOnce(&WebController::OnGetFormAndFieldDataForFillingForm, base::BindOnce(&WebController::OnGetFormAndFieldDataForFillingForm,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
std::move(data_to_autofill), std::move(callback), std::move(data_to_autofill), std::move(callback),
......
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