1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-24 12:06:15 +01:00

More options for copying TOTP values (#1130)

* Implement ability to copy TOTP values without needing to view the full record"

* Remove changes to popup as they will be addressed separately
This commit is contained in:
Matthew Knox 2020-03-04 02:40:06 +11:00 committed by GitHub
parent 8dea9daeea
commit ceb4f3771d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import MainBackground from './main.background';
import { Analytics } from 'jslib/misc'; import { Analytics } from 'jslib/misc';
import { TotpService } from 'jslib/abstractions';
import { CipherService } from 'jslib/abstractions/cipher.service'; import { CipherService } from 'jslib/abstractions/cipher.service';
import { EventService } from 'jslib/abstractions/event.service'; import { EventService } from 'jslib/abstractions/event.service';
import { LockService } from 'jslib/abstractions/lock.service'; import { LockService } from 'jslib/abstractions/lock.service';
@ -17,7 +18,7 @@ export default class ContextMenusBackground {
constructor(private main: MainBackground, private cipherService: CipherService, constructor(private main: MainBackground, private cipherService: CipherService,
private passwordGenerationService: PasswordGenerationService, private analytics: Analytics, private passwordGenerationService: PasswordGenerationService, private analytics: Analytics,
private platformUtilsService: PlatformUtilsService, private lockService: LockService, private platformUtilsService: PlatformUtilsService, private lockService: LockService,
private eventService: EventService) { private eventService: EventService, private totpService: TotpService) {
this.contextMenus = chrome.contextMenus; this.contextMenus = chrome.contextMenus;
} }
@ -29,8 +30,10 @@ export default class ContextMenusBackground {
this.contextMenus.onClicked.addListener(async (info: any, tab: any) => { this.contextMenus.onClicked.addListener(async (info: any, tab: any) => {
if (info.menuItemId === 'generate-password') { if (info.menuItemId === 'generate-password') {
await this.generatePasswordToClipboard(); await this.generatePasswordToClipboard();
} else if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' || } else if (info.parentMenuItemId === 'autofill' ||
info.parentMenuItemId === 'copy-password') { info.parentMenuItemId === 'copy-username' ||
info.parentMenuItemId === 'copy-password' ||
info.parentMenuItemId === 'copy-totp') {
await this.cipherAction(info); await this.cipherAction(info);
} }
}); });
@ -86,6 +89,13 @@ export default class ContextMenusBackground {
}); });
this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window }); this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window });
this.eventService.collect(EventType.Cipher_ClientCopiedPassword, cipher.id); this.eventService.collect(EventType.Cipher_ClientCopiedPassword, cipher.id);
} else if (info.parentMenuItemId === 'copy-totp') {
this.analytics.ga('send', {
hitType: 'event',
eventAction: 'Copied Totp From Context Menu',
});
const totpValue = await this.totpService.getCode(cipher.login.totp);
this.platformUtilsService.copyToClipboard(totpValue, { window: window });
} }
} }

View File

@ -213,7 +213,7 @@ export default class MainBackground {
this.tabsBackground = new TabsBackground(this); this.tabsBackground = new TabsBackground(this);
this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService, this.contextMenusBackground = new ContextMenusBackground(this, this.cipherService,
this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService, this.passwordGenerationService, this.analytics, this.platformUtilsService, this.lockService,
this.eventService); this.eventService, this.totpService);
this.idleBackground = new IdleBackground(this.lockService, this.storageService, this.notificationsService); this.idleBackground = new IdleBackground(this.lockService, this.storageService, this.notificationsService);
this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService, this.webRequestBackground = new WebRequestBackground(this.platformUtilsService, this.cipherService,
this.lockService); this.lockService);
@ -443,6 +443,14 @@ export default class MainBackground {
title: this.i18nService.t('copyPassword'), title: this.i18nService.t('copyPassword'),
}); });
await this.contextMenusCreate({
type: 'normal',
id: 'copy-totp',
parentId: 'root',
contexts: ['all'],
title: this.i18nService.t('copyVerificationCode'),
});
await this.contextMenusCreate({ await this.contextMenusCreate({
type: 'separator', type: 'separator',
parentId: 'root', parentId: 'root',
@ -575,6 +583,16 @@ export default class MainBackground {
title: title, title: title,
}); });
} }
if (cipher == null || (cipher.login.totp && cipher.login.totp !== '')) {
await this.contextMenusCreate({
type: 'normal',
id: 'copy-totp_' + idSuffix,
parentId: 'copy-totp',
contexts: ['all'],
title: title,
});
}
} }
private cleanupNotificationQueue() { private cleanupNotificationQueue() {