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
This commit is contained in:
Josep Marí 2020-08-12 22:05:12 +02:00 committed by GitHub
parent 289177259a
commit fe2557e21c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -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,

View File

@ -3,5 +3,5 @@ import AutofillPageDetails from '../../models/autofillPageDetails';
export abstract class AutofillService {
getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[];
doAutoFill: (options: any) => Promise<string>;
doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise<string>;
doAutoFillActiveTab: (pageDetails: any, fromCommand: boolean) => Promise<string>;
}

View File

@ -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,