From 86acca3bec219021e937b9c7bc7b59bddc22a046 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Wed, 31 Jul 2024 12:52:04 -0500 Subject: [PATCH] [PM-10079] Add keyboard shortcut to autofill identity and credit cards (#10254) * [BEEEP] Autofill Identity and Card Ciphers From Keyboard Shortcut * [PM-10079] Add keyboard shortcut to autofill identity and credit card ciphers * [PM-10079] Fixing jest tests * [PM-10079] Added an enum for the autofill commands, and adjusted how we filter out cipher types before sorting them by last used when calling for ID and card ciphers * [PM-10079] Updating copywriting for the autofill settings revolving around keyboard shortcuts * [PM-10079] Setting a method within CipherService as private --- apps/browser/src/_locales/en/messages.json | 21 +++++++--- .../notification.background.spec.ts | 3 +- .../background/notification.background.ts | 15 ++++++-- .../browser/context-menu-clicked-handler.ts | 3 +- .../popup/settings/autofill-v1.component.ts | 4 +- .../popup/settings/autofill.component.html | 2 +- .../popup/settings/autofill.component.ts | 4 +- .../services/autofill.service.spec.ts | 38 ++++++++----------- .../src/autofill/services/autofill.service.ts | 32 +++++++++++++--- .../src/background/commands.background.ts | 36 +++++++++++++++--- .../src/background/runtime.background.ts | 14 +++---- apps/browser/src/manifest.json | 8 +++- apps/browser/src/manifest.v3.json | 8 +++- .../browser-platform-utils.service.ts | 7 +++- libs/common/src/autofill/constants/index.ts | 14 +++++++ .../src/vault/abstractions/cipher.service.ts | 2 + .../src/vault/services/cipher.service.ts | 37 ++++++++++++++++++ 17 files changed, 187 insertions(+), 61 deletions(-) diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 432479aa80..582aa254c7 100644 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -1343,8 +1343,14 @@ "commandOpenSidebar": { "message": "Open vault in sidebar" }, - "commandAutofillDesc": { - "message": "Auto-fill the last used login for the current website" + "commandAutofillLoginDesc": { + "message": "Autofill the last used login for the current website" + }, + "commandAutofillCardDesc": { + "message": "Autofill the last used card for the current website" + }, + "commandAutofillIdentityDesc": { + "message": "Autofill the last used identity for the current website" }, "commandGeneratePasswordDesc": { "message": "Generate and copy a new random password to the clipboard" @@ -2774,14 +2780,17 @@ "autofillKeyboardShortcutUpdateLabel": { "message": "Change shortcut" }, + "autofillKeyboardManagerShortcutsLabel": { + "message": "Manage shortcuts" + }, "autofillShortcut": { "message": "Autofill keyboard shortcut" }, - "autofillShortcutNotSet": { - "message": "The autofill shortcut is not set. Change this in the browser's settings." + "autofillLoginShortcutNotSet": { + "message": "The autofill login shortcut is not set. Change this in the browser's settings." }, - "autofillShortcutText": { - "message": "The autofill shortcut is: $COMMAND$. Change this in the browser's settings.", + "autofillLoginShortcutText": { + "message": "The autofill login shortcut is $COMMAND$. Manage all shortcuts in the browser's settings.", "placeholders": { "command": { "content": "$1", diff --git a/apps/browser/src/autofill/background/notification.background.spec.ts b/apps/browser/src/autofill/background/notification.background.spec.ts index 9c2e63c1aa..111871d57d 100644 --- a/apps/browser/src/autofill/background/notification.background.spec.ts +++ b/apps/browser/src/autofill/background/notification.background.spec.ts @@ -4,6 +4,7 @@ import { BehaviorSubject, firstValueFrom } from "rxjs"; import { PolicyService } from "@bitwarden/common/admin-console/services/policy/policy.service"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; import { AuthService } from "@bitwarden/common/auth/services/auth.service"; +import { ExtensionCommand } from "@bitwarden/common/autofill/constants"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { UserNotificationSettingsService } from "@bitwarden/common/autofill/services/user-notification-settings.service"; import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; @@ -151,7 +152,7 @@ describe("NotificationBackground", () => { const message: NotificationBackgroundExtensionMessage = { command: "unlockCompleted", data: { - commandToRetry: { message: { command: "autofill_login" } }, + commandToRetry: { message: { command: ExtensionCommand.AutofillLogin } }, } as LockedVaultPendingNotificationsData, }; jest.spyOn(BrowserApi, "tabSendMessageData").mockImplementation(); diff --git a/apps/browser/src/autofill/background/notification.background.ts b/apps/browser/src/autofill/background/notification.background.ts index 9e989b73e6..a047a3533a 100644 --- a/apps/browser/src/autofill/background/notification.background.ts +++ b/apps/browser/src/autofill/background/notification.background.ts @@ -4,7 +4,11 @@ import { PolicyService } from "@bitwarden/common/admin-console/abstractions/poli import { PolicyType } from "@bitwarden/common/admin-console/enums"; import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service"; import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status"; -import { NOTIFICATION_BAR_LIFESPAN_MS } from "@bitwarden/common/autofill/constants"; +import { + ExtensionCommand, + ExtensionCommandType, + NOTIFICATION_BAR_LIFESPAN_MS, +} from "@bitwarden/common/autofill/constants"; import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service"; import { UserNotificationSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/user-notification-settings.service"; import { NeverDomains } from "@bitwarden/common/models/domain/domain-service"; @@ -45,6 +49,11 @@ export default class NotificationBackground { private openUnlockPopout = openUnlockPopout; private openAddEditVaultItemPopout = openAddEditVaultItemPopout; private notificationQueue: NotificationQueueMessageItem[] = []; + private allowedRetryCommands: Set = new Set([ + ExtensionCommand.AutofillLogin, + ExtensionCommand.AutofillCard, + ExtensionCommand.AutofillIdentity, + ]); private readonly extensionMessageHandlers: NotificationBackgroundExtensionMessageHandlers = { unlockCompleted: ({ message, sender }) => this.handleUnlockCompleted(message, sender), bgGetFolderData: () => this.getFolderData(), @@ -689,8 +698,8 @@ export default class NotificationBackground { sender: chrome.runtime.MessageSender, ): Promise { const messageData = message.data as LockedVaultPendingNotificationsData; - const retryCommand = messageData.commandToRetry.message.command; - if (retryCommand === "autofill_login") { + const retryCommand = messageData.commandToRetry.message.command as ExtensionCommandType; + if (this.allowedRetryCommands.has(retryCommand)) { await BrowserApi.tabSendMessageData(sender.tab, "closeNotificationBar"); } diff --git a/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts b/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts index cb1c59dca5..c1567b46cd 100644 --- a/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts +++ b/apps/browser/src/autofill/browser/context-menu-clicked-handler.ts @@ -16,6 +16,7 @@ import { CREATE_CARD_ID, CREATE_IDENTITY_ID, CREATE_LOGIN_ID, + ExtensionCommand, GENERATE_PASSWORD_ID, NOOP_COMMAND_SUFFIX, } from "@bitwarden/common/autofill/constants"; @@ -79,7 +80,7 @@ export class ContextMenuClickedHandler { if ((await this.authService.getAuthStatus()) < AuthenticationStatus.Unlocked) { const retryMessage: LockedVaultPendingNotificationsData = { commandToRetry: { - message: { command: NOOP_COMMAND_SUFFIX, contextMenuOnClickData: info }, + message: { command: ExtensionCommand.NoopCommand, contextMenuOnClickData: info }, sender: { tab: tab }, }, target: "contextmenus.background", diff --git a/apps/browser/src/autofill/popup/settings/autofill-v1.component.ts b/apps/browser/src/autofill/popup/settings/autofill-v1.component.ts index 261c6e459b..20657693fd 100644 --- a/apps/browser/src/autofill/popup/settings/autofill-v1.component.ts +++ b/apps/browser/src/autofill/popup/settings/autofill-v1.component.ts @@ -159,9 +159,9 @@ export class AutofillV1Component implements OnInit { private async setAutofillKeyboardHelperText(command: string) { if (command) { - this.autofillKeyboardHelperText = this.i18nService.t("autofillShortcutText", command); + this.autofillKeyboardHelperText = this.i18nService.t("autofillLoginShortcutText", command); } else { - this.autofillKeyboardHelperText = this.i18nService.t("autofillShortcutNotSet"); + this.autofillKeyboardHelperText = this.i18nService.t("autofillLoginShortcutNotSet"); } } diff --git a/apps/browser/src/autofill/popup/settings/autofill.component.html b/apps/browser/src/autofill/popup/settings/autofill.component.html index 3b419cf8f0..0933bc5421 100644 --- a/apps/browser/src/autofill/popup/settings/autofill.component.html +++ b/apps/browser/src/autofill/popup/settings/autofill.component.html @@ -107,7 +107,7 @@