-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
content_autofill_driver.h
247 lines (210 loc) · 10.6 KB
/
content_autofill_driver.h
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_
#define COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/supports_user_data.h"
#include "build/build_config.h"
#include "components/autofill/content/browser/key_press_handler_manager.h"
#include "components/autofill/content/browser/webauthn/internal_authenticator_impl.h"
#include "components/autofill/content/common/mojom/autofill_agent.mojom.h"
#include "components/autofill/content/common/mojom/autofill_driver.mojom.h"
#include "components/autofill/core/browser/autofill_driver.h"
#include "components/autofill/core/browser/browser_autofill_manager.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
namespace content {
class NavigationHandle;
class RenderFrameHost;
} // namespace content
namespace autofill {
class AutofillClient;
class LogManager;
// Use <Phone><WebOTP><OTC> as the bit pattern to identify the metrics state.
enum class PhoneCollectionMetricState {
kNone = 0, // Site did not collect phone, not use OTC, not use WebOTP
kOTC = 1, // Site used OTC only
kWebOTP = 2, // Site used WebOTP only
kWebOTPPlusOTC = 3, // Site used WebOTP and OTC
kPhone = 4, // Site collected phone, not used neither WebOTP nor OTC
kPhonePlusOTC = 5, // Site collected phone number and used OTC
kPhonePlusWebOTP = 6, // Site collected phone number and used WebOTP
kPhonePlusWebOTPPlusOTC = 7, // Site collected phone number and used both
kMaxValue = kPhonePlusWebOTPPlusOTC,
};
namespace phone_collection_metric {
constexpr uint32_t kOTCUsed = 1 << 0;
constexpr uint32_t kWebOTPUsed = 1 << 1;
constexpr uint32_t kPhoneCollected = 1 << 2;
} // namespace phone_collection_metric
// Class that drives autofill flow in the browser process based on
// communication from the renderer and from the external world. There is one
// instance per RenderFrameHost.
class ContentAutofillDriver : public AutofillDriver,
public mojom::AutofillDriver,
public KeyPressHandlerManager::Delegate {
public:
ContentAutofillDriver(
content::RenderFrameHost* render_frame_host,
AutofillClient* client,
const std::string& app_locale,
AutofillManager::AutofillDownloadManagerState enable_download_manager,
AutofillManager::AutofillManagerFactoryCallback
autofill_manager_factory_callback);
~ContentAutofillDriver() override;
// Gets the driver for |render_frame_host|.
static ContentAutofillDriver* GetForRenderFrameHost(
content::RenderFrameHost* render_frame_host);
void BindPendingReceiver(
mojo::PendingAssociatedReceiver<mojom::AutofillDriver> pending_receiver);
// AutofillDriver:
bool IsIncognito() const override;
bool IsInMainFrame() const override;
bool CanShowAutofillUi() const override;
ui::AXTreeID GetAxTreeId() const override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
bool RendererIsAvailable() override;
InternalAuthenticator* GetOrCreateCreditCardInternalAuthenticator() override;
void SendFormDataToRenderer(int query_id,
RendererFormDataAction action,
const FormData& data) override;
void PropagateAutofillPredictions(
const std::vector<autofill::FormStructure*>& forms) override;
void HandleParsedForms(const std::vector<const FormData*>& forms) override;
void SendAutofillTypePredictionsToRenderer(
const std::vector<FormStructure*>& forms) override;
void RendererShouldAcceptDataListSuggestion(
const FieldGlobalId& field_id,
const std::u16string& value) override;
void RendererShouldClearFilledSection() override;
void RendererShouldClearPreviewedForm() override;
void RendererShouldFillFieldWithValue(const FieldGlobalId& field_id,
const std::u16string& value) override;
void RendererShouldPreviewFieldWithValue(
const FieldGlobalId& field_id,
const std::u16string& value) override;
void RendererShouldSetSuggestionAvailability(
const FieldGlobalId& field_id,
const mojom::AutofillState state) override;
void PopupHidden() override;
gfx::RectF TransformBoundingBoxToViewportCoordinates(
const gfx::RectF& bounding_box) override;
net::IsolationInfo IsolationInfo() override;
void SendFieldsEligibleForManualFillingToRenderer(
const std::vector<FieldRendererId>& fields) override;
// mojom::AutofillDriver:
void SetFormToBeProbablySubmitted(
const base::Optional<FormData>& form) override;
void FormsSeen(const std::vector<FormData>& forms) override;
void FormSubmitted(const FormData& form,
bool known_success,
mojom::SubmissionSource source) override;
void TextFieldDidChange(const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box,
base::TimeTicks timestamp) override;
void TextFieldDidScroll(const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box) override;
void SelectControlDidChange(const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box) override;
void QueryFormFieldAutofill(int32_t id,
const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box,
bool autoselect_first_suggestion) override;
void HidePopup() override;
void FocusNoLongerOnForm(bool had_interacted_form) override;
void FocusOnFormField(const FormData& form,
const FormFieldData& field,
const gfx::RectF& bounding_box) override;
void DidFillAutofillFormData(const FormData& form,
base::TimeTicks timestamp) override;
void DidPreviewAutofillFormData() override;
void DidEndTextFieldEditing() override;
void SelectFieldOptionsDidChange(const FormData& form) override;
void ProbablyFormSubmitted();
// DidNavigateFrame() is called on the frame's driver, respectively, when a
// navigation occurs in that specific frame.
void DidNavigateFrame(content::NavigationHandle* navigation_handle);
BrowserAutofillManager* browser_autofill_manager() {
return browser_autofill_manager_;
}
AutofillManager* autofill_manager() { return autofill_manager_.get(); }
content::RenderFrameHost* render_frame_host() { return render_frame_host_; }
const mojo::AssociatedRemote<mojom::AutofillAgent>& GetAutofillAgent();
// Methods forwarded to key_press_handler_manager_.
void RegisterKeyPressHandler(
const content::RenderWidgetHost::KeyPressEventCallback& handler);
void RemoveKeyPressHandler();
// Sets the manager to |manager|. Takes ownership of |manager|.
void SetBrowserAutofillManager(
std::unique_ptr<BrowserAutofillManager> manager);
// Reports whether a document collects phone numbers, uses one time code, uses
// WebOTP. There are cases that the reporting is not expected:
// 1. some unit tests do not set necessary members,
// |browser_autofill_manager_|
// 2. there is no form and WebOTP is not used
// |MaybeReportAutofillWebOTPMetrics| is to exclude the cases above.
// |ReportAutofillWebOTPMetrics| is visible for unit tests where the
// |render_frame_host_| is not set.
void MaybeReportAutofillWebOTPMetrics();
void ReportAutofillWebOTPMetrics(bool document_used_webotp);
protected:
// Constructor for tests.
ContentAutofillDriver();
private:
// KeyPressHandlerManager::Delegate:
void AddHandler(
const content::RenderWidgetHost::KeyPressEventCallback& handler) override;
void RemoveHandler(
const content::RenderWidgetHost::KeyPressEventCallback& handler) override;
// Returns whether navigator.credentials.get({otp: {transport:"sms"}}) has
// been used.
bool DocumentUsedWebOTP() const;
// Show a bubble or infobar indicating that the current page has an eligible
// offer or reward, if the bubble/infobar is not currently being visible.
void ShowOfferNotificationIfApplicable(
content::NavigationHandle* navigation_handle);
// Weak ref to the RenderFrameHost the driver is associated with. Should
// always be non-NULL and valid for lifetime of |this|.
content::RenderFrameHost* const render_frame_host_;
// The form pushed from the AutofillAgent to the AutofillDriver. When the
// ProbablyFormSubmitted() event is fired, this form is considered the
// submitted one.
base::Optional<FormData> potentially_submitted_form_;
// Keeps track of the forms for which FormSubmitted() event has been triggered
// to avoid duplicates fired by AutofillAgent.
std::set<FormRendererId> submitted_forms_;
// AutofillManager instance via which this object drives the shared Autofill
// code.
std::unique_ptr<AutofillManager> autofill_manager_;
// The pointer to autofill_manager_ if it is BrowserAutofillManager instance.
// TODO: unify autofill_manager_ and browser_autofill_manager_ to a single
// pointer to a common root.
BrowserAutofillManager* browser_autofill_manager_;
// Pointer to an implementation of InternalAuthenticator.
std::unique_ptr<InternalAuthenticator> authenticator_impl_;
KeyPressHandlerManager key_press_handler_manager_;
LogManager* const log_manager_;
mojo::AssociatedReceiver<mojom::AutofillDriver> receiver_{this};
mojo::AssociatedRemote<mojom::AutofillAgent> autofill_agent_;
// Helps with measuring whether phone number is collected and whether it is in
// conjunction with WebOTP or OneTimeCode (OTC).
// value="0" label="Phone Not Collected, WebOTP Not Used, OTC Not Used"
// value="1" label="Phone Not Collected, WebOTP Not Used, OTC Used"
// value="2" label="Phone Not Collected, WebOTP Used, OTC Not Used"
// value="3" label="Phone Not Collected, WebOTP Used, OTC Used"
// value="4" label="Phone Collected, WebOTP Not Used, OTC Not Used"
// value="5" label="Phone Collected, WebOTP Not Used, OTC Used"
// value="6" label="Phone Collected, WebOTP Used, OTC Not Used"
// value="7" label="Phone Collected, WebOTP Used, OTC Used"
uint32_t phone_collection_metric_state_ = 0;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_H_