chromium/components/autofill/core/browser/form_forest.cc

// Copyright 2021 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/core/browser/form_forest.h"

#include <limits>
#include <memory>
#include <optional>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/stack.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "components/autofill/core/browser/form_forest_util_inl.h"
#include "third_party/abseil-cpp/absl/types/variant.h"

namespace autofill::internal {

FormForest::FrameData::FrameData(LocalFrameToken frame_token)
    :{}
FormForest::FrameData::~FrameData() = default;

FormForest::FormForest() = default;
FormForest::~FormForest() = default;

FormForest::FrameData* FormForest::GetOrCreateFrameData(LocalFrameToken frame) {}

FormForest::FrameData* FormForest::GetFrameData(LocalFrameToken frame) {}

FormData* FormForest::GetFormData(FormGlobalId form, FrameData* frame_data) {}

FormForest::FrameAndForm FormForest::GetRoot(FormGlobalId form) {}

void FormForest::EraseReferencesTo(
    absl::variant<LocalFrameToken, FormGlobalId> frame_or_form,
    base::flat_set<FormGlobalId>* forms_with_removed_fields) {}

base::flat_set<FormGlobalId> FormForest::EraseForms(
    base::span<const FormGlobalId> renderer_forms) {}

void FormForest::EraseFormsOfFrame(LocalFrameToken frame, bool keep_frame) {}

// Maintains the following invariants:
// 1. The graph is a disjoint union of trees, and the trees faithfully represent
//    the frame-transcending forms in the DOMs.
// 2. The root forms of each tree contain (only) the nodes of all forms in
//    the subtree in DOM order, and all non-root forms have no fields.
//
// We keep the FormData::child_frame and FrameData::parent_form relations in
// symmetry to ease reasoning about the tree. Since children are predetermined
// by FormData:child_frame, we do so by always updating the childrens'
// FrameData::parent_form.
//
// If |form| is not part of a frame-transcending form, the function has minimal
// overhead. That is, if |form|'s FormData::child_frames is empty and |form|'s
// frame has no parent frame, the function reduces to a few moves and index
// lookups.
//
// If the FrameData::parent_form of |form|'s frame is not set although a parent
// frame exists, the function triggers form re-extraction in the parent frame.
// This will trigger UpdateTreeOfRendererForm() for the true parent form
// (amongst others), which will then also set the child frame's
// FrameData::parent_form.
void FormForest::UpdateTreeOfRendererForm(FormData* form,
                                          AutofillDriver& driver) {}

const FormData& FormForest::GetBrowserForm(FormGlobalId renderer_form) const {}

FormForest::SecurityOptions::SecurityOptions(
    const url::Origin* main_origin,
    const url::Origin* triggered_origin,
    const base::flat_map<FieldGlobalId, FieldType>* field_type_map)
    :{}

FieldType FormForest::SecurityOptions::GetFieldType(
    const FieldGlobalId& field) const {}

FormForest::RendererForms::RendererForms() = default;
FormForest::RendererForms::RendererForms(RendererForms&&) = default;
FormForest::RendererForms& FormForest::RendererForms::operator=(
    RendererForms&&) = default;
FormForest::RendererForms::~RendererForms() = default;

FormForest::RendererForms FormForest::GetRendererFormsOfBrowserFields(
    base::span<const FormFieldData> browser_fields,
    const SecurityOptions& security_options) const {}

}  // namespace autofill::internal