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
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ANDROID_AUTOFILL_BROWSER_ANDROID_AUTOFILL_MANAGER_H_
#define COMPONENTS_ANDROID_AUTOFILL_BROWSER_ANDROID_AUTOFILL_MANAGER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "components/autofill/core/browser/crowdsourcing/autofill_crowdsourcing_manager.h"
#include "components/autofill/core/browser/foundations/autofill_manager.h"
#include "components/autofill/core/common/dense_set.h"
namespace autofill {
class AutofillProvider;
class AndroidFormEventLogger;
// This class forwards AutofillManager calls to AutofillProvider.
class AndroidAutofillManager : public AutofillManager,
public AutofillManager::Observer {
public:
explicit AndroidAutofillManager(AutofillDriver* driver);
AndroidAutofillManager(const AndroidAutofillManager&) = delete;
AndroidAutofillManager& operator=(const AndroidAutofillManager&) = delete;
~AndroidAutofillManager() override;
base::WeakPtr<AndroidAutofillManager> GetWeakPtrToLeafClass() {
return weak_ptr_factory_.GetWeakPtr();
}
base::WeakPtr<AutofillManager> GetWeakPtr() override;
bool ShouldClearPreviewedForm() override;
void OnFocusOnNonFormFieldImpl() override;
void OnDidFillAutofillFormDataImpl(const FormData& form,
const base::TimeTicks timestamp) override;
void OnDidEndTextFieldEditingImpl() override {}
void OnHidePopupImpl() override;
void OnSelectFieldOptionsDidChangeImpl(const FormData& form) override {}
void ReportAutofillWebOTPMetrics(bool used_web_otp) override {}
bool has_server_prediction(FormGlobalId form) const {
return forms_with_server_predictions_.contains(form);
}
FieldTypeGroup ComputeFieldTypeGroupForField(const FormGlobalId& form_id,
const FieldGlobalId& field_id);
// Send the |form| to the renderer for the specified |action|.
//
// |triggered_origin| is the origin of the field from which the autofill is
// triggered; this affects the security policy for cross-frame fills. See
// AutofillDriver::FillOrPreviewForm() for further details.
void FillOrPreviewForm(mojom::ActionPersistence action_persistence,
FormData form,
const FieldTypeGroup field_type_group,
const url::Origin& triggered_origin);
protected:
void Reset() override;
void OnFormSubmittedImpl(const FormData& form,
mojom::SubmissionSource source) override;
void OnCaretMovedInFormFieldImpl(const FormData& form,
const FieldGlobalId& field_id,
const gfx::Rect& caret_bounds) override {}
void OnTextFieldValueChangedImpl(const FormData& form,
const FieldGlobalId& field_id,
const base::TimeTicks timestamp) override;
void OnTextFieldDidScrollImpl(const FormData& form,
const FieldGlobalId& field_id) override;
void OnAskForValuesToFillImpl(
const FormData& form,
const FieldGlobalId& field_id,
const gfx::Rect& caret_bounds,
AutofillSuggestionTriggerSource trigger_source,
std::optional<PasswordSuggestionRequest> password_request) override;
void OnFocusOnFormFieldImpl(const FormData& form,
const FieldGlobalId& field_id) override;
void OnSelectControlSelectionChangedImpl(
const FormData& form,
const FieldGlobalId& field_id) override;
void OnJavaScriptChangedAutofilledValueImpl(
const FormData& form,
const FieldGlobalId& field_id,
const std::u16string& old_value) override {}
void OnLoadedServerPredictionsImpl(
base::span<const raw_ptr<FormStructure, VectorExperimental>> forms)
override {}
bool ShouldParseForms() override;
void OnBeforeProcessParsedForms() override {}
void OnFormProcessed(const FormData& form,
const FormStructure& form_structure) override;
private:
// AutofillManager::Observer:
void OnFieldTypesDetermined(AutofillManager& manager,
FormGlobalId form,
FieldTypeSource source) override;
AutofillProvider* GetAutofillProvider();
// Records metrics for loggers and creates new logging session.
void StartNewLoggingSession();
// Returns logger associated with the passed-in `form_id` and `field_id`.
AndroidFormEventLogger* GetEventFormLogger(const FormGlobalId& form_id,
const FieldGlobalId& field_id);
// Returns logger associated with the passed-in `field_type_group`.
AndroidFormEventLogger* GetEventFormLogger(FieldTypeGroup field_type_group);
// Returns logger associated with the passed-in `form_type`.
AndroidFormEventLogger* GetEventFormLogger(FormType form_type);
// The forms that have received server predictions.
base::flat_set<FormGlobalId> forms_with_server_predictions_;
std::unique_ptr<AndroidFormEventLogger> address_logger_;
std::unique_ptr<AndroidFormEventLogger> loyalty_card_logger_;
std::unique_ptr<AndroidFormEventLogger> payments_logger_;
std::unique_ptr<AndroidFormEventLogger> password_logger_;
base::ScopedObservation<AutofillManager, AutofillManager::Observer>
autofill_manager_observation{this};
base::WeakPtrFactory<AndroidAutofillManager> weak_ptr_factory_{this};
};
} // namespace autofill
#endif // COMPONENTS_ANDROID_AUTOFILL_BROWSER_ANDROID_AUTOFILL_MANAGER_H_
|