From 8fda52ef7e91616d239d40ca47d7e5a54e1d9214 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Fri, 7 Jun 2024 07:24:35 -0500 Subject: [PATCH] [PM-8027] Incorporating a feature flag to allow us to fallback to the basic inline menu fielld qualification method if needed --- ...inline-menu-field-qualification.service.ts | 28 +++++++++++++++++++ .../src/background/runtime.background.ts | 5 ++++ libs/common/src/enums/feature-flag.enum.ts | 2 ++ 3 files changed, 35 insertions(+) diff --git a/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts b/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts index 84e0d4614e..d96100f913 100644 --- a/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts +++ b/apps/browser/src/autofill/services/inline-menu-field-qualification.service.ts @@ -1,5 +1,6 @@ import AutofillField from "../models/autofill-field"; import AutofillPageDetails from "../models/autofill-page-details"; +import { sendExtensionMessage } from "../utils"; import { InlineMenuFieldQualificationsService as InlineMenuFieldQualificationsServiceInterface } from "./abstractions/inline-menu-field-qualifications.service"; import { AutoFillConstants } from "./autofill-constants"; @@ -16,6 +17,15 @@ export class InlineMenuFieldQualificationService private autofillFieldKeywordsMap: WeakMap = new WeakMap(); private autocompleteDisabledValues = new Set(["off", "false"]); private newFieldKeywords = new Set(["new", "change", "neue", "ändern"]); + private useBasicInlineMenuFieldQualificationFlagSet = false; + + constructor() { + void sendExtensionMessage("getUseTreeWalkerApiForPageDetailsCollectionFeatureFlag").then( + (getUseBasicInlineMenuFieldQualificationFlag) => + (this.useBasicInlineMenuFieldQualificationFlagSet = + !!getUseBasicInlineMenuFieldQualificationFlag?.result), + ); + } /** * Validates the provided field as a field for a login form. @@ -24,6 +34,10 @@ export class InlineMenuFieldQualificationService * @param pageDetails - The details of the page that the field is on. */ isFieldForLoginForm(field: AutofillField, pageDetails: AutofillPageDetails): boolean { + if (this.useBasicInlineMenuFieldQualificationFlagSet) { + return this.isFieldForLoginFormFallback(field); + } + const isCurrentPasswordField = this.isCurrentPasswordField(field); if (isCurrentPasswordField) { return this.isPasswordFieldForLoginForm(field, pageDetails); @@ -392,4 +406,18 @@ export class InlineMenuFieldQualificationService return keywordValues; } + + /** + * This method represents the previous rudimentary approach to qualifying fields for login forms. + * + * @param field - The field to validate + * @deprecated - This method will only be used when the fallback flag is set to true. + */ + private isFieldForLoginFormFallback(field: AutofillField): boolean { + if (field.type === "password") { + return true; + } + + return this.isUsernameField(field); + } } diff --git a/apps/browser/src/background/runtime.background.ts b/apps/browser/src/background/runtime.background.ts index 7ddd5302ac..e207220e57 100644 --- a/apps/browser/src/background/runtime.background.ts +++ b/apps/browser/src/background/runtime.background.ts @@ -186,6 +186,11 @@ export default class RuntimeBackground { FeatureFlag.UseTreeWalkerApiForPageDetailsCollection, ); } + case "getUseBasicInlineMenuFieldQualificationFeatureFlag": { + return await this.configService.getFeatureFlag( + FeatureFlag.UseBasicInlineMenuFieldQualification, + ); + } } } diff --git a/libs/common/src/enums/feature-flag.enum.ts b/libs/common/src/enums/feature-flag.enum.ts index f3bea6964e..4efb8668ad 100644 --- a/libs/common/src/enums/feature-flag.enum.ts +++ b/libs/common/src/enums/feature-flag.enum.ts @@ -17,6 +17,7 @@ export enum FeatureFlag { RestrictProviderAccess = "restrict-provider-access", UseTreeWalkerApiForPageDetailsCollection = "use-tree-walker-api-for-page-details-collection", BulkDeviceApproval = "bulk-device-approval", + UseBasicInlineMenuFieldQualification = "use-basic-inline-menu-field-qualification", } export type AllowedFeatureFlagTypes = boolean | number | string; @@ -44,6 +45,7 @@ export const DefaultFeatureFlagValue = { [FeatureFlag.RestrictProviderAccess]: FALSE, [FeatureFlag.UseTreeWalkerApiForPageDetailsCollection]: FALSE, [FeatureFlag.BulkDeviceApproval]: FALSE, + [FeatureFlag.UseBasicInlineMenuFieldQualification]: FALSE, } satisfies Record; export type DefaultFeatureFlagValueType = typeof DefaultFeatureFlagValue;