1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/content/browser/content_autofill_driver.h"
#include <concepts>
#include <functional>
#include <type_traits>
#include <utility>
#include <variant>
#include "base/barrier_callback.h"
#include "base/functional/callback.h"
#include "components/autofill/content/browser/bad_message.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/core/browser/form_structure.h"
#include "components/autofill/core/browser/foundations/autofill_client.h"
#include "components/autofill/core/browser/foundations/autofill_driver_router.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_data_predictions.h"
#include "components/autofill/core/common/signatures.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/message.h"
#include "services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "url/origin.h"
namespace autofill {
namespace {
template <typename T, typename... Ts>
concept AnyOf =
(std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<Ts>> || ...);
// Lift() elevates data from the a renderer process to the browser process.
// Every data received from a renderer should immediately be lifted.
//
// Lifting includes, for example, setting security-critical data like frame
// tokens and origins of Form[Field]Data. Another example is transforming
// coordinates from the originating frame's space to the top-level frame.
// No-op: add types to the `requires` clause below as necessary.
template <typename T>
requires(std::is_scalar_v<std::remove_cvref_t<T>> ||
AnyOf<T,
bool,
AutofillDriverRouter::RoutedCallback<>,
base::TimeTicks,
std::u16string>)
T&& Lift(ContentAutofillDriver& source, T&& x) {
return std::forward<T>(x);
}
gfx::Rect Lift(ContentAutofillDriver& source, gfx::Rect r) {
if (content::RenderWidgetHostView* view =
source.render_frame_host()->GetView()) {
r.set_origin(view->TransformPointToRootCoordSpace(r.origin()));
}
return r;
}
gfx::RectF Lift(ContentAutofillDriver& source, gfx::RectF r) {
if (content::RenderWidgetHostView* view =
source.render_frame_host()->GetView()) {
r.set_origin(view->TransformPointToRootCoordSpaceF(r.origin()));
}
return r;
}
FormData Lift(ContentAutofillDriver& source, FormData form) {
content::RenderFrameHost& rfh = *source.render_frame_host();
form.set_host_frame(source.GetFrameToken());
form.set_main_frame_origin(rfh.GetMainFrame()->GetLastCommittedOrigin());
// GetLastCommittedURL() doesn't include URL updates due to
// document.open() and so it might be about:blank or about:srcdoc. In this
// case fallback to GetLastCommittedOrigin(). See crbug.com/1209270.
GURL unstripped_url = rfh.GetLastCommittedURL();
if (unstripped_url.SchemeIs(url::kAboutScheme)) {
unstripped_url = rfh.GetLastCommittedOrigin().GetURL();
}
form.set_url(StripAuthAndParams(unstripped_url));
form.set_full_url(StripAuth(unstripped_url));
// The form signature must be calculated after setting FormData::url.
FormSignature signature = CalculateFormSignature(form);
std::vector<FormFieldData> fields = form.ExtractFields();
for (FormFieldData& field : fields) {
field.set_host_frame(form.host_frame());
field.set_host_form_id(form.renderer_id());
field.set_host_form_signature(signature);
field.set_origin(rfh.GetLastCommittedOrigin());
field.set_bounds(Lift(source, field.bounds()));
}
form.set_fields(std::move(fields));
return form;
}
FormGlobalId Lift(ContentAutofillDriver& source, FormRendererId id) {
return FormGlobalId(source.GetFrameToken(), id);
}
FieldGlobalId Lift(ContentAutofillDriver& source, FieldRendererId id) {
return FieldGlobalId(source.GetFrameToken(), id);
}
PasswordSuggestionRequest Lift(ContentAutofillDriver& source,
PasswordSuggestionRequest request) {
// These indices are equal to fields().size() for manual requests.
if (request.username_field_index > request.form_data.fields().size() ||
request.password_field_index > request.form_data.fields().size()) {
mojo::ReportBadMessage(
"username_field_index or password_field_index cannot be greater than "
"form.fields.size()!");
}
request.form_data = Lift(source, std::move(request.form_data));
request.field.bounds = Lift(source, std::move(request.field.bounds));
return request;
}
template <typename T>
std::optional<T> Lift(ContentAutofillDriver& source, std::optional<T> x) {
std::optional<T> y;
if (x) {
y.emplace(Lift(source, *std::move(x)));
}
return y;
}
template <typename T>
auto Lift(ContentAutofillDriver& source, const std::vector<T>& xs) {
std::vector<std::remove_cvref_t<decltype(Lift(source, xs.front()))>> ys;
ys.reserve(xs.size());
for (const auto& x : xs) {
ys.push_back(Lift(source, x));
}
return ys;
}
template <typename... Args>
base::OnceCallback<void(Args...)> Lift(ContentAutofillDriver& source,
base::OnceCallback<void(Args...)> cb) {
return base::BindOnce(
[](raw_ref<ContentAutofillDriver> source,
base::OnceCallback<void(Args...)> cb, Args... args) {
std::move(cb).Run(Lift(*source, std::forward<Args>(args))...);
},
raw_ref(source), std::move(cb));
}
// WithNewVersion() bumps the FormData::version of each form. This should be
// called for every browser form before it enters AutofillManager so that
// AutofillManager can distinguish newer and older forms.
//
// TODO(crbug.com/40144964): Remove once FormData objects aren't stored
// globally anymore.
// No-op: add types to the `requires` clause below as necessary.
template <typename T>
requires(std::is_scalar_v<std::remove_cvref_t<T>> ||
AnyOf<T,
bool,
FieldGlobalId,
base::TimeTicks,
gfx::Rect,
std::u16string,
std::vector<FormGlobalId>>)
T&& WithNewVersion(T&& x) {
return std::forward<T>(x);
}
auto& WithNewVersion(const FormData& browser_form) {
static FormVersion version_counter;
++*version_counter;
// This const_cast is a hack to avoid additional copies. It's OK because the
// FormData is owned by AutofillDriverRouter, FormData::version is written
// only here and read only in AutofillManager.
const_cast<FormData&>(browser_form).set_version(version_counter);
return browser_form;
}
auto& WithNewVersion(const std::optional<FormData>& browser_form) {
if (browser_form) {
WithNewVersion(*browser_form);
}
return browser_form;
}
auto& WithNewVersion(const std::vector<FormData>& browser_forms) {
for (const FormData& form : browser_forms) {
WithNewVersion(form);
}
return browser_forms;
}
std::optional<PasswordSuggestionRequest> WithNewVersion(
std::optional<PasswordSuggestionRequest> password_request) {
if (password_request) {
WithNewVersion(password_request->form_data);
}
return password_request;
}
template <typename... Args>
base::OnceCallback<void(Args...)> WithNewVersion(
base::OnceCallback<void(Args...)> cb) {
return base::BindOnce(
[](base::OnceCallback<void(Args...)> cb, Args... args) {
std::move(cb).Run(WithNewVersion(std::forward<Args>(args))...);
},
std::move(cb));
}
// Routes an event from the browser to one or multiple AutofillAgents.
//
// Routing converts values and types: for example, browser forms become renderer
// forms, and FieldGlobalIds become FieldRendererIds.
template <typename R,
typename... RouterArgs,
typename... AgentArgs,
typename... ActualArgs>
R RouteToAgent(AutofillDriverRouter& router,
R (AutofillDriverRouter::*router_fun)(
AutofillDriverRouter::RoutedCallback<AgentArgs...>,
RouterArgs...),
void (mojom::AutofillAgent::*agent_fun)(AgentArgs...),
ActualArgs&&... args) {
return (router.*router_fun)(
[&agent_fun](autofill::AutofillDriver& target, AgentArgs... args) {
if (!target.IsActive()) {
// We early-return rather than crashing or killing the renderer
// because Autofill might want to communicate with a frame that just
// became inactive due to race conditions. See crbug.com/345195973.
LOG(WARNING) << "Skipped Autofill message for inactive frame";
return;
}
mojom::AutofillAgent& agent =
*static_cast<ContentAutofillDriver&>(target).GetAutofillAgent();
(agent.*agent_fun)(std::forward<AgentArgs>(args)...);
},
std::forward<ActualArgs>(args)...);
}
// Routes an event from the renderer to one or multiple AutofillManagers.
//
// Routing converts values and types: for example, renderer forms become browser
// forms, and FieldRendererIds become FieldGlobalIds. Additionally, this
// function takes care of some necessary pre- and postprocessing: for example,
// it sets FormData::frame_token and transforms graphical coordinates, and bumps
// the browser form's FormData::version.
template <typename... RouterArgs,
typename... ManagerArgs,
typename... ActualArgs>
void RouteToManager(ContentAutofillDriver& source,
AutofillDriverRouter& router,
void (AutofillDriverRouter::*router_fun)(
AutofillDriverRouter::RoutedCallback<ManagerArgs...>,
autofill::AutofillDriver& source,
RouterArgs...),
void (AutofillManager::*manager_fun)(ManagerArgs...),
ActualArgs&&... args) {
if (!bad_message::CheckArgs(args...) ||
!bad_message::CheckFrameNotPrerendering(source.render_frame_host())) {
return;
}
return (router.*router_fun)(
[&manager_fun](autofill::AutofillDriver& target, ManagerArgs... args) {
AutofillManager& manager = target.GetAutofillManager();
(manager.*
manager_fun)(WithNewVersion(std::forward<ManagerArgs>(args))...);
},
source, Lift(source, std::forward<ActualArgs>(args))...);
}
} // namespace
ContentAutofillDriver::ContentAutofillDriver(
content::RenderFrameHost* render_frame_host,
ContentAutofillDriverFactory* owner)
: render_frame_host_(*render_frame_host), owner_(*owner) {
autofill_manager_ = GetAutofillClient().CreateManager(/*pass_key=*/{}, *this);
}
ContentAutofillDriver::~ContentAutofillDriver() {
owner_->router().UnregisterDriver(*this, /*driver_is_dying=*/true);
}
void ContentAutofillDriver::Reset(ContentAutofillDriverFactoryPassKey) {
owner_->router().UnregisterDriver(*this, /*driver_is_dying=*/false);
}
void ContentAutofillDriver::TriggerFormExtractionInDriverFrame(
AutofillDriverRouterAndFormForestPassKey pass_key) {
if (!IsActive()) {
LOG(WARNING) << "Skipped Autofill message for inactive frame";
return;
}
GetAutofillAgent()->TriggerFormExtraction();
}
void ContentAutofillDriver::TriggerFormExtractionInAllFrames(
base::OnceCallback<void(bool success)> form_extraction_finished_callback) {
std::vector<ContentAutofillDriver*> drivers;
render_frame_host()->GetMainFrame()->ForEachRenderFrameHost(
[&drivers](content::RenderFrameHost* rfh) {
if (rfh->IsActive()) {
if (auto* driver = GetForRenderFrameHost(rfh)) {
drivers.push_back(driver);
}
}
});
auto barrier_callback = base::BarrierCallback<bool>(
drivers.size(),
base::BindOnce(
[](base::OnceCallback<void(bool success)>
form_extraction_finished_callback,
const std::vector<bool>& successes) {
std::move(form_extraction_finished_callback)
.Run(std::ranges::all_of(successes, std::identity()));
},
std::move(form_extraction_finished_callback)));
for (ContentAutofillDriver* driver : drivers) {
driver->GetAutofillAgent()->TriggerFormExtractionWithResponse(
barrier_callback);
}
}
void ContentAutofillDriver::GetFourDigitCombinationsFromDom(
base::OnceCallback<void(const std::vector<std::string>&)>
potential_matches) {
if (!IsActive()) {
LOG(WARNING) << "Skipped Autofill message for inactive frame";
std::move(potential_matches).Run({});
return;
}
content::RenderFrameHost* main_rfh = render_frame_host_->GetMainFrame();
if (auto* main_driver = GetForRenderFrameHost(main_rfh)) {
main_driver->GetAutofillAgent()
->GetPotentialLastFourCombinationsForStandaloneCvc(
std::move(potential_matches));
}
}
void ContentAutofillDriver::ExtractLabeledTextNodeValue(
const std::u16string& value_regex,
const std::u16string& label_regex,
uint32_t number_of_ancestor_levels_to_search,
base::OnceCallback<void(const std::string& amount)> response_callback) {
if (!IsActive()) {
LOG(WARNING) << "Skipped Autofill message for inactive frame";
std::move(response_callback).Run(std::string());
return;
}
content::RenderFrameHost* main_rfh = render_frame_host_->GetMainFrame();
if (auto* main_driver = GetForRenderFrameHost(main_rfh)) {
main_driver->GetAutofillAgent()->ExtractLabeledTextNodeValue(
value_regex, label_regex, number_of_ancestor_levels_to_search,
std::move(response_callback));
}
}
// static
ContentAutofillDriver* ContentAutofillDriver::GetForRenderFrameHost(
content::RenderFrameHost* render_frame_host) {
ContentAutofillDriverFactory* factory =
ContentAutofillDriverFactory::FromWebContents(
content::WebContents::FromRenderFrameHost(render_frame_host));
return factory
? factory->DriverForFrame(render_frame_host,
base::PassKey<ContentAutofillDriver>())
: nullptr;
}
void ContentAutofillDriver::BindPendingReceiver(
mojo::PendingAssociatedReceiver<mojom::AutofillDriver> pending_receiver) {
receiver_.Bind(std::move(pending_receiver));
}
LocalFrameToken ContentAutofillDriver::GetFrameToken() const {
return LocalFrameToken(render_frame_host_->GetFrameToken().value());
}
ContentAutofillDriver* ContentAutofillDriver::GetParent() {
content::RenderFrameHost* parent_rfh = render_frame_host_->GetParent();
if (!parent_rfh) {
return nullptr;
}
return GetForRenderFrameHost(parent_rfh);
}
ContentAutofillClient& ContentAutofillDriver::GetAutofillClient() {
return owner_->client();
}
AutofillManager& ContentAutofillDriver::GetAutofillManager() {
return *autofill_manager_;
}
std::optional<LocalFrameToken> ContentAutofillDriver::Resolve(
FrameToken query) {
if (std::holds_alternative<LocalFrameToken>(query)) {
return std::get<LocalFrameToken>(query);
}
DCHECK(std::holds_alternative<RemoteFrameToken>(query));
content::RenderProcessHost* rph = render_frame_host_->GetProcess();
blink::RemoteFrameToken blink_remote_token(
std::get<RemoteFrameToken>(query).value());
content::RenderFrameHost* remote_rfh =
content::RenderFrameHost::FromPlaceholderToken(rph->GetDeprecatedID(),
blink_remote_token);
if (!remote_rfh) {
return std::nullopt;
}
return LocalFrameToken(remote_rfh->GetFrameToken().value());
}
ukm::SourceId ContentAutofillDriver::GetPageUkmSourceId() const {
CHECK(!render_frame_host_->IsInLifecycleState(
content::RenderFrameHost::LifecycleState::kPrerendering));
return render_frame_host_->GetPageUkmSourceId();
}
bool ContentAutofillDriver::IsActive() const {
return render_frame_host_->IsActive();
}
bool ContentAutofillDriver::HasSharedAutofillPermission() const {
return render_frame_host_->IsFeatureEnabled(
network::mojom::PermissionsPolicyFeature::kSharedAutofill);
}
bool ContentAutofillDriver::CanShowAutofillUi() const {
// Don't show AutofillUi for inactive RenderFrameHost. Here it is safe to
// ignore the calls from inactive RFH as the renderer is not expecting a reply
// and it doesn't lead to browser-renderer consistency issues.
return render_frame_host_->IsActive();
}
std::optional<net::IsolationInfo> ContentAutofillDriver::GetIsolationInfo() {
return render_frame_host_->GetIsolationInfoForSubresources();
}
base::flat_set<FieldGlobalId> ContentAutofillDriver::ApplyFormAction(
mojom::FormActionType action_type,
mojom::ActionPersistence action_persistence,
base::span<const FormFieldData> data,
const url::Origin& triggered_origin,
const base::flat_map<FieldGlobalId, FieldType>& field_type_map) {
// If this driver is active, then its main frame is identical to the main
// frame at the time the form was received from a renderer and their origins
// are the same.
url::Origin main_origin = [&] {
if (auto* main_rfh = render_frame_host_->GetMainFrame();
main_rfh->IsInPrimaryMainFrame()) {
return main_rfh->GetLastCommittedOrigin();
} else {
return url::Origin();
}
}();
return RouteToAgent(router(), &AutofillDriverRouter::ApplyFormAction,
&mojom::AutofillAgent::ApplyFieldsAction, action_type,
action_persistence, data, main_origin, triggered_origin,
field_type_map);
}
void ContentAutofillDriver::ApplyFieldAction(
mojom::FieldActionType action_type,
mojom::ActionPersistence action_persistence,
const FieldGlobalId& field_id,
const std::u16string& value) {
RouteToAgent(router(), &AutofillDriverRouter::ApplyFieldAction,
&mojom::AutofillAgent::ApplyFieldAction, action_type,
action_persistence, field_id, value);
}
void ContentAutofillDriver::ExtractForm(FormGlobalId form_id,
BrowserFormHandler final_handler) {
if (!IsActive()) {
LOG(WARNING) << "Skipped Autofill message for inactive frame";
std::move(final_handler).Run(nullptr, std::nullopt);
return;
}
router().ExtractForm(
[](autofill::AutofillDriver& request_target, FormRendererId form_id,
AutofillDriverRouter::RendererFormHandler route_response) {
auto& source = static_cast<ContentAutofillDriver&>(request_target);
source.GetAutofillAgent()->ExtractForm(
form_id, Lift(source, std::move(route_response)));
},
form_id, WithNewVersion(std::move(final_handler)));
}
void ContentAutofillDriver::ExposeDomNodeIDs() {
GetAutofillAgent()->ExposeDomNodeIDs();
}
void ContentAutofillDriver::SendTypePredictionsToRenderer(
const FormStructure& form) {
CHECK(base::FeatureList::IsEnabled(
features::test::kAutofillShowTypePredictions));
RouteToAgent(router(), &AutofillDriverRouter::SendTypePredictionsToRenderer,
&mojom::AutofillAgent::FieldTypePredictionsAvailable,
form.GetFieldTypePredictions());
}
void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion(
const FieldGlobalId& field_id,
const std::u16string& value) {
RouteToAgent(
router(), &AutofillDriverRouter::RendererShouldAcceptDataListSuggestion,
&mojom::AutofillAgent::AcceptDataListSuggestion, field_id, value);
}
void ContentAutofillDriver::RendererShouldClearPreviewedForm() {
RouteToAgent(router(),
&AutofillDriverRouter::RendererShouldClearPreviewedForm,
&mojom::AutofillAgent::ClearPreviewedForm);
}
void ContentAutofillDriver::RendererShouldTriggerSuggestions(
const FieldGlobalId& field_id,
AutofillSuggestionTriggerSource trigger_source) {
RouteToAgent(
router(), &AutofillDriverRouter::RendererShouldTriggerSuggestions,
&mojom::AutofillAgent::TriggerSuggestions, field_id, trigger_source);
}
void ContentAutofillDriver::RendererShouldSetSuggestionAvailability(
const FieldGlobalId& field_id,
mojom::AutofillSuggestionAvailability suggestion_availability) {
RouteToAgent(router(),
&AutofillDriverRouter::RendererShouldSetSuggestionAvailability,
&mojom::AutofillAgent::SetSuggestionAvailability, field_id,
suggestion_availability);
}
void ContentAutofillDriver::FormsSeen(
const std::vector<FormData>& updated_forms,
const std::vector<FormRendererId>& removed_forms) {
RouteToManager(*this, router(), &AutofillDriverRouter::FormsSeen,
&AutofillManager::OnFormsSeen, updated_forms, removed_forms);
}
void ContentAutofillDriver::FormSubmitted(
const FormData& form,
mojom::SubmissionSource submission_source) {
RouteToManager(*this, router(), &AutofillDriverRouter::FormSubmitted,
&AutofillManager::OnFormSubmitted, form, submission_source);
}
void ContentAutofillDriver::CaretMovedInFormField(
const FormData& form,
FieldRendererId field_id,
const gfx::Rect& caret_bounds) {
RouteToManager(*this, router(), &AutofillDriverRouter::CaretMovedInFormField,
&AutofillManager::OnCaretMovedInFormField, form, field_id,
caret_bounds);
}
void ContentAutofillDriver::TextFieldValueChanged(const FormData& form,
FieldRendererId field_id,
base::TimeTicks timestamp) {
RouteToManager(*this, router(), &AutofillDriverRouter::TextFieldValueChanged,
&AutofillManager::OnTextFieldValueChanged, form, field_id,
timestamp);
}
void ContentAutofillDriver::TextFieldDidScroll(const FormData& form,
FieldRendererId field_id) {
RouteToManager(*this, router(), &AutofillDriverRouter::TextFieldDidScroll,
&AutofillManager::OnTextFieldDidScroll, form, field_id);
}
void ContentAutofillDriver::SelectControlSelectionChanged(
const FormData& form,
FieldRendererId field_id) {
RouteToManager(
*this, router(), &AutofillDriverRouter::SelectControlSelectionChanged,
&AutofillManager::OnSelectControlSelectionChanged, form, field_id);
}
void ContentAutofillDriver::AskForValuesToFill(
const FormData& form,
FieldRendererId field_id,
const gfx::Rect& caret_bounds,
AutofillSuggestionTriggerSource trigger_source,
const std::optional<PasswordSuggestionRequest>& password_request) {
RouteToManager(*this, router(), &AutofillDriverRouter::AskForValuesToFill,
&AutofillManager::OnAskForValuesToFill, form, field_id,
caret_bounds, trigger_source, password_request);
}
void ContentAutofillDriver::HidePopup() {
RouteToManager(*this, router(), &AutofillDriverRouter::HidePopup,
&AutofillManager::OnHidePopup);
}
void ContentAutofillDriver::FocusOnNonFormField() {
RouteToManager(*this, router(), &AutofillDriverRouter::FocusOnNonFormField,
&AutofillManager::OnFocusOnNonFormField);
}
void ContentAutofillDriver::FocusOnFormField(const FormData& form,
FieldRendererId field_id) {
auto focus_no_longer_on_form = [](autofill::AutofillDriver& target) {
target.GetAutofillManager().OnFocusOnNonFormField();
};
RouteToManager(
*this, router(), &AutofillDriverRouter::FocusOnFormField,
&AutofillManager::OnFocusOnFormField, form, field_id,
AutofillDriverRouter::RoutedCallback<>(focus_no_longer_on_form));
}
void ContentAutofillDriver::DidFillAutofillFormData(const FormData& form,
base::TimeTicks timestamp) {
RouteToManager(*this, router(),
&AutofillDriverRouter::DidFillAutofillFormData,
&AutofillManager::OnDidFillAutofillFormData, form, timestamp);
}
void ContentAutofillDriver::DidEndTextFieldEditing() {
RouteToManager(*this, router(), &AutofillDriverRouter::DidEndTextFieldEditing,
&AutofillManager::OnDidEndTextFieldEditing);
}
void ContentAutofillDriver::SelectFieldOptionsDidChange(const FormData& form) {
RouteToManager(*this, router(),
&AutofillDriverRouter::SelectFieldOptionsDidChange,
&AutofillManager::OnSelectFieldOptionsDidChange, form);
}
void ContentAutofillDriver::JavaScriptChangedAutofilledValue(
const FormData& form,
FieldRendererId field_id,
const std::u16string& old_value) {
RouteToManager(*this, router(),
&AutofillDriverRouter::JavaScriptChangedAutofilledValue,
&AutofillManager::OnJavaScriptChangedAutofilledValue, form,
field_id, old_value);
}
const mojo::AssociatedRemote<mojom::AutofillAgent>&
ContentAutofillDriver::GetAutofillAgent() {
// Here is a lazy binding, and will not reconnect after connection error.
if (!autofill_agent_) {
render_frame_host_->GetRemoteAssociatedInterfaces()->GetInterface(
&autofill_agent_);
}
return autofill_agent_;
}
void ContentAutofillDriver::LiftForTest(FormData& form) {
form = Lift(*this, form);
}
AutofillDriverRouter& ContentAutofillDriver::router() {
return owner_->router();
}
} // namespace autofill
|