Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autofill only one field #224

Merged
merged 4 commits into from
Jul 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { PageDetail } from "../../services/abstractions/autofill.service";

import { LockedVaultPendingNotificationsData } from "./notification.background";

/* start Cozy imports */
/* eslint-disable */
import { AutofillFieldQualifierType } from "src/autofill/enums/autofill-field.enums";
/* eslint-enable */
/* end Cozy imports */

export type PageDetailsForTab = Record<
chrome.runtime.MessageSender["tab"]["id"],
Map<chrome.runtime.MessageSender["frameId"], PageDetail>
Expand Down Expand Up @@ -39,6 +45,11 @@ export type FocusedFieldData = {
frameId?: number;
accountCreationFieldType?: string;
showInlineMenuAccountCreation?: boolean;
// Cozy customization
fieldQualifier?: AutofillFieldQualifierType;
fieldHtmlID?: string;
fieldValue?: string;
// Cozy customization end
};

export type InlineMenuElementPosition = {
Expand Down
13 changes: 13 additions & 0 deletions apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export class OverlayBackground implements OverlayBackgroundInterface {
private readonly openUnlockPopout = openUnlockPopout;
private readonly openViewVaultItemPopout = openViewVaultItemPopout;
private readonly openAddEditVaultItemPopout = openAddEditVaultItemPopout;
// Cozy customization
private lastFilledCipherId: string;
// Cozy customization end
private pageDetailsForTab: PageDetailsForTab = {};
private subFrameOffsetsForTab: SubFrameOffsetsForTab = {};
private portKeyForTab: Record<number, string> = {};
Expand Down Expand Up @@ -791,6 +794,10 @@ export class OverlayBackground implements OverlayBackgroundInterface {
allowTotpAutofill: true,
});

// Cozy customization
this.lastFilledCipherId = inlineMenuCipherId;
// Cozy customization end

if (totpCode) {
this.platformUtilsService.copyToClipboard(totpCode);
}
Expand Down Expand Up @@ -1910,6 +1917,12 @@ export class OverlayBackground implements OverlayBackgroundInterface {
theme: await firstValueFrom(this.themeStateService.selectedTheme$),
translations: this.getInlineMenuTranslations(),
ciphers: isInlineMenuListPort ? await this.getInlineMenuCipherData() : null,
// Cozy customization
lastFilledCipherId: this.lastFilledCipherId,
fieldQualifier: this.focusedFieldData?.fieldQualifier,
fieldHtmlID: this.focusedFieldData?.fieldHtmlID,
fieldValue: this.focusedFieldData?.fieldValue,
// Cozy customization end
portKey: this.portKeyForTab[port.sender.tab.id],
portName: isInlineMenuListPort
? AutofillOverlayPort.ListMessageConnector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { CipherType } from "@bitwarden/common/vault/enums";

import { InlineMenuCipherData } from "../../../background/abstractions/overlay.background";

/* start Cozy imports */
/* eslint-disable */
import { AutofillFieldQualifierType } from "src/autofill/enums/autofill-field.enums";
/* eslint-enable */
/* end Cozy imports */

type AutofillInlineMenuListMessage = { command: string };

export type UpdateAutofillInlineMenuListCiphersMessage = AutofillInlineMenuListMessage & {
Expand All @@ -16,6 +22,12 @@ export type InitAutofillInlineMenuListMessage = AutofillInlineMenuListMessage &
theme: string;
translations: Record<string, string>;
ciphers?: InlineMenuCipherData[];
// Cozy customization
lastFilledCipherId?: string;
fieldQualifier?: AutofillFieldQualifierType;
fieldHtmlID?: string;
fieldValue?: string;
// Cozy customization end
filledByCipherType?: CipherType;
showInlineMenuAccountCreation?: boolean;
portKey: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class AutofillInlineMenuList extends AutofillInlineMenuPageElement {
portKey,
filledByCipherType,
showInlineMenuAccountCreation,
// Cozy customization
lastFilledCipherId,
fieldQualifier,
fieldHtmlID,
fieldValue,
// Cozy customization end
}: InitAutofillInlineMenuListMessage) {
const linkElement = await this.initAutofillInlineMenuPage(
"list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface AutoFillOptions {
allowTotpAutofill?: boolean;
// Cozy customization
cozyProfile?: CozyProfile;
fillOnlyThisFieldHtmlID?: string;
// Cozy customization end
}

Expand All @@ -60,6 +61,7 @@ export interface GenerateFillScriptOptions {
defaultUriMatch: UriMatchStrategySetting;
// Cozy customization
cozyProfile?: CozyProfile;
fillOnlyThisFieldHtmlID?: string;
// Cozy customization end
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,16 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
const { width, height, top, left } =
await this.getMostRecentlyFocusedFieldRects(formFieldElement);
const autofillFieldData = this.formFieldElements.get(formFieldElement);

// Cozy customization; ensure fieldQualifier is present for contacts
if (
autofillFieldData?.fieldQualifier ||
autofillFieldData?.filledByCipherType === CipherType.Contact
) {
this.qualifyUserFilledIdentityField(autofillFieldData);
}
// Cozy customization end

let accountCreationFieldType = null;
if (
(autofillFieldData?.showInlineMenuAccountCreation ||
Expand All @@ -788,6 +798,9 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ
focusedFieldRects: { width, height, top, left },
filledByCipherType: autofillFieldData?.filledByCipherType,
showInlineMenuAccountCreation: autofillFieldData?.showInlineMenuAccountCreation,
fieldQualifier: autofillFieldData.fieldQualifier,
fieldHtmlID: autofillFieldData.htmlID,
fieldValue: formFieldElement.value,
accountCreationFieldType,
};

Expand Down
13 changes: 13 additions & 0 deletions apps/browser/src/autofill/services/autofill.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export default class AutofillService implements AutofillServiceInterface {
tabUrl: tab.url,
defaultUriMatch: defaultUriMatch,
cozyProfile: options.cozyProfile, // Cozy customization
fillOnlyThisFieldHtmlID: options.fillOnlyThisFieldHtmlID, // Cozy customization
});

if (!fillScript || !fillScript.script || !fillScript.script.length) {
Expand Down Expand Up @@ -585,6 +586,18 @@ export default class AutofillService implements AutofillServiceInterface {
return null;
}

// Cozy customization; autofill only one field
if (options.fillOnlyThisFieldHtmlID) {
pageDetails = {
...pageDetails,
fields: pageDetails.fields.filter(
(field) => field.htmlID === options.fillOnlyThisFieldHtmlID,
),
};
}

// Cozy customization end

let fillScript = new AutofillScript();
const filledFields: { [id: string]: AutofillField } = {};
const fields = options.cipher.fields;
Expand Down
Loading