From 38e40a0471e2f7928b06260d1490d96312cc6a61 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Fri, 23 Feb 2024 12:27:25 -0600 Subject: [PATCH] [PM-5697] Capture all form data from page when selecting "New item" within the inline menu even if popout is already open (#7773) * [PM-5679] Capture all form data from page when selecting "New item" even if popout is already open * [PM-5679] Capture all form data from page when selecting "New item" even if popout is already open * [PM-5697] Fixing floating promise within the handleExtensionMessage method --- .../background/overlay.background.spec.ts | 5 +++++ .../autofill/background/overlay.background.ts | 1 + .../components/vault/add-edit.component.ts | 20 +++++++++++-------- .../vault/components/add-edit.component.ts | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 9cc56709dd..79feeb410a 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -615,6 +615,8 @@ describe("OverlayBackground", () => { }); it("will open the add edit popout window after creating a new cipher", async () => { + jest.spyOn(BrowserApi, "sendMessage"); + sendExtensionRuntimeMessage( { command: "autofillOverlayAddNewVaultItem", @@ -630,6 +632,9 @@ describe("OverlayBackground", () => { await flushPromises(); expect(overlayBackground["stateService"].setAddEditCipherInfo).toHaveBeenCalled(); + expect(BrowserApi.sendMessage).toHaveBeenCalledWith( + "inlineAutofillMenuRefreshAddEditCipher", + ); expect(overlayBackground["openAddEditVaultItemPopout"]).toHaveBeenCalled(); }); }); diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 2bb008e63b..e2d4b72c33 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -670,6 +670,7 @@ class OverlayBackground implements OverlayBackgroundInterface { collectionIds: cipherView.collectionIds, }); + await BrowserApi.sendMessage("inlineAutofillMenuRefreshAddEditCipher"); await this.openAddEditVaultItemPopout(sender.tab, { cipherId: cipherView.id }); } diff --git a/apps/browser/src/vault/popup/components/vault/add-edit.component.ts b/apps/browser/src/vault/popup/components/vault/add-edit.component.ts index 8d0a569852..8e52d44069 100644 --- a/apps/browser/src/vault/popup/components/vault/add-edit.component.ts +++ b/apps/browser/src/vault/popup/components/vault/add-edit.component.ts @@ -43,7 +43,6 @@ export class AddEditComponent extends BaseAddEditComponent { showAttachments = true; openAttachmentsInPopup: boolean; showAutoFillOnPageLoadOptions: boolean; - private singleActionKey: string; private fido2PopoutSessionData$ = fido2PopoutSessionData$(); @@ -123,9 +122,7 @@ export class AddEditComponent extends BaseAddEditComponent { if (params.selectedVault) { this.organizationId = params.selectedVault; } - if (params.singleActionKey) { - this.singleActionKey = params.singleActionKey; - } + await this.load(); if (!this.editMode || this.cloneMode) { @@ -141,6 +138,10 @@ export class AddEditComponent extends BaseAddEditComponent { } this.openAttachmentsInPopup = BrowserPopupUtils.inPopup(window); + + if (this.inAddEditPopoutWindow()) { + BrowserApi.messageListener("add-edit-popout", this.handleExtensionMessage.bind(this)); + } }); if (!this.editMode) { @@ -358,10 +359,7 @@ export class AddEditComponent extends BaseAddEditComponent { } private inAddEditPopoutWindow() { - return BrowserPopupUtils.inSingleActionPopout( - window, - this.singleActionKey || VaultPopoutType.addEditVaultItem, - ); + return BrowserPopupUtils.inSingleActionPopout(window, VaultPopoutType.addEditVaultItem); } async captureTOTPFromTab() { @@ -385,4 +383,10 @@ export class AddEditComponent extends BaseAddEditComponent { ); } } + + private handleExtensionMessage(message: { [key: string]: any; command: string }) { + if (message.command === "inlineAutofillMenuRefreshAddEditCipher") { + this.load().catch((error) => this.logService.error(error)); + } + } } diff --git a/libs/angular/src/vault/components/add-edit.component.ts b/libs/angular/src/vault/components/add-edit.component.ts index 5c0eadc739..1b625d0236 100644 --- a/libs/angular/src/vault/components/add-edit.component.ts +++ b/libs/angular/src/vault/components/add-edit.component.ts @@ -111,7 +111,7 @@ export class AddEditComponent implements OnInit, OnDestroy { protected messagingService: MessagingService, protected eventCollectionService: EventCollectionService, protected policyService: PolicyService, - private logService: LogService, + protected logService: LogService, protected passwordRepromptService: PasswordRepromptService, private organizationService: OrganizationService, protected sendApiService: SendApiService,