From 698e68b5355e2721b1ea2584ac743e55536d0209 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Wed, 22 May 2024 07:32:07 -0500 Subject: [PATCH] [PM-5189] Fixing issues found with focusing elements between iframes, as well as fade in of the inline menu in a simultaneous manner for all visual elements --- .../autofill/background/overlay.background.ts | 36 ++++++++++++++----- .../autofill-overlay-content.service.ts | 1 + .../autofill-overlay-content.service.ts | 5 +++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 719e5603ad5..419f6faa615 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -343,15 +343,33 @@ export class OverlayBackground implements OverlayBackgroundInterface { await this.buildSubFrameOffsets(sender.tab, frameId, sender.url); } - this.updateInlineMenuPositionTimeout = setTimeout(() => { - if (this.isFieldCurrentlyFocused) { - void this.updateInlineMenuPosition({ overlayElement: AutofillOverlayElement.List }, sender); - void this.updateInlineMenuPosition( - { overlayElement: AutofillOverlayElement.Button }, - sender, - ); - } - }, 650); + this.updateInlineMenuPositionTimeout = setTimeout( + () => this.updateInlineMenuPositionAfterSubFrameRebuild(sender), + 650, + ); + } + + private async updateInlineMenuPositionAfterSubFrameRebuild(sender: chrome.runtime.MessageSender) { + if (!this.isFieldCurrentlyFocused) { + return; + } + + void this.updateInlineMenuPosition({ overlayElement: AutofillOverlayElement.Button }, sender); + + const mostRecentlyFocusedFieldHasValue = await BrowserApi.tabSendMessage( + sender.tab, + { command: "checkMostRecentlyFocusedFieldHasValue" }, + { frameId: this.focusedFieldData.frameId }, + ); + if ( + mostRecentlyFocusedFieldHasValue && + (this.checkIsOverlayLoginCiphersPopulated(sender) || + this.userAuthStatus !== AuthenticationStatus.Unlocked) + ) { + return; + } + + void this.updateInlineMenuPosition({ overlayElement: AutofillOverlayElement.List }, sender); } /** diff --git a/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts b/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts index ce5f1a24487..36575a6d73e 100644 --- a/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/abstractions/autofill-overlay-content.service.ts @@ -23,6 +23,7 @@ export type AutofillOverlayContentExtensionMessageHandlers = { updateAutofillInlineMenuVisibility: ({ message }: AutofillExtensionMessageParam) => void; getSubFrameOffsets: ({ message }: AutofillExtensionMessageParam) => Promise; getSubFrameOffsetsFromWindowMessage: ({ message }: AutofillExtensionMessageParam) => void; + checkMostRecentlyFocusedFieldHasValue: () => boolean; }; export interface AutofillOverlayContentService { diff --git a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts index b65dcd3cd1f..00688e4c175 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts @@ -54,6 +54,7 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ getSubFrameOffsets: ({ message }) => this.getSubFrameOffsets(message), getSubFrameOffsetsFromWindowMessage: ({ message }) => this.getSubFrameOffsetsFromWindowMessage(message), + checkMostRecentlyFocusedFieldHasValue: () => this.mostRecentlyFocusedFieldHasValue(), }; /** @@ -859,6 +860,10 @@ export class AutofillOverlayContentService implements AutofillOverlayContentServ ); } + private mostRecentlyFocusedFieldHasValue() { + return Boolean((this.mostRecentlyFocusedField as FillableFormFieldElement)?.value); + } + /** * Sets up global event listeners and the mutation * observer to facilitate required changes to the