mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
Revert to MV2 Autofill Logic (#4705)
This commit is contained in:
@@ -9,13 +9,12 @@ import { CipherType } from "@bitwarden/common/vault/enums/cipher-type";
|
|||||||
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
|
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
|
||||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||||
|
|
||||||
import { AutofillTabCommand } from "../commands/autofill-tab-command";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CopyToClipboardAction,
|
CopyToClipboardAction,
|
||||||
ContextMenuClickedHandler,
|
ContextMenuClickedHandler,
|
||||||
CopyToClipboardOptions,
|
CopyToClipboardOptions,
|
||||||
GeneratePasswordToClipboardAction,
|
GeneratePasswordToClipboardAction,
|
||||||
|
AutofillAction,
|
||||||
} from "./context-menu-clicked-handler";
|
} from "./context-menu-clicked-handler";
|
||||||
import {
|
import {
|
||||||
AUTOFILL_ID,
|
AUTOFILL_ID,
|
||||||
@@ -59,9 +58,9 @@ describe("ContextMenuClickedHandler", () => {
|
|||||||
|
|
||||||
let copyToClipboard: CopyToClipboardAction;
|
let copyToClipboard: CopyToClipboardAction;
|
||||||
let generatePasswordToClipboard: GeneratePasswordToClipboardAction;
|
let generatePasswordToClipboard: GeneratePasswordToClipboardAction;
|
||||||
|
let autofill: AutofillAction;
|
||||||
let authService: MockProxy<AuthService>;
|
let authService: MockProxy<AuthService>;
|
||||||
let cipherService: MockProxy<CipherService>;
|
let cipherService: MockProxy<CipherService>;
|
||||||
let autofillTabCommand: MockProxy<AutofillTabCommand>;
|
|
||||||
let totpService: MockProxy<TotpService>;
|
let totpService: MockProxy<TotpService>;
|
||||||
let eventCollectionService: MockProxy<EventCollectionService>;
|
let eventCollectionService: MockProxy<EventCollectionService>;
|
||||||
|
|
||||||
@@ -70,18 +69,18 @@ describe("ContextMenuClickedHandler", () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
copyToClipboard = jest.fn<void, [CopyToClipboardOptions]>();
|
copyToClipboard = jest.fn<void, [CopyToClipboardOptions]>();
|
||||||
generatePasswordToClipboard = jest.fn<Promise<void>, [tab: chrome.tabs.Tab]>();
|
generatePasswordToClipboard = jest.fn<Promise<void>, [tab: chrome.tabs.Tab]>();
|
||||||
|
autofill = jest.fn<Promise<void>, [tab: chrome.tabs.Tab, cipher: CipherView]>();
|
||||||
authService = mock();
|
authService = mock();
|
||||||
cipherService = mock();
|
cipherService = mock();
|
||||||
autofillTabCommand = mock();
|
|
||||||
totpService = mock();
|
totpService = mock();
|
||||||
eventCollectionService = mock();
|
eventCollectionService = mock();
|
||||||
|
|
||||||
sut = new ContextMenuClickedHandler(
|
sut = new ContextMenuClickedHandler(
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
generatePasswordToClipboard,
|
generatePasswordToClipboard,
|
||||||
|
autofill,
|
||||||
authService,
|
authService,
|
||||||
cipherService,
|
cipherService,
|
||||||
autofillTabCommand,
|
|
||||||
totpService,
|
totpService,
|
||||||
eventCollectionService
|
eventCollectionService
|
||||||
);
|
);
|
||||||
@@ -106,9 +105,9 @@ describe("ContextMenuClickedHandler", () => {
|
|||||||
|
|
||||||
await sut.run(createData("T_1", AUTOFILL_ID), { id: 5 } as any);
|
await sut.run(createData("T_1", AUTOFILL_ID), { id: 5 } as any);
|
||||||
|
|
||||||
expect(autofillTabCommand.doAutofillTabWithCipherCommand).toBeCalledTimes(1);
|
expect(autofill).toBeCalledTimes(1);
|
||||||
|
|
||||||
expect(autofillTabCommand.doAutofillTabWithCipherCommand).toBeCalledWith({ id: 5 }, cipher);
|
expect(autofill).toBeCalledWith({ id: 5 }, cipher);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("copies username to clipboard", async () => {
|
it("copies username to clipboard", async () => {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import {
|
|||||||
|
|
||||||
export type CopyToClipboardOptions = { text: string; tab: chrome.tabs.Tab };
|
export type CopyToClipboardOptions = { text: string; tab: chrome.tabs.Tab };
|
||||||
export type CopyToClipboardAction = (options: CopyToClipboardOptions) => void;
|
export type CopyToClipboardAction = (options: CopyToClipboardOptions) => void;
|
||||||
|
export type AutofillAction = (tab: chrome.tabs.Tab, cipher: CipherView) => Promise<void>;
|
||||||
|
|
||||||
export type GeneratePasswordToClipboardAction = (tab: chrome.tabs.Tab) => Promise<void>;
|
export type GeneratePasswordToClipboardAction = (tab: chrome.tabs.Tab) => Promise<void>;
|
||||||
|
|
||||||
@@ -53,9 +54,9 @@ export class ContextMenuClickedHandler {
|
|||||||
constructor(
|
constructor(
|
||||||
private copyToClipboard: CopyToClipboardAction,
|
private copyToClipboard: CopyToClipboardAction,
|
||||||
private generatePasswordToClipboard: GeneratePasswordToClipboardAction,
|
private generatePasswordToClipboard: GeneratePasswordToClipboardAction,
|
||||||
|
private autofillAction: AutofillAction,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
private autofillTabCommand: AutofillTabCommand,
|
|
||||||
private totpService: TotpService,
|
private totpService: TotpService,
|
||||||
private eventCollectionService: EventCollectionService
|
private eventCollectionService: EventCollectionService
|
||||||
) {}
|
) {}
|
||||||
@@ -104,12 +105,16 @@ export class ContextMenuClickedHandler {
|
|||||||
await stateServiceFactory(cachedServices, serviceOptions)
|
await stateServiceFactory(cachedServices, serviceOptions)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const autofillCommand = new AutofillTabCommand(
|
||||||
|
await autofillServiceFactory(cachedServices, serviceOptions)
|
||||||
|
);
|
||||||
|
|
||||||
return new ContextMenuClickedHandler(
|
return new ContextMenuClickedHandler(
|
||||||
(options) => copyToClipboard(options.tab, options.text),
|
(options) => copyToClipboard(options.tab, options.text),
|
||||||
(tab) => generatePasswordToClipboardCommand.generatePasswordToClipboard(tab),
|
(tab) => generatePasswordToClipboardCommand.generatePasswordToClipboard(tab),
|
||||||
|
(tab, cipher) => autofillCommand.doAutofillTabWithCipherCommand(tab, cipher),
|
||||||
await authServiceFactory(cachedServices, serviceOptions),
|
await authServiceFactory(cachedServices, serviceOptions),
|
||||||
await cipherServiceFactory(cachedServices, serviceOptions),
|
await cipherServiceFactory(cachedServices, serviceOptions),
|
||||||
new AutofillTabCommand(await autofillServiceFactory(cachedServices, serviceOptions)),
|
|
||||||
await totpServiceFactory(cachedServices, serviceOptions),
|
await totpServiceFactory(cachedServices, serviceOptions),
|
||||||
await eventCollectionServiceFactory(cachedServices, serviceOptions)
|
await eventCollectionServiceFactory(cachedServices, serviceOptions)
|
||||||
);
|
);
|
||||||
@@ -205,7 +210,7 @@ export class ContextMenuClickedHandler {
|
|||||||
if (tab == null) {
|
if (tab == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.autofillTabCommand.doAutofillTabWithCipherCommand(tab, cipher);
|
await this.autofillAction(tab, cipher);
|
||||||
break;
|
break;
|
||||||
case COPY_USERNAME_ID:
|
case COPY_USERNAME_ID:
|
||||||
this.copyToClipboard({ text: cipher.login.username, tab: tab });
|
this.copyToClipboard({ text: cipher.login.username, tab: tab });
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ import TabsBackground from "../autofill/background/tabs.background";
|
|||||||
import { CipherContextMenuHandler } from "../autofill/browser/cipher-context-menu-handler";
|
import { CipherContextMenuHandler } from "../autofill/browser/cipher-context-menu-handler";
|
||||||
import { ContextMenuClickedHandler } from "../autofill/browser/context-menu-clicked-handler";
|
import { ContextMenuClickedHandler } from "../autofill/browser/context-menu-clicked-handler";
|
||||||
import { MainContextMenuHandler } from "../autofill/browser/main-context-menu-handler";
|
import { MainContextMenuHandler } from "../autofill/browser/main-context-menu-handler";
|
||||||
import { AutofillTabCommand } from "../autofill/commands/autofill-tab-command";
|
|
||||||
import { AutofillService as AutofillServiceAbstraction } from "../autofill/services/abstractions/autofill.service";
|
import { AutofillService as AutofillServiceAbstraction } from "../autofill/services/abstractions/autofill.service";
|
||||||
import AutofillService from "../autofill/services/autofill.service";
|
import AutofillService from "../autofill/services/autofill.service";
|
||||||
import { BrowserApi } from "../browser/browserApi";
|
import { BrowserApi } from "../browser/browserApi";
|
||||||
@@ -543,9 +542,20 @@ export default class MainBackground {
|
|||||||
this.platformUtilsService.copyToClipboard(password, { window: window });
|
this.platformUtilsService.copyToClipboard(password, { window: window });
|
||||||
this.passwordGenerationService.addHistory(password);
|
this.passwordGenerationService.addHistory(password);
|
||||||
},
|
},
|
||||||
|
async (tab, cipher) => {
|
||||||
|
this.loginToAutoFill = cipher;
|
||||||
|
if (tab == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BrowserApi.tabSendMessage(tab, {
|
||||||
|
command: "collectPageDetails",
|
||||||
|
tab: tab,
|
||||||
|
sender: "contextMenu",
|
||||||
|
});
|
||||||
|
},
|
||||||
this.authService,
|
this.authService,
|
||||||
this.cipherService,
|
this.cipherService,
|
||||||
new AutofillTabCommand(this.autofillService),
|
|
||||||
this.totpService,
|
this.totpService,
|
||||||
this.eventCollectionService
|
this.eventCollectionService
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user