Closed Bug 2044287 Opened 28 days ago Closed 12 days ago

Refactor Form Autofill to drive all per-type behavior from a central data-type registry

Categories

(Toolkit :: Form Autofill, task, P2)

task

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox154 --- fixed

People

(Reporter: dimi, Assigned: dimi)

References

(Blocks 1 open bug)

Details

(Whiteboard: [fxcm-backlog])

Attachments

(8 files, 6 obsolete files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Form Autofill currently hardcodes address-vs-credit-card branches throughout the codebase (feature availability, field detection, section classification, autocomplete, submission capture, and telemetry). Adding a new data type means touching all of these scattered call sites, which doesn't scale as we add support for more data types.

This bug introduces a central data-type registry that describes each data type by a single descriptor, and routes the existing per-type logic through it so a new type can be added by configuration rather than new branches.

Introduce AutofillDataTypes.sys.mjs, a central registry class describing each
data type (address, credit card) by id and pref namespace; the feature prefs
(supported/supportedCountries/enabled/experiments) are derived from the
namespace, and the canonical ids are exposed as AutofillDataTypes.ADDRESS /
.CREDIT_CARD so callers avoid bare strings. This is the foundation for adding
new data types by configuration rather than scattered per-type branches.

FormAutofill computes availability and enabled-state directly from the registry
via isAutofillType{Available,Enabled}(typeId), and isAnyAutofillFeatureAvailable
/ isAutofillEnabled iterate AutofillDataTypes.all. The per-type
isAutofill{Addresses,CreditCards}{Available,Enabled} getters, the dead Locked
getters, and their backing lazy pref getters are removed; callers in api.js,
FormAutofillParent, FormAutofillSection, FormAutofillChild and the affected tests
use the parameterized methods. isAutofillAddressesAvailableInCountry is unchanged.

Add the collectionName/subCategories/sectionClassName descriptor fields and the
typeIdForSubCategory lookup, and use them to replace the address-or-credit-card
branches in field categorization and section building. FormAutofillUtils gains
typeIdFromFieldName, and isAddressField/isCreditCardField (via
AutofillDataTypes.ADDRESS/.CREDIT_CARD) and getCollectionNameFromFieldName
resolve through the registry.

FormSection derives its type from the first recognized field's data type (still
defaulting to AutofillDataTypes.ADDRESS), and classifySections buckets fields by
type id and instantiates the section class named by each descriptor via a local
name-to-class table. FormAutofillChild's notify-parent check now asks whether any
detected field belongs to a known data type. Adds test_autofillDataTypes.js.

Depends on D304036

Add the resultClassName descriptor field. shouldSearchForAutoComplete gates the
search with FormAutofill.isAutofillTypeEnabled using the field's data type id,
and searchResultToAutoCompleteResult picks the autocomplete result class named by
the type's descriptor (resultClassName), falling back to AddressResult.

Depends on D304037

onFormSubmit groups submitted records by data type id, matching each section to
its type via the descriptor's section class name (the section's constructor
name), and dispatches to the per-type handler resolved by the _on<Type>Submit
convention. Per-type doorhangers are still shown sequentially while different
types are handled in parallel. setTemporaryRecordsForTab routes records to
storage through gFormAutofillStorage[collection] and initializes the temporary
record buckets from the registry. The section-class lazy imports are no longer
needed.

Depends on D304038

Add the telemetryChannel descriptor field. Telemetry dispatch resolves the
per-type telemetry instance from the data type's telemetryChannel via a
#getTelemetryByChannel helper. #getTelemetryByFieldDetail looks up the field's
type id and uses its channel, and #getTelemetryByType delegates to the same
helper. The helper returns null for channels without a Glean schema, so the
record entry points guard the call and no-op instead of recording into the wrong
channel.

Depends on D304039

Introduce AutofillDataTypes.sys.mjs, a central registry class describing each
data type (address, credit card) by id and pref namespace; the feature prefs
(supported/supportedCountries/enabled/experiments) are derived from the
namespace, and the canonical ids are exposed as AutofillDataTypes.ADDRESS /
.CREDIT_CARD so callers avoid bare strings. This is the foundation for adding
new data types by configuration rather than scattered per-type branches.

