mirror of
https://github.com/bitwarden/browser
synced 2026-02-04 10:43:47 +00:00
add autofill targeting rules state to domain settings service
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/** @deprecated use `AutofillFieldQualifier` in `libs/common/src/autofill/constants` instead */
|
||||
export const AutofillFieldQualifier = {
|
||||
password: "password",
|
||||
newPassword: "newPassword",
|
||||
@@ -26,5 +27,6 @@ export const AutofillFieldQualifier = {
|
||||
identityUsername: "identityUsername",
|
||||
} as const;
|
||||
|
||||
/** @deprecated use `AutofillFieldQualifierType` in `libs/common/src/autofill/types` instead */
|
||||
export type AutofillFieldQualifierType =
|
||||
(typeof AutofillFieldQualifier)[keyof typeof AutofillFieldQualifier];
|
||||
|
||||
@@ -72,6 +72,34 @@ export const AutofillOverlayVisibility = {
|
||||
OnFieldFocus: 2,
|
||||
} as const;
|
||||
|
||||
export const AutofillFieldQualifier = {
|
||||
password: "password",
|
||||
newPassword: "newPassword",
|
||||
username: "username",
|
||||
cardholderName: "cardholderName",
|
||||
cardNumber: "cardNumber",
|
||||
cardExpirationMonth: "cardExpirationMonth",
|
||||
cardExpirationYear: "cardExpirationYear",
|
||||
cardExpirationDate: "cardExpirationDate",
|
||||
cardCvv: "cardCvv",
|
||||
identityTitle: "identityTitle",
|
||||
identityFirstName: "identityFirstName",
|
||||
identityMiddleName: "identityMiddleName",
|
||||
identityLastName: "identityLastName",
|
||||
identityFullName: "identityFullName",
|
||||
identityAddress1: "identityAddress1",
|
||||
identityAddress2: "identityAddress2",
|
||||
identityAddress3: "identityAddress3",
|
||||
identityCity: "identityCity",
|
||||
identityState: "identityState",
|
||||
identityPostalCode: "identityPostalCode",
|
||||
identityCountry: "identityCountry",
|
||||
identityCompany: "identityCompany",
|
||||
identityPhone: "identityPhone",
|
||||
identityEmail: "identityEmail",
|
||||
identityUsername: "identityUsername",
|
||||
} as const;
|
||||
|
||||
export const BrowserClientVendors = {
|
||||
Chrome: "Chrome",
|
||||
Opera: "Opera",
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
UserKeyDefinition,
|
||||
} from "../../platform/state";
|
||||
import { UserId } from "../../types/guid";
|
||||
import { AutofillTargetingRulesByDomain, AutofillTargetingRules } from "../types";
|
||||
|
||||
const SHOW_FAVICONS = new KeyDefinition(DOMAIN_SETTINGS_DISK, "showFavicons", {
|
||||
deserializer: (value: boolean) => value ?? true,
|
||||
@@ -57,10 +58,23 @@ const DEFAULT_URI_MATCH_STRATEGY = new UserKeyDefinition(
|
||||
},
|
||||
);
|
||||
|
||||
const AUTOFILL_TARGETING_RULES = new UserKeyDefinition(
|
||||
DOMAIN_SETTINGS_DISK,
|
||||
"autofillTargetingRules",
|
||||
{
|
||||
deserializer: (value: AutofillTargetingRulesByDomain) => value ?? {},
|
||||
clearOn: [],
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* The Domain Settings service; provides client settings state for "active client view" URI concerns
|
||||
*/
|
||||
export abstract class DomainSettingsService {
|
||||
autofillTargetingRules$: Observable<AutofillTargetingRulesByDomain>;
|
||||
setAutofillTargetingRules: (newValue: AutofillTargetingRulesByDomain) => Promise<void>;
|
||||
getUrlAutofillTargetingRules$: (url: string) => Observable<AutofillTargetingRules>;
|
||||
|
||||
/**
|
||||
* Indicates if the favicons for ciphers' URIs should be shown instead of a placeholder
|
||||
*/
|
||||
@@ -112,6 +126,9 @@ export abstract class DomainSettingsService {
|
||||
}
|
||||
|
||||
export class DefaultDomainSettingsService implements DomainSettingsService {
|
||||
private autofillTargetingRulesState: ActiveUserState<AutofillTargetingRulesByDomain>;
|
||||
readonly autofillTargetingRules$: Observable<AutofillTargetingRulesByDomain>;
|
||||
|
||||
private showFaviconsState: GlobalState<boolean>;
|
||||
readonly showFavicons$: Observable<boolean>;
|
||||
|
||||
@@ -136,6 +153,9 @@ export class DefaultDomainSettingsService implements DomainSettingsService {
|
||||
private policyService: PolicyService,
|
||||
private accountService: AccountService,
|
||||
) {
|
||||
this.autofillTargetingRulesState = this.stateProvider.getActive(AUTOFILL_TARGETING_RULES);
|
||||
this.autofillTargetingRules$ = this.autofillTargetingRulesState.state$.pipe(map((x) => (x && Object.keys(x).length) ? x : {}));
|
||||
|
||||
this.showFaviconsState = this.stateProvider.getGlobal(SHOW_FAVICONS);
|
||||
this.showFavicons$ = this.showFaviconsState.state$.pipe(map((x) => x ?? true));
|
||||
|
||||
@@ -182,6 +202,10 @@ export class DefaultDomainSettingsService implements DomainSettingsService {
|
||||
);
|
||||
}
|
||||
|
||||
async setAutofillTargetingRules(newValue: AutofillTargetingRulesByDomain): Promise<void> {
|
||||
await this.autofillTargetingRulesState.update(() => newValue);
|
||||
}
|
||||
|
||||
async setShowFavicons(newValue: boolean): Promise<void> {
|
||||
await this.showFaviconsState.update(() => newValue);
|
||||
}
|
||||
@@ -218,4 +242,18 @@ export class DefaultDomainSettingsService implements DomainSettingsService {
|
||||
|
||||
return domains$;
|
||||
}
|
||||
|
||||
getUrlAutofillTargetingRules$(url: string): Observable<AutofillTargetingRules> {
|
||||
return this.autofillTargetingRules$.pipe(
|
||||
map((autofillTargetingRules) => {
|
||||
const domain = Utils.getHostname(url);
|
||||
|
||||
if (domain == null) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return autofillTargetingRules?.[domain] || {};
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
AutofillFieldQualifier,
|
||||
AutofillOverlayVisibility,
|
||||
BrowserClientVendors,
|
||||
BrowserShortcutsUris,
|
||||
@@ -16,3 +17,14 @@ export type BrowserClientVendor = (typeof BrowserClientVendors)[keyof typeof Bro
|
||||
export type BrowserShortcutsUri = (typeof BrowserShortcutsUris)[keyof typeof BrowserShortcutsUris];
|
||||
export type DisablePasswordManagerUri =
|
||||
(typeof DisablePasswordManagerUris)[keyof typeof DisablePasswordManagerUris];
|
||||
|
||||
export type AutofillFieldQualifierType =
|
||||
(typeof AutofillFieldQualifier)[keyof typeof AutofillFieldQualifier];
|
||||
|
||||
export type AutofillTargetingRules = {
|
||||
[type in AutofillFieldQualifierType]?: string;
|
||||
};
|
||||
|
||||
export type AutofillTargetingRulesByDomain = {
|
||||
[key: string]: AutofillTargetingRules
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user