1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-30 22:41:33 +01:00

[PM-5189] Fixing issues with how we handle repositioning the inline menu

This commit is contained in:
Cesar Gonzalez 2024-04-07 18:15:09 -05:00
parent 3e13cbfb5c
commit 6a1a684435
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
4 changed files with 23 additions and 21 deletions

View File

@ -112,6 +112,7 @@ type OverlayBackgroundExtensionMessageHandlers = {
updateIsFieldCurrentlyFilling: ({ message }: BackgroundMessageParam) => void;
checkIsInlineMenuButtonVisible: ({ sender }: BackgroundSenderParam) => void;
checkIsInlineMenuListVisible: ({ sender }: BackgroundSenderParam) => void;
checkIsInlineMenuCiphersPopulated: ({ sender }: BackgroundSenderParam) => void;
updateSubFrameData: ({ message, sender }: BackgroundOnMessageHandlerParams) => void;
rebuildSubFrameOffsets: ({ sender }: BackgroundSenderParam) => void;
};

View File

@ -85,6 +85,8 @@ class OverlayBackground implements OverlayBackgroundInterface {
(this.isCurrentlyFilling = message.isFieldCurrentlyFilling),
checkIsInlineMenuButtonVisible: ({ sender }) => this.checkIsInlineMenuButtonVisible(sender),
checkIsInlineMenuListVisible: ({ sender }) => this.checkIsInlineMenuListVisible(sender),
checkIsInlineMenuCiphersPopulated: ({ sender }) =>
this.checkIsInlineMenuCiphersPopulated(sender),
updateSubFrameData: ({ message, sender }) => this.updateSubFrameData(message, sender),
rebuildSubFrameOffsets: ({ sender }) => this.rebuildSubFrameOffsets(sender),
};
@ -137,6 +139,10 @@ class OverlayBackground implements OverlayBackgroundInterface {
);
}
private checkIsInlineMenuCiphersPopulated(sender: chrome.runtime.MessageSender) {
return sender.tab.id === this.focusedFieldData.tabId && this.overlayLoginCiphers.size > 0;
}
updateSubFrameData(message: any, sender: chrome.runtime.MessageSender) {
const subFrameOffsetsForTab = this.subFrameOffsetsForTab[sender.tab.id];
if (subFrameOffsetsForTab) {
@ -199,9 +205,6 @@ class OverlayBackground implements OverlayBackgroundInterface {
const ciphers = await this.getOverlayCipherData();
this.overlayListPort?.postMessage({ command: "updateOverlayListCiphers", ciphers });
await BrowserApi.tabSendMessageData(currentTab, "updateIsOverlayCiphersPopulated", {
isOverlayCiphersPopulated: Boolean(ciphers.length),
});
}
/**

View File

@ -20,15 +20,11 @@ export type AutofillOverlayContentExtensionMessageHandlers = {
bgVaultItemRepromptPopoutOpened: () => void;
redirectOverlayFocusOut: ({ message }: AutofillExtensionMessageParam) => void;
updateAutofillOverlayVisibility: ({ message }: AutofillExtensionMessageParam) => void;
updateIsOverlayCiphersPopulated: ({ message }: AutofillExtensionMessageParam) => void;
getSubFrameOffsets: ({ message }: AutofillExtensionMessageParam) => Promise<SubFrameOffsetData>;
getSubFrameOffsetsFromWindowMessage: ({ message }: AutofillExtensionMessageParam) => void;
};
export interface AutofillOverlayContentService {
// isFieldCurrentlyFocused: boolean;
// isCurrentlyFilling: boolean;
isOverlayCiphersPopulated: boolean;
pageDetailsUpdateRequired: boolean;
autofillOverlayVisibility: number;
extensionMessageHandlers: any;
@ -37,11 +33,6 @@ export interface AutofillOverlayContentService {
autofillFieldElement: ElementWithOpId<FormFieldElement>,
autofillFieldData: AutofillField,
): Promise<void>;
openAutofillOverlay(options: OpenAutofillOverlayOptions): void;
// removeAutofillOverlay(): void;
// removeAutofillOverlayButton(): void;
// removeAutofillOverlayList(): void;
addNewVaultItem(): void;
focusMostRecentOverlayField(): void;
blurMostRecentOverlayField(isRemovingOverlay?: boolean): void;
destroy(): void;

View File

@ -23,7 +23,6 @@ import {
import { AutoFillConstants } from "./autofill-constants";
class AutofillOverlayContentService implements AutofillOverlayContentServiceInterface {
isOverlayCiphersPopulated = false;
pageDetailsUpdateRequired = false;
autofillOverlayVisibility: number;
private readonly findTabs = tabbable;
@ -47,7 +46,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
bgVaultItemRepromptPopoutOpened: () => this.blurMostRecentOverlayField(true),
redirectOverlayFocusOut: ({ message }) => this.redirectOverlayFocusOut(message),
updateAutofillOverlayVisibility: ({ message }) => this.updateAutofillOverlayVisibility(message),
updateIsOverlayCiphersPopulated: ({ message }) => this.updateIsOverlayCiphersPopulated(message),
getSubFrameOffsets: ({ message }) => this.getSubFrameOffsets(message),
getSubFrameOffsetsFromWindowMessage: ({ message }) =>
this.getSubFrameOffsetsFromWindowMessage(message),
@ -365,14 +363,17 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
*
* @param formFieldElement - The form field element that triggered the input event.
*/
private triggerFormFieldInput(formFieldElement: ElementWithOpId<FormFieldElement>) {
private async triggerFormFieldInput(formFieldElement: ElementWithOpId<FormFieldElement>) {
if (!elementIsFillableFormField(formFieldElement)) {
return;
}
this.storeModifiedFormElement(formFieldElement);
if (formFieldElement.value && (this.isOverlayCiphersPopulated || !this.isUserAuthed())) {
if (
formFieldElement.value &&
((await this.isOverlayCiphersPopulated()) || !this.isUserAuthed())
) {
void this.sendExtensionMessage("closeAutofillOverlay", {
overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true,
@ -475,7 +476,10 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
});
}
if (!formElementHasValue || (!this.isOverlayCiphersPopulated && this.isUserAuthed())) {
if (
!formElementHasValue ||
(!(await this.isOverlayCiphersPopulated()) && this.isUserAuthed())
) {
void this.sendExtensionMessage("openAutofillOverlay");
return;
}
@ -764,9 +768,12 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField);
this.updateOverlayElementsPosition();
setTimeout(() => {
setTimeout(async () => {
this.toggleOverlayHidden(false);
if ((this.mostRecentlyFocusedField as HTMLInputElement).value) {
if (
(this.mostRecentlyFocusedField as HTMLInputElement).value &&
((await this.isOverlayCiphersPopulated()) || !this.isUserAuthed())
) {
void this.sendExtensionMessage("closeAutofillOverlay", {
overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true,
@ -946,8 +953,8 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
this.autofillOverlayVisibility = data.autofillOverlayVisibility;
}
private updateIsOverlayCiphersPopulated({ data }: AutofillExtensionMessage) {
this.isOverlayCiphersPopulated = Boolean(data?.isOverlayCiphersPopulated);
private async isOverlayCiphersPopulated() {
return (await this.sendExtensionMessage("checkIsInlineMenuCiphersPopulated")) === true;
}
/**