chromium/components/autofill/content/browser/content_autofill_driver.cc

// 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 "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/autofill_client.h"
#include "components/autofill/core/browser/autofill_driver_router.h"
#include "components/autofill/core/browser/form_structure.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 "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/permissions_policy/permissions_policy_features.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
#include "url/origin.h"

namespace autofill {

namespace {

AnyOf;

// 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) {}

FormData Lift(ContentAutofillDriver& source, FormData form) {}

FormGlobalId Lift(ContentAutofillDriver& source, FormRendererId id) {}

FieldGlobalId Lift(ContentAutofillDriver& source, FieldRendererId id) {}

template <typename T>
auto Lift(ContentAutofillDriver& source, const std::optional<T>& x) {}

template <typename T>
auto Lift(ContentAutofillDriver& source, const std::vector<T>& xs) {}

gfx::Rect Lift(ContentAutofillDriver& source, gfx::Rect r) {}

template <typename... Args>
base::OnceCallback<void(Args...)> Lift(ContentAutofillDriver& source,
                                       base::OnceCallback<void(Args...)> 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) {}

auto& WithNewVersion(const FormData& browser_form) {}

auto& WithNewVersion(const std::optional<FormData>& browser_form) {}

auto& WithNewVersion(const std::vector<FormData>& browser_forms) {}

template <typename... Args>
base::OnceCallback<void(Args...)> WithNewVersion(
    base::OnceCallback<void(Args...)> 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) {}

// 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) {}

}  // namespace

ContentAutofillDriver::ContentAutofillDriver(
    content::RenderFrameHost* render_frame_host,
    ContentAutofillDriverFactory* owner)
    :{}

ContentAutofillDriver::~ContentAutofillDriver() {}

void ContentAutofillDriver::Reset(ContentAutofillDriverFactoryPassKey) {}

void ContentAutofillDriver::TriggerFormExtractionInDriverFrame(
    AutofillDriverRouterAndFormForestPassKey pass_key) {}

void ContentAutofillDriver::TriggerFormExtractionInAllFrames(
    base::OnceCallback<void(bool success)> form_extraction_finished_callback) {}

void ContentAutofillDriver::GetFourDigitCombinationsFromDom(
    base::OnceCallback<void(const std::vector<std::string>&)>
        potential_matches) {}

// static
ContentAutofillDriver* ContentAutofillDriver::GetForRenderFrameHost(
    content::RenderFrameHost* render_frame_host) {}

void ContentAutofillDriver::BindPendingReceiver(
    mojo::PendingAssociatedReceiver<mojom::AutofillDriver> pending_receiver) {}

LocalFrameToken ContentAutofillDriver::GetFrameToken() const {}

ContentAutofillDriver* ContentAutofillDriver::GetParent() {}

ContentAutofillClient& ContentAutofillDriver::GetAutofillClient() {}

AutofillManager& ContentAutofillDriver::GetAutofillManager() {}

std::optional<LocalFrameToken> ContentAutofillDriver::Resolve(
    FrameToken query) {}

bool ContentAutofillDriver::IsActive() const {}

bool ContentAutofillDriver::IsInAnyMainFrame() const {}

bool ContentAutofillDriver::HasSharedAutofillPermission() const {}

bool ContentAutofillDriver::CanShowAutofillUi() const {}

std::optional<net::IsolationInfo> ContentAutofillDriver::GetIsolationInfo() {}

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) {}

void ContentAutofillDriver::ApplyFieldAction(
    mojom::FieldActionType action_type,
    mojom::ActionPersistence action_persistence,
    const FieldGlobalId& field_id,
    const std::u16string& value) {}

void ContentAutofillDriver::ExtractForm(FormGlobalId form_id,
                                        BrowserFormHandler final_handler) {}

void ContentAutofillDriver::SendTypePredictionsToRenderer(
    const std::vector<raw_ptr<FormStructure, VectorExperimental>>& forms) {}

void ContentAutofillDriver::RendererShouldAcceptDataListSuggestion(
    const FieldGlobalId& field_id,
    const std::u16string& value) {}

void ContentAutofillDriver::RendererShouldClearPreviewedForm() {}

void ContentAutofillDriver::RendererShouldTriggerSuggestions(
    const FieldGlobalId& field_id,
    AutofillSuggestionTriggerSource trigger_source) {}

void ContentAutofillDriver::RendererShouldSetSuggestionAvailability(
    const FieldGlobalId& field_id,
    mojom::AutofillSuggestionAvailability suggestion_availability) {}

void ContentAutofillDriver::FormsSeen(
    const std::vector<FormData>& updated_forms,
    const std::vector<FormRendererId>& removed_forms) {}

void ContentAutofillDriver::FormSubmitted(
    const FormData& form,
    bool known_success,
    mojom::SubmissionSource submission_source) {}

void ContentAutofillDriver::CaretMovedInFormField(
    const FormData& form,
    FieldRendererId field_id,
    const gfx::Rect& caret_bounds) {}

void ContentAutofillDriver::TextFieldDidChange(const FormData& form,
                                               FieldRendererId field_id,
                                               base::TimeTicks timestamp) {}

void ContentAutofillDriver::TextFieldDidScroll(const FormData& form,
                                               FieldRendererId field_id) {}

void ContentAutofillDriver::SelectControlDidChange(const FormData& form,
                                                   FieldRendererId field_id) {}

void ContentAutofillDriver::AskForValuesToFill(
    const FormData& form,
    FieldRendererId field_id,
    const gfx::Rect& caret_bounds,
    AutofillSuggestionTriggerSource trigger_source) {}

void ContentAutofillDriver::HidePopup() {}

void ContentAutofillDriver::FocusOnNonFormField() {}

void ContentAutofillDriver::FocusOnFormField(const FormData& form,
                                             FieldRendererId field_id) {}

void ContentAutofillDriver::DidFillAutofillFormData(const FormData& form,
                                                    base::TimeTicks timestamp) {}

void ContentAutofillDriver::DidEndTextFieldEditing() {}

void ContentAutofillDriver::SelectOrSelectListFieldOptionsDidChange(
    const FormData& form) {}

void ContentAutofillDriver::JavaScriptChangedAutofilledValue(
    const FormData& form,
    FieldRendererId field_id,
    const std::u16string& old_value,
    bool formatting_only) {}

const mojo::AssociatedRemote<mojom::AutofillAgent>&
ContentAutofillDriver::GetAutofillAgent() {}

void ContentAutofillDriver::LiftForTest(FormData& form) {}

AutofillDriverRouter& ContentAutofillDriver::router() {}

}  // namespace autofill