Autofill is a layered component. It has the following structure:
core/
: Code shared by content/
and ios/
.content/
: Driver using the //content
layer (all platforms except iOS).ios/
: Driver using //ios
(as opposed to //content
).android/
: Java code for Android.The following architecture diagram shows instances of Autofill's core objects. For simplicity, we only consider the case of Chrome Autofill on non-iOS platforms. The diagram is best read bottom-up because every Autofill flow starts with AutofillAgent
extracting a form from the DOM.
┌────────────────────┐ │PersonalDataManager ├────────┬──────────────────┐ │1 per BrowserContext│ owns N│ owns N│ └─▲──────────────────┘ ┌─▼─────────────┐ ┌─▼────────┐ │ │AutofillProfile│ │CreditCard│ │weak ref └───────────────┘ └──────────┘ ┌─┴───────────────┐ │FormDataImporter ◄─────────────────────┐ │1 per WebContents│ events│ └─▲───────────────┘ │ │ │ │ ┌────────────────────────┐ ┌─┴────────────────────┐ │ │AutofillExternalDelegate◄────────┤BrowserAutofillManager├───────┐ ┌───────────────┐ │ │1 per RenderFrameHost │ owns 1│1 per RenderFrameHost │ votes│ │Autofill server│ │ └──────────────────────┬─┘ └─▲──────────────────┬─┘ │ └─────────────▲─┘ │ events│ │ events│ │ HTTP│ │ │ │ │ ┌─▼───────────────────▼─┐ ├────────────────────────┼────────────┼──────────────────┼───────►AutofillDownloadManager│ │ │ │ │ │1 per WebContents │ │ │ │ │ └─────────────────────▲─┘ │ │ │ │ │ │ │ │ │ ┌──────────────┐ │ │ │ │ │ │FormStructure │ │ │ │ │ │ │1 per FormData│ │ │ │ │ └──┐ └─▲────────────┘ │ │owns 1 │ │events │ │sets types │ ┌─┴──────────────────┐ │ ┌─┴───────────────────┐ │ │owns N queries│ │ChromeAutofillClient◄─────┼──────────┤AutofillManager ├─┼───┴──────────────────────┘ │1 per WebContents │ │ weak ref│1 per RenderFrameHost│ │ └────────────────────┘ │ └─▲─────────────────┬─┘ │ │ │ events│ │ └────────────┼────────────────►│◄──┘ │ │ ┌────────────┼─────────────────┼────────────┐ │owns 1 │events │ │ │ │owns 1 │ │ ┌──────────────────────────┴─┐ ┌─┴─────────────────▼─┐ ┌─▼───────────────────┐ │ContentAutofillDriverFactory├────────►ContentAutofillDriver◄────────►ContentAutofillRouter│ │1 per WebContents │owns N │1 per RenderFrameHost│ events │1 per WebContents │ └────────────────────────────┘ └─▲─────────┬─────────┘ └─────────────────────┘ │ │fill form and Browser │ │other events 1 process │ │ ────────────────────────────────────────┼─────────┼───────────────────────────────────────── Renderer │ │ N processes events, often with│ │ FormData objects │ │ ┌─┴─────────▼─────┐ ┌─────────────────────┐ │AutofillAgent ├───────►form_autofill_util.cc│ │1 per RenderFrame│calls └─────────────────────┘ └─────────────────┘
To edit the diagram, copy-paste it to asciiflow.com.
A WebContents
corresponds to a tab. A RenderFrameHost
roughly corresponds to a frame or a document (but to neither exactly; they differ in whether or not they survive navigations; details are here and here). A BrowserContext
corresponds to a Profile
.
//chrome
.AutofillManager
and everything north of it, but AutofillDriverIOS*
instead of ContentAutofill*
, and a different but identically named AutofillAgent
.AutofillManager
and everything south of it, but AwAutofillClient
instead of ChromeAutofillClient
, and AndroidAutofillManager
instead of BrowserAutofillManager
.core/
common/
browser/
autofill_client.h
//android_webview/browser/aw_autofill_client.h
(WebView implementation)//chrome/browser/ui/autofill/chrome_autofill_client.h
(Chrome implementation)autofill_download_manager.h
autofill_driver.h
../../content/browser/content_autofill_driver.h
(non-iOS implementation)../../ios/browser/autofill_driver_ios.h
(iOS implementation)autofill_external_delegate.h
autofill_manager.h
browser_autofill_manager.h
(Chrome specialization)//components/android_autofill/browser/android_autofill_manager.h
(WebView specialization)data_model/
form_data_importer.h
form_structure.h
personal_data_manager.h
proto/
(Autofill server)content/
ios/
There are some closely related directories in //chrome
:
//chrome/browser/autofill
//chrome/browser/ui/android/autofill
//chrome/browser/ui/autofill
//chrome/browser/ui/views/autofill
This is a cheatsheet to navigate Autofill. It is not necessarily exhaustive and may sacrifice a little bit of correctness in favor of simplicity.
AutofillAgent
RenderFrame
(frame).blink::WebAutofillClient
to communicate with Blink.ContentAutofillDriver
RenderFrameHost
(frame), owned by ContentAutofillDriverFactory
AutofillDriver
and mojom::AutofillDriver
AutofillDriverIOS
for iOSContentAutofillDriverFactory
WebContents
(tab)ContentAutofillDriver
and ensures that there is one Driver instance per renderer frame.AutofillDriverIOSFactory
for iOSAutofillManager
and BrowserAutofillManager
RenderFrameHost
(frame), owned by AutofillDriver
.BrowserAutofillManager
extends the AutofillManager
base class.BrowserAutofillManager
has sibling AndroidAutofillManager
which is responsible for Android Autofill for WebViews.ChromeAutofillClient
WebContents
(tab)BrowserAutofillManager
to the OS specific logic.AutofillClient
interface.AwAutofillClient
, ChromeAutofillClientIOS
and WebViewAutofillClientIOS
.AutocompleteHistoryManager
.FormData
FormFieldData
).blink::WebFormElement
FormFieldData
global_id()
gives a globally unique and non-changing identifier of a field in the renderer process.blink::WebFormControlElement
FormStructure
- corresponds to a FormData
FormFieldData
objectsAutofillField
- corresponds to a FormFieldData
FormFieldData
and extends it byFormGlobalId
is a pair of a LocalFrameToken
and a FormRendererId
, which uniquely identify the frame and the form element in that frame.FieldGlobalId
is a pair of a LocalFrameToken
and a FieldRendererId
.FormSignature
is a 64 bit hash value of the form URL (target URL or location of the embedding website as a fallback) and normalized field names.FieldSignature
is a 32 bit hash value of the field name (name attribute, falling back to id attribute of the form control) and type (text, search, password, tel, ...)components/autofill/core/browser/form_parsing/
.FormField::ParseFormFields
is the global entry point for parsing fields with heuristics.ParseSingleFieldForms
).components/autofill/core/common/autofill_regex_constants.h
or components/autofill/core/browser/form_parsing/regex_patterns.h
if features::kAutofillParsingPatternProvider
is enabled.AutofillDownloadManager
is responsible for downloading field classifications.http://cs/IsSmallForm%20file:autofill
.ParseAutocompleteAttribute
.off
).components/autofill/core/browser/data_model/
components/autofill/core/browser/data_model/autofill_structured_address.h
and components/autofill/core/browser/data_model/autofill_structured_address_name.h
.AddressComponent::ParseValueAndAssignSubcomponents()
.ParseValueAndAssignSubcomponentsByMethod()
ParseValueAndAssignSubcomponentsByRegularExpressions()
ParseValueAndAssignSubcomponentsByFallbackMethod()
GetParseRegularExpressionsByRelevance()
.AddressComponent::FormatValueFromSubcomponents()
.GetBestFormatString()
, in particular StreetAddress::GetBestFormatString()
.AddressComponent::WipeInvalidStructure()
.