FormAutofill computes availability and enabled-state directly from the registry
via isAutofillType{Available,Enabled}(typeId), and isAnyAutofillFeatureAvailable
/ isAutofillEnabled iterate AutofillDataTypes.all. The per-type
isAutofill{Addresses,CreditCards}{Available,Enabled} getters, the dead Locked
getters, and their backing lazy pref getters are removed; callers in api.js,
FormAutofillParent, FormAutofillSection, FormAutofillChild and the affected tests
use the parameterized methods. isAutofillAddressesAvailableInCountry is unchanged.

The registry is imported via ChromeUtils.defineESModuleGetters(lazy, ...) where
possible; FormAutofillParent keeps a static import because it reads
AutofillDataTypes.all at module-eval time.

Add the collectionName/subCategories/sectionClassName descriptor fields and the
typeIdForSubCategory lookup, and use them to replace the address-or-credit-card
branches in field categorization and section building. FormAutofillUtils gains
typeIdFromFieldName, and isAddressField/isCreditCardField (via
lazy.AutofillDataTypes.ADDRESS/.CREDIT_CARD) and getCollectionNameFromFieldName
resolve through the registry.

FormSection derives its type from the first recognized field's data type (still
defaulting to lazy.AutofillDataTypes.ADDRESS), and classifySections buckets
fields by type id and instantiates the section class named by each descriptor via
a local name-to-class table. FormAutofillChild's notify-parent check now asks
whether any detected field belongs to a known data type. Adds
test_autofillDataTypes.js.

Depends on D304062

shouldSearchForAutoComplete gates the search with FormAutofill.isAutofillTypeEnabled
using the field's data type id. searchResultToAutoCompleteResult delegates result
construction to ProfileAutoCompleteResult.createResult(typeId, ...), a factory that
selects AddressResult or CreditCardResult; FormAutofillChild no longer imports those
classes or carries a name-to-class table. The result class is therefore resolved by
the module that owns it, and the registry needs no resultClassName field.

Depends on D304063

onFormSubmit groups submitted records by data type id, matching each section to
its type via the descriptor's section class name (the section's constructor
name), and dispatches each type's records to its own submit handler
(_onAddressSubmit / _onCreditCardSubmit) via an explicit per-type map. Per-type
doorhangers are still shown sequentially while different types are handled in
parallel. setTemporaryRecordsForTab routes records to storage through
gFormAutofillStorage[collection] and initializes the temporary record buckets
from the registry. The section-class lazy imports are no longer needed.

Depends on D304064

Add the telemetryChannel descriptor field. Telemetry dispatch resolves the
per-type telemetry instance from the data type's telemetryChannel via a
#getTelemetryByChannel helper. #getTelemetryByFieldDetail looks up the field's
type id and uses its channel, and #getTelemetryByType delegates to the same
helper. The helper returns null for channels without a Glean schema, so the
record entry points guard the call and no-op instead of recording into the wrong
channel.

Depends on D304065

Telemetry dispatch resolves the per-type telemetry instance directly from the
data type id: AutofillTelemetry.#getTelemetryByType switches on
AutofillDataTypes.ADDRESS/CREDIT_CARD, and #getTelemetryByFieldDetail maps the
field's type id the same way. The record entry points (doorhanger, form
interaction, manage, profile count, ML detection) take a data-type id and no-op
when the type has no telemetry instance.

Callers (editDialog, manageDialog, FormAutofillPrompter, FormAutofillStorageBase)
now pass AutofillDataTypes.ADDRESS/CREDIT_CARD instead of the removed
AutofillTelemetry.ADDRESS/CREDIT_CARD constants. The Glean metric category lives
only on each telemetry instance's EVENT_CATEGORY, so the registry no longer
carries a telemetryChannel field.

Depends on D304065

Attachment #9592513 - Attachment is obsolete: true

updateSavedFieldNames iterates AutofillDataTypes.all and unions the saved field
names of each available type's storage collection (gFormAutofillStorage by
collectionName), instead of hardcoding addresses plus a credit-card branch. A new
data type is now included automatically. Each type's store is only touched when
its feature is available; unlike before, address is also gated on availability,
which is harmless since an unavailable type can't be autocompleted anyway.

Depends on D304088

FormAutofillChild.onFieldsDetectedComplete buckets detected fields by data type
id instead of hardcoded address/creditcard arrays, marking every detected type's
fields and registering submission interest for any saveable section. The
address-only rules (Bug 1905040 valid-section gate, street-address requirement)
stay as the address type's conditions; any other type needs no change here.

Depends on D304126

