Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/browser/src/autofill/services/autofill-constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import { AutofillTargetingRuleTypes } from "@bitwarden/common/autofill/constants";
import { AutofillTargetingRuleType } from "@bitwarden/common/autofill/types";

const targetingRuleTypeValues: ReadonlySet<string> = new Set(
Object.values(AutofillTargetingRuleTypes),
);

/**
* Type guard for `AutofillTargetingRuleType`. Use at boundaries where a value
* typed more loosely (e.g. `AutofillField.fieldQualifier`, which can carry
* either heuristic or targeting-rule qualifiers) needs to be narrowed before
* being compared against targeting-rule-specific groupings.
*/
export function isAutofillTargetingRuleType(value: unknown): value is AutofillTargetingRuleType {
return typeof value === "string" && targetingRuleTypeValues.has(value);
}

export const loginQualifiers: AutofillTargetingRuleType[] = [
AutofillTargetingRuleTypes.username,
AutofillTargetingRuleTypes.password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
AUTOFILL_TRIGGER_FORM_FIELD_SUBMIT,
EVENTS,
} from "@bitwarden/common/autofill/constants";
import { AutofillTargetingRuleType } from "@bitwarden/common/autofill/types";
import { CipherType } from "@bitwarden/common/vault/enums";

import { ModifyLoginCipherFormData } from "../background/abstractions/overlay-notifications.background";
Expand Down Expand Up @@ -62,6 +61,7 @@ import {
loginQualifiers,
cardQualifiers,
identityQualifiers,
isAutofillTargetingRuleType,
} from "./autofill-constants";

export class AutofillOverlayContentService implements AutofillOverlayContentServiceInterface {
Expand Down Expand Up @@ -1174,33 +1174,27 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
* bypassing heuristic qualification.
*/
private setTargetedFieldFillType(autofillFieldData: AutofillField): void {
// Targeted fields use AutofillTargetingRuleType values in fieldQualifier,
// which are distinct from the heuristic AutofillFieldQualifierType values.
const qualifier = autofillFieldData.fieldQualifier as AutofillTargetingRuleType;
// Targeted fields use `AutofillTargetingRuleType` values in `fieldQualifier`,
// which are distinct from the heuristic `AutofillFieldQualifierType` values.
const qualifier = autofillFieldData.fieldQualifier;

if (qualifier === AutofillTargetingRuleTypes.newPassword) {
if (!isAutofillTargetingRuleType(qualifier)) {
autofillFieldData.inlineMenuFillType = CipherType.Login;
} else if (qualifier === AutofillTargetingRuleTypes.newPassword) {
autofillFieldData.inlineMenuFillType = InlineMenuFillTypes.PasswordGeneration;
return;
}

if (loginQualifiers.includes(qualifier)) {
} else if (loginQualifiers.includes(qualifier)) {
autofillFieldData.inlineMenuFillType = CipherType.Login;
return;
}

if (cardQualifiers.includes(qualifier)) {
} else if (cardQualifiers.includes(qualifier)) {
autofillFieldData.inlineMenuFillType = CipherType.Card;
return;
}

if (identityQualifiers.includes(qualifier)) {
} else if (identityQualifiers.includes(qualifier)) {
autofillFieldData.inlineMenuFillType = CipherType.Identity;
return;
} else {
// The fallback `CipherType.Login` covers both the unrecognized-qualifier
// case and qualifier groups that don't have a dedicated fill type yet;
// it avoids inline menu re-render churn that occurs when
// `inlineMenuFillType` is left undefined.
autofillFieldData.inlineMenuFillType = CipherType.Login;
}

// Fallback: default to Login to avoid inline menu re-render churn that
// occurs when `inlineMenuFillType` is left undefined.
autofillFieldData.inlineMenuFillType = CipherType.Login;
}

/**
Expand Down
Loading
Loading