copy totp from each implementation of autofill

This commit is contained in:
Kyle Spearrin 2018-04-23 10:02:30 -04:00
parent 271f9df8ae
commit 06e56f0b57
5 changed files with 18 additions and 24 deletions

View File

@ -147,7 +147,7 @@ export default class MainBackground {
this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService);
this.totpService = new TotpService(this.storageService, cryptoFunctionService);
this.autofillService = new AutofillService(this.cipherService, this.tokenService,
this.totpService, this.utilsService, this.platformUtilsService);
this.totpService);
this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService);
this.auditService = new AuditService(cryptoFunctionService);
this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService,

View File

@ -136,11 +136,15 @@ export default class RuntimeBackground {
break;
case 'autofiller':
case 'autofill_cmd':
await this.autofillService.doAutoFillForLastUsedLogin([{
const totpCode = await this.autofillService.doAutoFillForLastUsedLogin([{
frameId: sender.frameId,
tab: msg.tab,
details: msg.details,
}], msg.sender === 'autofill_cmd');
if (totpCode !== null && !this.platformUtilsService.isFirefox()) {
this.platformUtilsService.copyToClipboard(totpCode);
}
break;
case 'contextMenu':
clearTimeout(this.autofillTimeout);
@ -161,12 +165,15 @@ export default class RuntimeBackground {
}
private async autofillPage() {
await this.autofillService.doAutoFill({
const totpCode = await this.autofillService.doAutoFill({
cipher: this.main.loginToAutoFill,
pageDetails: this.pageDetailsToAutoFill,
fromBackground: true,
});
if (totpCode !== null && !this.platformUtilsService.isFirefox()) {
this.platformUtilsService.copyToClipboard(totpCode);
}
// reset
this.main.loginToAutoFill = null;
this.pageDetailsToAutoFill = [];

View File

@ -134,12 +134,11 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
const totpCode = await this.autofillService.doAutoFill({
cipher: cipher,
pageDetails: this.pageDetails,
fromBackground: false,
doc: window.document,
});
this.analytics.eventTrack.next({ action: 'Autofilled' });
if (totpCode != null && this.platformUtilsService.isFirefox()) {
if (totpCode != null) {
this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document });
}

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<void>;
doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise<string>;
}

View File

@ -105,10 +105,8 @@ var IsoProvinces: { [id: string]: string; } = {
/* tslint:enable */
export default class AutofillService implements AutofillServiceInterface {
constructor(public cipherService: CipherService, public tokenService: TokenService,
public totpService: TotpService, public utilsService: UtilsServiceAbstraction,
public platformUtilsService: PlatformUtilsService) {
}
constructor(private cipherService: CipherService, private tokenService: TokenService,
private totpService: TotpService) { }
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
const formData: any[] = [];
@ -180,8 +178,7 @@ export default class AutofillService implements AutofillServiceInterface {
fillScript: fillScript,
}, { frameId: pd.frameId });
if (options.cipher.type !== CipherType.Login || totpPromise ||
(options.fromBackground && this.platformUtilsService.isFirefox()) || options.skipTotp ||
if (options.cipher.type !== CipherType.Login || totpPromise || options.skipTotp ||
!options.cipher.login.totp || !this.tokenService.getPremium()) {
return;
}
@ -190,21 +187,13 @@ export default class AutofillService implements AutofillServiceInterface {
if (enabled) {
return this.totpService.getCode(options.cipher.login.totp);
}
return null;
}).then((code: string) => {
if (code) {
UtilsService.copyToClipboard(code, options.doc);
}
return code;
});
});
if (didAutofill) {
if (totpPromise != null) {
const totpCode = await totpPromise;
return totpCode;
return await totpPromise;
} else {
return null;
}
@ -224,11 +213,10 @@ export default class AutofillService implements AutofillServiceInterface {
return;
}
await this.doAutoFill({
return await this.doAutoFill({
cipher: lastUsedCipher,
// tslint:disable-next-line
pageDetails: pageDetails,
fromBackground: true,
skipTotp: !fromCommand,
skipLastUsed: true,
skipUsernameOnlyFill: !fromCommand,