From fe2557e21cc89cd609ea2e74a64dab1446dfa990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josep=20Mar=C3=AD?= Date: Wed, 12 Aug 2020 22:05:12 +0200 Subject: [PATCH] Cycle through every login when using the auto-fill shortcut (#956) * Cycle through every login when using the auto-fill shortcut * Leave imports ordering as it was * Undo formatting * Move logic to jslib * Remove unused method --- src/background/runtime.background.ts | 2 +- src/services/abstractions/autofill.service.ts | 2 +- src/services/autofill.service.ts | 18 +++++++++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 7578f109db..6aad2decfa 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -140,7 +140,7 @@ export default class RuntimeBackground { break; case 'autofiller': case 'autofill_cmd': - const totpCode = await this.autofillService.doAutoFillForLastUsedLogin([{ + const totpCode = await this.autofillService.doAutoFillActiveTab([{ frameId: sender.frameId, tab: msg.tab, details: msg.details, diff --git a/src/services/abstractions/autofill.service.ts b/src/services/abstractions/autofill.service.ts index 0b022bc7f1..f0490b41a2 100644 --- a/src/services/abstractions/autofill.service.ts +++ b/src/services/abstractions/autofill.service.ts @@ -3,5 +3,5 @@ import AutofillPageDetails from '../../models/autofillPageDetails'; export abstract class AutofillService { getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[]; doAutoFill: (options: any) => Promise; - doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise; + doAutoFillActiveTab: (pageDetails: any, fromCommand: boolean) => Promise; } diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index b5e0345d86..f1530cf676 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -3,6 +3,8 @@ import { FieldType, } from 'jslib/enums'; +import { CipherView } from 'jslib/models/view'; + import AutofillField from '../models/autofillField'; import AutofillPageDetails from '../models/autofillPageDetails'; import AutofillScript from '../models/autofillScript'; @@ -117,6 +119,7 @@ var IsoProvinces: { [id: string]: string; } = { /* tslint:enable */ export default class AutofillService implements AutofillServiceInterface { + constructor(private cipherService: CipherService, private userService: UserService, private totpService: TotpService, private eventService: EventService) { } @@ -217,23 +220,24 @@ export default class AutofillService implements AutofillServiceInterface { } } - async doAutoFillForLastUsedLogin(pageDetails: any, fromCommand: boolean) { + async doAutoFillActiveTab(pageDetails: any, fromCommand: boolean) { const tab = await this.getActiveTab(); if (!tab || !tab.url) { return; } - const lastUsedCipher = await this.cipherService.getLastUsedForUrl(tab.url); - if (!lastUsedCipher) { - return; + let cipher: CipherView; + if (fromCommand) { + cipher = await this.cipherService.getNextCipherForUrl(tab.url); + } else { + cipher = await this.cipherService.getLastUsedForUrl(tab.url); } return await this.doAutoFill({ - cipher: lastUsedCipher, - // tslint:disable-next-line + cipher: cipher, pageDetails: pageDetails, skipTotp: !fromCommand, - skipLastUsed: true, + skipLastUsed: !fromCommand, skipUsernameOnlyFill: !fromCommand, onlyEmptyFields: !fromCommand, onlyVisibleFields: !fromCommand,