Each descriptor declares its field names grouped by sub-category (the fields
map), making it the single source of truth for a type's fields; subCategories
and the flat fieldToSubCategory map are derived from it. FormAutofillUtils
reads the registry directly and the hand-maintained _fieldNameInfo literal is
removed.

Depends on D304414

Attachment #9592509 - Attachment description: WIP: Bug 2044287 - P1. Add a Form Autofill data-type registry and drive feature availability from it. → Bug 2044287 - P1. Add a Form Autofill data-type registry and drive feature availability from it. r=NeilDeakin
Attachment #9592510 - Attachment description: WIP: Bug 2044287 - P2. Drive Form Autofill field detection and section classification from the data-type registry. → Bug 2044287 - P2. Drive Form Autofill field detection and section classification from the data-type registry. r=NeilDeakin
Attachment #9592511 - Attachment description: WIP: Bug 2044287 - P3. Resolve Form Autofill autocomplete search and result class from the data-type registry. → Bug 2044287 - P3. Resolve Form Autofill autocomplete search and result class from the data-type registry. r=NeilDeakin
Attachment #9592512 - Attachment description: WIP: Bug 2044287 - P4. Dispatch Form Autofill submission capture through the data-type registry. → Bug 2044287 - P4. Dispatch Form Autofill submission capture through the data-type registry. r=NeilDeakin
Attachment #9592540 - Attachment description: WIP: Bug 2044287 - P5. Route Form Autofill telemetry through the data-type registry. → Bug 2044287 - P5. Route Form Autofill telemetry through the data-type registry. r=NeilDeakin
Attachment #9592600 - Attachment description: WIP: Bug 2044287 - P6. Compute Form Autofill saved field names from the data-type registry. → Bug 2044287 - P6. Compute Form Autofill saved field names from the data-type registry. r=NeilDeakin
Attachment #9593008 - Attachment description: WIP: Bug 2044287 - P7. Drive content-side field markup and submission interest from the data-type registry. → Bug 2044287 - P7. Drive content-side field markup and submission interest from the data-type registry. r=NeilDeakin
Attachment #9593009 - Attachment description: WIP: Bug 2044287 - P8. Move the Form Autofill field vocabulary into the data-type registry. → Bug 2044287 - P8. Move the Form Autofill field vocabulary into the data-type registry. r=NeilDeakin
Blocks: 2043564
Attachment #9592481 - Attachment is obsolete: true
Attachment #9592480 - Attachment is obsolete: true
Attachment #9592479 - Attachment is obsolete: true
Attachment #9592478 - Attachment is obsolete: true
Attachment #9592477 - Attachment is obsolete: true
Pushed by dlee@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/2ae9e6fd6ea9 https://hg.mozilla.org/integration/autoland/rev/8038285fd4a3 P1. Add a Form Autofill data-type registry and drive feature availability from it. r=NeilDeakin,credential-management-reviewers,mstriemer https://github.com/mozilla-firefox/firefox/commit/c775fed21a05 https://hg.mozilla.org/integration/autoland/rev/9290b1554e58 P2. Drive Form Autofill field detection and section classification from the data-type registry. r=NeilDeakin,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/d92d4f68b646 https://hg.mozilla.org/integration/autoland/rev/21b26aef18f5 P3. Resolve Form Autofill autocomplete search and result class from the data-type registry. r=NeilDeakin,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/cb3e4c43207b https://hg.mozilla.org/integration/autoland/rev/a994467ac2db P4. Dispatch Form Autofill submission capture through the data-type registry. r=NeilDeakin,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/e0426abd1dba https://hg.mozilla.org/integration/autoland/rev/7e2abc3cf1dd P5. Route Form Autofill telemetry through the data-type registry. r=NeilDeakin,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/2d88754fe58c https://hg.mozilla.org/integration/autoland/rev/3c991fd82271 P6. Compute Form Autofill saved field names from the data-type registry. r=NeilDeakin,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/189e673db247 https://hg.mozilla.org/integration/autoland/rev/1a05d26ae0f3 P7. Drive content-side field markup and submission interest from the data-type registry. r=NeilDeakin,credential-management-reviewers https://github.com/mozilla-firefox/firefox/commit/0a7de2a14531 https://hg.mozilla.org/integration/autoland/rev/2931eac69646 P8. Move the Form Autofill field vocabulary into the data-type registry. r=NeilDeakin,credential-management-reviewers
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: